1 2; Check that when variables are allocated on the stack we generate debug locations 3; for the stack location directly instead of generating a register+offset indirection. 4 5; RUN: llc -O2 -filetype=obj -disable-post-ra -mtriple=x86_64-unknown-linux-gnu < %s \ 6; RUN: | llvm-dwarfdump - | FileCheck %s 7; 8; int data = 17; 9; int sum = 0; 10; int zero = 0; 11; int *ptr; 12; 13; extern void foo(int i, int *p); 14; 15; int main() 16; { 17; int val; 18; val = data; 19; foo(1, &val); 20; foo(2, &data); 21; return zero; 22; } 23; 24; CHECK: .debug_info contents 25; CHECK: DW_TAG_subprogram 26; CHECK-NOT: NULL 27; CHECK: DW_TAG_variable 28; CHECK: DW_AT_location ({{.*}} 29; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_reg0 RAX 30; 31; Note: This is a location, so we don't want an extra DW_OP_deref at the end. 32; LLDB gets the location right without it: 33; Variable: ... name = "val", type = "int", location = [rsp+4], decl = frame.c:10 34; Adding the deref actually creates an invalid location: 35; ... [rsp+4] DW_OP_deref 36; 37; CHECK-NEXT: [{{0x.*}}, {{0x.*}}): DW_OP_breg7 RSP+4) 38; CHECK-NEXT: DW_AT_name ("val") 39 40; ModuleID = 'frame.c' 41source_filename = "frame.c" 42 43@data = dso_local global i32 17, align 4, !dbg !0 44@sum = dso_local local_unnamed_addr global i32 0, align 4, !dbg !6 45@zero = dso_local local_unnamed_addr global i32 0, align 4, !dbg !9 46@ptr = common dso_local local_unnamed_addr global ptr null, align 8, !dbg !11 47 48define dso_local i32 @main() local_unnamed_addr !dbg !17 { 49entry: 50 %val = alloca i32, align 4 51 %0 = bitcast ptr %val to ptr, !dbg !22 52 call void @llvm.lifetime.start(i64 4, ptr %0), !dbg !22 53 %1 = load i32, ptr @data, align 4, !dbg !23, !tbaa !24 54 tail call void @llvm.dbg.value(metadata i32 %1, metadata !21, metadata !28), !dbg !29 55 store i32 %1, ptr %val, align 4, !dbg !30, !tbaa !24 56 tail call void @llvm.dbg.value(metadata ptr %val, metadata !21, metadata !31), !dbg !29 57 call void @foo(i32 1, ptr nonnull %val), !dbg !32 58 call void @foo(i32 2, ptr nonnull @data), !dbg !33 59 %2 = load i32, ptr @zero, align 4, !dbg !34, !tbaa !24 60 call void @llvm.lifetime.end(i64 4, ptr %0), !dbg !35 61 ret i32 %2, !dbg !36 62} 63 64; Function Attrs: argmemonly nounwind 65declare void @llvm.lifetime.start(i64, ptr nocapture) #0 66 67declare void @foo(i32, ptr) local_unnamed_addr 68 69; Function Attrs: argmemonly nounwind 70declare void @llvm.lifetime.end(i64, ptr nocapture) #0 71 72; Function Attrs: nounwind readnone 73declare void @llvm.dbg.value(metadata, metadata, metadata) #1 74 75attributes #0 = { argmemonly nounwind } 76attributes #1 = { nounwind readnone } 77 78!llvm.dbg.cu = !{!2} 79!llvm.module.flags = !{!14, !15} 80!llvm.ident = !{!16} 81 82!0 = distinct !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 83!1 = !DIGlobalVariable(name: "data", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) 84!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 3.9.0 (trunk 273961)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) 85!3 = !DIFile(filename: "frame.c", directory: "/home/user/test") 86!4 = !{} 87!5 = !{!0, !6, !9, !11} 88!6 = distinct !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 89!7 = !DIGlobalVariable(name: "sum", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true) 90!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 91!9 = distinct !DIGlobalVariableExpression(var: !10, expr: !DIExpression()) 92!10 = !DIGlobalVariable(name: "zero", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true) 93!11 = distinct !DIGlobalVariableExpression(var: !12, expr: !DIExpression()) 94!12 = !DIGlobalVariable(name: "ptr", scope: !2, file: !3, line: 4, type: !13, isLocal: false, isDefinition: true) 95!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, align: 64) 96!14 = !{i32 2, !"Dwarf Version", i32 4} 97!15 = !{i32 2, !"Debug Info Version", i32 3} 98!16 = !{!"clang version 3.9.0 (trunk 273961)"} 99!17 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 8, type: !18, isLocal: false, isDefinition: true, scopeLine: 9, isOptimized: true, unit: !2, retainedNodes: !20) 100!18 = !DISubroutineType(types: !19) 101!19 = !{!8} 102!20 = !{!21} 103!21 = !DILocalVariable(name: "val", scope: !17, file: !3, line: 10, type: !8) 104!22 = !DILocation(line: 10, column: 3, scope: !17) 105!23 = !DILocation(line: 11, column: 9, scope: !17) 106!24 = !{!25, !25, i64 0} 107!25 = !{!"int", !26, i64 0} 108!26 = !{!"omnipotent char", !27, i64 0} 109!27 = !{!"Simple C/C++ TBAA"} 110!28 = !DIExpression() 111!29 = !DILocation(line: 10, column: 7, scope: !17) 112!30 = !DILocation(line: 11, column: 7, scope: !17) 113!31 = !DIExpression(DW_OP_deref) 114!32 = !DILocation(line: 12, column: 3, scope: !17) 115!33 = !DILocation(line: 13, column: 3, scope: !17) 116!34 = !DILocation(line: 14, column: 10, scope: !17) 117!35 = !DILocation(line: 15, column: 1, scope: !17) 118!36 = !DILocation(line: 14, column: 3, scope: !17) 119 120