Index: clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp +++ 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. Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -333,6 +333,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}") Index: clang/bindings/python/clang/cindex.py =================================================================== --- clang/bindings/python/clang/cindex.py +++ clang/bindings/python/clang/cindex.py @@ -233,7 +233,7 @@ """ A SourceLocation represents a particular location within a source file. """ - _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)] + _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_ulonglong)] _data = None def _get_instantiation(self): @@ -307,8 +307,8 @@ """ _fields_ = [ ("ptr_data", c_void_p * 2), - ("begin_int_data", c_uint), - ("end_int_data", c_uint)] + ("begin_int_data", c_ulonglong), + ("end_int_data", c_ulonglong)] # FIXME: Eliminate this and make normal constructor? Requires hiding ctypes # object. @@ -563,7 +563,8 @@ for i in range(0, count): token = Token() - token.int_data = tokens_array[i].int_data + token.uint_data = tokens_array[i].uint_data + token.ulint_data = tokens_array[i].ulint_data token.ptr_data = tokens_array[i].ptr_data token._tu = tu token._group = token_group @@ -3279,7 +3280,8 @@ can't create tokens manually. """ _fields_ = [ - ('int_data', c_uint * 4), + ('ulint_data', c_ulonglong * 2), + ('uint_data', c_uint * 2), ('ptr_data', c_void_p) ] Index: clang/include/clang-c/Index.h =================================================================== --- clang/include/clang-c/Index.h +++ clang/include/clang-c/Index.h @@ -32,7 +32,7 @@ * The policy about the libclang API was always to keep it source and ABI * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ -#define CINDEX_VERSION_MAJOR 0 +#define CINDEX_VERSION_MAJOR 1 #define CINDEX_VERSION_MINOR 61 #define CINDEX_VERSION_ENCODE(major, minor) (((major)*10000) + ((minor)*1)) @@ -455,7 +455,7 @@ */ typedef struct { const void *ptr_data[2]; - unsigned int_data; + unsigned long long int_data; } CXSourceLocation; /** @@ -466,8 +466,8 @@ */ typedef struct { const void *ptr_data[2]; - unsigned begin_int_data; - unsigned end_int_data; + unsigned long long begin_int_data; + unsigned long long end_int_data; } CXSourceRange; /** @@ -4973,7 +4973,8 @@ * Describes a single preprocessing token. */ typedef struct { - unsigned int_data[4]; + unsigned long long ulint_data[2]; + unsigned uint_data[2]; void *ptr_data; } CXToken; @@ -6188,7 +6189,7 @@ */ typedef struct { void *ptr_data[2]; - unsigned int_data; + unsigned long long int_data; } CXIdxLoc; /** Index: clang/include/clang/AST/DeclBase.h =================================================================== --- clang/include/clang/AST/DeclBase.h +++ clang/include/clang/AST/DeclBase.h @@ -1760,28 +1760,28 @@ LinkageSpecDeclBitfields LinkageSpecDeclBits; BlockDeclBitfields BlockDeclBits; - static_assert(sizeof(DeclContextBitfields) <= 8, - "DeclContextBitfields is larger than 8 bytes!"); - static_assert(sizeof(TagDeclBitfields) <= 8, - "TagDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(EnumDeclBitfields) <= 8, - "EnumDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(RecordDeclBitfields) <= 8, - "RecordDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(OMPDeclareReductionDeclBitfields) <= 8, - "OMPDeclareReductionDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(FunctionDeclBitfields) <= 8, - "FunctionDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(CXXConstructorDeclBitfields) <= 8, - "CXXConstructorDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(ObjCMethodDeclBitfields) <= 8, - "ObjCMethodDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(ObjCContainerDeclBitfields) <= 8, - "ObjCContainerDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(LinkageSpecDeclBitfields) <= 8, - "LinkageSpecDeclBitfields is larger than 8 bytes!"); - static_assert(sizeof(BlockDeclBitfields) <= 8, - "BlockDeclBitfields is larger than 8 bytes!"); + static_assert(sizeof(DeclContextBitfields) <= 16, + "DeclContextBitfields is larger than 16 bytes!"); + static_assert(sizeof(TagDeclBitfields) <= 16, + "TagDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(EnumDeclBitfields) <= 16, + "EnumDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(RecordDeclBitfields) <= 16, + "RecordDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(OMPDeclareReductionDeclBitfields) <= 16, + "OMPDeclareReductionDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(FunctionDeclBitfields) <= 16, + "FunctionDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(CXXConstructorDeclBitfields) <= 16, + "CXXConstructorDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(ObjCMethodDeclBitfields) <= 16, + "ObjCMethodDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(ObjCContainerDeclBitfields) <= 16, + "ObjCContainerDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(LinkageSpecDeclBitfields) <= 16, + "LinkageSpecDeclBitfields is larger than 16 bytes!"); + static_assert(sizeof(BlockDeclBitfields) <= 16, + "BlockDeclBitfields is larger than 16 bytes!"); }; /// FirstDecl - The first declaration stored within this declaration Index: clang/include/clang/AST/DeclarationName.h =================================================================== --- clang/include/clang/AST/DeclarationName.h +++ 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; Index: clang/include/clang/AST/Stmt.h =================================================================== --- clang/include/clang/AST/Stmt.h +++ clang/include/clang/AST/Stmt.h @@ -1151,7 +1151,7 @@ Stmt &operator=(Stmt &&) = delete; Stmt(StmtClass SC) { - static_assert(sizeof(*this) <= 8, + static_assert(sizeof(*this) <= 16, "changing bitfields changed sizeof(Stmt)"); static_assert(sizeof(*this) % alignof(void *) == 0, "Insufficient alignment!"); Index: clang/include/clang/Analysis/ProgramPoint.h =================================================================== --- clang/include/clang/Analysis/ProgramPoint.h +++ 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; Index: clang/include/clang/Basic/SourceLocation.h =================================================================== --- clang/include/clang/Basic/SourceLocation.h +++ clang/include/clang/Basic/SourceLocation.h @@ -85,18 +85,26 @@ /// 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; +public: +#ifdef CLANG_64_BIT_SOURCE_LOCATIONS + using UIntType = uint64_t; + using IntType = int64_t; +#else + using UIntType = uint32_t; + using IntType = int32_t; +#endif +private: + UIntType ID = 0; - enum : unsigned { - MacroIDBit = 1U << 31 - }; + enum : UIntType { MacroIDBit = 1ULL << (8 * sizeof(UIntType) - 1) }; public: bool isFileID() const { return (ID & MacroIDBit) == 0; } @@ -112,18 +120,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 +139,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 +151,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 +177,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 +495,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 +518,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 Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ 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; Index: clang/include/clang/Lex/Preprocessor.h =================================================================== --- clang/include/clang/Lex/Preprocessor.h +++ 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 Index: clang/include/clang/Lex/Token.h =================================================================== --- clang/include/clang/Lex/Token.h +++ 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: Index: clang/include/clang/Serialization/ASTBitCodes.h =================================================================== --- clang/include/clang/Serialization/ASTBitCodes.h +++ 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()), @@ -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 Index: clang/include/clang/Serialization/ASTReader.h =================================================================== --- clang/include/clang/Serialization/ASTReader.h +++ clang/include/clang/Serialization/ASTReader.h @@ -2137,12 +2137,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); } @@ -2156,7 +2159,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); } Index: clang/include/clang/Serialization/ASTWriter.h =================================================================== --- clang/include/clang/Serialization/ASTWriter.h +++ 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; Index: clang/include/clang/Serialization/ModuleFile.h =================================================================== --- clang/include/clang/Serialization/ModuleFile.h +++ 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 === Index: clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp =================================================================== --- clang/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp +++ 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) Index: clang/lib/AST/NestedNameSpecifier.cpp =================================================================== --- clang/lib/AST/NestedNameSpecifier.cpp +++ clang/lib/AST/NestedNameSpecifier.cpp @@ -355,7 +355,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: @@ -367,7 +367,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: @@ -392,8 +392,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); } @@ -430,8 +430,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: { @@ -486,10 +487,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. Index: clang/lib/AST/SelectorLocationsKind.cpp =================================================================== --- clang/lib/AST/SelectorLocationsKind.cpp +++ 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); Index: clang/lib/Basic/SourceLocation.cpp =================================================================== --- clang/lib/Basic/SourceLocation.cpp +++ 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( Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -449,9 +449,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) @@ -531,7 +531,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); } @@ -539,7 +540,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)); @@ -558,7 +560,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, @@ -571,7 +574,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); @@ -593,7 +597,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; @@ -632,14 +637,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); @@ -657,9 +659,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; @@ -761,7 +762,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); @@ -776,7 +777,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 @@ -827,7 +829,8 @@ NumProbes = 0; while (true) { unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex; - unsigned MidOffset = getLocalSLocEntry(MiddleIndex).getOffset(); + SourceLocation::UIntType MidOffset = + getLocalSLocEntry(MiddleIndex).getOffset(); ++NumProbes; @@ -858,7 +861,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"); @@ -1572,7 +1576,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) @@ -1780,8 +1784,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 @@ -1793,9 +1797,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; @@ -1887,7 +1892,7 @@ --I; - unsigned MacroArgBeginOffs = I->first; + SourceLocation::UIntType MacroArgBeginOffs = I->first; SourceLocation MacroArgExpandedLoc = I->second; if (MacroArgExpandedLoc.isValid()) return MacroArgExpandedLoc.getLocWithOffset(Offset - MacroArgBeginOffs); @@ -2107,7 +2112,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]) { Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -11891,13 +11891,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 { Index: clang/lib/CodeGen/CGStmt.cpp =================================================================== --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -2095,7 +2095,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(); @@ -2110,7 +2110,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()))); } } @@ -2145,8 +2145,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))); Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -380,8 +380,8 @@ Gen->HandleVTable(RD); } - static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context, - unsigned LocCookie) { + static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM, + void *Context, uint64_t LocCookie) { SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie); ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc); } @@ -988,8 +988,7 @@ } static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, - void *Context, - unsigned LocCookie) { + void *Context, uint64_t LocCookie) { SM.print(nullptr, llvm::errs()); auto Diags = static_cast(Context); Index: clang/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.cpp +++ clang/lib/CodeGen/CoverageMappingGen.cpp @@ -242,7 +242,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)); } Index: clang/lib/Format/FormatTokenLexer.cpp =================================================================== --- clang/lib/Format/FormatTokenLexer.cpp +++ clang/lib/Format/FormatTokenLexer.cpp @@ -850,7 +850,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; Index: clang/lib/Lex/Lexer.cpp =================================================================== --- clang/lib/Lex/Lexer.cpp +++ 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()); @@ -714,8 +715,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, Index: clang/lib/Lex/ModuleMap.cpp =================================================================== --- clang/lib/Lex/ModuleMap.cpp +++ clang/lib/Lex/ModuleMap.cpp @@ -1369,7 +1369,7 @@ RSquare } Kind; - unsigned Location; + SourceLocation::UIntType Location; unsigned StringLength; union { // If Kind != IntegerLiteral. Index: clang/lib/Lex/PPCaching.cpp =================================================================== --- clang/lib/Lex/PPCaching.cpp +++ 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) Index: clang/lib/Lex/TokenLexer.cpp =================================================================== --- clang/lib/Lex/TokenLexer.cpp +++ 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)); } Index: clang/lib/Parse/ParseStmtAsm.cpp =================================================================== --- clang/lib/Parse/ParseStmtAsm.cpp +++ 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; } @@ -630,7 +630,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(); Index: clang/lib/Serialization/ASTReader.cpp =================================================================== --- clang/lib/Serialization/ASTReader.cpp +++ 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(); @@ -3403,7 +3403,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, @@ -3421,7 +3421,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)); @@ -3430,8 +3430,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; @@ -3855,8 +3855,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); @@ -3887,8 +3890,8 @@ return; } - uint32_t SLocOffset = - endian::readNext(Data); + SourceLocation::UIntType SLocOffset = + endian::readNext(Data); uint32_t IdentifierIDOffset = endian::readNext(Data); uint32_t MacroIDOffset = @@ -3904,15 +3907,21 @@ uint32_t TypeIndexOffset = endian::readNext(Data); - uint32_t None = std::numeric_limits::max(); - 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, Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ 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); @@ -4672,7 +4672,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 @@ -4701,16 +4701,20 @@ 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 @@ -5097,8 +5101,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) { Index: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ 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); } Index: clang/test/CMakeLists.txt =================================================================== --- clang/test/CMakeLists.txt +++ 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 Index: clang/test/Lexer/SourceLocationsOverflow.c =================================================================== --- clang/test/Lexer/SourceLocationsOverflow.c +++ 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" Index: clang/test/lit.cfg.py =================================================================== --- clang/test/lit.cfg.py +++ clang/test/lit.cfg.py @@ -197,6 +197,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: Index: clang/test/lit.site.cfg.py.in =================================================================== --- clang/test/lit.site.cfg.py.in +++ clang/test/lit.site.cfg.py.in @@ -22,6 +22,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@ Index: clang/tools/libclang/CIndex.cpp =================================================================== --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -1982,7 +1982,8 @@ return static_cast(data[0]); } SourceLocation getLoc() const { - return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)data[1]); + return SourceLocation::getFromRawEncoding( + (SourceLocation::UIntType)(uintptr_t)data[1]); } }; class EnqueueVisitor : public ConstStmtVisitor { @@ -6748,15 +6749,15 @@ //===----------------------------------------------------------------------===// /* CXToken layout: - * int_data[0]: a CXTokenKind - * int_data[1]: starting token location - * int_data[2]: token length - * int_data[3]: reserved + * uint_data[0]: a CXTokenKind + * uint_data[1]: token length + * ulint_data[0]: starting token location + * ulint_data[1]: reserved * ptr_data: for identifiers and keywords, an IdentifierInfo*. * otherwise unused. */ CXTokenKind clang_getTokenKind(CXToken CXTok) { - return static_cast(CXTok.int_data[0]); + return static_cast(CXTok.uint_data[0]); } CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) { @@ -6770,7 +6771,7 @@ case CXToken_Literal: { // We have stashed the starting pointer in the ptr_data field. Use it. const char *Text = static_cast(CXTok.ptr_data); - return cxstring::createDup(StringRef(Text, CXTok.int_data[2])); + return cxstring::createDup(StringRef(Text, CXTok.uint_data[1])); } case CXToken_Punctuation: @@ -6789,7 +6790,7 @@ if (!CXXUnit) return cxstring::createEmpty(); - SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]); + SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.ulint_data[0]); std::pair LocInfo = CXXUnit->getSourceManager().getDecomposedSpellingLoc(Loc); bool Invalid = false; @@ -6798,7 +6799,7 @@ if (Invalid) return cxstring::createEmpty(); - return cxstring::createDup(Buffer.substr(LocInfo.second, CXTok.int_data[2])); + return cxstring::createDup(Buffer.substr(LocInfo.second, CXTok.uint_data[1])); } CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) { @@ -6813,7 +6814,7 @@ return cxloc::translateSourceLocation( CXXUnit->getASTContext(), - SourceLocation::getFromRawEncoding(CXTok.int_data[1])); + SourceLocation::getFromRawEncoding(CXTok.ulint_data[0])); } CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) { @@ -6828,7 +6829,7 @@ return cxloc::translateSourceRange( CXXUnit->getASTContext(), - SourceLocation::getFromRawEncoding(CXTok.int_data[1])); + SourceLocation::getFromRawEncoding(CXTok.ulint_data[0])); } static void getTokens(ASTUnit *CXXUnit, SourceRange Range, @@ -6868,30 +6869,30 @@ CXToken CXTok; // - Common fields - CXTok.int_data[1] = Tok.getLocation().getRawEncoding(); - CXTok.int_data[2] = Tok.getLength(); - CXTok.int_data[3] = 0; + CXTok.uint_data[1] = Tok.getLength(); + CXTok.ulint_data[0] = Tok.getLocation().getRawEncoding(); + CXTok.ulint_data[1] = 0; // - Kind-specific fields if (Tok.isLiteral()) { - CXTok.int_data[0] = CXToken_Literal; + CXTok.uint_data[0] = CXToken_Literal; CXTok.ptr_data = const_cast(Tok.getLiteralData()); } else if (Tok.is(tok::raw_identifier)) { // Lookup the identifier to determine whether we have a keyword. IdentifierInfo *II = CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok); if ((II->getObjCKeywordID() != tok::objc_not_keyword) && previousWasAt) { - CXTok.int_data[0] = CXToken_Keyword; + CXTok.uint_data[0] = CXToken_Keyword; } else { - CXTok.int_data[0] = + CXTok.uint_data[0] = Tok.is(tok::identifier) ? CXToken_Identifier : CXToken_Keyword; } CXTok.ptr_data = II; } else if (Tok.is(tok::comment)) { - CXTok.int_data[0] = CXToken_Comment; + CXTok.uint_data[0] = CXToken_Comment; CXTok.ptr_data = nullptr; } else { - CXTok.int_data[0] = CXToken_Punctuation; + CXTok.uint_data[0] = CXToken_Punctuation; CXTok.ptr_data = nullptr; } CXTokens.push_back(CXTok); @@ -7024,13 +7025,13 @@ unsigned NextToken() const { return TokIdx; } void AdvanceToken() { ++TokIdx; } SourceLocation GetTokenLoc(unsigned tokI) { - return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]); + return SourceLocation::getFromRawEncoding(getTok(tokI).ulint_data[0]); } bool isFunctionMacroToken(unsigned tokI) const { - return getTok(tokI).int_data[3] != 0; + return getTok(tokI).ulint_data[1] != 0; } SourceLocation getFunctionMacroTokenLoc(unsigned tokI) const { - return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[3]); + return SourceLocation::getFromRawEncoding(getTok(tokI).ulint_data[1]); } void annotateAndAdvanceTokens(CXCursor, RangeComparisonResult, SourceRange); @@ -7525,13 +7526,13 @@ } SourceLocation getTokenLoc(unsigned tokI) { - return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]); + return SourceLocation::getFromRawEncoding(getTok(tokI).ulint_data[0]); } void setFunctionMacroTokenLoc(unsigned tokI, SourceLocation loc) { - // The third field is reserved and currently not used. Use it here + // The second long int 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(); + getTok(tokI).ulint_data[1] = loc.getRawEncoding(); } }; @@ -7592,7 +7593,7 @@ break; unsigned TokIdx = NextIdx - 1; assert(Tok.getLocation() == - SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1])); + SourceLocation::getFromRawEncoding(Tokens[TokIdx].ulint_data[0])); reprocess: if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) { @@ -7643,7 +7644,7 @@ unsigned LastIdx = finished ? NextIdx - 1 : NextIdx - 2; assert(TokIdx <= LastIdx); SourceLocation EndLoc = - SourceLocation::getFromRawEncoding(Tokens[LastIdx].int_data[1]); + SourceLocation::getFromRawEncoding(Tokens[LastIdx].ulint_data[0]); CXCursor Cursor = MakePreprocessingDirectiveCursor(SourceRange(BeginLoc, EndLoc), TU); @@ -7735,7 +7736,7 @@ .Case("weak", true) .Case("class", true) .Default(false)) - Tokens[I].int_data[0] = CXToken_Keyword; + Tokens[I].uint_data[0] = CXToken_Keyword; } continue; } @@ -7751,13 +7752,13 @@ .Case("bycopy", true) .Case("byref", true) .Default(false)) - Tokens[I].int_data[0] = CXToken_Keyword; + Tokens[I].uint_data[0] = CXToken_Keyword; continue; } if (Cursors[I].kind == CXCursor_CXXFinalAttr || Cursors[I].kind == CXCursor_CXXOverrideAttr) { - Tokens[I].int_data[0] = CXToken_Keyword; + Tokens[I].uint_data[0] = CXToken_Keyword; continue; } } Index: llvm/include/llvm/IR/DiagnosticInfo.h =================================================================== --- llvm/include/llvm/IR/DiagnosticInfo.h +++ llvm/include/llvm/IR/DiagnosticInfo.h @@ -130,7 +130,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. @@ -148,7 +148,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) {} @@ -161,7 +161,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; } Index: llvm/include/llvm/IR/LLVMContext.h =================================================================== --- llvm/include/llvm/IR/LLVMContext.h +++ llvm/include/llvm/IR/LLVMContext.h @@ -153,8 +153,8 @@ void enableDebugTypeODRUniquing(); void disableDebugTypeODRUniquing(); - using InlineAsmDiagHandlerTy = void (*)(const SMDiagnostic&, void *Context, - unsigned LocCookie); + using InlineAsmDiagHandlerTy = void (*)(const SMDiagnostic &, void *Context, + uint64_t LocCookie); /// Defines the type of a yield callback. /// \see LLVMContext::setYieldCallback. @@ -311,7 +311,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); Index: llvm/include/llvm/MC/MCParser/MCAsmParser.h =================================================================== --- llvm/include/llvm/MC/MCParser/MCAsmParser.h +++ llvm/include/llvm/MC/MCParser/MCAsmParser.h @@ -200,7 +200,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, Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -172,7 +172,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"; @@ -314,7 +314,7 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, int AsmPrinterVariant, - 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. @@ -523,7 +523,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() && Index: llvm/lib/CodeGen/MachineInstr.cpp =================================================================== --- llvm/lib/CodeGen/MachineInstr.cpp +++ llvm/lib/CodeGen/MachineInstr.cpp @@ -2078,7 +2078,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() && Index: llvm/lib/IR/LLVMContext.cpp =================================================================== --- llvm/lib/IR/LLVMContext.cpp +++ llvm/lib/IR/LLVMContext.cpp @@ -268,7 +268,7 @@ exit(1); } -void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) { +void LLVMContext::emitError(uint64_t LocCookie, const Twine &ErrorStr) { diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); } Index: llvm/lib/MC/MCParser/AsmParser.cpp =================================================================== --- llvm/lib/MC/MCParser/AsmParser.cpp +++ llvm/lib/MC/MCParser/AsmParser.cpp @@ -235,9 +235,9 @@ } bool isParsingMSInlineAsm() override { return ParsingMSInlineAsm; } - 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, @@ -5879,7 +5879,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, Index: llvm/lib/MC/MCParser/MasmParser.cpp =================================================================== --- llvm/lib/MC/MCParser/MasmParser.cpp +++ 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, @@ -7021,7 +7021,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, Index: llvm/tools/llc/llc.cpp =================================================================== --- llvm/tools/llc/llc.cpp +++ llvm/tools/llc/llc.cpp @@ -306,7 +306,7 @@ }; static void InlineAsmDiagHandler(const SMDiagnostic &SMD, void *Context, - unsigned LocCookie) { + uint64_t LocCookie) { bool *HasError = static_cast(Context); if (SMD.getKind() == SourceMgr::DK_Error) *HasError = true;