Skip to content

Commit 38292f0

Browse files
committed
[Assignment Tracking] Fix assertion in AssignmentTrackingPass::runOnFunction
The assertion exists to ensure all variables passed into `trackAssignments` end up with dbg.assigns associated with their backing allocas. The assertion compared the passed-in and tracked variables using `DebugVariable`, which includes the fragment as part of the variable identity. It is possible for the backing alloca to be smaller than a variable (see test case). In this case the input variable `(Var X, no fragment, no InlinedAt)` isn't equal to the dbg.assign variable `(Var X, some fragment, no InlinedAt)`. To cover this case the assertion now ignores fragments through the use of `DebugVariableAggregate`. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D148100
1 parent ca7a20d commit 38292f0

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

llvm/lib/IR/DebugInfo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,10 +2025,14 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
20252025
(void)Markers;
20262026
for (DbgDeclareInst *DDI : P.second) {
20272027
// Assert that the alloca that DDI uses is now linked to a dbg.assign
2028-
// describing the same variable (i.e. check that this dbg.declare
2029-
// has been replaced by a dbg.assign).
2028+
// describing the same variable (i.e. check that this dbg.declare has
2029+
// been replaced by a dbg.assign). Use DebugVariableAggregate to Discard
2030+
// the fragment part because trackAssignments may alter the
2031+
// fragment. e.g. if the alloca is smaller than the variable, then
2032+
// trackAssignments will create an alloca-sized fragment for the
2033+
// dbg.assign.
20302034
assert(llvm::any_of(Markers, [DDI](DbgAssignIntrinsic *DAI) {
2031-
return DebugVariable(DAI) == DebugVariable(DDI);
2035+
return DebugVariableAggregate(DAI) == DebugVariableAggregate(DDI);
20322036
}));
20332037
// Delete DDI because the variable location is now tracked using
20342038
// assignment tracking.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; RUN: opt %s -S -passes=declare-to-assign -o - | FileCheck %s
2+
3+
;; Generated from this C++:
4+
;; long double get();
5+
;; void fun() {
6+
;; long double f;
7+
;; }
8+
9+
;; Check a variable that is larger (128 bits according to !15) than its backing
10+
;; alloca (80 bits) can be represented with assignment tracking. Create a
11+
;; fragment for the dbg.assign for bits 0-80.
12+
13+
; CHECK: llvm.dbg.assign(metadata i1 undef, metadata ![[#]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 80), metadata ![[#]], metadata ptr %f, metadata !DIExpression())
14+
15+
define dso_local void @_Z3funv() #0 !dbg !10 {
16+
entry:
17+
%f = alloca x86_fp80, align 16
18+
call void @llvm.dbg.declare(metadata ptr %f, metadata !14, metadata !DIExpression()), !dbg !16
19+
ret void
20+
}
21+
22+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
23+
24+
!llvm.dbg.cu = !{!0}
25+
!llvm.module.flags = !{!2, !3}
26+
!llvm.ident = !{!9}
27+
28+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
29+
!1 = !DIFile(filename: "test.cpp", directory: "/")
30+
!2 = !{i32 7, !"Dwarf Version", i32 5}
31+
!3 = !{i32 2, !"Debug Info Version", i32 3}
32+
!9 = !{!"clang version 17.0.0"}
33+
!10 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 2, type: !11, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
34+
!11 = !DISubroutineType(types: !12)
35+
!12 = !{null}
36+
!13 = !{}
37+
!14 = !DILocalVariable(name: "f", scope: !10, file: !1, line: 3, type: !15)
38+
!15 = !DIBasicType(name: "long double", size: 128, encoding: DW_ATE_float)
39+
!16 = !DILocation(line: 3, column: 15, scope: !10)

0 commit comments

Comments
 (0)