Skip to content

Commit fb37659

Browse files
[llvm-debuginfo-analyzer] Common handling of unsigned attribute values. (#116027)
- In the DWARF reader, for those attributes that can have an unsigned value, allow for the following cases: * Is an implicit constant * Is an optional value - The testing is done by creating a file with generated DWARF, using `DwarfGenerator` (generate DWARF debug info for unit tests).
1 parent f710b04 commit fb37659

File tree

4 files changed

+384
-13
lines changed

4 files changed

+384
-13
lines changed

llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,18 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
253253
// We are processing .debug_info section, implicit_const attribute
254254
// values are not really stored here, but in .debug_abbrev section.
255255
auto GetAsUnsignedConstant = [&]() -> int64_t {
256-
return AttrSpec.isImplicitConst() ? AttrSpec.getImplicitConstValue()
257-
: *FormValue.getAsUnsignedConstant();
256+
if (AttrSpec.isImplicitConst())
257+
return AttrSpec.getImplicitConstValue();
258+
if (std::optional<uint64_t> Val = FormValue.getAsUnsignedConstant())
259+
return *Val;
260+
return 0;
258261
};
259262

260263
auto GetFlag = [](const DWARFFormValue &FormValue) -> bool {
261264
return FormValue.isFormClass(DWARFFormValue::FC_Flag);
262265
};
263266

264-
auto GetBoundValue = [](const DWARFFormValue &FormValue) -> int64_t {
267+
auto GetBoundValue = [&AttrSpec](const DWARFFormValue &FormValue) -> int64_t {
265268
switch (FormValue.getForm()) {
266269
case dwarf::DW_FORM_ref_addr:
267270
case dwarf::DW_FORM_ref1:
@@ -282,6 +285,8 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
282285
return *FormValue.getAsUnsignedConstant();
283286
case dwarf::DW_FORM_sdata:
284287
return *FormValue.getAsSignedConstant();
288+
case dwarf::DW_FORM_implicit_const:
289+
return AttrSpec.getImplicitConstValue();
285290
default:
286291
return 0;
287292
}
@@ -294,13 +299,13 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
294299

295300
switch (AttrSpec.Attr) {
296301
case dwarf::DW_AT_accessibility:
297-
CurrentElement->setAccessibilityCode(*FormValue.getAsUnsignedConstant());
302+
CurrentElement->setAccessibilityCode(GetAsUnsignedConstant());
298303
break;
299304
case dwarf::DW_AT_artificial:
300305
CurrentElement->setIsArtificial();
301306
break;
302307
case dwarf::DW_AT_bit_size:
303-
CurrentElement->setBitSize(*FormValue.getAsUnsignedConstant());
308+
CurrentElement->setBitSize(GetAsUnsignedConstant());
304309
break;
305310
case dwarf::DW_AT_call_file:
306311
CurrentElement->setCallFilenameIndex(IncrementFileIndex
@@ -332,13 +337,12 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
332337
Stream << hexString(Value, 2);
333338
CurrentElement->setValue(Stream.str());
334339
} else
335-
CurrentElement->setValue(
336-
hexString(*FormValue.getAsUnsignedConstant(), 2));
340+
CurrentElement->setValue(hexString(GetAsUnsignedConstant(), 2));
337341
} else
338342
CurrentElement->setValue(dwarf::toStringRef(FormValue));
339343
break;
340344
case dwarf::DW_AT_count:
341-
CurrentElement->setCount(*FormValue.getAsUnsignedConstant());
345+
CurrentElement->setCount(GetAsUnsignedConstant());
342346
break;
343347
case dwarf::DW_AT_decl_line:
344348
CurrentElement->setLineNumber(GetAsUnsignedConstant());
@@ -357,10 +361,10 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
357361
CurrentElement->setIsExternal();
358362
break;
359363
case dwarf::DW_AT_GNU_discriminator:
360-
CurrentElement->setDiscriminator(*FormValue.getAsUnsignedConstant());
364+
CurrentElement->setDiscriminator(GetAsUnsignedConstant());
361365
break;
362366
case dwarf::DW_AT_inline:
363-
CurrentElement->setInlineCode(*FormValue.getAsUnsignedConstant());
367+
CurrentElement->setInlineCode(GetAsUnsignedConstant());
364368
break;
365369
case dwarf::DW_AT_lower_bound:
366370
CurrentElement->setLowerBound(GetBoundValue(FormValue));
@@ -380,7 +384,7 @@ void LVDWARFReader::processOneAttribute(const DWARFDie &Die,
380384
CurrentElement->setUpperBound(GetBoundValue(FormValue));
381385
break;
382386
case dwarf::DW_AT_virtuality:
383-
CurrentElement->setVirtualityCode(*FormValue.getAsUnsignedConstant());
387+
CurrentElement->setVirtualityCode(GetAsUnsignedConstant());
384388
break;
385389

386390
case dwarf::DW_AT_abstract_origin:

llvm/test/tools/llvm-debuginfo-analyzer/DWARF/05-dwarf-incorrect-lexical-scope-variable.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
; ONE-EMPTY:
4444
; ONE-NEXT: [001] {CompileUnit} 'pr-43860.cpp'
4545
; ONE-NEXT: [002] {Producer} 'clang version 15.0.0 {{.*}}'
46-
; ONE-NEXT: [002] 2 {Function} extern not_inlined 'InlineFunction' -> 'int'
46+
; ONE-NEXT: [002] 2 {Function} extern inlined 'InlineFunction' -> 'int'
4747
; ONE-NEXT: [003] {Block}
4848
; ONE-NEXT: [004] 5 {Variable} 'Var_2' -> 'int'
4949
; ONE-NEXT: [003] 2 {Parameter} 'Param' -> 'int'
5050
; ONE-NEXT: [003] 3 {Variable} 'Var_1' -> 'int'
5151
; ONE-NEXT: [002] 11 {Function} extern not_inlined 'test' -> 'int'
5252
; ONE-NEXT: [003] 12 {Variable} 'A' -> 'int'
53-
; ONE-NEXT: [003] 13 {InlinedFunction} not_inlined 'InlineFunction' -> 'int'
53+
; ONE-NEXT: [003] 13 {InlinedFunction} inlined 'InlineFunction' -> 'int'
5454
; ONE-NEXT: [004] {Block}
5555
; ONE-NEXT: [005] {Variable} 'Var_2' -> 'int'
5656
; ONE-NEXT: [004] {Parameter} 'Param' -> 'int'

llvm/unittests/DebugInfo/LogicalView/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
set(LLVM_LINK_COMPONENTS
2+
${LLVM_TARGETS_TO_BUILD}
23
AllTargetsDescs
34
AllTargetsDisassemblers
45
AllTargetsInfos
6+
AsmPrinter
57
DebugInfoLogicalView
68
MC
79
MCDisassembler
810
TargetParser
911
)
1012

1113
add_llvm_unittest_with_input_files(DebugInfoLogicalViewTests
14+
../DWARF/DwarfGenerator.cpp
15+
../DWARF/DwarfUtils.cpp
1216
CodeViewReaderTest.cpp
1317
CommandLineOptionsTest.cpp
1418
CompareElementsTest.cpp
19+
DWARFGeneratedTest.cpp
1520
DWARFReaderTest.cpp
1621
SelectElementsTest.cpp
1722
LocationRangesTest.cpp

0 commit comments

Comments
 (0)