[clang] [clang][bytecode] Print 8 bit integers as 32 bit in Function::dump() (PR #156858)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 4 04:16:39 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Otherwise we get the char representation in our disassembly output, which we don't want.

---
Full diff: https://github.com/llvm/llvm-project/pull/156858.diff


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Disasm.cpp (+14-1) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp
index ac904d359d8cc..ab3b9f7c3b1d7 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -44,7 +44,20 @@ inline static std::string printArg(Program &P, CodePtr &OpPC) {
     std::string Result;
     llvm::raw_string_ostream SS(Result);
     auto Arg = OpPC.read<T>();
-    SS << Arg;
+    // Make sure we print the integral value of chars.
+    if constexpr (std::is_integral_v<T>) {
+      if constexpr (sizeof(T) == 1) {
+        if constexpr (std::is_signed_v<T>)
+          SS << static_cast<int32_t>(Arg);
+        else
+          SS << static_cast<uint32_t>(Arg);
+      } else {
+        SS << Arg;
+      }
+    } else {
+      SS << Arg;
+    }
+
     return Result;
   }
 }

``````````

</details>


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


More information about the cfe-commits mailing list