[llvm] [DWARF] Emit 0/1 for constant boolean values (PR #151225)

Michael Buch via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 8 04:50:29 PDT 2025


================
@@ -820,6 +833,22 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
   }
   if (!DVal->isVariadic()) {
     const DbgValueLocEntry *Entry = DVal->getLocEntries().begin();
+
+    // Helper function to handle boolean constant values with type safety
+    auto addConstantValueWithBooleanNormalization =
----------------
Michael137 wrote:

Hmmm should we address this in instruction selection perhaps then, when we create the debug `MachineOperand`? I see that `SelectionDAG` sign extends the constant: https://github.com/llvm/llvm-project/blob/a80c393a9c498279a1ec9fd630535b9ff139b49f/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp#L736

Whereas `GlobalISel` zero extends it: https://github.com/llvm/llvm-project/blob/3dc314b8519099b1da43d01302d3d1710a6ccb3c/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp#L113

So `GlobalISel` turns the `i1 true` constant into `1`.

My main worry with the normalization you're doing in this patch is that we silently lose information about whether the boolean representation has exhibits the UB that David mentioned. It also feels a bit strange to do the normalization in one place, but not other places where we may emit constants.

@dwblaikie @jmorse This is a bit out of my wheelhouse. Do you have an opinion at which level to do the normalization?

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


More information about the llvm-commits mailing list