Skip to content

Commit 207b9ae

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f3da9af3fd26' from llvm.org/release/19.x into stable/20240723
2 parents b4e725f + f3da9af commit 207b9ae

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

llvm/lib/IR/DebugProgramInstruction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,12 @@ DbgLabelRecord::createDebugIntrinsic(Module *M,
473473

474474
Value *DbgVariableRecord::getAddress() const {
475475
auto *MD = getRawAddress();
476-
if (auto *V = dyn_cast<ValueAsMetadata>(MD))
476+
if (auto *V = dyn_cast_or_null<ValueAsMetadata>(MD))
477477
return V->getValue();
478478

479479
// When the value goes to null, it gets replaced by an empty MDNode.
480-
assert(!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
480+
assert(!MD ||
481+
!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
481482
return nullptr;
482483
}
483484

llvm/lib/IR/TypeFinder.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
8888
for (const auto &MD : MDForInst)
8989
incorporateMDNode(MD.second);
9090
MDForInst.clear();
91+
92+
// Incorporate types hiding in variable-location information.
93+
for (const auto &Dbg : I.getDbgRecordRange()) {
94+
// Pick out records that have Values.
95+
if (const DbgVariableRecord *DVI =
96+
dyn_cast<DbgVariableRecord>(&Dbg)) {
97+
for (Value *V : DVI->location_ops())
98+
incorporateValue(V);
99+
if (DVI->isDbgAssign()) {
100+
if (Value *Addr = DVI->getAddress())
101+
incorporateValue(Addr);
102+
}
103+
}
104+
}
91105
}
92106
}
93107

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: opt --passes=verify %s -o - -S | FileCheck %s
2+
3+
;; Test that the type definitions are discovered when serialising to LLVM-IR,
4+
;; even if they're only present inside a DbgRecord, and thus not normally
5+
;; visible.
6+
7+
; CHECK: %union.anon = type { %struct.a }
8+
; CHECK: %struct.a = type { i32 }
9+
; CHECK: %union.anon2 = type { %struct.a2 }
10+
; CHECK: %struct.a2 = type { i32 }
11+
12+
; ModuleID = 'bbi-98372.ll'
13+
source_filename = "bbi-98372.ll"
14+
15+
%union.anon = type { %struct.a }
16+
%struct.a = type { i32 }
17+
%union.anon2 = type { %struct.a2 }
18+
%struct.a2 = type { i32 }
19+
20+
@d = global [1 x { i16, i16 }] [{ i16, i16 } { i16 0, i16 undef }], align 1
21+
@e = global [1 x { i16, i16 }] [{ i16, i16 } { i16 0, i16 undef }], align 1
22+
23+
define void @f() {
24+
entry:
25+
#dbg_value(ptr getelementptr inbounds ([1 x %union.anon], ptr @d, i32 0, i32 3), !7, !DIExpression(), !14)
26+
#dbg_assign(ptr null, !7, !DIExpression(), !16, ptr getelementptr inbounds ([1 x %union.anon2], ptr @e, i32 0, i32 3), !17, !14)
27+
ret void, !dbg !15
28+
}
29+
30+
!llvm.dbg.cu = !{!0}
31+
!llvm.module.flags = !{!2, !3, !4, !5}
32+
!llvm.ident = !{!6}
33+
34+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
35+
!1 = !DIFile(filename: "foo.c", directory: "/bar")
36+
!2 = !{i32 7, !"Dwarf Version", i32 4}
37+
!3 = !{i32 2, !"Debug Info Version", i32 3}
38+
!4 = !{i32 1, !"wchar_size", i32 1}
39+
!5 = !{i32 7, !"frame-pointer", i32 2}
40+
!6 = !{!"clang"}
41+
!7 = !DILocalVariable(name: "f", scope: !8, file: !1, line: 8, type: !12)
42+
!8 = distinct !DISubprogram(name: "e", scope: !1, file: !1, line: 8, type: !9, scopeLine: 8, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
43+
!9 = !DISubroutineType(types: !10)
44+
!10 = !{null}
45+
!11 = !{!7}
46+
!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 16)
47+
!13 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
48+
!14 = !DILocation(line: 0, scope: !8)
49+
!15 = !DILocation(line: 8, column: 28, scope: !8)
50+
!16 = distinct !DIAssignID()
51+
!17 = !DIExpression()

0 commit comments

Comments
 (0)