diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp @@ -131,12 +131,12 @@ // https://sonarcloud.io/projects?languages=c%2Ccpp&size=5 we can estimate: // value ~20 would result in no allocs for 98% of functions, ~12 for 96%, ~10 // for 91%, ~8 for 88%, ~6 for 84%, ~4 for 77%, ~2 for 64%, and ~1 for 37%. - static_assert(sizeof(Detail) <= 8, + static_assert(sizeof(Detail) <= 16, "Since we use SmallVector to minimize the amount of " "allocations, we also need to consider the price we pay for " "that in terms of stack usage. " "Thus, it is good to minimize the size of the Detail struct."); - SmallVector Details; // 25 elements is 200 bytes. + SmallVector Details; // 25 elements is 400 bytes. // Yes, 25 is a magic number. This is the seemingly-sane default for the // upper limit for function cognitive complexity. Thus it would make sense // to avoid allocations for any function that does not violate the limit. diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -335,6 +335,12 @@ "LLVM_LINK_LLVM_DYLIB=OFF") endif() +set(CLANG_64_BIT_SOURCE_LOCATIONS OFF CACHE BOOL + "SourceLocation underlying type is 64-bit") +if (CLANG_64_BIT_SOURCE_LOCATIONS) + add_definitions(-DCLANG_64_BIT_SOURCE_LOCATIONS) +endif() + # The libdir suffix must exactly match whatever LLVM's configuration used. set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}") diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -1719,12 +1719,13 @@ // Not a bitfield but this saves space. // Note that ObjCContainerDeclBitfields is full. - SourceLocation AtStart; + SourceLocation::LowBits AtStart_lo; }; - /// Number of non-inherited bits in ObjCContainerDeclBitfields. - /// Note that here we rely on the fact that SourceLocation is 32 bits - /// wide. We check this with the static_assert in the ctor of DeclContext. + /// Number of non-inherited bits in ObjCContainerDeclBitfields. Note that + /// here we rely on the fact that we only keep 32 bits of the SourceLocation + /// in that bitfield class. We check this with the static_assert in the ctor + /// of DeclContext. enum { NumObjCContainerDeclBits = 64 - NumDeclContextBits }; /// Stores the bits used by LinkageSpecDecl. diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -950,6 +950,8 @@ // The first points to the '@' token, and the second to the 'end' token. SourceRange AtEnd; + SourceLocation::OptionalHighBits AtStart_hi; + void anchor() override; public: @@ -1088,10 +1090,13 @@ virtual void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const {} - SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; } + SourceLocation getAtStartLoc() const { + return SourceLocation::getFromLowHigh(ObjCContainerDeclBits.AtStart_lo, + AtStart_hi); + } void setAtStartLoc(SourceLocation Loc) { - ObjCContainerDeclBits.AtStart = Loc; + Loc.writeLowHigh(ObjCContainerDeclBits.AtStart_lo, AtStart_hi); } // Marks the end of the container. diff --git a/clang/include/clang/AST/DeclarationName.h b/clang/include/clang/AST/DeclarationName.h --- a/clang/include/clang/AST/DeclarationName.h +++ b/clang/include/clang/AST/DeclarationName.h @@ -660,13 +660,13 @@ // The location (if any) of the operator keyword is stored elsewhere. struct CXXOpName { - unsigned BeginOpNameLoc; - unsigned EndOpNameLoc; + SourceLocation::UIntType BeginOpNameLoc; + SourceLocation::UIntType EndOpNameLoc; }; // The location (if any) of the operator keyword is stored elsewhere. struct CXXLitOpName { - unsigned OpNameLoc; + SourceLocation::UIntType OpNameLoc; }; // struct {} CXXUsingDirective; diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1126,12 +1126,14 @@ friend class ASTStmtReader; Expr *SourceExpr; + SourceLocation::OptionalHighBits Loc_hi; + public: OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, ExprObjectKind OK = OK_Ordinary, Expr *SourceExpr = nullptr) : Expr(OpaqueValueExprClass, T, VK, OK), SourceExpr(SourceExpr) { setIsUnique(false); - OpaqueValueExprBits.Loc = Loc; + setLocation(Loc); setDependence(computeDependence(this)); } @@ -1144,7 +1146,12 @@ : Expr(OpaqueValueExprClass, Empty) {} /// Retrieve the location of this expression. - SourceLocation getLocation() const { return OpaqueValueExprBits.Loc; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(OpaqueValueExprBits.Loc_lo, Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(OpaqueValueExprBits.Loc_lo, Loc_hi); + } SourceLocation getBeginLoc() const LLVM_READONLY { return SourceExpr ? SourceExpr->getBeginLoc() : getLocation(); @@ -1222,6 +1229,9 @@ /// The declaration that we are referencing. ValueDecl *D; + /// The location of the declaration name itself. + SourceLocation::OptionalHighBits Loc_hi; + /// Provides source/type location info for the declaration name /// embedded in D. DeclarationNameLoc DNLoc; @@ -1290,8 +1300,12 @@ return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc); } - SourceLocation getLocation() const { return DeclRefExprBits.Loc; } - void setLocation(SourceLocation L) { DeclRefExprBits.Loc = L; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(DeclRefExprBits.Loc_lo, Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(DeclRefExprBits.Loc_lo, Loc_hi); + } SourceLocation getBeginLoc() const LLVM_READONLY; SourceLocation getEndLoc() const LLVM_READONLY; @@ -1952,6 +1966,9 @@ friend class ASTStmtReader; friend TrailingObjects; + /// The location of this PredefinedExpr. + SourceLocation::OptionalHighBits Loc_hi; + // PredefinedExpr is optionally followed by a single trailing // "Stmt *" for the predefined identifier. It is present if and only if // hasFunctionName() is true and is always a "StringLiteral *". @@ -1998,8 +2015,12 @@ return static_cast(PredefinedExprBits.Kind); } - SourceLocation getLocation() const { return PredefinedExprBits.Loc; } - void setLocation(SourceLocation L) { PredefinedExprBits.Loc = L; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(PredefinedExprBits.Loc_lo, Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(PredefinedExprBits.Loc_lo, Loc_hi); + } StringLiteral *getFunctionName() { return hasFunctionName() @@ -2155,6 +2176,8 @@ private llvm::TrailingObjects { Stmt *Val; + SourceLocation::OptionalHighBits Loc_hi; + size_t numTrailingObjects(OverloadToken) const { return UnaryOperatorBits.HasFPFeatures ? 1 : 0; } @@ -2201,8 +2224,12 @@ void setSubExpr(Expr *E) { Val = E; } /// getOperatorLoc - Return the location of the operator. - SourceLocation getOperatorLoc() const { return UnaryOperatorBits.Loc; } - void setOperatorLoc(SourceLocation L) { UnaryOperatorBits.Loc = L; } + SourceLocation getOperatorLoc() const { + return SourceLocation::getFromLowHigh(UnaryOperatorBits.Loc_lo, Loc_hi); + } + void setOperatorLoc(SourceLocation L) { + L.writeLowHigh(UnaryOperatorBits.Loc_lo, Loc_hi); + } /// Returns true if the unary operator can cause an overflow. For instance, /// signed int i = INT_MAX; i++; @@ -2635,6 +2662,8 @@ enum { LHS, RHS, END_EXPR }; Stmt *SubExprs[END_EXPR]; + SourceLocation::OptionalHighBits RBracketLoc_hi; + bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); } public: @@ -2643,7 +2672,7 @@ : Expr(ArraySubscriptExprClass, t, VK, OK) { SubExprs[LHS] = lhs; SubExprs[RHS] = rhs; - ArrayOrMatrixSubscriptExprBits.RBracketLoc = rbracketloc; + setRBracketLoc(rbracketloc); setDependence(computeDependence(this)); } @@ -2680,10 +2709,12 @@ SourceLocation getEndLoc() const { return getRBracketLoc(); } SourceLocation getRBracketLoc() const { - return ArrayOrMatrixSubscriptExprBits.RBracketLoc; + return SourceLocation::getFromLowHigh( + ArrayOrMatrixSubscriptExprBits.RBracketLoc_lo, RBracketLoc_hi); } void setRBracketLoc(SourceLocation L) { - ArrayOrMatrixSubscriptExprBits.RBracketLoc = L; + L.writeLowHigh(ArrayOrMatrixSubscriptExprBits.RBracketLoc_lo, + RBracketLoc_hi); } SourceLocation getExprLoc() const LLVM_READONLY { @@ -2712,6 +2743,7 @@ class MatrixSubscriptExpr : public Expr { enum { BASE, ROW_IDX, COLUMN_IDX, END_EXPR }; Stmt *SubExprs[END_EXPR]; + SourceLocation::OptionalHighBits RBracketLoc_hi; public: MatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, QualType T, @@ -2721,7 +2753,7 @@ SubExprs[BASE] = Base; SubExprs[ROW_IDX] = RowIdx; SubExprs[COLUMN_IDX] = ColumnIdx; - ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc; + setRBracketLoc(RBracketLoc); setDependence(computeDependence(this)); } @@ -2762,10 +2794,12 @@ } SourceLocation getRBracketLoc() const { - return ArrayOrMatrixSubscriptExprBits.RBracketLoc; + return SourceLocation::getFromLowHigh( + ArrayOrMatrixSubscriptExprBits.RBracketLoc_lo, RBracketLoc_hi); } void setRBracketLoc(SourceLocation L) { - ArrayOrMatrixSubscriptExprBits.RBracketLoc = L; + L.writeLowHigh(ArrayOrMatrixSubscriptExprBits.RBracketLoc_lo, + RBracketLoc_hi); } static bool classof(const Stmt *T) { @@ -3165,6 +3199,9 @@ /// declaration name embedded in MemberDecl. DeclarationNameLoc MemberDNLoc; + /// This is the location of the -> or . in the expression. + SourceLocation::OptionalHighBits OperatorLoc_hi; + /// MemberLoc - This is the location of the member name. SourceLocation MemberLoc; @@ -3325,7 +3362,13 @@ MemberLoc, MemberDNLoc); } - SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; } + SourceLocation getOperatorLoc() const { + return SourceLocation::getFromLowHigh(MemberExprBits.OperatorLoc_lo, + OperatorLoc_hi); + } + void setOperatorLoc(SourceLocation L) { + L.writeLowHigh(MemberExprBits.OperatorLoc_lo, OperatorLoc_hi); + } bool isArrow() const { return MemberExprBits.IsArrow; } void setArrow(bool A) { MemberExprBits.IsArrow = A; } @@ -3787,6 +3830,7 @@ class BinaryOperator : public Expr { enum { LHS, RHS, END_EXPR }; Stmt *SubExprs[END_EXPR]; + SourceLocation::OptionalHighBits OpLoc_hi; public: typedef BinaryOperatorKind Opcode; @@ -3825,8 +3869,13 @@ ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures); SourceLocation getExprLoc() const { return getOperatorLoc(); } - SourceLocation getOperatorLoc() const { return BinaryOperatorBits.OpLoc; } - void setOperatorLoc(SourceLocation L) { BinaryOperatorBits.OpLoc = L; } + SourceLocation getOperatorLoc() const { + return SourceLocation::getFromLowHigh(BinaryOperatorBits.OpLoc_lo, + OpLoc_hi); + } + void setOperatorLoc(SourceLocation L) { + L.writeLowHigh(BinaryOperatorBits.OpLoc_lo, OpLoc_hi); + } Opcode getOpcode() const { return static_cast(BinaryOperatorBits.Opc); @@ -5623,6 +5672,9 @@ AssocExprStartIndex = 1 }; + /// The location of the "_Generic". + SourceLocation::OptionalHighBits GenericLoc_hi; + /// The location of the "default" and of the right parenthesis. SourceLocation DefaultLoc, RParenLoc; @@ -5852,7 +5904,11 @@ } SourceLocation getGenericLoc() const { - return GenericSelectionExprBits.GenericLoc; + return SourceLocation::getFromLowHigh( + GenericSelectionExprBits.GenericLoc_lo, GenericLoc_hi); + } + void setGenericLoc(SourceLocation L) { + L.writeLowHigh(GenericSelectionExprBits.GenericLoc_lo, GenericLoc_hi); } SourceLocation getDefaultLoc() const { return DefaultLoc; } SourceLocation getRParenLoc() const { return RParenLoc; } diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -719,11 +719,13 @@ /// A boolean literal, per ([C++ lex.bool] Boolean literals). class CXXBoolLiteralExpr : public Expr { + SourceLocation::OptionalHighBits Loc_hi; + public: CXXBoolLiteralExpr(bool Val, QualType Ty, SourceLocation Loc) : Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary) { CXXBoolLiteralExprBits.Value = Val; - CXXBoolLiteralExprBits.Loc = Loc; + setLocation(Loc); setDependence(ExprDependence::None); } @@ -736,8 +738,13 @@ SourceLocation getBeginLoc() const { return getLocation(); } SourceLocation getEndLoc() const { return getLocation(); } - SourceLocation getLocation() const { return CXXBoolLiteralExprBits.Loc; } - void setLocation(SourceLocation L) { CXXBoolLiteralExprBits.Loc = L; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(CXXBoolLiteralExprBits.Loc_lo, + Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(CXXBoolLiteralExprBits.Loc_lo, Loc_hi); + } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXBoolLiteralExprClass; @@ -757,10 +764,12 @@ /// /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr. class CXXNullPtrLiteralExpr : public Expr { + SourceLocation::OptionalHighBits Loc_hi; + public: CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc) : Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary) { - CXXNullPtrLiteralExprBits.Loc = Loc; + setLocation(Loc); setDependence(ExprDependence::None); } @@ -770,8 +779,13 @@ SourceLocation getBeginLoc() const { return getLocation(); } SourceLocation getEndLoc() const { return getLocation(); } - SourceLocation getLocation() const { return CXXNullPtrLiteralExprBits.Loc; } - void setLocation(SourceLocation L) { CXXNullPtrLiteralExprBits.Loc = L; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(CXXNullPtrLiteralExprBits.Loc_lo, + Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(CXXNullPtrLiteralExprBits.Loc_lo, Loc_hi); + } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXNullPtrLiteralExprClass; @@ -1140,18 +1154,24 @@ /// }; /// \endcode class CXXThisExpr : public Expr { + SourceLocation::OptionalHighBits Loc_hi; + public: CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit) : Expr(CXXThisExprClass, Ty, VK_RValue, OK_Ordinary) { CXXThisExprBits.IsImplicit = IsImplicit; - CXXThisExprBits.Loc = L; + setLocation(L); setDependence(computeDependence(this)); } CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} - SourceLocation getLocation() const { return CXXThisExprBits.Loc; } - void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(CXXThisExprBits.Loc_lo, Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(CXXThisExprBits.Loc_lo, Loc_hi); + } SourceLocation getBeginLoc() const { return getLocation(); } SourceLocation getEndLoc() const { return getLocation(); } @@ -1181,6 +1201,9 @@ class CXXThrowExpr : public Expr { friend class ASTStmtReader; + /// The location of the "throw". + SourceLocation::OptionalHighBits ThrowLoc_hi; + /// The optional expression in the throw statement. Stmt *Operand; @@ -1192,7 +1215,7 @@ CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc, bool IsThrownVariableInScope) : Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary), Operand(Operand) { - CXXThrowExprBits.ThrowLoc = Loc; + setThrowLoc(Loc); CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope; setDependence(computeDependence(this)); } @@ -1201,7 +1224,13 @@ const Expr *getSubExpr() const { return cast_or_null(Operand); } Expr *getSubExpr() { return cast_or_null(Operand); } - SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; } + SourceLocation getThrowLoc() const { + return SourceLocation::getFromLowHigh(CXXThrowExprBits.ThrowLoc_lo, + ThrowLoc_hi); + } + void setThrowLoc(SourceLocation L) { + L.writeLowHigh(CXXThrowExprBits.ThrowLoc_lo, ThrowLoc_hi); + } /// Determines whether the variable thrown by this expression (if any!) /// is within the innermost try block. @@ -1241,6 +1270,9 @@ class CXXDefaultArgExpr final : public Expr { friend class ASTStmtReader; + /// The location where the default argument expression was used. + SourceLocation::OptionalHighBits Loc_hi; + /// The parameter whose default is being used. ParmVarDecl *Param; @@ -1256,7 +1288,7 @@ Param->getDefaultArg()->getValueKind(), Param->getDefaultArg()->getObjectKind()), Param(Param), UsedContext(UsedContext) { - CXXDefaultArgExprBits.Loc = Loc; + setUsedLocation(Loc); setDependence(ExprDependence::None); } @@ -1284,7 +1316,12 @@ DeclContext *getUsedContext() { return UsedContext; } /// Retrieve the location where this default argument was actually used. - SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; } + SourceLocation getUsedLocation() const { + return SourceLocation::getFromLowHigh(CXXDefaultArgExprBits.Loc_lo, Loc_hi); + } + void setUsedLocation(SourceLocation L) { + L.writeLowHigh(CXXDefaultArgExprBits.Loc_lo, Loc_hi); + } /// Default argument expressions have no representation in the /// source, so they have an empty source range. @@ -1325,6 +1362,9 @@ /// The context where the default initializer expression was used. DeclContext *UsedContext; + /// The location where the default initializer expression was used. + SourceLocation::OptionalHighBits Loc_hi; + CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, QualType Ty, DeclContext *UsedContext); @@ -1357,10 +1397,16 @@ /// Retrieve the location where this default initializer expression was /// actually used. - SourceLocation getUsedLocation() const { return getBeginLoc(); } + SourceLocation getUsedLocation() const { + return SourceLocation::getFromLowHigh(CXXDefaultInitExprBits.Loc_lo, + Loc_hi); + } + void setUsedLocation(SourceLocation L) { + L.writeLowHigh(CXXDefaultInitExprBits.Loc_lo, Loc_hi); + } - SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; } - SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; } + SourceLocation getBeginLoc() const { return getUsedLocation(); } + SourceLocation getEndLoc() const { return getUsedLocation(); } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXDefaultInitExprClass; @@ -1472,6 +1518,8 @@ /// A pointer to the constructor which will be ultimately called. CXXConstructorDecl *Constructor; + SourceLocation::OptionalHighBits Loc_hi; + SourceRange ParenOrBraceRange; /// The number of arguments. @@ -1531,8 +1579,12 @@ /// Get the constructor that this expression will (ultimately) call. CXXConstructorDecl *getConstructor() const { return Constructor; } - SourceLocation getLocation() const { return CXXConstructExprBits.Loc; } - void setLocation(SourceLocation Loc) { CXXConstructExprBits.Loc = Loc; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(CXXConstructExprBits.Loc_lo, Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(CXXConstructExprBits.Loc_lo, Loc_hi); + } /// Whether this construction is elidable. bool isElidable() const { return CXXConstructExprBits.Elidable; } @@ -2093,6 +2145,8 @@ class CXXScalarValueInitExpr : public Expr { friend class ASTStmtReader; + SourceLocation::OptionalHighBits RParenLoc_hi; + TypeSourceInfo *TypeInfo; public: @@ -2102,7 +2156,7 @@ SourceLocation RParenLoc) : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary), TypeInfo(TypeInfo) { - CXXScalarValueInitExprBits.RParenLoc = RParenLoc; + setRParenLoc(RParenLoc); setDependence(computeDependence(this)); } @@ -2114,7 +2168,11 @@ } SourceLocation getRParenLoc() const { - return CXXScalarValueInitExprBits.RParenLoc; + return SourceLocation::getFromLowHigh( + CXXScalarValueInitExprBits.RParenLoc_lo, RParenLoc_hi); + } + void setRParenLoc(SourceLocation L) { + L.writeLowHigh(CXXScalarValueInitExprBits.RParenLoc_lo, RParenLoc_hi); } SourceLocation getBeginLoc() const LLVM_READONLY; @@ -2398,6 +2456,9 @@ class CXXDeleteExpr : public Expr { friend class ASTStmtReader; + /// Location of the expression. + SourceLocation::OptionalHighBits Loc_hi; + /// Points to the operator delete overload that is used. Could be a member. FunctionDecl *OperatorDelete = nullptr; @@ -2414,7 +2475,7 @@ CXXDeleteExprBits.ArrayForm = ArrayForm; CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten; CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize; - CXXDeleteExprBits.Loc = Loc; + setLocation(Loc); setDependence(computeDependence(this)); } @@ -2445,7 +2506,14 @@ /// be a pointer, return an invalid type. QualType getDestroyedType() const; - SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; } + SourceLocation getLocation() const { + return SourceLocation::getFromLowHigh(CXXDeleteExprBits.Loc_lo, Loc_hi); + } + void setLocation(SourceLocation L) { + L.writeLowHigh(CXXDeleteExprBits.Loc_lo, Loc_hi); + } + + SourceLocation getBeginLoc() const { return getLocation(); } SourceLocation getEndLoc() const LLVM_READONLY { return Argument->getEndLoc(); } @@ -3575,6 +3643,9 @@ /// FIXME: could also be a template-id DeclarationNameInfo MemberNameInfo; + /// The location of the '->' or '.' operator. + SourceLocation::OptionalHighBits OperatorLoc_hi; + // CXXDependentScopeMemberExpr is followed by several trailing objects, // some of which optional. They are in order: // @@ -3658,7 +3729,12 @@ /// Retrieve the location of the '->' or '.' operator. SourceLocation getOperatorLoc() const { - return CXXDependentScopeMemberExprBits.OperatorLoc; + return SourceLocation::getFromLowHigh( + CXXDependentScopeMemberExprBits.OperatorLoc_lo, OperatorLoc_hi); + } + void setOperatorLoc(SourceLocation L) { + L.writeLowHigh(CXXDependentScopeMemberExprBits.OperatorLoc_lo, + OperatorLoc_hi); } /// Retrieve the nested-name-specifier that qualifies the member name. @@ -4246,6 +4322,9 @@ friend class ASTReader; friend class ASTStmtReader; + /// The location of the non-type template parameter reference. + SourceLocation::OptionalHighBits NameLoc_hi; + /// The replaced parameter and a flag indicating if it was a reference /// parameter. For class NTTPs, we can't determine that based on the value /// category alone. @@ -4264,12 +4343,16 @@ Expr *Replacement) : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary), ParamAndRef(Param, RefParam), Replacement(Replacement) { - SubstNonTypeTemplateParmExprBits.NameLoc = Loc; + setNameLoc(Loc); setDependence(computeDependence(this)); } SourceLocation getNameLoc() const { - return SubstNonTypeTemplateParmExprBits.NameLoc; + return SourceLocation::getFromLowHigh( + SubstNonTypeTemplateParmExprBits.NameLoc_lo, NameLoc_hi); + } + void setNameLoc(SourceLocation L) { + L.writeLowHigh(SubstNonTypeTemplateParmExprBits.NameLoc_lo, NameLoc_hi); } SourceLocation getBeginLoc() const { return getNameLoc(); } SourceLocation getEndLoc() const { return getNameLoc(); } diff --git a/clang/include/clang/AST/ExprConcepts.h b/clang/include/clang/AST/ExprConcepts.h --- a/clang/include/clang/AST/ExprConcepts.h +++ b/clang/include/clang/AST/ExprConcepts.h @@ -481,6 +481,7 @@ unsigned NumLocalParameters; unsigned NumRequirements; RequiresExprBodyDecl *Body; + SourceLocation::OptionalHighBits RequiresKWLoc_hi; SourceLocation RBraceLoc; unsigned numTrailingObjects(OverloadToken) const { @@ -528,7 +529,11 @@ } SourceLocation getRequiresKWLoc() const { - return RequiresExprBits.RequiresKWLoc; + return SourceLocation::getFromLowHigh(RequiresExprBits.RequiresKWLoc_lo, + RequiresKWLoc_hi); + } + void setRequiresKWLoc(SourceLocation L) { + L.writeLowHigh(RequiresExprBits.RequiresKWLoc_lo, RequiresKWLoc_hi); } SourceLocation getRBraceLoc() const { return RBraceLoc; } @@ -538,7 +543,7 @@ } SourceLocation getBeginLoc() const LLVM_READONLY { - return RequiresExprBits.RequiresKWLoc; + return getRequiresKWLoc(); } SourceLocation getEndLoc() const LLVM_READONLY { return RBraceLoc; diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -118,7 +118,7 @@ unsigned HasLeadingEmptyMacro : 1; /// The location of the semi-colon. - SourceLocation SemiLoc; + SourceLocation::LowBits SemiLoc_lo; }; class CompoundStmtBitfields { @@ -130,7 +130,7 @@ unsigned NumStmts : 32 - NumStmtBits; /// The location of the opening "{". - SourceLocation LBraceLoc; + SourceLocation::LowBits LBraceLoc_lo; }; class LabelStmtBitfields { @@ -138,7 +138,7 @@ unsigned : NumStmtBits; - SourceLocation IdentLoc; + SourceLocation::LowBits IdentLoc_lo; }; class AttributedStmtBitfields { @@ -151,7 +151,7 @@ unsigned NumAttrs : 32 - NumStmtBits; /// The location of the attribute. - SourceLocation AttrLoc; + SourceLocation::LowBits AttrLoc_lo; }; class IfStmtBitfields { @@ -173,7 +173,7 @@ unsigned HasInit : 1; /// The location of the "if". - SourceLocation IfLoc; + SourceLocation::LowBits IfLoc_lo; }; class SwitchStmtBitfields { @@ -193,7 +193,7 @@ unsigned AllEnumCasesCovered : 1; /// The location of the "switch". - SourceLocation SwitchLoc; + SourceLocation::LowBits SwitchLoc_lo; }; class WhileStmtBitfields { @@ -206,7 +206,7 @@ unsigned HasVar : 1; /// The location of the "while". - SourceLocation WhileLoc; + SourceLocation::LowBits WhileLoc_lo; }; class DoStmtBitfields { @@ -215,7 +215,7 @@ unsigned : NumStmtBits; /// The location of the "do". - SourceLocation DoLoc; + SourceLocation::LowBits DoLoc_lo; }; class ForStmtBitfields { @@ -224,7 +224,7 @@ unsigned : NumStmtBits; /// The location of the "for". - SourceLocation ForLoc; + SourceLocation::LowBits ForLoc_lo; }; class GotoStmtBitfields { @@ -234,7 +234,7 @@ unsigned : NumStmtBits; /// The location of the "goto". - SourceLocation GotoLoc; + SourceLocation::LowBits GotoLoc_lo; }; class ContinueStmtBitfields { @@ -243,7 +243,7 @@ unsigned : NumStmtBits; /// The location of the "continue". - SourceLocation ContinueLoc; + SourceLocation::LowBits ContinueLoc_lo; }; class BreakStmtBitfields { @@ -252,7 +252,7 @@ unsigned : NumStmtBits; /// The location of the "break". - SourceLocation BreakLoc; + SourceLocation::LowBits BreakLoc_lo; }; class ReturnStmtBitfields { @@ -264,7 +264,7 @@ unsigned HasNRVOCandidate : 1; /// The location of the "return". - SourceLocation RetLoc; + SourceLocation::LowBits RetLoc_lo; }; class SwitchCaseBitfields { @@ -278,7 +278,7 @@ unsigned CaseStmtIsGNURange : 1; /// The location of the "case" or "default" keyword. - SourceLocation KeywordLoc; + SourceLocation::LowBits KeywordLoc_lo; }; //===--- Expression bitfields classes ---===// @@ -360,7 +360,7 @@ unsigned HasFunctionName : 1; /// The location of this PredefinedExpr. - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class DeclRefExprBitfields { @@ -377,7 +377,7 @@ unsigned NonOdrUseReason : 2; /// The location of the declaration name itself. - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; @@ -433,7 +433,7 @@ /// It is 0 otherwise. unsigned HasFPFeatures : 1; - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class UnaryExprOrTypeTraitExprBitfields { @@ -451,7 +451,7 @@ unsigned : NumExprBits; - SourceLocation RBracketLoc; + SourceLocation::LowBits RBracketLoc_lo; }; class CallExprBitfields { @@ -509,7 +509,7 @@ unsigned NonOdrUseReason : 2; /// This is the location of the -> or . in the expression. - SourceLocation OperatorLoc; + SourceLocation::LowBits OperatorLoc_lo; }; class CastExprBitfields { @@ -541,7 +541,7 @@ /// It is 0 otherwise. unsigned HasFPFeatures : 1; - SourceLocation OpLoc; + SourceLocation::LowBits OpLoc_lo; }; class InitListExprBitfields { @@ -571,7 +571,7 @@ unsigned : NumExprBits; /// The location of the "_Generic". - SourceLocation GenericLoc; + SourceLocation::LowBits GenericLoc_lo; }; class PseudoObjectExprBitfields { @@ -640,7 +640,7 @@ unsigned Value : 1; /// The location of the boolean literal. - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class CXXNullPtrLiteralExprBitfields { @@ -649,7 +649,7 @@ unsigned : NumExprBits; /// The location of the null pointer literal. - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class CXXThisExprBitfields { @@ -661,7 +661,7 @@ unsigned IsImplicit : 1; /// The location of the "this". - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class CXXThrowExprBitfields { @@ -674,7 +674,7 @@ unsigned IsThrownVariableInScope : 1; /// The location of the "throw". - SourceLocation ThrowLoc; + SourceLocation::LowBits ThrowLoc_lo; }; class CXXDefaultArgExprBitfields { @@ -684,7 +684,7 @@ unsigned : NumExprBits; /// The location where the default argument expression was used. - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class CXXDefaultInitExprBitfields { @@ -694,7 +694,7 @@ unsigned : NumExprBits; /// The location where the default initializer expression was used. - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class CXXScalarValueInitExprBitfields { @@ -703,7 +703,7 @@ unsigned : NumExprBits; - SourceLocation RParenLoc; + SourceLocation::LowBits RParenLoc_lo; }; class CXXNewExprBitfields { @@ -761,7 +761,7 @@ unsigned UsualArrayDeleteWantsSize : 1; /// Location of the expression. - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class TypeTraitExprBitfields { @@ -809,7 +809,7 @@ unsigned ZeroInitialization : 1; unsigned ConstructionKind : 3; - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; class ExprWithCleanupsBitfields { @@ -853,7 +853,7 @@ unsigned HasFirstQualifierFoundInScope : 1; /// The location of the '->' or '.' operator. - SourceLocation OperatorLoc; + SourceLocation::LowBits OperatorLoc_lo; }; class OverloadExprBitfields { @@ -927,7 +927,7 @@ unsigned : NumExprBits; /// The location of the non-type template parameter reference. - SourceLocation NameLoc; + SourceLocation::LowBits NameLoc_lo; }; class LambdaExprBitfields { @@ -960,7 +960,7 @@ unsigned : NumExprBits; unsigned IsSatisfied : 1; - SourceLocation RequiresKWLoc; + SourceLocation::LowBits RequiresKWLoc_lo; }; //===--- C++ Coroutines TS bitfields classes ---===// @@ -995,7 +995,7 @@ /// bit is set to true. unsigned IsUnique : 1; - SourceLocation Loc; + SourceLocation::LowBits Loc_lo; }; union { @@ -1361,6 +1361,9 @@ /// NullStmt - This is the null statement ";": C99 6.8.3p3. /// class NullStmt : public Stmt { + /// The location of the semi-colon. + SourceLocation::OptionalHighBits SemiLoc_hi; + public: NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false) : Stmt(NullStmtClass) { @@ -1371,8 +1374,12 @@ /// Build an empty null statement. explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {} - SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; } - void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; } + SourceLocation getSemiLoc() const { + return SourceLocation::getFromLowHigh(NullStmtBits.SemiLoc_lo, SemiLoc_hi); + } + void setSemiLoc(SourceLocation L) { + L.writeLowHigh(NullStmtBits.SemiLoc_lo, SemiLoc_hi); + } bool hasLeadingEmptyMacro() const { return NullStmtBits.HasLeadingEmptyMacro; @@ -1400,7 +1407,10 @@ friend class ASTStmtReader; friend TrailingObjects; - /// The location of the closing "}". LBraceLoc is stored in CompoundStmtBits. + /// The location of the opening "{". + SourceLocation::OptionalHighBits LBraceLoc_hi; + + /// The location of the closing "}". SourceLocation RBraceLoc; CompoundStmt(ArrayRef Stmts, SourceLocation LB, SourceLocation RB); @@ -1416,7 +1426,7 @@ explicit CompoundStmt(SourceLocation Loc) : Stmt(CompoundStmtClass), RBraceLoc(Loc) { CompoundStmtBits.NumStmts = 0; - CompoundStmtBits.LBraceLoc = Loc; + setLBracLoc(Loc); } // Build an empty compound statement. @@ -1499,10 +1509,17 @@ return const_cast(this)->getStmtExprResult(); } - SourceLocation getBeginLoc() const { return CompoundStmtBits.LBraceLoc; } + SourceLocation getBeginLoc() const { return getLBracLoc(); } SourceLocation getEndLoc() const { return RBraceLoc; } - SourceLocation getLBracLoc() const { return CompoundStmtBits.LBraceLoc; } + SourceLocation getLBracLoc() const { + return SourceLocation::getFromLowHigh(CompoundStmtBits.LBraceLoc_lo, + LBraceLoc_hi); + } + void setLBracLoc(SourceLocation L) { + L.writeLowHigh(CompoundStmtBits.LBraceLoc_lo, LBraceLoc_hi); + } + SourceLocation getRBracLoc() const { return RBraceLoc; } static bool classof(const Stmt *T) { @@ -1523,8 +1540,8 @@ /// The location of the ":". SourceLocation ColonLoc; - // The location of the "case" or "default" keyword. Stored in SwitchCaseBits. - // SourceLocation KeywordLoc; + /// The location of the "case" or "default" keyword. + SourceLocation::OptionalHighBits KeywordLoc_hi; /// A pointer to the following CaseStmt or DefaultStmt class, /// used by SwitchStmt. @@ -1542,8 +1559,14 @@ SwitchCase *getNextSwitchCase() { return NextSwitchCase; } void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } - SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; } - void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; } + SourceLocation getKeywordLoc() const { + return SourceLocation::getFromLowHigh(SwitchCaseBits.KeywordLoc_lo, + KeywordLoc_hi); + } + void setKeywordLoc(SourceLocation L) { + L.writeLowHigh(SwitchCaseBits.KeywordLoc_lo, KeywordLoc_hi); + } + SourceLocation getColonLoc() const { return ColonLoc; } void setColonLoc(SourceLocation L) { ColonLoc = L; } @@ -1800,6 +1823,8 @@ Stmt *SubStmt; bool SideEntry = false; + SourceLocation::OptionalHighBits IdentLoc_hi; + public: /// Build a label statement. LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) @@ -1810,8 +1835,13 @@ /// Build an empty label statement. explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {} - SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; } - void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; } + SourceLocation getIdentLoc() const { + return SourceLocation::getFromLowHigh(LabelStmtBits.IdentLoc_lo, + IdentLoc_hi); + } + void setIdentLoc(SourceLocation L) { + L.writeLowHigh(LabelStmtBits.IdentLoc_lo, IdentLoc_hi); + } LabelDecl *getDecl() const { return TheDecl; } void setDecl(LabelDecl *D) { TheDecl = D; } @@ -1848,20 +1878,23 @@ friend class ASTStmtReader; friend TrailingObjects; + /// The location of the attribute. + SourceLocation::OptionalHighBits AttrLoc_hi; + Stmt *SubStmt; AttributedStmt(SourceLocation Loc, ArrayRef Attrs, Stmt *SubStmt) : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) { AttributedStmtBits.NumAttrs = Attrs.size(); - AttributedStmtBits.AttrLoc = Loc; + setAttrLoc(Loc); std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr()); } explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) : ValueStmt(AttributedStmtClass, Empty) { AttributedStmtBits.NumAttrs = NumAttrs; - AttributedStmtBits.AttrLoc = SourceLocation{}; + setAttrLoc(SourceLocation{}); std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr); } @@ -1877,7 +1910,13 @@ // Build an empty attributed statement. static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs); - SourceLocation getAttrLoc() const { return AttributedStmtBits.AttrLoc; } + SourceLocation getAttrLoc() const { + return SourceLocation::getFromLowHigh(AttributedStmtBits.AttrLoc_lo, + AttrLoc_hi); + } + void setAttrLoc(SourceLocation L) { + L.writeLowHigh(AttributedStmtBits.AttrLoc_lo, AttrLoc_hi); + } ArrayRef getAttrs() const { return llvm::makeArrayRef(getAttrArrayPtr(), AttributedStmtBits.NumAttrs); } @@ -1929,6 +1968,7 @@ // Present if and only if hasElseStorage(). enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 }; enum { NumMandatoryStmtPtr = 2 }; + SourceLocation::OptionalHighBits IfLoc_hi; SourceLocation LParenLoc; SourceLocation RParenLoc; @@ -2063,8 +2103,12 @@ getTrailingObjects()[initOffset()] = Init; } - SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; } - void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; } + SourceLocation getIfLoc() const { + return SourceLocation::getFromLowHigh(IfStmtBits.IfLoc_lo, IfLoc_hi); + } + void setIfLoc(SourceLocation L) { + L.writeLowHigh(IfStmtBits.IfLoc_lo, IfLoc_hi); + } SourceLocation getElseLoc() const { return hasElseStorage() ? *getTrailingObjects() @@ -2144,6 +2188,7 @@ // Always present. enum { InitOffset = 0, BodyOffsetFromCond = 1 }; enum { NumMandatoryStmtPtr = 2 }; + SourceLocation::OptionalHighBits SwitchLoc_hi; SourceLocation LParenLoc; SourceLocation RParenLoc; @@ -2255,8 +2300,13 @@ const SwitchCase *getSwitchCaseList() const { return FirstCase; } void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } - SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; } - void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; } + SourceLocation getSwitchLoc() const { + return SourceLocation::getFromLowHigh(SwitchStmtBits.SwitchLoc_lo, + SwitchLoc_hi); + } + void setSwitchLoc(SourceLocation L) { + L.writeLowHigh(SwitchStmtBits.SwitchLoc_lo, SwitchLoc_hi); + } SourceLocation getLParenLoc() const { return LParenLoc; } void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } SourceLocation getRParenLoc() const { return RParenLoc; } @@ -2331,6 +2381,7 @@ enum { VarOffset = 0, BodyOffsetFromCond = 1 }; enum { NumMandatoryStmtPtr = 2 }; + SourceLocation::OptionalHighBits WhileLoc_hi; SourceLocation LParenLoc, RParenLoc; unsigned varOffset() const { return VarOffset; } @@ -2414,8 +2465,13 @@ : nullptr; } - SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; } - void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; } + SourceLocation getWhileLoc() const { + return SourceLocation::getFromLowHigh(WhileStmtBits.WhileLoc_lo, + WhileLoc_hi); + } + void setWhileLoc(SourceLocation L) { + L.writeLowHigh(WhileStmtBits.WhileLoc_lo, WhileLoc_hi); + } SourceLocation getLParenLoc() const { return LParenLoc; } void setLParenLoc(SourceLocation L) { LParenLoc = L; } @@ -2449,6 +2505,7 @@ class DoStmt : public Stmt { enum { BODY, COND, END_EXPR }; Stmt *SubExprs[END_EXPR]; + SourceLocation::OptionalHighBits DoLoc_hi; SourceLocation WhileLoc; SourceLocation RParenLoc; // Location of final ')' in do stmt condition. @@ -2475,8 +2532,12 @@ const Stmt *getBody() const { return SubExprs[BODY]; } void setBody(Stmt *Body) { SubExprs[BODY] = Body; } - SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; } - void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; } + SourceLocation getDoLoc() const { + return SourceLocation::getFromLowHigh(DoStmtBits.DoLoc_lo, DoLoc_hi); + } + void setDoLoc(SourceLocation L) { + L.writeLowHigh(DoStmtBits.DoLoc_lo, DoLoc_hi); + } SourceLocation getWhileLoc() const { return WhileLoc; } void setWhileLoc(SourceLocation L) { WhileLoc = L; } SourceLocation getRParenLoc() const { return RParenLoc; } @@ -2505,6 +2566,8 @@ class ForStmt : public Stmt { enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. + + SourceLocation::OptionalHighBits ForLoc_hi; SourceLocation LParenLoc, RParenLoc; public: @@ -2548,8 +2611,12 @@ void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast(E); } void setBody(Stmt *S) { SubExprs[BODY] = S; } - SourceLocation getForLoc() const { return ForStmtBits.ForLoc; } - void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; } + SourceLocation getForLoc() const { + return SourceLocation::getFromLowHigh(ForStmtBits.ForLoc_lo, ForLoc_hi); + } + void setForLoc(SourceLocation L) { + L.writeLowHigh(ForStmtBits.ForLoc_lo, ForLoc_hi); + } SourceLocation getLParenLoc() const { return LParenLoc; } void setLParenLoc(SourceLocation L) { LParenLoc = L; } SourceLocation getRParenLoc() const { return RParenLoc; } @@ -2575,6 +2642,7 @@ /// GotoStmt - This represents a direct goto. class GotoStmt : public Stmt { LabelDecl *Label; + SourceLocation::OptionalHighBits GotoLoc_hi; SourceLocation LabelLoc; public: @@ -2589,8 +2657,12 @@ LabelDecl *getLabel() const { return Label; } void setLabel(LabelDecl *D) { Label = D; } - SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; } - void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; } + SourceLocation getGotoLoc() const { + return SourceLocation::getFromLowHigh(GotoStmtBits.GotoLoc_lo, GotoLoc_hi); + } + void setGotoLoc(SourceLocation L) { + L.writeLowHigh(GotoStmtBits.GotoLoc_lo, GotoLoc_hi); + } SourceLocation getLabelLoc() const { return LabelLoc; } void setLabelLoc(SourceLocation L) { LabelLoc = L; } @@ -2613,6 +2685,7 @@ /// IndirectGotoStmt - This represents an indirect goto. class IndirectGotoStmt : public Stmt { + SourceLocation::OptionalHighBits GotoLoc_hi; SourceLocation StarLoc; Stmt *Target; @@ -2627,8 +2700,12 @@ explicit IndirectGotoStmt(EmptyShell Empty) : Stmt(IndirectGotoStmtClass, Empty) {} - void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; } - SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; } + SourceLocation getGotoLoc() const { + return SourceLocation::getFromLowHigh(GotoStmtBits.GotoLoc_lo, GotoLoc_hi); + } + void setGotoLoc(SourceLocation L) { + L.writeLowHigh(GotoStmtBits.GotoLoc_lo, GotoLoc_hi); + } void setStarLoc(SourceLocation L) { StarLoc = L; } SourceLocation getStarLoc() const { return StarLoc; } @@ -2662,6 +2739,9 @@ /// ContinueStmt - This represents a continue. class ContinueStmt : public Stmt { + /// The location of the "continue". + SourceLocation::OptionalHighBits ContinueLoc_hi; + public: ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass) { setContinueLoc(CL); @@ -2670,8 +2750,13 @@ /// Build an empty continue statement. explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) {} - SourceLocation getContinueLoc() const { return ContinueStmtBits.ContinueLoc; } - void setContinueLoc(SourceLocation L) { ContinueStmtBits.ContinueLoc = L; } + SourceLocation getContinueLoc() const { + return SourceLocation::getFromLowHigh(ContinueStmtBits.ContinueLoc_lo, + ContinueLoc_hi); + } + void setContinueLoc(SourceLocation L) { + L.writeLowHigh(ContinueStmtBits.ContinueLoc_lo, ContinueLoc_hi); + } SourceLocation getBeginLoc() const { return getContinueLoc(); } SourceLocation getEndLoc() const { return getContinueLoc(); } @@ -2692,6 +2777,8 @@ /// BreakStmt - This represents a break. class BreakStmt : public Stmt { + SourceLocation::OptionalHighBits BreakLoc_hi; + public: BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass) { setBreakLoc(BL); @@ -2700,8 +2787,13 @@ /// Build an empty break statement. explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) {} - SourceLocation getBreakLoc() const { return BreakStmtBits.BreakLoc; } - void setBreakLoc(SourceLocation L) { BreakStmtBits.BreakLoc = L; } + SourceLocation getBreakLoc() const { + return SourceLocation::getFromLowHigh(BreakStmtBits.BreakLoc_lo, + BreakLoc_hi); + } + void setBreakLoc(SourceLocation L) { + L.writeLowHigh(BreakStmtBits.BreakLoc_lo, BreakLoc_hi); + } SourceLocation getBeginLoc() const { return getBreakLoc(); } SourceLocation getEndLoc() const { return getBreakLoc(); } @@ -2733,6 +2825,9 @@ private llvm::TrailingObjects { friend TrailingObjects; + /// The location of the "return". + SourceLocation::OptionalHighBits RetLoc_hi; + /// The return expression. Stmt *RetExpr; @@ -2784,8 +2879,12 @@ *getTrailingObjects() = Var; } - SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; } - void setReturnLoc(SourceLocation L) { ReturnStmtBits.RetLoc = L; } + SourceLocation getReturnLoc() const { + return SourceLocation::getFromLowHigh(ReturnStmtBits.RetLoc_lo, RetLoc_hi); + } + void setReturnLoc(SourceLocation L) { + L.writeLowHigh(ReturnStmtBits.RetLoc_lo, RetLoc_hi); + } SourceLocation getBeginLoc() const { return getReturnLoc(); } SourceLocation getEndLoc() const LLVM_READONLY { diff --git a/clang/include/clang/Analysis/ProgramPoint.h b/clang/include/clang/Analysis/ProgramPoint.h --- a/clang/include/clang/Analysis/ProgramPoint.h +++ b/clang/include/clang/Analysis/ProgramPoint.h @@ -21,6 +21,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/AlignOf.h" #include "llvm/Support/Casting.h" #include "llvm/Support/DataTypes.h" #include @@ -85,9 +86,31 @@ MaxImplicitCallKind = PostImplicitCallKind, LoopExitKind, EpsilonKind}; - private: - const void *Data1; + union PtrOrSLoc { + PtrOrSLoc() {} + PtrOrSLoc(const void *P) { + memset(Raw.buffer, 0, sizeof(Raw.buffer)); + Ptr = P; + } + PtrOrSLoc(SourceLocation L) { + memset(Raw.buffer, 0, sizeof(Raw.buffer)); + new (&SLoc) SourceLocation(L); + } + bool operator==(const PtrOrSLoc &RHS) const { + return memcmp(this, &RHS, sizeof(PtrOrSLoc)) == 0; + } + bool operator!=(const PtrOrSLoc &RHS) const { return !(*this == RHS); } + StringRef AsBuffer() const { + const char *c = (const char *)this; + return StringRef(c, sizeof(PtrOrSLoc)); + } + const void *Ptr; + SourceLocation SLoc; + llvm::AlignedCharArrayUnion Raw; + }; + + PtrOrSLoc Data1; llvm::PointerIntPair Data2; // The LocationContext could be NULL to allow ProgramPoint to be used in @@ -108,30 +131,38 @@ Tag(tag, (((unsigned) k) >> 4) & 0x3) { assert(getKind() == k); assert(getLocationContext() == l); - assert(getData1() == P); + assert(getData1Ptr() == P); } - ProgramPoint(const void *P1, - const void *P2, - Kind k, - const LocationContext *l, - const ProgramPointTag *tag = nullptr) - : Data1(P1), - Data2(P2, (((unsigned) k) >> 0) & 0x3), - L(l, (((unsigned) k) >> 2) & 0x3), - Tag(tag, (((unsigned) k) >> 4) & 0x3) {} - -protected: - const void *getData1() const { return Data1; } - const void *getData2() const { return Data2.getPointer(); } - void setData2(const void *d) { Data2.setPointer(d); } - -public: - /// Create a new ProgramPoint object that is the same as the original - /// except for using the specified tag value. - ProgramPoint withTag(const ProgramPointTag *tag) const { - return ProgramPoint(getData1(), getData2(), getKind(), - getLocationContext(), tag); + ProgramPoint(PtrOrSLoc D1, const void *P2, Kind k, + const LocationContext *l, + const ProgramPointTag *tag = nullptr) + : Data1(D1), Data2(P2, (((unsigned)k) >> 0) & 0x3), + L(l, (((unsigned)k) >> 2) & 0x3), + Tag(tag, (((unsigned)k) >> 4) & 0x3) {} + + ProgramPoint(const void *P1, const void *P2, Kind k, + const LocationContext *l, + const ProgramPointTag *tag = nullptr) + : ProgramPoint(PtrOrSLoc(P1), P2, k, l, tag) {} + + ProgramPoint(SourceLocation Loc, const void *P2, Kind k, + const LocationContext *l, + const ProgramPointTag *tag = nullptr) + : ProgramPoint(PtrOrSLoc(Loc), P2, k, l, tag) {} + + protected: + const PtrOrSLoc &getData1() const { return Data1; } + const void *getData1Ptr() const { return Data1.Ptr; } + const void *getData2() const { return Data2.getPointer(); } + void setData2(const void *d) { Data2.setPointer(d); } + + public: + /// Create a new ProgramPoint object that is the same as the original + /// except for using the specified tag value. + ProgramPoint withTag(const ProgramPointTag *tag) const { + return ProgramPoint(getData1(), getData2(), getKind(), + getLocationContext(), tag); } /// Convert to the specified ProgramPoint type, asserting that this @@ -207,7 +238,7 @@ void Profile(llvm::FoldingSetNodeID& ID) const { ID.AddInteger((unsigned) getKind()); - ID.AddPointer(getData1()); + ID.AddString(getData1().AsBuffer()); ID.AddPointer(getData2()); ID.AddPointer(getLocationContext()); ID.AddPointer(getTag()); @@ -231,7 +262,7 @@ } const CFGBlock *getBlock() const { - return reinterpret_cast(getData1()); + return reinterpret_cast(getData1Ptr()); } Optional getFirstElement() const { @@ -253,7 +284,7 @@ : ProgramPoint(B, BlockExitKind, L) {} const CFGBlock *getBlock() const { - return reinterpret_cast(getData1()); + return reinterpret_cast(getData1Ptr()); } const Stmt *getTerminator() const { @@ -276,7 +307,7 @@ assert(S); } - const Stmt *getStmt() const { return (const Stmt*) getData1(); } + const Stmt *getStmt() const { return (const Stmt *)getData1Ptr(); } template const T* getStmtAs() const { return dyn_cast(getStmt()); } @@ -344,7 +375,7 @@ } const ReturnStmt *getStmt() const { - return reinterpret_cast(getData1()); + return reinterpret_cast(getData1Ptr()); } private: @@ -509,7 +540,7 @@ } const CFGBlock *getSrc() const { - return static_cast(getData1()); + return static_cast(getData1Ptr()); } const CFGBlock *getDst() const { @@ -537,7 +568,7 @@ : ProgramPoint(I, Loc, PostInitializerKind, L) {} const CXXCtorInitializer *getInitializer() const { - return static_cast(getData1()); + return static_cast(getData1Ptr()); } /// Returns the location of the field. @@ -560,12 +591,10 @@ public: ImplicitCallPoint(const Decl *D, SourceLocation Loc, Kind K, const LocationContext *L, const ProgramPointTag *Tag) - : ProgramPoint(Loc.getPtrEncoding(), D, K, L, Tag) {} + : ProgramPoint(Loc, D, K, L, Tag) {} const Decl *getDecl() const { return static_cast(getData2()); } - SourceLocation getLocation() const { - return SourceLocation::getFromPtrEncoding(getData1()); - } + SourceLocation getLocation() const { return getData1().SLoc; } protected: ImplicitCallPoint() = default; @@ -634,7 +663,7 @@ : ProgramPoint(stmt, calleeCtx, CallEnterKind, callerCtx, nullptr) {} const Stmt *getCallExpr() const { - return static_cast(getData1()); + return static_cast(getData1Ptr()); } const StackFrameContext *getCalleeContext() const { @@ -672,7 +701,7 @@ : ProgramPoint(RS, CallExitBeginKind, L, nullptr) { } const ReturnStmt *getReturnStmt() const { - return static_cast(getData1()); + return static_cast(getData1Ptr()); } private: @@ -693,7 +722,7 @@ : ProgramPoint(CalleeCtx, CallExitEndKind, CallerCtx, nullptr) {} const StackFrameContext *getCalleeContext() const { - return static_cast(getData1()); + return static_cast(getData1Ptr()); } private: @@ -716,7 +745,7 @@ : ProgramPoint(LoopStmt, nullptr, LoopExitKind, LC) {} const Stmt *getLoopStmt() const { - return static_cast(getData1()); + return static_cast(getData1Ptr()); } private: @@ -736,7 +765,7 @@ const ProgramPointTag *tag = nullptr) : ProgramPoint(Data1, Data2, EpsilonKind, L, tag) {} - const void *getData() const { return getData1(); } + const void *getData() const { return getData1Ptr(); } private: friend class ProgramPoint; diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h --- a/clang/include/clang/Basic/SourceLocation.h +++ b/clang/include/clang/Basic/SourceLocation.h @@ -85,18 +85,66 @@ /// In addition, one bit of SourceLocation is used for quick access to the /// information whether the location is in a file or a macro expansion. /// -/// It is important that this type remains small. It is currently 32 bits wide. +/// It is important that this type remains small. It is currently 32/64 bits +/// wide. class SourceLocation { friend class ASTReader; friend class ASTWriter; friend class SourceManager; friend struct llvm::FoldingSetTrait; - unsigned ID = 0; - - enum : unsigned { - MacroIDBit = 1U << 31 +public: + class LowBits { + friend class SourceLocation; + uint32_t lo; + }; +#ifdef CLANG_64_BIT_SOURCE_LOCATIONS + using UIntType = uint64_t; + using IntType = int64_t; + class OptionalHighBits { + friend class SourceLocation; + uint32_t hi; }; + static SourceLocation getFromLowHigh(LowBits L, OptionalHighBits H) { + return getFromRawEncoding(((uint64_t)H.hi << 32) | L.lo); + } + void writeLowHigh(LowBits &L, OptionalHighBits &H) { + L.lo = ID; + H.hi = ID >> 32; + } + bool getRawEncoding32(uint32_t &Result) const { + if ((ID ^ (ID << 1)) & 0x7FFFFFFF80000000) + return false; // won't fit + uint32_t TruncatedValue = ID & 0x7FFFFFFF; + Result = TruncatedValue | ((ID & 0x8000000000000000) >> 32); + return true; + } + static SourceLocation getFromRawEncoding32(uint32_t Raw32) { + uint64_t Raw = Raw32 & 0x7FFFFFFF; + Raw += 0x1FFFFFFFE * (Raw & 0x40000000); + Raw |= (uint64_t)(Raw32 & 0x80000000) << 32; + return getFromRawEncoding(Raw); + } +#else + using UIntType = uint32_t; + using IntType = int32_t; + class OptionalHighBits {}; + static SourceLocation getFromLowHigh(LowBits L, OptionalHighBits H) { + return getFromRawEncoding(L.lo); + } + void writeLowHigh(LowBits &L, OptionalHighBits &H) { L.lo = ID; } + bool getRawEncoding32(uint32_t &Result) const { + Result = ID; + return true; + } + static SourceLocation getFromRawEncoding32(uint32_t Raw32) { + return getFromRawEncoding(Raw32); + } +#endif +private: + UIntType ID = 0; + + enum : UIntType { MacroIDBit = 1ULL << (8 * sizeof(UIntType) - 1) }; public: bool isFileID() const { return (ID & MacroIDBit) == 0; } @@ -112,18 +160,16 @@ private: /// Return the offset into the manager's global input view. - unsigned getOffset() const { - return ID & ~MacroIDBit; - } + UIntType getOffset() const { return ID & ~MacroIDBit; } - static SourceLocation getFileLoc(unsigned ID) { + static SourceLocation getFileLoc(UIntType ID) { assert((ID & MacroIDBit) == 0 && "Ran out of source locations!"); SourceLocation L; L.ID = ID; return L; } - static SourceLocation getMacroLoc(unsigned ID) { + static SourceLocation getMacroLoc(UIntType ID) { assert((ID & MacroIDBit) == 0 && "Ran out of source locations!"); SourceLocation L; L.ID = MacroIDBit | ID; @@ -133,7 +179,7 @@ public: /// Return a source location with the specified offset from this /// SourceLocation. - SourceLocation getLocWithOffset(int Offset) const { + SourceLocation getLocWithOffset(IntType Offset) const { assert(((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"); SourceLocation L; L.ID = ID+Offset; @@ -145,13 +191,13 @@ /// /// This should only be passed to SourceLocation::getFromRawEncoding, it /// should not be inspected directly. - unsigned getRawEncoding() const { return ID; } + UIntType getRawEncoding() const { return ID; } /// Turn a raw encoding of a SourceLocation object into /// a real SourceLocation. /// /// \see getRawEncoding. - static SourceLocation getFromRawEncoding(unsigned Encoding) { + static SourceLocation getFromRawEncoding(UIntType Encoding) { SourceLocation X; X.ID = Encoding; return X; @@ -171,7 +217,7 @@ /// Turn a pointer encoding of a SourceLocation object back /// into a real SourceLocation. static SourceLocation getFromPtrEncoding(const void *Encoding) { - return getFromRawEncoding((unsigned)(uintptr_t)Encoding); + return getFromRawEncoding((SourceLocation::UIntType)(uintptr_t)Encoding); } static bool isPairOfFileLocations(SourceLocation Start, SourceLocation End) { @@ -489,11 +535,13 @@ /// DenseMapInfo which uses SourceLocation::ID is used as a key. template <> struct DenseMapInfo { static clang::SourceLocation getEmptyKey() { - return clang::SourceLocation::getFromRawEncoding(~0U); + constexpr clang::SourceLocation::UIntType Zero = 0; + return clang::SourceLocation::getFromRawEncoding(~Zero); } static clang::SourceLocation getTombstoneKey() { - return clang::SourceLocation::getFromRawEncoding(~0U - 1); + constexpr clang::SourceLocation::UIntType Zero = 0; + return clang::SourceLocation::getFromRawEncoding(~Zero - 1); } static unsigned getHashValue(clang::SourceLocation Loc) { @@ -510,20 +558,6 @@ static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID); }; - // Teach SmallPtrSet how to handle SourceLocation. - template<> - struct PointerLikeTypeTraits { - static constexpr int NumLowBitsAvailable = 0; - - static void *getAsVoidPointer(clang::SourceLocation L) { - return L.getPtrEncoding(); - } - - static clang::SourceLocation getFromVoidPointer(void *P) { - return clang::SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)P); - } - }; - } // namespace llvm #endif // LLVM_CLANG_BASIC_SOURCELOCATION_H diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -465,8 +465,9 @@ /// SourceManager keeps an array of these objects, and they are uniquely /// identified by the FileID datatype. class SLocEntry { - unsigned Offset : 31; - unsigned IsExpansion : 1; + static constexpr int OffsetBits = 8 * sizeof(SourceLocation::UIntType) - 1; + SourceLocation::UIntType Offset : OffsetBits; + SourceLocation::UIntType IsExpansion : 1; union { FileInfo File; ExpansionInfo Expansion; @@ -475,7 +476,7 @@ public: SLocEntry() : Offset(), IsExpansion(), File() {} - unsigned getOffset() const { return Offset; } + SourceLocation::UIntType getOffset() const { return Offset; } bool isExpansion() const { return IsExpansion; } bool isFile() const { return !isExpansion(); } @@ -490,8 +491,8 @@ return Expansion; } - static SLocEntry get(unsigned Offset, const FileInfo &FI) { - assert(!(Offset & (1u << 31)) && "Offset is too large"); + static SLocEntry get(SourceLocation::UIntType Offset, const FileInfo &FI) { + assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large"); SLocEntry E; E.Offset = Offset; E.IsExpansion = false; @@ -499,8 +500,9 @@ return E; } - static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) { - assert(!(Offset & (1u << 31)) && "Offset is too large"); + static SLocEntry get(SourceLocation::UIntType Offset, + const ExpansionInfo &Expansion) { + assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large"); SLocEntry E; E.Offset = Offset; E.IsExpansion = true; @@ -690,17 +692,18 @@ /// The starting offset of the next local SLocEntry. /// /// This is LocalSLocEntryTable.back().Offset + the size of that entry. - unsigned NextLocalOffset; + SourceLocation::UIntType NextLocalOffset; /// The starting offset of the latest batch of loaded SLocEntries. /// /// This is LoadedSLocEntryTable.back().Offset, except that that entry might /// not have been loaded, so that value would be unknown. - unsigned CurrentLoadedOffset; + SourceLocation::UIntType CurrentLoadedOffset; - /// The highest possible offset is 2^31-1, so CurrentLoadedOffset - /// starts at 2^31. - static const unsigned MaxLoadedOffset = 1U << 31U; + /// The highest possible offset is 2^32-1 (2^63-1 for 64-bit source + /// locations), so CurrentLoadedOffset starts at 2^31 (2^63 resp.). + static const SourceLocation::UIntType MaxLoadedOffset = + 1ULL << (8 * sizeof(SourceLocation::UIntType) - 1); /// A bitmap that indicates whether the entries of LoadedSLocEntryTable /// have already been loaded from the external source. @@ -865,11 +868,13 @@ /// This translates NULL into standard input. FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID = 0, unsigned LoadedOffset = 0); + int LoadedID = 0, + SourceLocation::UIntType LoadedOffset = 0); FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID = 0, unsigned LoadedOffset = 0); + int LoadedID = 0, + SourceLocation::UIntType LoadedOffset = 0); /// Create a new FileID that represents the specified memory buffer. /// @@ -877,7 +882,8 @@ /// MemoryBuffer, so only pass a MemoryBuffer to this once. FileID createFileID(std::unique_ptr Buffer, SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, - int LoadedID = 0, unsigned LoadedOffset = 0, + int LoadedID = 0, + SourceLocation::UIntType LoadedOffset = 0, SourceLocation IncludeLoc = SourceLocation()); /// Create a new FileID that represents the specified memory buffer. @@ -886,7 +892,8 @@ /// outlive the SourceManager. FileID createFileID(const llvm::MemoryBufferRef &Buffer, SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, - int LoadedID = 0, unsigned LoadedOffset = 0, + int LoadedID = 0, + SourceLocation::UIntType LoadedOffset = 0, SourceLocation IncludeLoc = SourceLocation()); /// Get the FileID for \p SourceFile if it exists. Otherwise, create a @@ -905,13 +912,11 @@ /// Return a new SourceLocation that encodes the fact /// that a token from SpellingLoc should actually be referenced from /// ExpansionLoc. - SourceLocation createExpansionLoc(SourceLocation Loc, - SourceLocation ExpansionLocStart, - SourceLocation ExpansionLocEnd, - unsigned TokLength, - bool ExpansionIsTokenRange = true, - int LoadedID = 0, - unsigned LoadedOffset = 0); + SourceLocation + createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, + SourceLocation ExpansionLocEnd, unsigned TokLength, + bool ExpansionIsTokenRange = true, int LoadedID = 0, + SourceLocation::UIntType LoadedOffset = 0); /// Return a new SourceLocation that encodes that the token starting /// at \p TokenStart ends prematurely at \p TokenEnd. @@ -1098,7 +1103,7 @@ /// the entry in SLocEntryTable which contains the specified location. /// FileID getFileID(SourceLocation SpellingLoc) const { - unsigned SLocOffset = SpellingLoc.getOffset(); + SourceLocation::UIntType SLocOffset = SpellingLoc.getOffset(); // If our one-entry cache covers this offset, just return it. if (isOffsetInFileID(LastFileIDLookup, SLocOffset)) @@ -1221,7 +1226,7 @@ if (!Entry) return SourceLocation(); - unsigned GlobalOffset = Entry->getOffset() + Offset; + SourceLocation::UIntType GlobalOffset = Entry->getOffset() + Offset; return Entry->isFile() ? SourceLocation::getFileLoc(GlobalOffset) : SourceLocation::getMacroLoc(GlobalOffset); } @@ -1326,17 +1331,17 @@ /// /// If it's true and \p RelativeOffset is non-null, it will be set to the /// relative offset of \p Loc inside the chunk. - bool isInSLocAddrSpace(SourceLocation Loc, - SourceLocation Start, unsigned Length, - unsigned *RelativeOffset = nullptr) const { + bool + isInSLocAddrSpace(SourceLocation Loc, SourceLocation Start, unsigned Length, + SourceLocation::UIntType *RelativeOffset = nullptr) const { assert(((Start.getOffset() < NextLocalOffset && Start.getOffset()+Length <= NextLocalOffset) || (Start.getOffset() >= CurrentLoadedOffset && Start.getOffset()+Length < MaxLoadedOffset)) && "Chunk is not valid SLoc address space"); - unsigned LocOffs = Loc.getOffset(); - unsigned BeginOffs = Start.getOffset(); - unsigned EndOffs = BeginOffs + Length; + SourceLocation::UIntType LocOffs = Loc.getOffset(); + SourceLocation::UIntType BeginOffs = Start.getOffset(); + SourceLocation::UIntType EndOffs = BeginOffs + Length; if (LocOffs >= BeginOffs && LocOffs < EndOffs) { if (RelativeOffset) *RelativeOffset = LocOffs - BeginOffs; @@ -1352,8 +1357,9 @@ /// If it's true and \p RelativeOffset is non-null, it will be set to the /// offset of \p RHS relative to \p LHS. bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS, - int *RelativeOffset) const { - unsigned LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset(); + SourceLocation::IntType *RelativeOffset) const { + SourceLocation::UIntType LHSOffs = LHS.getOffset(), + RHSOffs = RHS.getOffset(); bool LHSLoaded = LHSOffs >= CurrentLoadedOffset; bool RHSLoaded = RHSOffs >= CurrentLoadedOffset; @@ -1517,7 +1523,7 @@ /// of FileID) to \p relativeOffset. bool isInFileID(SourceLocation Loc, FileID FID, unsigned *RelativeOffset = nullptr) const { - unsigned Offs = Loc.getOffset(); + SourceLocation::UIntType Offs = Loc.getOffset(); if (isOffsetInFileID(FID, Offs)) { if (RelativeOffset) *RelativeOffset = Offs - getSLocEntry(FID).getOffset(); @@ -1636,8 +1642,9 @@ /// offset in the "source location address space". /// /// Note that we always consider source locations loaded from - bool isBeforeInSLocAddrSpace(SourceLocation LHS, unsigned RHS) const { - unsigned LHSOffset = LHS.getOffset(); + bool isBeforeInSLocAddrSpace(SourceLocation LHS, + SourceLocation::UIntType RHS) const { + SourceLocation::UIntType LHSOffset = LHS.getOffset(); bool LHSLoaded = LHSOffset >= CurrentLoadedOffset; bool RHSLoaded = RHS >= CurrentLoadedOffset; if (LHSLoaded == RHSLoaded) @@ -1699,7 +1706,9 @@ return getSLocEntryByID(FID.ID, Invalid); } - unsigned getNextLocalOffset() const { return NextLocalOffset; } + SourceLocation::UIntType getNextLocalOffset() const { + return NextLocalOffset; + } void setExternalSLocEntrySource(ExternalSLocEntrySource *Source) { assert(LoadedSLocEntryTable.empty() && @@ -1713,8 +1722,9 @@ /// NumSLocEntries will be allocated, which occupy a total of TotalSize space /// in the global source view. The lowest ID and the base offset of the /// entries will be returned. - std::pair - AllocateLoadedSLocEntries(unsigned NumSLocEntries, unsigned TotalSize); + std::pair + AllocateLoadedSLocEntries(unsigned NumSLocEntries, + SourceLocation::UIntType TotalSize); /// Returns true if \p Loc came from a PCH/Module. bool isLoadedSourceLocation(SourceLocation Loc) const { @@ -1795,14 +1805,15 @@ /// Implements the common elements of storing an expansion info struct into /// the SLocEntry table and producing a source location that refers to it. - SourceLocation createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion, - unsigned TokLength, - int LoadedID = 0, - unsigned LoadedOffset = 0); + SourceLocation + createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion, + unsigned TokLength, int LoadedID = 0, + SourceLocation::UIntType LoadedOffset = 0); /// Return true if the specified FileID contains the /// specified SourceLocation offset. This is a very hot method. - inline bool isOffsetInFileID(FileID FID, unsigned SLocOffset) const { + inline bool isOffsetInFileID(FileID FID, + SourceLocation::UIntType SLocOffset) const { const SrcMgr::SLocEntry &Entry = getSLocEntry(FID); // If the entry is after the offset, it can't contain it. if (SLocOffset < Entry.getOffset()) return false; @@ -1836,7 +1847,7 @@ FileID createFileIDImpl(SrcMgr::ContentCache &File, StringRef Filename, SourceLocation IncludePos, SrcMgr::CharacteristicKind DirCharacter, int LoadedID, - unsigned LoadedOffset); + SourceLocation::UIntType LoadedOffset); SrcMgr::ContentCache &getOrCreateContentCache(FileEntryRef SourceFile, bool isSystemFile = false); @@ -1845,9 +1856,9 @@ SrcMgr::ContentCache & createMemBufferContentCache(std::unique_ptr Buf); - FileID getFileIDSlow(unsigned SLocOffset) const; - FileID getFileIDLocal(unsigned SLocOffset) const; - FileID getFileIDLoaded(unsigned SLocOffset) const; + FileID getFileIDSlow(SourceLocation::UIntType SLocOffset) const; + FileID getFileIDLocal(SourceLocation::UIntType SLocOffset) const; + FileID getFileIDLoaded(SourceLocation::UIntType SLocOffset) const; SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const; SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const; diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -781,8 +781,7 @@ /// deserializing from PCH, we don't need to deserialize identifier & macros /// just so that we can report that they are unused, we just warn using /// the SourceLocations of this set (that will be filled by the ASTReader). - /// We are using SmallPtrSet instead of a vector for faster removal. - using WarnUnusedMacroLocsTy = llvm::SmallPtrSet; + using WarnUnusedMacroLocsTy = llvm::SmallDenseSet; WarnUnusedMacroLocsTy WarnUnusedMacroLocs; /// A "freelist" of MacroArg objects that can be diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h --- a/clang/include/clang/Lex/Token.h +++ b/clang/include/clang/Lex/Token.h @@ -33,7 +33,7 @@ /// information about the SourceRange of the tokens and the type object. class Token { /// The location of the token. This is actually a SourceLocation. - unsigned Loc; + SourceLocation::UIntType Loc; // Conceptually these next two fields could be in a union. However, this // causes gcc 4.2 to pessimize LexTokenInternal, a very performance critical @@ -43,7 +43,7 @@ /// UintData - This holds either the length of the token text, when /// a normal token, or the end of the SourceRange when an annotation /// token. - unsigned UintData; + SourceLocation::UIntType UintData; /// PtrData - This is a union of four different pointer types, which depends /// on what type of token this is: diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -176,10 +176,10 @@ /// Source range/offset of a preprocessed entity. struct PPEntityOffset { /// Raw source location of beginning of range. - unsigned Begin; + SourceLocation::UIntType Begin; /// Raw source location of end of range. - unsigned End; + SourceLocation::UIntType End; /// Offset in the AST file relative to ModuleFile::MacroOffsetsBase. uint32_t BitOffset; @@ -200,9 +200,9 @@ /// Source range of a skipped preprocessor region struct PPSkippedRange { /// Raw source location of beginning of range. - unsigned Begin; + SourceLocation::UIntType Begin; /// Raw source location of end of range. - unsigned End; + SourceLocation::UIntType End; PPSkippedRange(SourceRange R) : Begin(R.getBegin().getRawEncoding()), End(R.getEnd().getRawEncoding()) { @@ -240,7 +240,7 @@ /// Source location and bit offset of a declaration. struct DeclOffset { /// Raw source location. - unsigned Loc = 0; + SourceLocation::UIntType Loc = 0; /// Offset relative to the start of the DECLTYPES_BLOCK block. Keep /// structure alignment 32-bit and avoid padding gap because undefined diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -781,7 +781,7 @@ /// /// CodeGen has to emit VTables for these records, so they have to be eagerly /// deserialized. - SmallVector VTableUses; + SmallVector VTableUses; /// A snapshot of the pending instantiations in the chain. /// @@ -789,7 +789,7 @@ /// end of the TU. It consists of a pair of values for every pending /// instantiation where the first value is the ID of the decl and the second /// is the instantiation location. - SmallVector PendingInstantiations; + SmallVector PendingInstantiations; //@} @@ -807,11 +807,11 @@ /// Method selectors used in a @selector expression. Used for /// implementation of -Wselector. - SmallVector ReferencedSelectorsData; + SmallVector ReferencedSelectorsData; /// A snapshot of Sema's weak undeclared identifier tracking, for /// generating warnings. - SmallVector WeakUndeclaredIdentifiers; + SmallVector WeakUndeclaredIdentifiers; /// The IDs of type aliases for ext_vectors that exist in the chain. /// @@ -900,7 +900,7 @@ /// A list of undefined decls with internal linkage followed by the /// SourceLocation of a matching ODR-use. - SmallVector UndefinedButUsed; + SmallVector UndefinedButUsed; /// Delete expressions to analyze at the end of translation unit. SmallVector DelayedDeleteExprs; @@ -2136,12 +2136,15 @@ /// Read a source location from raw form and return it in its /// originating module file's source location space. - SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const { - return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31)); + SourceLocation + ReadUntranslatedSourceLocation(SourceLocation::UIntType Raw) const { + return SourceLocation::getFromRawEncoding((Raw >> 1) | + (Raw << (8 * sizeof(Raw) - 1))); } /// Read a source location from raw form. - SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const { + SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, + SourceLocation::UIntType Raw) const { SourceLocation Loc = ReadUntranslatedSourceLocation(Raw); return TranslateSourceLocation(ModuleFile, Loc); } @@ -2155,7 +2158,8 @@ assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && "Cannot find offset to remap."); - int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second; + SourceLocation::IntType Remap = + ModuleFile.SLocRemap.find(Loc.getOffset())->second; return Loc.getLocWithOffset(Remap); } diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -347,7 +347,7 @@ union { const Decl *Dcl; void *Type; - unsigned Loc; + SourceLocation::UIntType Loc; unsigned Val; Module *Mod; const Attr *Attribute; diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h --- a/clang/include/clang/Serialization/ModuleFile.h +++ b/clang/include/clang/Serialization/ModuleFile.h @@ -260,7 +260,7 @@ int SLocEntryBaseID = 0; /// The base offset in the source manager's view of this module. - unsigned SLocEntryBaseOffset = 0; + SourceLocation::UIntType SLocEntryBaseOffset = 0; /// Base file offset for the offsets in SLocEntryOffsets. Real file offset /// for the entry is SLocEntryOffsetsBase + SLocEntryOffsets[i]. @@ -274,7 +274,8 @@ SmallVector PreloadSLocEntries; /// Remapping table for source locations in this module. - ContinuousRangeMap SLocRemap; + ContinuousRangeMap + SLocRemap; // === Identifiers === diff --git a/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp b/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp --- a/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp +++ b/clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp @@ -52,7 +52,7 @@ if (AfterMacroLoc == SemiLoc) return true; - int RelOffs = 0; + SourceLocation::IntType RelOffs = 0; if (!SM.isInSameSLocAddrSpace(AfterMacroLoc, SemiLoc, &RelOffs)) return false; if (RelOffs < 0) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -391,7 +391,7 @@ DeclRefExprBits.RefersToEnclosingVariableOrCapture = RefersToEnclosingVariableOrCapture; DeclRefExprBits.NonOdrUseReason = NOUR; - DeclRefExprBits.Loc = L; + setLocation(L); setDependence(computeDependence(this, Ctx)); } @@ -404,7 +404,7 @@ QualType T, ExprValueKind VK, NonOdrUseReason NOUR) : Expr(DeclRefExprClass, T, VK, OK_Ordinary), D(D), DNLoc(NameInfo.getInfo()) { - DeclRefExprBits.Loc = NameInfo.getLoc(); + setLocation(NameInfo.getLoc()); DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0; if (QualifierLoc) new (getTrailingObjects()) @@ -576,7 +576,7 @@ "IdentKind do not fit in PredefinedExprBitfields!"); bool HasFunctionName = SL != nullptr; PredefinedExprBits.HasFunctionName = HasFunctionName; - PredefinedExprBits.Loc = L; + setLocation(L); if (HasFunctionName) setFunctionName(SL); setDependence(computeDependence(this)); @@ -1646,7 +1646,7 @@ MemberExprBits.HasTemplateKWAndArgsInfo = false; MemberExprBits.HadMultipleCandidates = false; MemberExprBits.NonOdrUseReason = NOUR; - MemberExprBits.OperatorLoc = OperatorLoc; + setOperatorLoc(OperatorLoc); setDependence(computeDependence(this)); } @@ -4196,7 +4196,7 @@ " and TypeSourceInfo!"); assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!"); - GenericSelectionExprBits.GenericLoc = GenericLoc; + setGenericLoc(GenericLoc); getTrailingObjects()[ControllingIndex] = ControllingExpr; std::copy(AssocExprs.begin(), AssocExprs.end(), getTrailingObjects() + AssocExprStartIndex); @@ -4219,7 +4219,7 @@ "Must have the same number of association expressions" " and TypeSourceInfo!"); - GenericSelectionExprBits.GenericLoc = GenericLoc; + setGenericLoc(GenericLoc); getTrailingObjects()[ControllingIndex] = ControllingExpr; std::copy(AssocExprs.begin(), AssocExprs.end(), getTrailingObjects() + AssocExprStartIndex); @@ -4475,7 +4475,7 @@ BinaryOperatorBits.Opc = opc; assert(!isCompoundAssignmentOp() && "Use CompoundAssignOperator for compound assignments"); - BinaryOperatorBits.OpLoc = opLoc; + setOperatorLoc(opLoc); SubExprs[LHS] = lhs; SubExprs[RHS] = rhs; BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(); @@ -4492,7 +4492,7 @@ BinaryOperatorBits.Opc = opc; assert(isCompoundAssignmentOp() && "Use CompoundAssignOperator for compound assignments"); - BinaryOperatorBits.OpLoc = opLoc; + setOperatorLoc(opLoc); SubExprs[LHS] = lhs; SubExprs[RHS] = rhs; BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(); @@ -4559,7 +4559,7 @@ : Expr(UnaryOperatorClass, type, VK, OK), Val(input) { UnaryOperatorBits.Opc = opc; UnaryOperatorBits.CanOverflow = CanOverflow; - UnaryOperatorBits.Loc = l; + setOperatorLoc(l); UnaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(); if (hasStoredFPFeatures()) setStoredFPFeatures(FPFeatures); diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -956,7 +956,7 @@ : Ty->isRValueReferenceType() ? VK_XValue : VK_RValue, /*FIXME*/ OK_Ordinary), Field(Field), UsedContext(UsedContext) { - CXXDefaultInitExprBits.Loc = Loc; + setUsedLocation(Loc); assert(Field->hasInClassInitializer()); setDependence(computeDependence(this)); @@ -1065,7 +1065,7 @@ CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization; CXXConstructExprBits.ZeroInitialization = ZeroInitialization; CXXConstructExprBits.ConstructionKind = ConstructKind; - CXXConstructExprBits.Loc = Loc; + setLocation(Loc); Stmt **TrailingArgs = getTrailingArgs(); for (unsigned I = 0, N = Args.size(); I != N; ++I) { @@ -1373,7 +1373,7 @@ (TemplateArgs != nullptr) || TemplateKWLoc.isValid(); CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr; - CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc; + setOperatorLoc(OperatorLoc); if (TemplateArgs) { auto Deps = TemplateArgumentDependence::None; diff --git a/clang/lib/AST/ExprConcepts.cpp b/clang/lib/AST/ExprConcepts.cpp --- a/clang/lib/AST/ExprConcepts.cpp +++ b/clang/lib/AST/ExprConcepts.cpp @@ -150,7 +150,7 @@ NumLocalParameters(LocalParameters.size()), NumRequirements(Requirements.size()), Body(Body), RBraceLoc(RBraceLoc) { RequiresExprBits.IsSatisfied = false; - RequiresExprBits.RequiresKWLoc = RequiresKWLoc; + setRequiresKWLoc(RequiresKWLoc); bool Dependent = false; bool ContainsUnexpandedParameterPack = false; for (ParmVarDecl *P : LocalParameters) { diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp --- a/clang/lib/AST/NestedNameSpecifier.cpp +++ b/clang/lib/AST/NestedNameSpecifier.cpp @@ -356,7 +356,7 @@ assert(Qualifier && "Expected a non-NULL qualifier"); // Location of the trailing '::'. - unsigned Length = sizeof(unsigned); + unsigned Length = sizeof(SourceLocation::UIntType); switch (Qualifier->getKind()) { case NestedNameSpecifier::Global: @@ -368,7 +368,7 @@ case NestedNameSpecifier::NamespaceAlias: case NestedNameSpecifier::Super: // The location of the identifier or namespace name. - Length += sizeof(unsigned); + Length += sizeof(SourceLocation::UIntType); break; case NestedNameSpecifier::TypeSpecWithTemplate: @@ -393,8 +393,8 @@ /// Load a (possibly unaligned) source location from a given address /// and offset. static SourceLocation LoadSourceLocation(void *Data, unsigned Offset) { - unsigned Raw; - memcpy(&Raw, static_cast(Data) + Offset, sizeof(unsigned)); + SourceLocation::UIntType Raw; + memcpy(&Raw, static_cast(Data) + Offset, sizeof(Raw)); return SourceLocation::getFromRawEncoding(Raw); } @@ -431,8 +431,9 @@ case NestedNameSpecifier::Namespace: case NestedNameSpecifier::NamespaceAlias: case NestedNameSpecifier::Super: - return SourceRange(LoadSourceLocation(Data, Offset), - LoadSourceLocation(Data, Offset + sizeof(unsigned))); + return SourceRange( + LoadSourceLocation(Data, Offset), + LoadSourceLocation(Data, Offset + sizeof(SourceLocation::UIntType))); case NestedNameSpecifier::TypeSpecWithTemplate: case NestedNameSpecifier::TypeSpec: { @@ -487,10 +488,10 @@ /// Save a source location to the given buffer. static void SaveSourceLocation(SourceLocation Loc, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity) { - unsigned Raw = Loc.getRawEncoding(); + SourceLocation::UIntType Raw = Loc.getRawEncoding(); Append(reinterpret_cast(&Raw), - reinterpret_cast(&Raw) + sizeof(unsigned), - Buffer, BufferSize, BufferCapacity); + reinterpret_cast(&Raw) + sizeof(Raw), Buffer, BufferSize, + BufferCapacity); } /// Save a pointer to the given buffer. diff --git a/clang/lib/AST/SelectorLocationsKind.cpp b/clang/lib/AST/SelectorLocationsKind.cpp --- a/clang/lib/AST/SelectorLocationsKind.cpp +++ b/clang/lib/AST/SelectorLocationsKind.cpp @@ -27,7 +27,7 @@ if (EndLoc.isInvalid()) return SourceLocation(); IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0); - unsigned Len = II ? II->getLength() : 0; + int Len = II ? II->getLength() : 0; return EndLoc.getLocWithOffset(-Len); } @@ -35,7 +35,7 @@ if (ArgLoc.isInvalid()) return SourceLocation(); IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index); - unsigned Len = /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1; + int Len = /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1; if (WithArgSpace) ++Len; return ArgLoc.getLocWithOffset(-Len); diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -366,7 +366,7 @@ : Stmt(CompoundStmtClass), RBraceLoc(RB) { CompoundStmtBits.NumStmts = Stmts.size(); setStmts(Stmts); - CompoundStmtBits.LBraceLoc = LB; + setLBracLoc(LB); } void CompoundStmt::setStmts(ArrayRef Stmts) { @@ -1019,7 +1019,7 @@ SubExprs[COND] = Cond; SubExprs[INC] = Inc; SubExprs[BODY] = Body; - ForStmtBits.ForLoc = FL; + setForLoc(FL); } VarDecl *ForStmt::getConditionVariable() const { diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -51,7 +51,7 @@ "used in unions"); unsigned SourceLocation::getHashValue() const { - return llvm::DenseMapInfo::getHashValue(ID); + return llvm::DenseMapInfo::getHashValue(ID); } void llvm::FoldingSetTrait::Profile( diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -450,9 +450,9 @@ return LoadedSLocEntryTable[Index]; } -std::pair +std::pair SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries, - unsigned TotalSize) { + SourceLocation::UIntType TotalSize) { assert(ExternalSLocEntries && "Don't have an external sloc source"); // Make sure we're not about to run out of source locations. if (CurrentLoadedOffset - TotalSize < NextLocalOffset) @@ -532,7 +532,8 @@ FileID SourceManager::createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset) { + int LoadedID, + SourceLocation::UIntType LoadedOffset) { return createFileID(SourceFile->getLastRef(), IncludePos, FileCharacter, LoadedID, LoadedOffset); } @@ -540,7 +541,8 @@ FileID SourceManager::createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset) { + int LoadedID, + SourceLocation::UIntType LoadedOffset) { SrcMgr::ContentCache &IR = getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); @@ -559,7 +561,8 @@ /// MemoryBuffer, so only pass a MemoryBuffer to this once. FileID SourceManager::createFileID(std::unique_ptr Buffer, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset, + int LoadedID, + SourceLocation::UIntType LoadedOffset, SourceLocation IncludeLoc) { StringRef Name = Buffer->getBufferIdentifier(); return createFileIDImpl(createMemBufferContentCache(std::move(Buffer)), Name, @@ -572,7 +575,8 @@ /// outlive the SourceManager. FileID SourceManager::createFileID(const llvm::MemoryBufferRef &Buffer, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset, + int LoadedID, + SourceLocation::UIntType LoadedOffset, SourceLocation IncludeLoc) { return createFileID(llvm::MemoryBuffer::getMemBuffer(Buffer), FileCharacter, LoadedID, LoadedOffset, IncludeLoc); @@ -594,7 +598,8 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, - int LoadedID, unsigned LoadedOffset) { + int LoadedID, + SourceLocation::UIntType LoadedOffset) { if (LoadedID < 0) { assert(LoadedID != -1 && "Loading sentinel FileID"); unsigned Index = unsigned(-LoadedID) - 2; @@ -633,14 +638,11 @@ return createExpansionLocImpl(Info, TokLength); } -SourceLocation -SourceManager::createExpansionLoc(SourceLocation SpellingLoc, - SourceLocation ExpansionLocStart, - SourceLocation ExpansionLocEnd, - unsigned TokLength, - bool ExpansionIsTokenRange, - int LoadedID, - unsigned LoadedOffset) { +SourceLocation SourceManager::createExpansionLoc( + SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, + SourceLocation ExpansionLocEnd, unsigned TokLength, + bool ExpansionIsTokenRange, int LoadedID, + SourceLocation::UIntType LoadedOffset) { ExpansionInfo Info = ExpansionInfo::create( SpellingLoc, ExpansionLocStart, ExpansionLocEnd, ExpansionIsTokenRange); return createExpansionLocImpl(Info, TokLength, LoadedID, LoadedOffset); @@ -658,9 +660,8 @@ SourceLocation SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, - unsigned TokLength, - int LoadedID, - unsigned LoadedOffset) { + unsigned TokLength, int LoadedID, + SourceLocation::UIntType LoadedOffset) { if (LoadedID < 0) { assert(LoadedID != -1 && "Loading sentinel FileID"); unsigned Index = unsigned(-LoadedID) - 2; @@ -762,7 +763,7 @@ /// This is the cache-miss path of getFileID. Not as hot as that function, but /// still very important. It is responsible for finding the entry in the /// SLocEntry tables that contains the specified location. -FileID SourceManager::getFileIDSlow(unsigned SLocOffset) const { +FileID SourceManager::getFileIDSlow(SourceLocation::UIntType SLocOffset) const { if (!SLocOffset) return FileID::get(0); @@ -777,7 +778,8 @@ /// /// This function knows that the SourceLocation is in a local buffer, not a /// loaded one. -FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const { +FileID +SourceManager::getFileIDLocal(SourceLocation::UIntType SLocOffset) const { assert(SLocOffset < NextLocalOffset && "Bad function choice"); // After the first and second level caches, I see two common sorts of @@ -828,7 +830,8 @@ NumProbes = 0; while (true) { unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex; - unsigned MidOffset = getLocalSLocEntry(MiddleIndex).getOffset(); + SourceLocation::UIntType MidOffset = + getLocalSLocEntry(MiddleIndex).getOffset(); ++NumProbes; @@ -859,7 +862,8 @@ /// /// This function knows that the SourceLocation is in a loaded buffer, not a /// local one. -FileID SourceManager::getFileIDLoaded(unsigned SLocOffset) const { +FileID +SourceManager::getFileIDLoaded(SourceLocation::UIntType SLocOffset) const { // Sanity checking, otherwise a bug may lead to hanging in release build. if (SLocOffset < CurrentLoadedOffset) { assert(0 && "Invalid SLocOffset or bad function choice"); @@ -1619,7 +1623,7 @@ return 0; int ID = FID.ID; - unsigned NextOffset; + SourceLocation::UIntType NextOffset; if ((ID > 0 && unsigned(ID+1) == local_sloc_entry_size())) NextOffset = getNextLocalOffset(); else if (ID+1 == -1) @@ -1827,8 +1831,8 @@ SourceLocation ExpansionLoc, unsigned ExpansionLength) const { if (!SpellLoc.isFileID()) { - unsigned SpellBeginOffs = SpellLoc.getOffset(); - unsigned SpellEndOffs = SpellBeginOffs + ExpansionLength; + SourceLocation::UIntType SpellBeginOffs = SpellLoc.getOffset(); + SourceLocation::UIntType SpellEndOffs = SpellBeginOffs + ExpansionLength; // The spelling range for this macro argument expansion can span multiple // consecutive FileID entries. Go through each entry contained in the @@ -1840,9 +1844,10 @@ std::tie(SpellFID, SpellRelativeOffs) = getDecomposedLoc(SpellLoc); while (true) { const SLocEntry &Entry = getSLocEntry(SpellFID); - unsigned SpellFIDBeginOffs = Entry.getOffset(); + SourceLocation::UIntType SpellFIDBeginOffs = Entry.getOffset(); unsigned SpellFIDSize = getFileIDSize(SpellFID); - unsigned SpellFIDEndOffs = SpellFIDBeginOffs + SpellFIDSize; + SourceLocation::UIntType SpellFIDEndOffs = + SpellFIDBeginOffs + SpellFIDSize; const ExpansionInfo &Info = Entry.getExpansion(); if (Info.isMacroArgExpansion()) { unsigned CurrSpellLength; @@ -1934,7 +1939,7 @@ --I; - unsigned MacroArgBeginOffs = I->first; + SourceLocation::UIntType MacroArgBeginOffs = I->first; SourceLocation MacroArgExpandedLoc = I->second; if (MacroArgExpandedLoc.isValid()) return MacroArgExpandedLoc.getLocWithOffset(Offset - MacroArgBeginOffs); @@ -2154,7 +2159,7 @@ llvm::raw_ostream &out = llvm::errs(); auto DumpSLocEntry = [&](int ID, const SrcMgr::SLocEntry &Entry, - llvm::Optional NextStart) { + llvm::Optional NextStart) { out << "SLocEntry " << (Entry.isFile() ? "file" : "expansion") << " NextStart; + llvm::Optional NextStart; for (unsigned Index = 0; Index != LoadedSLocEntryTable.size(); ++Index) { int ID = -(int)Index - 2; if (SLocEntryLoaded[Index]) { diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -12021,13 +12021,14 @@ // Cleanup action for allocate support. class OMPAllocateCleanupTy final : public EHScopeStack::Cleanup { llvm::FunctionCallee RTLFn; - unsigned LocEncoding; + SourceLocation::UIntType LocEncoding; Address Addr; const Expr *Allocator; public: - OMPAllocateCleanupTy(llvm::FunctionCallee RTLFn, unsigned LocEncoding, - Address Addr, const Expr *Allocator) + OMPAllocateCleanupTy(llvm::FunctionCallee RTLFn, + SourceLocation::UIntType LocEncoding, Address Addr, + const Expr *Allocator) : RTLFn(RTLFn), LocEncoding(LocEncoding), Addr(Addr), Allocator(Allocator) {} void Emit(CodeGenFunction &CGF, Flags /*flags*/) override { diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -2120,7 +2120,7 @@ SmallVector Locs; // Add the location of the first line to the MDNode. Locs.push_back(llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( - CGF.Int32Ty, Str->getBeginLoc().getRawEncoding()))); + CGF.Int64Ty, Str->getBeginLoc().getRawEncoding()))); StringRef StrVal = Str->getString(); if (!StrVal.empty()) { const SourceManager &SM = CGF.CGM.getContext().getSourceManager(); @@ -2135,7 +2135,7 @@ SourceLocation LineLoc = Str->getLocationOfByte( i + 1, SM, LangOpts, CGF.getTarget(), &StartToken, &ByteOffset); Locs.push_back(llvm::ConstantAsMetadata::get( - llvm::ConstantInt::get(CGF.Int32Ty, LineLoc.getRawEncoding()))); + llvm::ConstantInt::get(CGF.Int64Ty, LineLoc.getRawEncoding()))); } } @@ -2172,8 +2172,8 @@ getAsmSrcLocInfo(gccAsmStmt->getAsmString(), CGF)); else { // At least put the line number on MS inline asm blobs. - llvm::Constant *Loc = llvm::ConstantInt::get(CGF.Int32Ty, - S.getAsmLoc().getRawEncoding()); + llvm::Constant *Loc = + llvm::ConstantInt::get(CGF.Int64Ty, S.getAsmLoc().getRawEncoding()); Result.setMetadata("srcloc", llvm::MDNode::get(CGF.getLLVMContext(), llvm::ConstantAsMetadata::get(Loc))); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -233,7 +233,7 @@ /// Return the start location of an included file or expanded macro. SourceLocation getStartOfFileOrMacro(SourceLocation Loc) { if (Loc.isMacroID()) - return Loc.getLocWithOffset(-SM.getFileOffset(Loc)); + return Loc.getLocWithOffset(-(int)SM.getFileOffset(Loc)); return SM.getLocForStartOfFile(SM.getFileID(Loc)); } diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -830,7 +830,7 @@ FormatTok = new (Allocator.Allocate()) FormatToken; readRawToken(*FormatTok); SourceLocation WhitespaceStart = - FormatTok->Tok.getLocation().getLocWithOffset(-TrailingWhitespace); + FormatTok->Tok.getLocation().getLocWithOffset(-(int)TrailingWhitespace); FormatTok->IsFirst = IsFirstToken; IsFirstToken = false; diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -527,7 +527,7 @@ return Loc; // Create a lexer starting at the beginning of this token. - SourceLocation LexerStartLoc = Loc.getLocWithOffset(-LocInfo.second); + SourceLocation LexerStartLoc = Loc.getLocWithOffset(-(int)LocInfo.second); Lexer TheLexer(LexerStartLoc, LangOpts, Buffer.data(), LexStart, Buffer.end()); TheLexer.SetCommentRetentionState(true); @@ -570,7 +570,8 @@ SM.getDecomposedLoc(BeginFileLoc); assert(FileLocInfo.first == BeginFileLocInfo.first && FileLocInfo.second >= BeginFileLocInfo.second); - return Loc.getLocWithOffset(BeginFileLocInfo.second - FileLocInfo.second); + return Loc.getLocWithOffset( + (int)(BeginFileLocInfo.second - FileLocInfo.second)); } namespace { @@ -588,7 +589,7 @@ // Create a lexer starting at the beginning of the file. Note that we use a // "fake" file source location at offset 1 so that the lexer will track our // position within the file. - const unsigned StartOffset = 1; + const SourceLocation::UIntType StartOffset = 1; SourceLocation FileLoc = SourceLocation::getFromRawEncoding(StartOffset); Lexer TheLexer(FileLoc, LangOpts, Buffer.begin(), Buffer.begin(), Buffer.end()); @@ -716,8 +717,9 @@ else End = TheTok.getLocation(); - return PreambleBounds(End.getRawEncoding() - FileLoc.getRawEncoding(), - TheTok.isAtStartOfLine()); + return PreambleBounds( + (unsigned)(End.getRawEncoding() - FileLoc.getRawEncoding()), + TheTok.isAtStartOfLine()); } unsigned Lexer::getTokenPrefixLength(SourceLocation TokStart, unsigned CharNo, diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1378,7 +1378,7 @@ RSquare } Kind; - unsigned Location; + SourceLocation::UIntType Location; unsigned StringLength; union { // If Kind != IntegerLiteral. diff --git a/clang/lib/Lex/PPCaching.cpp b/clang/lib/Lex/PPCaching.cpp --- a/clang/lib/Lex/PPCaching.cpp +++ b/clang/lib/Lex/PPCaching.cpp @@ -145,7 +145,7 @@ if (LastCachedTok.getKind() != Tok.getKind()) return false; - int RelOffset = 0; + SourceLocation::IntType RelOffset = 0; if ((!getSourceManager().isInSameSLocAddrSpace( Tok.getLocation(), getLastCachedTokenLocation(), &RelOffset)) || RelOffset) diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -971,7 +971,7 @@ assert(SM.isInSLocAddrSpace(loc, MacroDefStart, MacroDefLength) && "Expected loc to come from the macro definition"); - unsigned relativeOffset = 0; + SourceLocation::UIntType relativeOffset = 0; SM.isInSLocAddrSpace(loc, MacroDefStart, MacroDefLength, &relativeOffset); return MacroExpansionStart.getLocWithOffset(relativeOffset); } @@ -1010,7 +1010,7 @@ if (CurLoc.isFileID() != NextLoc.isFileID()) break; // Token from different kind of FileID. - int RelOffs; + SourceLocation::IntType RelOffs; if (!SM.isInSameSLocAddrSpace(CurLoc, NextLoc, &RelOffs)) break; // Token from different local/loaded location. // Check that token is not before the previous token or more than 50 @@ -1027,10 +1027,11 @@ // For the consecutive tokens, find the length of the SLocEntry to contain // all of them. Token &LastConsecutiveTok = *(NextTok-1); - int LastRelOffs = 0; + SourceLocation::IntType LastRelOffs = 0; SM.isInSameSLocAddrSpace(FirstLoc, LastConsecutiveTok.getLocation(), &LastRelOffs); - unsigned FullLength = LastRelOffs + LastConsecutiveTok.getLength(); + SourceLocation::UIntType FullLength = + LastRelOffs + LastConsecutiveTok.getLength(); // Create a macro expansion SLocEntry that will "contain" all of the tokens. SourceLocation Expansion = @@ -1040,7 +1041,7 @@ // expanded location. for (; begin_tokens < NextTok; ++begin_tokens) { Token &Tok = *begin_tokens; - int RelOffs = 0; + SourceLocation::IntType RelOffs = 0; SM.isInSameSLocAddrSpace(FirstLoc, Tok.getLocation(), &RelOffs); Tok.setLocation(Expansion.getLocWithOffset(RelOffs)); } diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -185,7 +185,7 @@ if (TokIndex < AsmToks.size()) { const Token &Tok = AsmToks[TokIndex]; Loc = Tok.getLocation(); - Loc = Loc.getLocWithOffset(Offset - TokOffset); + Loc = Loc.getLocWithOffset((int)(Offset - TokOffset)); } return Loc; } @@ -633,7 +633,7 @@ SmallVector, 4> OpExprs; SmallVector Constraints; SmallVector Clobbers; - if (Parser->parseMSInlineAsm(AsmLoc.getPtrEncoding(), AsmStringIR, NumOutputs, + if (Parser->parseMSInlineAsm(AsmLoc.getRawEncoding(), AsmStringIR, NumOutputs, NumInputs, OpExprs, Constraints, Clobbers, MII.get(), IP.get(), Callback)) return StmtError(); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1480,7 +1480,7 @@ } BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; - unsigned BaseOffset = F->SLocEntryBaseOffset; + SourceLocation::UIntType BaseOffset = F->SLocEntryBaseOffset; ++NumSLocEntriesRead; Expected MaybeEntry = SLocEntryCursor.advance(); @@ -3402,7 +3402,7 @@ case SOURCE_LOCATION_OFFSETS: { F.SLocEntryOffsets = (const uint32_t *)Blob.data(); F.LocalNumSLocEntries = Record[0]; - unsigned SLocSpaceSize = Record[1]; + SourceLocation::UIntType SLocSpaceSize = Record[1]; F.SLocEntryOffsetsBase = Record[2] + F.SourceManagerBlockStartOffset; std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, @@ -3420,7 +3420,7 @@ F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. - assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); + assert((F.SLocEntryBaseOffset & SourceLocation::MacroIDBit) == 0); GlobalSLocOffsetMap.insert( std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset - SLocSpaceSize,&F)); @@ -3429,8 +3429,8 @@ // Invalid stays invalid. F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); // This module. Base was 2 when being compiled. - F.SLocRemap.insertOrReplace(std::make_pair(2U, - static_cast(F.SLocEntryBaseOffset - 2))); + F.SLocRemap.insertOrReplace(std::make_pair( + 2U, static_cast(F.SLocEntryBaseOffset - 2))); TotalNumSLocEntries += F.LocalNumSLocEntries; break; @@ -3831,8 +3831,11 @@ } // Continuous range maps we may be updating in our module. + using SLocRemapBuilder = + ContinuousRangeMap::Builder; using RemapBuilder = ContinuousRangeMap::Builder; - RemapBuilder SLocRemap(F.SLocRemap); + SLocRemapBuilder SLocRemap(F.SLocRemap); RemapBuilder IdentifierRemap(F.IdentifierRemap); RemapBuilder MacroRemap(F.MacroRemap); RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); @@ -3863,8 +3866,7 @@ return; } - uint32_t SLocOffset = - endian::readNext(Data); + uint64_t SLocOffset = endian::readNext(Data); uint32_t IdentifierIDOffset = endian::readNext(Data); uint32_t MacroIDOffset = @@ -3880,15 +3882,30 @@ uint32_t TypeIndexOffset = endian::readNext(Data); - uint32_t None = std::numeric_limits::max(); + // SourceLocations are serialized as uint64_t, irrespective of + // CLANG_64_BIT_SOURCE_LOCATIONS. So we have to bounds-check them + // when reading back in. + if (SLocOffset > std::numeric_limits::max()) { + Error("This version of clang cannot handle SourceLocations bigger than " + "32 bits"); + return; + } auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, RemapBuilder &Remap) { + constexpr uint32_t None = std::numeric_limits::max(); if (Offset != None) Remap.insert(std::make_pair(Offset, static_cast(BaseOffset - Offset))); }; - mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); + + constexpr SourceLocation::UIntType SLocNone = + std::numeric_limits::max(); + if (SLocOffset != SLocNone) + SLocRemap.insert(std::make_pair( + SLocOffset, static_cast( + OM->SLocEntryBaseOffset - SLocOffset))); + mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -156,7 +156,7 @@ while (NumStmts--) Stmts.push_back(Record.readSubStmt()); S->setStmts(Stmts); - S->CompoundStmtBits.LBraceLoc = readSourceLocation(); + S->setLBracLoc(readSourceLocation()); S->RBraceLoc = readSourceLocation(); } @@ -207,7 +207,7 @@ assert(NumAttrs == Attrs.size()); std::copy(Attrs.begin(), Attrs.end(), S->getAttrArrayPtr()); S->SubStmt = Record.readSubStmt(); - S->AttributedStmtBits.AttrLoc = readSourceLocation(); + S->setAttrLoc(readSourceLocation()); } void ASTStmtReader::VisitIfStmt(IfStmt *S) { @@ -838,7 +838,7 @@ VisitExpr(E); unsigned NumLocalParameters = Record.readInt(); unsigned NumRequirements = Record.readInt(); - E->RequiresExprBits.RequiresKWLoc = Record.readSourceLocation(); + E->setRequiresKWLoc(Record.readSourceLocation()); E->RequiresExprBits.IsSatisfied = Record.readInt(); E->Body = Record.readDeclAs(); llvm::SmallVector LocalParameters; @@ -1041,7 +1041,7 @@ E->MemberExprBits.HasTemplateKWAndArgsInfo = HasTemplateInfo; E->MemberExprBits.HadMultipleCandidates = Record.readInt(); E->MemberExprBits.NonOdrUseReason = Record.readInt(); - E->MemberExprBits.OperatorLoc = Record.readSourceLocation(); + E->setOperatorLoc(Record.readSourceLocation()); if (HasQualifier || HasFoundDecl) { DeclAccessPair FoundDecl; @@ -1364,7 +1364,7 @@ unsigned NumAssocs = Record.readInt(); assert(NumAssocs == E->getNumAssocs() && "Wrong NumAssocs!"); E->ResultIndex = Record.readInt(); - E->GenericSelectionExprBits.GenericLoc = readSourceLocation(); + E->setGenericLoc(readSourceLocation()); E->DefaultLoc = readSourceLocation(); E->RParenLoc = readSourceLocation(); @@ -1709,7 +1709,7 @@ E->CXXConstructExprBits.StdInitListInitialization = Record.readInt(); E->CXXConstructExprBits.ZeroInitialization = Record.readInt(); E->CXXConstructExprBits.ConstructionKind = Record.readInt(); - E->CXXConstructExprBits.Loc = readSourceLocation(); + E->setLocation(readSourceLocation()); E->Constructor = readDeclAs(); E->ParenOrBraceRange = readSourceRange(); @@ -1832,7 +1832,7 @@ void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) { VisitExpr(E); - E->CXXThrowExprBits.ThrowLoc = readSourceLocation(); + E->setThrowLoc(readSourceLocation()); E->Operand = Record.readSubExpr(); E->CXXThrowExprBits.IsThrownVariableInScope = Record.readInt(); } @@ -1841,14 +1841,14 @@ VisitExpr(E); E->Param = readDeclAs(); E->UsedContext = readDeclAs(); - E->CXXDefaultArgExprBits.Loc = readSourceLocation(); + E->setUsedLocation(readSourceLocation()); } void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { VisitExpr(E); E->Field = readDeclAs(); E->UsedContext = readDeclAs(); - E->CXXDefaultInitExprBits.Loc = readSourceLocation(); + E->setUsedLocation(readSourceLocation()); } void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { @@ -1860,7 +1860,7 @@ void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { VisitExpr(E); E->TypeInfo = readTypeSourceInfo(); - E->CXXScalarValueInitExprBits.RParenLoc = readSourceLocation(); + E->setRParenLoc(readSourceLocation()); } void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) { @@ -1908,7 +1908,7 @@ E->CXXDeleteExprBits.UsualArrayDeleteWantsSize = Record.readInt(); E->OperatorDelete = readDeclAs(); E->Argument = Record.readSubExpr(); - E->CXXDeleteExprBits.Loc = readSourceLocation(); + E->setLocation(readSourceLocation()); } void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { @@ -1973,7 +1973,7 @@ "Wrong NumTemplateArgs!"); E->CXXDependentScopeMemberExprBits.IsArrow = Record.readInt(); - E->CXXDependentScopeMemberExprBits.OperatorLoc = readSourceLocation(); + E->setOperatorLoc(readSourceLocation()); E->BaseType = Record.readType(); E->QualifierLoc = Record.readNestedNameSpecifierLoc(); E->Base = Record.readSubExpr(); @@ -2134,7 +2134,7 @@ VisitExpr(E); E->ParamAndRef.setPointer(readDeclAs()); E->ParamAndRef.setInt(Record.readInt()); - E->SubstNonTypeTemplateParmExprBits.NameLoc = readSourceLocation(); + E->setNameLoc(readSourceLocation()); E->Replacement = Record.readSubExpr(); } @@ -2185,7 +2185,7 @@ void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) { VisitExpr(E); E->SourceExpr = Record.readSubExpr(); - E->OpaqueValueExprBits.Loc = readSourceLocation(); + E->setLocation(readSourceLocation()); E->setIsUnique(Record.readInt()); } diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2041,7 +2041,7 @@ Record.push_back(Expansion.isExpansionTokenRange()); // Compute the token length for this macro expansion. - unsigned NextOffset = SourceMgr.getNextLocalOffset(); + SourceLocation::UIntType NextOffset = SourceMgr.getNextLocalOffset(); if (I + 1 != N) NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); Record.push_back(NextOffset - SLoc->getOffset() - 1); @@ -4607,7 +4607,7 @@ // The map consists solely of a blob with the following format: // *(module-kind:i8 // module-name-len:i16 module-name:len*i8 - // source-location-offset:i32 + // source-location-offset:i32/i64 // identifier-id:i32 // preprocessed-entity-id:i32 // macro-definition-id:i32 @@ -4636,21 +4636,29 @@ LE.write(Name.size()); Out.write(Name.data(), Name.size()); - // Note: if a base ID was uint max, it would not be possible to load - // another module after it or have more than one entity inside it. - uint32_t None = std::numeric_limits::max(); - - auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { - assert(BaseID < std::numeric_limits::max() && "base id too high"); + auto writeBaseIDOrNone = [&](auto BaseID, bool ShouldWrite) { + using T = decltype(BaseID); + static_assert(std::is_same::value || + std::is_same::value, + "Invalid BaseID type"); + assert(BaseID < std::numeric_limits::max() && "base id too high"); if (ShouldWrite) - LE.write(BaseID); - else - LE.write(None); + LE.write(BaseID); + else { + // Note: if a base ID was uint max, it would not be possible to load + // another module after it or have more than one entity inside it. + constexpr T None = std::numeric_limits::max(); + LE.write(None); + } }; // These values should be unique within a chain, since they will be read // as keys into ContinuousRangeMaps. - writeBaseIDOrNone(M.SLocEntryBaseOffset, M.LocalNumSLocEntries); + + // SourceLocations are serialized as uint64_t, irrespective of + // CLANG_64_BIT_SOURCE_LOCATIONS + writeBaseIDOrNone(static_cast(M.SLocEntryBaseOffset), + M.LocalNumSLocEntries); writeBaseIDOrNone(M.BaseIdentifierID, M.LocalNumIdentifiers); writeBaseIDOrNone(M.BaseMacroID, M.LocalNumMacros); writeBaseIDOrNone(M.BasePreprocessedEntityID, @@ -5027,8 +5035,8 @@ } void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { - uint32_t Raw = Loc.getRawEncoding(); - Record.push_back((Raw << 1) | (Raw >> 31)); + SourceLocation::UIntType Raw = Loc.getRawEncoding(); + Record.push_back((Raw << 1) | (Raw >> (8 * sizeof(Raw) - 1))); } void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -450,7 +450,7 @@ VisitExpr(E); Record.push_back(E->getLocalParameters().size()); Record.push_back(E->getRequirements().size()); - Record.AddSourceLocation(E->RequiresExprBits.RequiresKWLoc); + Record.AddSourceLocation(E->getRequiresKWLoc()); Record.push_back(E->RequiresExprBits.IsSatisfied); Record.AddDeclRef(E->getBody()); for (ParmVarDecl *P : E->getLocalParameters()) diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp --- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -1082,7 +1082,7 @@ // selected range. SourceLocation E = - InstantiationEnd.getLocWithOffset(EndColNo - OldEndColNo); + InstantiationEnd.getLocWithOffset((int)(EndColNo - OldEndColNo)); html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd); } diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -14,6 +14,7 @@ CLANG_ENABLE_ARCMT CLANG_ENABLE_STATIC_ANALYZER CLANG_SPAWN_CC1 + CLANG_64_BIT_SOURCE_LOCATIONS ENABLE_BACKTRACES LLVM_ENABLE_NEW_PASS_MANAGER LLVM_ENABLE_ZLIB diff --git a/clang/test/Lexer/SourceLocationsOverflow.c b/clang/test/Lexer/SourceLocationsOverflow.c --- a/clang/test/Lexer/SourceLocationsOverflow.c +++ b/clang/test/Lexer/SourceLocationsOverflow.c @@ -1,4 +1,6 @@ // RUN: not %clang %s -S -o - 2>&1 | FileCheck %s +// UNSUPPORTED: clang-64-bit-source-locations + // CHECK: In file included from {{.*}}SourceLocationsOverflow.c // CHECK-NEXT: inc1.h{{.*}}: fatal error: sorry, this include generates a translation unit too large for Clang to process. // CHECK-NEXT: #include "inc2.h" diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -222,6 +222,9 @@ if config.enable_threads: config.available_features.add('thread_support') +if config.clang_64_bit_source_locations: + config.available_features.add('clang-64-bit-source-locations') + # Check if we should allow outputs to console. run_console_tests = int(lit_config.params.get('enable_console', '0')) if run_console_tests != 0: diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in --- a/clang/test/lit.site.cfg.py.in +++ b/clang/test/lit.site.cfg.py.in @@ -24,6 +24,7 @@ config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@ config.clang_staticanalyzer_z3 = "@LLVM_WITH_Z3@" config.clang_examples = @CLANG_BUILD_EXAMPLES@ +config.clang_64_bit_source_locations = @CLANG_64_BIT_SOURCE_LOCATIONS@ config.enable_shared = @ENABLE_SHARED@ config.enable_backtrace = @ENABLE_BACKTRACES@ config.enable_experimental_new_pass_manager = @LLVM_ENABLE_NEW_PASS_MANAGER@ diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -159,15 +159,20 @@ EndLoc = EndLoc.getLocWithOffset(Length); } - CXSourceRange Result = { - {&SM, &LangOpts}, R.getBegin().getRawEncoding(), EndLoc.getRawEncoding()}; + uint32_t BeginRaw, EndRaw; + if (!R.getBegin().getRawEncoding32(BeginRaw) || + !EndLoc.getRawEncoding32(EndRaw)) + return clang_getNullRange(); // location is too big for libclang ABI + CXSourceRange Result = {{&SM, &LangOpts}, + static_cast(BeginRaw), + static_cast(EndRaw)}; return Result; } CharSourceRange cxloc::translateCXRangeToCharRange(CXSourceRange R) { return CharSourceRange::getCharRange( - SourceLocation::getFromRawEncoding(R.begin_int_data), - SourceLocation::getFromRawEncoding(R.end_int_data)); + SourceLocation::getFromRawEncoding32(R.begin_int_data), + SourceLocation::getFromRawEncoding32(R.end_int_data)); } //===----------------------------------------------------------------------===// @@ -1982,7 +1987,8 @@ return static_cast(data[0]); } SourceLocation getLoc() const { - return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)data[1]); + return SourceLocation::getFromRawEncoding32( + (SourceLocation::UIntType)(uintptr_t)data[1]); } }; class EnqueueVisitor : public ConstStmtVisitor { @@ -6823,7 +6829,7 @@ if (!CXXUnit) return cxstring::createEmpty(); - SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]); + SourceLocation Loc = SourceLocation::getFromRawEncoding32(CXTok.int_data[1]); std::pair LocInfo = CXXUnit->getSourceManager().getDecomposedSpellingLoc(Loc); bool Invalid = false; @@ -6847,7 +6853,7 @@ return cxloc::translateSourceLocation( CXXUnit->getASTContext(), - SourceLocation::getFromRawEncoding(CXTok.int_data[1])); + SourceLocation::getFromRawEncoding32(CXTok.int_data[1])); } CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) { @@ -6862,10 +6868,10 @@ return cxloc::translateSourceRange( CXXUnit->getASTContext(), - SourceLocation::getFromRawEncoding(CXTok.int_data[1])); + SourceLocation::getFromRawEncoding32(CXTok.int_data[1])); } -static void getTokens(ASTUnit *CXXUnit, SourceRange Range, +static bool getTokens(ASTUnit *CXXUnit, SourceRange Range, SmallVectorImpl &CXTokens) { SourceManager &SourceMgr = CXXUnit->getSourceManager(); std::pair BeginLocInfo = @@ -6875,13 +6881,13 @@ // Cannot tokenize across files. if (BeginLocInfo.first != EndLocInfo.first) - return; + return false; // Create a lexer bool Invalid = false; StringRef Buffer = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid); if (Invalid) - return; + return false; Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first), CXXUnit->getASTContext().getLangOpts(), Buffer.begin(), @@ -6902,7 +6908,10 @@ CXToken CXTok; // - Common fields - CXTok.int_data[1] = Tok.getLocation().getRawEncoding(); + uint32_t TokLocRaw; + if (!Tok.getLocation().getRawEncoding32(TokLocRaw)) + return false; // location is too big for libclang ABI + CXTok.int_data[1] = TokLocRaw; CXTok.int_data[2] = Tok.getLength(); CXTok.int_data[3] = 0; @@ -6931,6 +6940,8 @@ CXTokens.push_back(CXTok); previousWasAt = Tok.is(tok::at); } while (Lex.getBufferLocation() < EffectiveBufferEnd); + + return true; } CXToken *clang_getToken(CXTranslationUnit TU, CXSourceLocation Location) { @@ -6957,7 +6968,8 @@ SM.getComposedLoc(DecomposedEnd.first, DecomposedEnd.second); SmallVector CXTokens; - getTokens(CXXUnit, SourceRange(Begin, End), CXTokens); + if (!getTokens(CXXUnit, SourceRange(Begin, End), CXTokens)) + return NULL; if (CXTokens.empty()) return NULL; @@ -6994,7 +7006,8 @@ return; SmallVector CXTokens; - getTokens(CXXUnit, R, CXTokens); + if (!getTokens(CXXUnit, R, CXTokens)) + return; if (CXTokens.empty()) return; @@ -7058,13 +7071,13 @@ unsigned NextToken() const { return TokIdx; } void AdvanceToken() { ++TokIdx; } SourceLocation GetTokenLoc(unsigned tokI) { - return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]); + return SourceLocation::getFromRawEncoding32(getTok(tokI).int_data[1]); } bool isFunctionMacroToken(unsigned tokI) const { return getTok(tokI).int_data[3] != 0; } SourceLocation getFunctionMacroTokenLoc(unsigned tokI) const { - return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[3]); + return SourceLocation::getFromRawEncoding32(getTok(tokI).int_data[3]); } void annotateAndAdvanceTokens(CXCursor, RangeComparisonResult, SourceRange); @@ -7559,13 +7572,16 @@ } SourceLocation getTokenLoc(unsigned tokI) { - return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]); + return SourceLocation::getFromRawEncoding32(getTok(tokI).int_data[1]); } void setFunctionMacroTokenLoc(unsigned tokI, SourceLocation loc) { // The third field is reserved and currently not used. Use it here // to mark macro arg expanded tokens with their expanded locations. - getTok(tokI).int_data[3] = loc.getRawEncoding(); + uint32_t Raw; + if (!loc.getRawEncoding32(Raw)) + Raw = 0; // invalid source location + getTok(tokI).int_data[3] = Raw; } }; @@ -7626,7 +7642,7 @@ break; unsigned TokIdx = NextIdx - 1; assert(Tok.getLocation() == - SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1])); + SourceLocation::getFromRawEncoding32(Tokens[TokIdx].int_data[1])); reprocess: if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) { @@ -7677,7 +7693,7 @@ unsigned LastIdx = finished ? NextIdx - 1 : NextIdx - 2; assert(TokIdx <= LastIdx); SourceLocation EndLoc = - SourceLocation::getFromRawEncoding(Tokens[LastIdx].int_data[1]); + SourceLocation::getFromRawEncoding32(Tokens[LastIdx].int_data[1]); CXCursor Cursor = MakePreprocessingDirectiveCursor(SourceRange(BeginLoc, EndLoc), TU); diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -989,8 +989,8 @@ const CXIdxBaseClassInfo *baseInfo = BaseList.getBases()[i]; if (baseInfo->base) { const NamedDecl *BaseD = BaseList.BaseEntities[i].Dcl; - SourceLocation - Loc = SourceLocation::getFromRawEncoding(baseInfo->loc.int_data); + SourceLocation Loc = + SourceLocation::getFromRawEncoding32(baseInfo->loc.int_data); markEntityOccurrenceInFile(BaseD, Loc); } } @@ -1093,8 +1093,12 @@ if (Loc.isInvalid()) return idxLoc; + uint32_t LocRaw; + if (!Loc.getRawEncoding32(LocRaw)) + return idxLoc; + idxLoc.ptr_data[0] = const_cast(this); - idxLoc.int_data = Loc.getRawEncoding(); + idxLoc.int_data = LocRaw; return idxLoc; } diff --git a/clang/tools/libclang/CXSourceLocation.h b/clang/tools/libclang/CXSourceLocation.h --- a/clang/tools/libclang/CXSourceLocation.h +++ b/clang/tools/libclang/CXSourceLocation.h @@ -31,11 +31,14 @@ if (Loc.isInvalid()) return clang_getNullLocation(); - CXSourceLocation Result = { { &SM, &LangOpts, }, - Loc.getRawEncoding() }; + uint32_t LocRaw; + if (!Loc.getRawEncoding32(LocRaw)) + return clang_getNullLocation(); // location is too big for libclang ABI + + CXSourceLocation Result = {{&SM, &LangOpts}, static_cast(LocRaw)}; return Result; } - + /// Translate a Clang source location into a CIndex source location. static inline CXSourceLocation translateSourceLocation(ASTContext &Context, SourceLocation Loc) { @@ -63,12 +66,12 @@ } static inline SourceLocation translateSourceLocation(CXSourceLocation L) { - return SourceLocation::getFromRawEncoding(L.int_data); + return SourceLocation::getFromRawEncoding32(L.int_data); } static inline SourceRange translateCXSourceRange(CXSourceRange R) { - return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data), - SourceLocation::getFromRawEncoding(R.end_int_data)); + return SourceRange(SourceLocation::getFromRawEncoding32(R.begin_int_data), + SourceLocation::getFromRawEncoding32(R.end_int_data)); } /// Translates CXSourceRange to CharSourceRange. diff --git a/clang/tools/libclang/CXSourceLocation.cpp b/clang/tools/libclang/CXSourceLocation.cpp --- a/clang/tools/libclang/CXSourceLocation.cpp +++ b/clang/tools/libclang/CXSourceLocation.cpp @@ -199,7 +199,7 @@ int clang_Location_isInSystemHeader(CXSourceLocation location) { const SourceLocation Loc = - SourceLocation::getFromRawEncoding(location.int_data); + SourceLocation::getFromRawEncoding32(location.int_data); if (Loc.isInvalid()) return 0; @@ -210,7 +210,7 @@ int clang_Location_isFromMainFile(CXSourceLocation location) { const SourceLocation Loc = - SourceLocation::getFromRawEncoding(location.int_data); + SourceLocation::getFromRawEncoding32(location.int_data); if (Loc.isInvalid()) return 0; @@ -229,7 +229,7 @@ return; } - SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); + SourceLocation Loc = SourceLocation::getFromRawEncoding32(location.int_data); if (!location.ptr_data[0] || Loc.isInvalid()) { createNullLocation(file, line, column, offset); @@ -271,7 +271,7 @@ return; } - SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); + SourceLocation Loc = SourceLocation::getFromRawEncoding32(location.int_data); if (!location.ptr_data[0] || Loc.isInvalid()) { createNullLocation(filename, line, column); @@ -310,9 +310,9 @@ column, offset); return; } - - SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); - + + SourceLocation Loc = SourceLocation::getFromRawEncoding32(location.int_data); + if (!location.ptr_data[0] || Loc.isInvalid()) return createNullLocation(file, line, column, offset); @@ -348,7 +348,7 @@ return; } - SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); + SourceLocation Loc = SourceLocation::getFromRawEncoding32(location.int_data); if (!location.ptr_data[0] || Loc.isInvalid()) return createNullLocation(file, line, column, offset); diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -977,7 +977,7 @@ if (column) *column = 0; if (offset) *offset = 0; - SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); + SourceLocation Loc = SourceLocation::getFromRawEncoding32(location.int_data); if (!location.ptr_data[0] || Loc.isInvalid()) return; @@ -987,7 +987,7 @@ } CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc location) { - SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); + SourceLocation Loc = SourceLocation::getFromRawEncoding32(location.int_data); if (!location.ptr_data[0] || Loc.isInvalid()) return clang_getNullLocation(); diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h --- a/llvm/include/llvm/IR/DiagnosticInfo.h +++ b/llvm/include/llvm/IR/DiagnosticInfo.h @@ -131,7 +131,7 @@ class DiagnosticInfoInlineAsm : public DiagnosticInfo { private: /// Optional line information. 0 if not set. - unsigned LocCookie = 0; + uint64_t LocCookie = 0; /// Message to be reported. const Twine &MsgStr; /// Optional origin of the problem. @@ -149,7 +149,7 @@ /// \p MsgStr gives the message. /// This class does not copy \p MsgStr, therefore the reference must be valid /// for the whole life time of the Diagnostic. - DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr, + DiagnosticInfoInlineAsm(uint64_t LocCookie, const Twine &MsgStr, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie), MsgStr(MsgStr) {} @@ -162,7 +162,7 @@ DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr, DiagnosticSeverity Severity = DS_Error); - unsigned getLocCookie() const { return LocCookie; } + uint64_t getLocCookie() const { return LocCookie; } const Twine &getMsgStr() const { return MsgStr; } const Instruction *getInstruction() const { return Instr; } diff --git a/llvm/include/llvm/IR/LLVMContext.h b/llvm/include/llvm/IR/LLVMContext.h --- a/llvm/include/llvm/IR/LLVMContext.h +++ b/llvm/include/llvm/IR/LLVMContext.h @@ -290,7 +290,7 @@ /// be prepared to drop the erroneous construct on the floor and "not crash". /// The generated code need not be correct. The error message will be /// implicitly prefixed with "error: " and should not end with a ".". - void emitError(unsigned LocCookie, const Twine &ErrorStr); + void emitError(uint64_t LocCookie, const Twine &ErrorStr); void emitError(const Instruction *I, const Twine &ErrorStr); void emitError(const Twine &ErrorStr); diff --git a/llvm/include/llvm/MC/MCParser/MCAsmParser.h b/llvm/include/llvm/MC/MCParser/MCAsmParser.h --- a/llvm/include/llvm/MC/MCParser/MCAsmParser.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmParser.h @@ -202,7 +202,7 @@ /// Parse MS-style inline assembly. virtual bool parseMSInlineAsm( - void *AsmLoc, std::string &AsmString, unsigned &NumOutputs, + uint64_t AsmLoc, std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, SmallVectorImpl> &OpDecls, SmallVectorImpl &Constraints, SmallVectorImpl &Clobbers, const MCInstrInfo *MII, diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -129,7 +129,7 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, AsmPrinter *AP, - unsigned LocCookie, raw_ostream &OS) { + uint64_t LocCookie, raw_ostream &OS) { // Switch to the inline assembly variant. OS << "\t.intel_syntax\n\t"; @@ -271,7 +271,7 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, const MCAsmInfo *MAI, - AsmPrinter *AP, unsigned LocCookie, + AsmPrinter *AP, uint64_t LocCookie, raw_ostream &OS) { int CurVariant = -1; // The number of the {.|.|.} region we are in. const char *LastEmitted = AsmStr; // One past the last character emitted. @@ -482,7 +482,7 @@ // Get the !srcloc metadata node if we have it, and decode the loc cookie from // it. - unsigned LocCookie = 0; + uint64_t LocCookie = 0; const MDNode *LocMD = nullptr; for (unsigned i = MI->getNumOperands(); i != 0; --i) { if (MI->getOperand(i-1).isMetadata() && diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -2083,7 +2083,7 @@ void MachineInstr::emitError(StringRef Msg) const { // Find the source location cookie. - unsigned LocCookie = 0; + uint64_t LocCookie = 0; const MDNode *LocMD = nullptr; for (unsigned i = getNumOperands(); i != 0; --i) { if (getOperand(i-1).isMetadata() && diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp --- a/llvm/lib/IR/LLVMContext.cpp +++ b/llvm/lib/IR/LLVMContext.cpp @@ -248,7 +248,7 @@ exit(1); } -void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) { +void LLVMContext::emitError(uint64_t LocCookie, const Twine &ErrorStr) { diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); } diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -258,9 +258,9 @@ return LTODiscardSymbols.contains(Name); } - bool parseMSInlineAsm(void *AsmLoc, std::string &AsmString, + bool parseMSInlineAsm(uint64_t AsmLoc, std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, - SmallVectorImpl> &OpDecls, + SmallVectorImpl> &OpDecls, SmallVectorImpl &Constraints, SmallVectorImpl &Clobbers, const MCInstrInfo *MII, const MCInstPrinter *IP, @@ -5907,7 +5907,7 @@ } bool AsmParser::parseMSInlineAsm( - void *AsmLoc, std::string &AsmString, unsigned &NumOutputs, + uint64_t AsmLoc, std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, SmallVectorImpl> &OpDecls, SmallVectorImpl &Constraints, SmallVectorImpl &Clobbers, const MCInstrInfo *MII, diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -509,9 +509,9 @@ bool lookUpType(StringRef Name, AsmTypeInfo &Info) const override; - bool parseMSInlineAsm(void *AsmLoc, std::string &AsmString, + bool parseMSInlineAsm(uint64_t AsmLoc, std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, - SmallVectorImpl> &OpDecls, + SmallVectorImpl> &OpDecls, SmallVectorImpl &Constraints, SmallVectorImpl &Clobbers, const MCInstrInfo *MII, const MCInstPrinter *IP, @@ -7040,7 +7040,7 @@ } bool MasmParser::parseMSInlineAsm( - void *AsmLoc, std::string &AsmString, unsigned &NumOutputs, + uint64_t AsmLoc, std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, SmallVectorImpl> &OpDecls, SmallVectorImpl &Constraints, SmallVectorImpl &Clobbers, const MCInstrInfo *MII,