github-actions[bot] wrote: <!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning: <details> <summary> You can test this locally with the following command: </summary> ``````````bash git-clang-format --diff 22219873987587d8b5d793ab5dea982a0887ac7c c140ef583e6bdff8c7ac829be1ede32460663564 --extensions c,cpp,h -- clang/lib/AST/ASTContext.cpp clang/lib/AST/ExprConstShared.h clang/lib/AST/ExprConstant.cpp clang/lib/AST/ByteCode/Boolean.h clang/lib/AST/ByteCode/ByteCodeEmitter.cpp clang/lib/AST/ByteCode/ByteCodeEmitter.h clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/Compiler.h clang/lib/AST/ByteCode/Context.cpp clang/lib/AST/ByteCode/Context.h clang/lib/AST/ByteCode/Descriptor.cpp clang/lib/AST/ByteCode/Descriptor.h clang/lib/AST/ByteCode/Disasm.cpp clang/lib/AST/ByteCode/DynamicAllocator.cpp clang/lib/AST/ByteCode/DynamicAllocator.h clang/lib/AST/ByteCode/EvalEmitter.cpp clang/lib/AST/ByteCode/EvalEmitter.h clang/lib/AST/ByteCode/EvaluationResult.cpp clang/lib/AST/ByteCode/EvaluationResult.h clang/lib/AST/ByteCode/Floating.cpp clang/lib/AST/ByteCode/Floating.h clang/lib/AST/ByteCode/Frame.cpp clang/lib/AST/ByteCode/Frame.h clang/lib/AST/ByteCode/Function.cpp clang/lib/AST/ByteCode/Function.h clang/lib/AST/ByteCode/FunctionPointer.h clang/lib/AST/ByteCode/Integral.h clang/lib/AST/ByteCode/IntegralAP.h clang/lib/AST/ByteCode/Interp.cpp clang/lib/AST/ByteCode/Interp.h clang/lib/AST/ByteCode/InterpBlock.cpp clang/lib/AST/ByteCode/InterpBlock.h clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ByteCode/InterpFrame.cpp clang/lib/AST/ByteCode/InterpFrame.h clang/lib/AST/ByteCode/InterpShared.cpp clang/lib/AST/ByteCode/InterpShared.h clang/lib/AST/ByteCode/InterpStack.cpp clang/lib/AST/ByteCode/InterpStack.h clang/lib/AST/ByteCode/InterpState.cpp clang/lib/AST/ByteCode/InterpState.h clang/lib/AST/ByteCode/MemberPointer.cpp clang/lib/AST/ByteCode/MemberPointer.h clang/lib/AST/ByteCode/Opcode.h clang/lib/AST/ByteCode/Pointer.cpp clang/lib/AST/ByteCode/Pointer.h clang/lib/AST/ByteCode/PrimType.cpp clang/lib/AST/ByteCode/PrimType.h clang/lib/AST/ByteCode/Primitives.h clang/lib/AST/ByteCode/Program.cpp clang/lib/AST/ByteCode/Program.h clang/lib/AST/ByteCode/Record.cpp clang/lib/AST/ByteCode/Record.h clang/lib/AST/ByteCode/Source.cpp clang/lib/AST/ByteCode/Source.h clang/lib/AST/ByteCode/State.cpp clang/lib/AST/ByteCode/State.h clang/test/AST/ByteCode/arrays.cpp clang/test/AST/ByteCode/atomic.c clang/test/AST/ByteCode/atomic.cpp clang/test/AST/ByteCode/bitfields.cpp clang/test/AST/ByteCode/builtin-align-cxx.cpp clang/test/AST/ByteCode/builtin-constant-p.cpp clang/test/AST/ByteCode/builtin-functions.cpp clang/test/AST/ByteCode/builtins.cpp clang/test/AST/ByteCode/c.c clang/test/AST/ByteCode/c23.c clang/test/AST/ByteCode/codegen.cpp clang/test/AST/ByteCode/comma.cpp clang/test/AST/ByteCode/complex.c clang/test/AST/ByteCode/complex.cpp clang/test/AST/ByteCode/cond.cpp clang/test/AST/ByteCode/const-eval.c clang/test/AST/ByteCode/const-fpfeatures.cpp clang/test/AST/ByteCode/const-temporaries.cpp clang/test/AST/ByteCode/constexpr-frame-describe.cpp clang/test/AST/ByteCode/constexpr-nqueens.cpp clang/test/AST/ByteCode/constexpr-subobj-initialization.cpp clang/test/AST/ByteCode/crash-GH49103-2.cpp clang/test/AST/ByteCode/cxx03.cpp clang/test/AST/ByteCode/cxx11.cpp clang/test/AST/ByteCode/cxx17.cpp clang/test/AST/ByteCode/cxx20.cpp clang/test/AST/ByteCode/cxx23.cpp clang/test/AST/ByteCode/cxx26.cpp clang/test/AST/ByteCode/cxx2a.cpp clang/test/AST/ByteCode/cxx98.cpp clang/test/AST/ByteCode/depth-limit.cpp clang/test/AST/ByteCode/depth-limit2.cpp clang/test/AST/ByteCode/enums-targets.cpp clang/test/AST/ByteCode/enums.cpp clang/test/AST/ByteCode/eval-order.cpp clang/test/AST/ByteCode/floats.cpp clang/test/AST/ByteCode/functions.cpp clang/test/AST/ByteCode/if.cpp clang/test/AST/ByteCode/intap.cpp clang/test/AST/ByteCode/invalid.cpp clang/test/AST/ByteCode/lambda.cpp clang/test/AST/ByteCode/lifetimes.cpp clang/test/AST/ByteCode/literals.cpp clang/test/AST/ByteCode/loops.cpp clang/test/AST/ByteCode/memberpointers.cpp clang/test/AST/ByteCode/ms.cpp clang/test/AST/ByteCode/mutable.cpp clang/test/AST/ByteCode/new-delete.cpp clang/test/AST/ByteCode/nullable.cpp clang/test/AST/ByteCode/pointer-addition.c clang/test/AST/ByteCode/records.cpp clang/test/AST/ByteCode/references.cpp clang/test/AST/ByteCode/shifts.cpp clang/test/AST/ByteCode/spaceship.cpp clang/test/AST/ByteCode/switch.cpp clang/test/AST/ByteCode/sycl.cpp clang/test/AST/ByteCode/unions.cpp clang/test/AST/ByteCode/vectors.cpp clang/test/AST/ByteCode/weak.cpp clang/unittests/AST/ByteCode/Descriptor.cpp clang/unittests/AST/ByteCode/toAPValue.cpp `````````` </details> <details> <summary> View the diff from clang-format here. </summary> ``````````diff diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e92bd4ed80..f35a025fc8 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -11,8 +11,8 @@ //===----------------------------------------------------------------------===// #include "clang/AST/ASTContext.h" -#include "CXXABI.h" #include "ByteCode/Context.h" +#include "CXXABI.h" #include "clang/AST/APValue.h" #include "clang/AST/ASTConcept.h" #include "clang/AST/ASTMutationListener.h" diff --git a/clang/lib/AST/ByteCode/Boolean.h b/clang/lib/AST/ByteCode/Boolean.h index 23f7286036..0a2e0fe332 100644 --- a/clang/lib/AST/ByteCode/Boolean.h +++ b/clang/lib/AST/ByteCode/Boolean.h @@ -9,25 +9,25 @@ #ifndef LLVM_CLANG_AST_INTERP_BOOLEAN_H #define LLVM_CLANG_AST_INTERP_BOOLEAN_H -#include <cstddef> -#include <cstdint> #include "Integral.h" #include "clang/AST/APValue.h" #include "clang/AST/ComparisonCategories.h" #include "llvm/ADT/APSInt.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" +#include <cstddef> +#include <cstdint> namespace clang { namespace interp { /// Wrapper around boolean types. class Boolean final { - private: +private: /// Underlying boolean. bool V; - public: +public: /// Zero-initializes a boolean. Boolean() : V(false) {} explicit Boolean(bool V) : V(V) {} @@ -104,8 +104,7 @@ class Boolean final { static Boolean zero() { return from(false); } - template <typename T> - static Boolean from(T Value, unsigned NumBits) { + template <typename T> static Boolean from(T Value, unsigned NumBits) { return Boolean(Value); } @@ -153,7 +152,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Boolean &B) { return OS; } -} // namespace interp -} // namespace clang +} // namespace interp +} // namespace clang #endif diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp index a01fa15dc0..1f6bdaff50 100644 --- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp +++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp @@ -206,8 +206,7 @@ void ByteCodeEmitter::emitLabel(LabelTy Label) { const size_t Target = Code.size(); LabelOffsets.insert({Label, Target}); - if (auto It = LabelRelocs.find(Label); - It != LabelRelocs.end()) { + if (auto It = LabelRelocs.find(Label); It != LabelRelocs.end()) { for (unsigned Reloc : It->second) { using namespace llvm::support; @@ -228,8 +227,7 @@ int32_t ByteCodeEmitter::getOffset(LabelTy Label) { assert(aligned(Position)); // If target is known, compute jump offset. - if (auto It = LabelOffsets.find(Label); - It != LabelOffsets.end()) + if (auto It = LabelOffsets.find(Label); It != LabelOffsets.end()) return It->second - Position; // Otherwise, record relocation and return dummy offset. @@ -308,7 +306,8 @@ void emit(Program &P, std::vector<std::byte> &Code, const IntegralAP<true> &Val, } template <typename... Tys> -bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... Args, const SourceInfo &SI) { +bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args, + const SourceInfo &SI) { bool Success = true; // The opcode is followed by arguments. The source info is diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.h b/clang/lib/AST/ByteCode/ByteCodeEmitter.h index a19a25c2f9..59e12defd8 100644 --- a/clang/lib/AST/ByteCode/ByteCodeEmitter.h +++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.h @@ -92,7 +92,7 @@ private: /// Emits an opcode. template <typename... Tys> - bool emitOp(Opcode Op, const Tys &... Args, const SourceInfo &L); + bool emitOp(Opcode Op, const Tys &...Args, const SourceInfo &L); protected: #define GET_LINK_PROTO diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 5e1f507ca2..c3ecaa40b8 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3722,7 +3722,8 @@ bool Compiler<Emitter>::visitDeclAndReturn(const VarDecl *VD, } template <class Emitter> -VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, bool Toplevel) { +VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, + bool Toplevel) { // We don't know what to do with these, so just return false. if (VD->getType().isNull()) return false; @@ -5124,7 +5125,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { if (!this->visit(SubExpr)) return false; return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E); - case UO_Plus: // +x + case UO_Plus: // +x if (!T) return this->emitError(E); diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index 6f1adeb898..41899c3bd6 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -229,7 +229,7 @@ public: /// Returns the allocated size, including metadata. unsigned getAllocSize() const { return AllocSize; } /// returns the size of an element when the structure is viewed as an array. - unsigned getElemSize() const { return ElemSize; } + unsigned getElemSize() const { return ElemSize; } /// Returns the size of the metadata. unsigned getMetadataSize() const { return MDSize; } diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 08536536ac..e36d86c814 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -76,9 +76,7 @@ EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD, return std::move(this->EvalResult); } -void EvalEmitter::emitLabel(LabelTy Label) { - CurrentLabel = Label; -} +void EvalEmitter::emitLabel(LabelTy Label) { CurrentLabel = Label; } EvalEmitter::LabelTy EvalEmitter::getLabel() { return NextLabel++; } diff --git a/clang/lib/AST/ByteCode/Integral.h b/clang/lib/AST/ByteCode/Integral.h index aafdd02676..e06ec16692 100644 --- a/clang/lib/AST/ByteCode/Integral.h +++ b/clang/lib/AST/ByteCode/Integral.h @@ -13,8 +13,8 @@ #ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_H #define LLVM_CLANG_AST_INTERP_INTEGRAL_H -#include "clang/AST/ComparisonCategories.h" #include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" #include "llvm/ADT/APSInt.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" @@ -33,14 +33,30 @@ template <bool Signed> class IntegralAP; // Helper structure to select the representation. template <unsigned Bits, bool Signed> struct Repr; -template <> struct Repr<8, false> { using Type = uint8_t; }; -template <> struct Repr<16, false> { using Type = uint16_t; }; -template <> struct Repr<32, false> { using Type = uint32_t; }; -template <> struct Repr<64, false> { using Type = uint64_t; }; -template <> struct Repr<8, true> { using Type = int8_t; }; -template <> struct Repr<16, true> { using Type = int16_t; }; -template <> struct Repr<32, true> { using Type = int32_t; }; -template <> struct Repr<64, true> { using Type = int64_t; }; +template <> struct Repr<8, false> { + using Type = uint8_t; +}; +template <> struct Repr<16, false> { + using Type = uint16_t; +}; +template <> struct Repr<32, false> { + using Type = uint32_t; +}; +template <> struct Repr<64, false> { + using Type = uint64_t; +}; +template <> struct Repr<8, true> { + using Type = int8_t; +}; +template <> struct Repr<16, true> { + using Type = int16_t; +}; +template <> struct Repr<32, true> { + using Type = int32_t; +}; +template <> struct Repr<64, true> { + using Type = int64_t; +}; /// Wrapper around numeric types. /// @@ -159,12 +175,8 @@ public: void print(llvm::raw_ostream &OS) const { OS << V; } - static Integral min(unsigned NumBits) { - return Integral(Min); - } - static Integral max(unsigned NumBits) { - return Integral(Max); - } + static Integral min(unsigned NumBits) { return Integral(Min); } + static Integral max(unsigned NumBits) { return Integral(Max); } template <typename ValT> static Integral from(ValT Value) { if constexpr (std::is_integral<ValT>::value) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index c2d73f32f0..785c7852e4 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -1226,7 +1226,7 @@ template <PrimType Name, class T = typename PrimConv<Name>::T> bool GetField(InterpState &S, CodePtr OpPC, uint32_t I) { const Pointer &Obj = S.Stk.peek<Pointer>(); if (!CheckNull(S, OpPC, Obj, CSK_Field)) - return false; + return false; if (!CheckRange(S, OpPC, Obj, CSK_Field)) return false; const Pointer &Field = Obj.atField(I); @@ -1542,7 +1542,7 @@ inline bool GetPtrActiveField(InterpState &S, CodePtr OpPC, uint32_t Off) { } inline bool GetPtrActiveThisField(InterpState &S, CodePtr OpPC, uint32_t Off) { - if (S.checkingPotentialConstantExpression()) + if (S.checkingPotentialConstantExpression()) return false; const Pointer &This = S.Current->getThis(); if (!CheckThis(S, OpPC, This)) @@ -2053,7 +2053,7 @@ template <PrimType TIn, PrimType TOut> bool Cast(InterpState &S, CodePtr OpPC) { /// 1) Pops a Floating from the stack. /// 2) Pushes a new floating on the stack that uses the given semantics. inline bool CastFP(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem, - llvm::RoundingMode RM) { + llvm::RoundingMode RM) { Floating F = S.Stk.pop<Floating>(); Floating Result = F.toSemantics(Sem, RM); S.Stk.push<Floating>(Result); @@ -2467,7 +2467,8 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index) { } template <PrimType Name, class T = typename PrimConv<Name>::T> -inline bool CopyArray(InterpState &S, CodePtr OpPC, uint32_t SrcIndex, uint32_t DestIndex, uint32_t Size) { +inline bool CopyArray(InterpState &S, CodePtr OpPC, uint32_t SrcIndex, + uint32_t DestIndex, uint32_t Size) { const auto &SrcPtr = S.Stk.pop<Pointer>(); const auto &DestPtr = S.Stk.peek<Pointer>(); diff --git a/clang/lib/AST/ByteCode/InterpBlock.h b/clang/lib/AST/ByteCode/InterpBlock.h index 20cf8cb9d3..a5cd58e3a6 100644 --- a/clang/lib/AST/ByteCode/InterpBlock.h +++ b/clang/lib/AST/ByteCode/InterpBlock.h @@ -14,10 +14,10 @@ #define LLVM_CLANG_AST_INTERP_BLOCK_H #include "Descriptor.h" +#include "clang/AST/ComparisonCategories.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" -#include "clang/AST/ComparisonCategories.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/Support/raw_ostream.h" diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp b/clang/lib/AST/ByteCode/InterpFrame.cpp index 4530f28d69..8b55b61cbb 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.cpp +++ b/clang/lib/AST/ByteCode/InterpFrame.cpp @@ -137,7 +137,7 @@ void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, if (!Ty->isReferenceType()) OS << "&"; llvm::SmallVector<Pointer, 2> Levels; - for (Pointer F = P; !F.isRoot(); ) { + for (Pointer F = P; !F.isRoot();) { Levels.push_back(F); F = F.isArrayElement() ? F.getArray().expand() : F.getBase(); } diff --git a/clang/lib/AST/ByteCode/InterpFrame.h b/clang/lib/AST/ByteCode/InterpFrame.h index 91b9b41b5d..1e0d2b1d44 100644 --- a/clang/lib/AST/ByteCode/InterpFrame.h +++ b/clang/lib/AST/ByteCode/InterpFrame.h @@ -91,7 +91,7 @@ public: /// Mutates a local copy of a parameter. template <typename T> void setParam(unsigned Offset, const T &Value) { - getParamPointer(Offset).deref<T>() = Value; + getParamPointer(Offset).deref<T>() = Value; } /// Returns a pointer to an argument - lazily creates a block. diff --git a/clang/lib/AST/ByteCode/InterpStack.cpp b/clang/lib/AST/ByteCode/InterpStack.cpp index c7024740d3..b8cdaeee72 100644 --- a/clang/lib/AST/ByteCode/InterpStack.cpp +++ b/clang/lib/AST/ByteCode/InterpStack.cpp @@ -18,9 +18,7 @@ using namespace clang; using namespace clang::interp; -InterpStack::~InterpStack() { - clear(); -} +InterpStack::~InterpStack() { clear(); } void InterpStack::clear() { if (Chunk && Chunk->Next) diff --git a/clang/lib/AST/ByteCode/InterpStack.h b/clang/lib/AST/ByteCode/InterpStack.h index 4966e2870d..153d17f0d7 100644 --- a/clang/lib/AST/ByteCode/InterpStack.h +++ b/clang/lib/AST/ByteCode/InterpStack.h @@ -32,7 +32,7 @@ public: ~InterpStack(); /// Constructs a value in place on the top of the stack. - template <typename T, typename... Tys> void push(Tys &&... Args) { + template <typename T, typename... Tys> void push(Tys &&...Args) { new (grow(aligned_size<T>())) T(std::forward<Tys>(Args)...); #ifndef NDEBUG ItemTypes.push_back(toPrimType<T>()); @@ -153,8 +153,7 @@ private: template <typename T> static constexpr PrimType toPrimType() { if constexpr (std::is_same_v<T, Pointer>) return PT_Ptr; - else if constexpr (std::is_same_v<T, bool> || - std::is_same_v<T, Boolean>) + else if constexpr (std::is_same_v<T, bool> || std::is_same_v<T, Boolean>) return PT_Bool; else if constexpr (std::is_same_v<T, int8_t> || std::is_same_v<T, Integral<8, true>>) diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index 01ccb88ec0..8db081c0ec 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -173,7 +173,7 @@ public: /// Subtract the given offset from the current Base and Offset /// of the pointer. - [[nodiscard]] Pointer atFieldSub(unsigned Off) const { + [[nodiscard]] Pointer atFieldSub(unsigned Off) const { assert(Offset >= Off); unsigned O = Offset - Off; return Pointer(asBlockPointer().Pointee, O, O); diff --git a/clang/lib/AST/ByteCode/PrimType.h b/clang/lib/AST/ByteCode/PrimType.h index 20fb5e8177..bb2f59d86e 100644 --- a/clang/lib/AST/ByteCode/PrimType.h +++ b/clang/lib/AST/ByteCode/PrimType.h @@ -73,23 +73,45 @@ constexpr bool isIntegralType(PrimType T) { return T <= PT_Bool; } /// Mapping from primitive types to their representation. template <PrimType T> struct PrimConv; -template <> struct PrimConv<PT_Sint8> { using T = Integral<8, true>; }; -template <> struct PrimConv<PT_Uint8> { using T = Integral<8, false>; }; -template <> struct PrimConv<PT_Sint16> { using T = Integral<16, true>; }; -template <> struct PrimConv<PT_Uint16> { using T = Integral<16, false>; }; -template <> struct PrimConv<PT_Sint32> { using T = Integral<32, true>; }; -template <> struct PrimConv<PT_Uint32> { using T = Integral<32, false>; }; -template <> struct PrimConv<PT_Sint64> { using T = Integral<64, true>; }; -template <> struct PrimConv<PT_Uint64> { using T = Integral<64, false>; }; +template <> struct PrimConv<PT_Sint8> { + using T = Integral<8, true>; +}; +template <> struct PrimConv<PT_Uint8> { + using T = Integral<8, false>; +}; +template <> struct PrimConv<PT_Sint16> { + using T = Integral<16, true>; +}; +template <> struct PrimConv<PT_Uint16> { + using T = Integral<16, false>; +}; +template <> struct PrimConv<PT_Sint32> { + using T = Integral<32, true>; +}; +template <> struct PrimConv<PT_Uint32> { + using T = Integral<32, false>; +}; +template <> struct PrimConv<PT_Sint64> { + using T = Integral<64, true>; +}; +template <> struct PrimConv<PT_Uint64> { + using T = Integral<64, false>; +}; template <> struct PrimConv<PT_IntAP> { using T = IntegralAP<false>; }; template <> struct PrimConv<PT_IntAPS> { using T = IntegralAP<true>; }; -template <> struct PrimConv<PT_Float> { using T = Floating; }; -template <> struct PrimConv<PT_Bool> { using T = Boolean; }; -template <> struct PrimConv<PT_Ptr> { using T = Pointer; }; +template <> struct PrimConv<PT_Float> { + using T = Floating; +}; +template <> struct PrimConv<PT_Bool> { + using T = Boolean; +}; +template <> struct PrimConv<PT_Ptr> { + using T = Pointer; +}; template <> struct PrimConv<PT_FnPtr> { using T = FunctionPointer; }; @@ -117,8 +139,12 @@ static inline bool aligned(const void *P) { /// Helper macro to simplify type switches. /// The macro implicitly exposes a type T in the scope of the inner block. -#define TYPE_SWITCH_CASE(Name, B) \ - case Name: { using T = PrimConv<Name>::T; B; break; } +#define TYPE_SWITCH_CASE(Name, B) \ + case Name: { \ + using T = PrimConv<Name>::T; \ + B; \ + break; \ + } #define TYPE_SWITCH(Expr, B) \ do { \ switch (Expr) { \ @@ -181,7 +207,10 @@ static inline bool aligned(const void *P) { do { \ switch (Expr) { \ TYPE_SWITCH_CASE(PT_Ptr, B) \ - default: { D; break; } \ + default: { \ + D; \ + break; \ + } \ } \ } while (0) #endif diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index 9109956dc6..25b99115dd 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -76,26 +76,26 @@ unsigned Program::createGlobalString(const StringLiteral *S) { Pointer Field = Ptr.atIndex(I).narrow(); const uint32_t CodePoint = I == N ? 0 : S->getCodeUnit(I); switch (CharType) { - case PT_Sint8: { - using T = PrimConv<PT_Sint8>::T; - Field.deref<T>() = T::from(CodePoint, BitWidth); - Field.initialize(); - break; - } - case PT_Uint16: { - using T = PrimConv<PT_Uint16>::T; - Field.deref<T>() = T::from(CodePoint, BitWidth); - Field.initialize(); - break; - } - case PT_Uint32: { - using T = PrimConv<PT_Uint32>::T; - Field.deref<T>() = T::from(CodePoint, BitWidth); - Field.initialize(); - break; - } - default: - llvm_unreachable("unsupported character type"); + case PT_Sint8: { + using T = PrimConv<PT_Sint8>::T; + Field.deref<T>() = T::from(CodePoint, BitWidth); + Field.initialize(); + break; + } + case PT_Uint16: { + using T = PrimConv<PT_Uint16>::T; + Field.deref<T>() = T::from(CodePoint, BitWidth); + Field.initialize(); + break; + } + case PT_Uint32: { + using T = PrimConv<PT_Uint32>::T; + Field.deref<T>() = T::from(CodePoint, BitWidth); + Field.initialize(); + break; + } + default: + llvm_unreachable("unsupported character type"); } } return I; @@ -394,8 +394,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary); if (!ElemDesc) return nullptr; - unsigned ElemSize = - ElemDesc->getAllocSize() + sizeof(InlineDescriptor); + unsigned ElemSize = ElemDesc->getAllocSize() + sizeof(InlineDescriptor); if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) return {}; return allocateDescriptor(D, ElemDesc, MDSize, NumElems, IsConst, diff --git a/clang/lib/AST/ByteCode/Program.h b/clang/lib/AST/ByteCode/Program.h index 1cabc52121..7f69d9790f 100644 --- a/clang/lib/AST/ByteCode/Program.h +++ b/clang/lib/AST/ByteCode/Program.h @@ -13,8 +13,6 @@ #ifndef LLVM_CLANG_AST_INTERP_PROGRAM_H #define LLVM_CLANG_AST_INTERP_PROGRAM_H -#include <map> -#include <vector> #include "Function.h" #include "Pointer.h" #include "PrimType.h" @@ -24,6 +22,8 @@ #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Allocator.h" +#include <map> +#include <vector> namespace clang { class RecordDecl; @@ -94,15 +94,14 @@ public: /// Creates a new function from a code range. template <typename... Ts> - Function *createFunction(const FunctionDecl *Def, Ts &&... Args) { + Function *createFunction(const FunctionDecl *Def, Ts &&...Args) { Def = Def->getCanonicalDecl(); auto *Func = new Function(*this, Def, std::forward<Ts>(Args)...); Funcs.insert({Def, std::unique_ptr<Function>(Func)}); return Func; } /// Creates an anonymous function. - template <typename... Ts> - Function *createFunction(Ts &&... Args) { + template <typename... Ts> Function *createFunction(Ts &&...Args) { auto *Func = new Function(*this, std::forward<Ts>(Args)...); AnonFuncs.emplace_back(Func); return Func; @@ -213,8 +212,7 @@ private: llvm::DenseMap<const ValueDecl *, unsigned> DummyVariables; /// Creates a new descriptor. - template <typename... Ts> - Descriptor *allocateDescriptor(Ts &&... Args) { + template <typename... Ts> Descriptor *allocateDescriptor(Ts &&...Args) { return new (Allocator) Descriptor(std::forward<Ts>(Args)...); } @@ -232,9 +230,7 @@ private: } /// Ends a global declaration. - void endDeclaration() { - CurrentDeclaration = NoDeclaration; - } + void endDeclaration() { CurrentDeclaration = NoDeclaration; } public: /// Dumps the disassembled bytecode to \c llvm::errs(). diff --git a/clang/lib/AST/ByteCode/Record.cpp b/clang/lib/AST/ByteCode/Record.cpp index e7b741f2d4..ec1b55da34 100644 --- a/clang/lib/AST/ByteCode/Record.cpp +++ b/clang/lib/AST/ByteCode/Record.cpp @@ -18,7 +18,7 @@ Record::Record(const RecordDecl *Decl, BaseList &&SrcBases, : Decl(Decl), Bases(std::move(SrcBases)), Fields(std::move(SrcFields)), BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()) { for (Base &V : SrcVirtualBases) - VirtualBases.push_back({ V.Decl, V.Offset + BaseSize, V.Desc, V.R }); + VirtualBases.push_back({V.Decl, V.Offset + BaseSize, V.Desc, V.R}); for (Base &B : Bases) BaseMap[B.Decl] = &B; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index d2ab8e3431..7bfc63ffd8 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -32,10 +32,10 @@ // //===----------------------------------------------------------------------===// -#include "ExprConstShared.h" #include "ByteCode/Context.h" #include "ByteCode/Frame.h" #include "ByteCode/State.h" +#include "ExprConstShared.h" #include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDiagnostic.h" diff --git a/clang/unittests/AST/ByteCode/Descriptor.cpp b/clang/unittests/AST/ByteCode/Descriptor.cpp index 09320d8004..9e09c7f15a 100644 --- a/clang/unittests/AST/ByteCode/Descriptor.cpp +++ b/clang/unittests/AST/ByteCode/Descriptor.cpp @@ -15,17 +15,17 @@ using namespace clang::ast_matchers; /// Inspect generated Descriptors as well as the pointers we create. /// TEST(Descriptor, Primitives) { - constexpr char Code[] = - "struct A { bool a; bool b; };\n" - "struct S {\n" - " float f;\n" - " char s[4];\n" - " A a[3];\n" - " short l[3][3];\n" - " int EmptyA[0];\n" - "};\n" - "constexpr S d = {0.0, \"foo\", {{true, false}, {false, true}, {false, false}},\n" - " {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {}};\n"; + constexpr char Code[] = "struct A { bool a; bool b; };\n" + "struct S {\n" + " float f;\n" + " char s[4];\n" + " A a[3];\n" + " short l[3][3];\n" + " int EmptyA[0];\n" + "};\n" + "constexpr S d = {0.0, \"foo\", {{true, false}, " + "{false, true}, {false, false}},\n" + " {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {}};\n"; auto AST = tooling::buildASTFromCodeWithArgs( Code, {"-fexperimental-new-constant-interpreter"}); `````````` </details> https://github.com/llvm/llvm-project/pull/104552 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits