[llvm] Two DWARF variant part improvements (PR #138953)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed May 7 14:51:18 PDT 2025
================
@@ -961,6 +961,43 @@ void DwarfUnit::addAnnotation(DIE &Buffer, DINodeArray Annotations) {
}
}
+void DwarfUnit::addDiscriminant(DIE &Variant, Constant *Discriminant,
+ bool IsUnsigned) {
+ if (const auto *CI = dyn_cast_or_null<ConstantInt>(Discriminant)) {
+ addInt(Variant, dwarf::DW_AT_discr_value, CI->getValue(), IsUnsigned);
+ } else if (const auto *CA =
+ dyn_cast_or_null<ConstantDataArray>(Discriminant)) {
+ // Must have an even number of operands.
+ unsigned NElems = CA->getNumElements();
+ if (NElems % 2 != 0) {
+ return;
+ }
+
+ DIEBlock *Block = new (DIEValueAllocator) DIEBlock;
+
+ const auto AddInt = [&](const APInt &Val) {
----------------
dwblaikie wrote:
LLVM doesn't generally use top level `const` on locals. (distinct from const on references (locals or otherwise) which is recommended) - mostly I find it problematic because it's rarely, if ever, applied consistently (eg: `NElems` and `Block` are also not mutated in this scope, but aren't marked const, etc) & so makes it more confusing to read by raising questions about what the significance of some things being const and some not is.
(similarly with the APInts below)
https://github.com/llvm/llvm-project/pull/138953
More information about the llvm-commits
mailing list