[llvm] [CodeView] Write 128bit ints as LF_(U)OCTWORD (PR #212241)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 21:06:33 PDT 2026


================
@@ -391,3 +383,50 @@ Error CodeViewRecordIO::writeEncodedUnsignedInteger(const uint64_t &Value) {
 
   return Error::success();
 }
+
+Error CodeViewRecordIO::writeEncodedAPSInt(const APSInt &Value) {
+  if (LLVM_LIKELY(Value.isSingleWord())) {
+    if (Value.isSigned())
+      return writeEncodedSignedInteger(Value.getSExtValue());
+    return writeEncodedUnsignedInteger(Value.getZExtValue());
+  }
+
+  // Width > 64 bit, write a 128 bit integer.
+  TypeLeafKind Leaf = Value.isSigned() ? LF_OCTWORD : LF_UOCTWORD;
+  if (auto EC = Writer->writeInteger<uint16_t>(Leaf))
+    return EC;
+
+  APSInt Trunc = Value.extOrTrunc(128);
+  if constexpr (endianness::native == endianness::big)
+    Trunc = Trunc.byteSwap();
+
+  if (auto EC = Writer->writeBytes(
----------------
rnk wrote:

Add BinaryStreamWriter::writeInt128 to do this, so the caller doesn't have to encode the endianness. PDBs are always LE, but it makes the code cleaner.

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


More information about the llvm-commits mailing list