1; RUN: llc %s -start-after=codegenprepare -stop-before=finalize-isel -experimental-debug-variable-locations=false -o - | FileCheck %s 2 3;; Generated from clang -O2 -emit-llvm -S -g reduce.c -o - 4;; $ cat reduce.c 5;; struct { 6;; int a; 7;; } * b; 8;; int c; 9;; void d() { 10;; int *e = &b->a - 1; // XXX 11;; c = *e; 12;; } 13;; 14;; The line marked XXX becomes a load and gep in IR. We have a variadic 15;; dbg.value using the gep, but we lose that gep in SelectionDAG. Ensure that 16;; we salvage the value. 17 18; CHECK: [[E_REG:%[0-9]+]]{{.+}} = MOV{{.+}} @b 19; CHECK: DBG_VALUE_LIST {{.*}}, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_constu, 4, DW_OP_minus, DW_OP_stack_value), [[E_REG]], debug-location 20 21target triple = "x86_64-unknown-linux-gnu" 22 23%struct.anon = type { i32 } 24 25@b = dso_local local_unnamed_addr global ptr null, align 8, !dbg !0 26@c = dso_local local_unnamed_addr global i32 0, align 4, !dbg !6 27 28define dso_local void @d() local_unnamed_addr !dbg !17 { 29entry: 30 %0 = load ptr, ptr @b, align 8, !dbg !23 31 %add.ptr = getelementptr inbounds %struct.anon, ptr %0, i64 -1, i32 0, !dbg !28 32 call void @llvm.dbg.value(metadata !DIArgList(ptr %add.ptr), metadata !21, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_stack_value)), !dbg !29 33 %1 = load i32, ptr %add.ptr, align 4, !dbg !30 34 store i32 %1, ptr @c, align 4, !dbg !33 35 ret void, !dbg !34 36} 37 38declare void @llvm.dbg.value(metadata, metadata, metadata) 39 40!llvm.dbg.cu = !{!2} 41!llvm.module.flags = !{!13, !14, !15} 42!llvm.ident = !{!16} 43 44!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 45!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 3, type: !9, isLocal: false, isDefinition: true) 46!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) 47!3 = !DIFile(filename: "reduce.c", directory: "/") 48!4 = !{} 49!5 = !{!0, !6} 50!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 51!7 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) 52!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 53!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64) 54!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 1, size: 32, elements: !11) 55!11 = !{!12} 56!12 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !10, file: !3, line: 2, baseType: !8, size: 32) 57!13 = !{i32 7, !"Dwarf Version", i32 4} 58!14 = !{i32 2, !"Debug Info Version", i32 3} 59!15 = !{i32 1, !"wchar_size", i32 4} 60!16 = !{!"clang version 11.0.0"} 61!17 = distinct !DISubprogram(name: "d", scope: !3, file: !3, line: 5, type: !18, scopeLine: 5, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !20) 62!18 = !DISubroutineType(types: !19) 63!19 = !{null} 64!20 = !{!21} 65!21 = !DILocalVariable(name: "e", scope: !17, file: !3, line: 6, type: !22) 66!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64) 67!23 = !DILocation(line: 6, column: 13, scope: !17) 68!28 = !DILocation(line: 6, column: 18, scope: !17) 69!29 = !DILocation(line: 0, scope: !17) 70!30 = !DILocation(line: 7, column: 7, scope: !17) 71!33 = !DILocation(line: 7, column: 5, scope: !17) 72!34 = !DILocation(line: 8, column: 1, scope: !17) 73