80 lines · plain
1; RUN: opt -passes=mem2reg %s -S -o - | FileCheck %s2 3;; Check that mem2reg removes dbg.value(%local, DIExpression(DW_OP_deref...))4;; that instcombine LowerDbgDeclare inserted before the call to 'esc' when5;; promoting the alloca %local after 'esc' has been inlined. Without this we6;; provide no location for 'local', even though it is provably constant7;; throughout after inlining.8;;9;; $ clang reduce.c -O2 -g -emit-llvm -S -o tmp.ll -Xclang -disable-llvm-passes10;; $ opt tmp.ll -o - -instcombine -inline -S11;; $ cat reduce.c12;; __attribute__((__always_inline__))13;; static void esc(unsigned char **c) {14;; *c += 4;15;; }16;; void fun() {17;; unsigned char *local = 0;18;; esc(&local);19;; }20 21; CHECK: define dso_local void @fun()22; CHECK-NEXT: entry:23; CHECK-NEXT: #dbg_value(ptr null, ![[LOCAL:[0-9]+]], !DIExpression(),24; CHECK-NOT: #dbg_value({{.*}}, ![[LOCAL]]25; CHECK: ![[LOCAL]] = !DILocalVariable(name: "local",26 27define dso_local void @fun() !dbg !7 {28entry:29 %local = alloca ptr, align 830 %0 = bitcast ptr %local to ptr, !dbg !1431 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %0) #3, !dbg !1432 call void @llvm.dbg.value(metadata ptr null, metadata !11, metadata !DIExpression()), !dbg !1533 store ptr null, ptr %local, align 8, !dbg !1634 call void @llvm.dbg.value(metadata ptr %local, metadata !11, metadata !DIExpression(DW_OP_deref)), !dbg !1535 call void @llvm.dbg.value(metadata ptr %local, metadata !21, metadata !DIExpression()), !dbg !2736 call void @llvm.dbg.value(metadata ptr %local, metadata !21, metadata !DIExpression()), !dbg !2737 %1 = load ptr, ptr %local, align 8, !dbg !2938 %add.ptr.i = getelementptr inbounds i8, ptr %1, i64 4, !dbg !2939 store ptr %add.ptr.i, ptr %local, align 8, !dbg !2940 %2 = bitcast ptr %local to ptr, !dbg !3041 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3, !dbg !3042 ret void, !dbg !3043}44 45declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)46declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)47declare void @llvm.dbg.value(metadata, metadata, metadata)48 49!llvm.dbg.cu = !{!0}50!llvm.module.flags = !{!3, !4, !5}51!llvm.ident = !{!6}52 53!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)54!1 = !DIFile(filename: "reduce.c", directory: "/")55!2 = !{}56!3 = !{i32 7, !"Dwarf Version", i32 4}57!4 = !{i32 2, !"Debug Info Version", i32 3}58!5 = !{i32 1, !"wchar_size", i32 4}59!6 = !{!"clang version 12.0.0"}60!7 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)61!8 = !DISubroutineType(types: !9)62!9 = !{null}63!10 = !{!11}64!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 6, type: !12)65!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)66!13 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)67!14 = !DILocation(line: 6, column: 3, scope: !7)68!15 = !DILocation(line: 0, scope: !7)69!16 = !DILocation(line: 6, column: 18, scope: !7)70!21 = !DILocalVariable(name: "c", arg: 1, scope: !22, file: !1, line: 2, type: !25)71!22 = distinct !DISubprogram(name: "esc", scope: !1, file: !1, line: 2, type: !23, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !26)72!23 = !DISubroutineType(types: !24)73!24 = !{null, !25}74!25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)75!26 = !{!21}76!27 = !DILocation(line: 0, scope: !22, inlinedAt: !28)77!28 = distinct !DILocation(line: 7, column: 3, scope: !7)78!29 = !DILocation(line: 3, column: 6, scope: !22, inlinedAt: !28)79!30 = !DILocation(line: 8, column: 1, scope: !7)80