[PATCH] D73473: [DebugInfo] replaceDbgUsesWithUndef before removing dead alloca

Orlando Cazalet-Hyams via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 27 06:58:36 PST 2020


Orlando created this revision.
Orlando added reviewers: vsk, aprantl, djtodoro, probinson.
Orlando added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.

https://reviews.llvm.org/D73473

Files:
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/test/DebugInfo/X86/sroa-undef-dbg-value.ll


Index: llvm/test/DebugInfo/X86/sroa-undef-dbg-value.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/sroa-undef-dbg-value.ll
@@ -0,0 +1,44 @@
+; RUN: opt -sroa -S %s | FileCheck %s
+; CHECK: call void @llvm.dbg.value(metadata i32* undef, metadata ![[MD_c:[0-9]+]],
+; CHECK: [[MD_c]] = !DILocalVariable(name: "c",
+
+; clang reduce.c -O0 -g -w -emit-llvm -S -Xclang -disable-O0-optnone -o reduce.ll
+; cat reduce.c
+; void a() {
+;   int b;
+;   int *c = &b;
+; }
+
+define dso_local void @a() !dbg !7 {
+entry:
+  %b = alloca i32, align 4
+  %c = alloca i32*, align 8
+  call void @llvm.dbg.declare(metadata i32* %b, metadata !10, metadata !DIExpression()), !dbg !12
+  call void @llvm.dbg.declare(metadata i32** %c, metadata !13, metadata !DIExpression()), !dbg !15
+  store i32* %b, i32** %c, align 8, !dbg !15
+  ret void, !dbg !16
+}
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "reduce.c", directory: "/")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 10.0.0"}
+!7 = distinct !DISubprogram(name: "a", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 2, type: !11)
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !DILocation(line: 2, column: 7, scope: !7)
+!13 = !DILocalVariable(name: "c", scope: !7, file: !1, line: 3, type: !14)
+!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!15 = !DILocation(line: 3, column: 8, scope: !7)
+!16 = !DILocation(line: 4, column: 1, scope: !7)
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -4436,6 +4436,7 @@
 
   // Special case dead allocas, as they're trivial.
   if (AI.use_empty()) {
+    replaceDbgUsesWithUndef(&AI);
     AI.eraseFromParent();
     return true;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73473.240565.patch
Type: text/x-patch
Size: 2568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200127/9c6d585d/attachment.bin>


More information about the llvm-commits mailing list