[clang] [clang-tools-extra] [clang] Extend SourceLocation to 64 bits. (PR #147292)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 7 18:48:48 PDT 2025


================
@@ -43,17 +46,24 @@ namespace clang {
 // Macro locations have the top bit set, we rotate by one so it is the low bit.
 class SourceLocationEncoding {
   using UIntTy = SourceLocation::UIntTy;
-  constexpr static unsigned UIntBits = CHAR_BIT * sizeof(UIntTy);
 
   static UIntTy encodeRaw(UIntTy Raw) {
-    return (Raw << 1) | (Raw >> (UIntBits - 1));
+    return ((Raw & llvm::maskTrailingOnes<uint64_t>(SourceLocation::Bits - 1))
+            << 1) |
+           (Raw >> (SourceLocation::Bits - 1));
   }
   static UIntTy decodeRaw(UIntTy Raw) {
-    return (Raw >> 1) | (Raw << (UIntBits - 1));
+    return (Raw >> 1) | ((Raw & 1) << (SourceLocation::Bits - 1));
   }
 
 public:
   using RawLocEncoding = uint64_t;
+  // 16 bits should be sufficient to store the module file index.
+  constexpr static unsigned ModuleFileIndexBits = 16;
----------------
ChuanqiXu9 wrote:

This is inconsistent with the comment above, where says we use 24 (or 23) bits to store module file index. Personally I prefer to have higher bits.. since 2^16 = 66536 looks may be a possible number in practice. How about using 20 bits for module file index?

https://github.com/llvm/llvm-project/pull/147292


More information about the cfe-commits mailing list