389 lines · plain
1; RUN: %llc_dwarf -O2 -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck %s2 3; This is a test case that's as reduced as I can get it, though I haven't fully4; understood the mechanisms by which this bug occurs, so perhaps there's further5; simplification to be had (it's certainly a bit non-obvious what's going on). I6; hesitate to hand-craft or otherwise simplify the IR compared to what Clang7; generates as this is a particular tickling of optimizations and debug location8; propagation I want a realistic example of.9 10; Generated with clang-tot -cc1 -g -O2 -w -std=c++11 -fsanitize=address,use-after-return -fcxx-exceptions -fexceptions -x c++ incorrect-variable-debug-loc.cpp -emit-llvm11 12; struct A {13; int m_fn1();14; };15;16; struct B {17; void __attribute__((always_inline)) m_fn2() { i = 0; }18; int i;19; };20;21; struct C {22; void m_fn3();23; int j;24; B b;25; };26;27; int fn1() {28; C A;29; A.b.m_fn2();30; A.m_fn3();31; }32; void C::m_fn3() {33; A().m_fn1();34; b.m_fn2();35; }36 37; CHECK: DW_TAG_structure_type38; CHECK-NEXT: DW_AT_name ("C")39; CHECK: [[M_FN3_DECL:.*]]: DW_TAG_subprogram40; CHECK-NOT: {{DW_TAG|NULL}}41; CHECK: DW_AT_name ("m_fn3")42 43; CHECK: DW_AT_specification ([[M_FN3_DECL]]44; CHECK-NOT: DW_TAG45; CHECK: DW_TAG_formal_parameter46; CHECK-NOT: DW_TAG47; CHECK: DW_AT_name ("this")48 49%struct.C = type { i32, %struct.B }50%struct.B = type { i32 }51%struct.A = type { i8 }52 53@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @asan.module_ctor, ptr null }]54@__asan_option_detect_stack_use_after_return = external global i3255@___asan_gen_ = private unnamed_addr constant [11 x i8] c"1 32 8 1 A\00", align 156@___asan_gen_1 = private unnamed_addr constant [13 x i8] c"1 32 1 3 tmp\00", align 157 58; Function Attrs: noreturn sanitize_address59define i32 @_Z3fn1v() #0 !dbg !22 {60entry:61 %MyAlloca = alloca [64 x i8], align 32, !dbg !3962 %0 = ptrtoint ptr %MyAlloca to i64, !dbg !3963 %1 = load i32, ptr @__asan_option_detect_stack_use_after_return, !dbg !3964 %2 = icmp ne i32 %1, 0, !dbg !3965 br i1 %2, label %3, label %566 67; <label>:3 ; preds = %entry68 %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0), !dbg !3969 br label %570 71; <label>:5 ; preds = %entry, %372 %6 = phi i64 [ %0, %entry ], [ %4, %3 ], !dbg !3973 %7 = add i64 %6, 32, !dbg !3974 %8 = inttoptr i64 %7 to ptr, !dbg !3975 %9 = inttoptr i64 %6 to ptr, !dbg !3976 store i64 1102416563, ptr %9, !dbg !3977 %10 = add i64 %6, 8, !dbg !3978 %11 = inttoptr i64 %10 to ptr, !dbg !3979 store i64 ptrtoint (ptr @___asan_gen_ to i64), ptr %11, !dbg !3980 %12 = add i64 %6, 16, !dbg !3981 %13 = inttoptr i64 %12 to ptr, !dbg !3982 store i64 ptrtoint (ptr @_Z3fn1v to i64), ptr %13, !dbg !3983 %14 = lshr i64 %6, 3, !dbg !3984 %15 = add i64 %14, 2147450880, !dbg !3985 %16 = add i64 %15, 0, !dbg !3986 %17 = inttoptr i64 %16 to ptr, !dbg !3987 store i64 -868083117767659023, ptr %17, !dbg !3988 %i.i = getelementptr inbounds %struct.C, ptr %8, i64 0, i32 1, i32 0, !dbg !3989 %18 = ptrtoint ptr %i.i to i64, !dbg !3990 %19 = lshr i64 %18, 3, !dbg !3991 %20 = add i64 %19, 2147450880, !dbg !3992 %21 = inttoptr i64 %20 to ptr, !dbg !3993 %22 = load i8, ptr %21, !dbg !3994 %23 = icmp ne i8 %22, 0, !dbg !3995 br i1 %23, label %24, label %30, !dbg !3996 97; <label>:24 ; preds = %598 %25 = and i64 %18, 7, !dbg !3999 %26 = add i64 %25, 3, !dbg !39100 %27 = trunc i64 %26 to i8, !dbg !39101 %28 = icmp sge i8 %27, %22, !dbg !39102 br i1 %28, label %29, label %30103 104; <label>:29 ; preds = %24105 call void @__asan_report_store4(i64 %18), !dbg !39106 call void asm sideeffect "", ""()107 unreachable108 109; <label>:30 ; preds = %24, %5110 store i32 0, ptr %i.i, align 4, !dbg !39, !tbaa !41111 tail call void @llvm.dbg.value(metadata ptr %8, metadata !27, metadata !DIExpression(DW_OP_deref)), !dbg !46112 call void @_ZN1C5m_fn3Ev(ptr %8), !dbg !47113 unreachable, !dbg !47114}115 116; Function Attrs: sanitize_address117define void @_ZN1C5m_fn3Ev(ptr nocapture %this) #1 align 2 !dbg !28 {118entry:119 %MyAlloca = alloca [64 x i8], align 32, !dbg !48120 %0 = ptrtoint ptr %MyAlloca to i64, !dbg !48121 %1 = load i32, ptr @__asan_option_detect_stack_use_after_return, !dbg !48122 %2 = icmp ne i32 %1, 0, !dbg !48123 br i1 %2, label %3, label %5124 125; <label>:3 ; preds = %entry126 %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0), !dbg !48127 br label %5128 129; <label>:5 ; preds = %entry, %3130 %6 = phi i64 [ %0, %entry ], [ %4, %3 ], !dbg !48131 %7 = add i64 %6, 32, !dbg !48132 %8 = inttoptr i64 %7 to ptr, !dbg !48133 %9 = inttoptr i64 %6 to ptr, !dbg !48134 store i64 1102416563, ptr %9, !dbg !48135 %10 = add i64 %6, 8, !dbg !48136 %11 = inttoptr i64 %10 to ptr, !dbg !48137 store i64 ptrtoint (ptr @___asan_gen_1 to i64), ptr %11, !dbg !48138 %12 = add i64 %6, 16, !dbg !48139 %13 = inttoptr i64 %12 to ptr, !dbg !48140 store i64 ptrtoint (ptr @_ZN1C5m_fn3Ev to i64), ptr %13, !dbg !48141 %14 = lshr i64 %6, 3, !dbg !48142 %15 = add i64 %14, 2147450880, !dbg !48143 %16 = add i64 %15, 0, !dbg !48144 %17 = inttoptr i64 %16 to ptr, !dbg !48145 store i64 -868083113472691727, ptr %17, !dbg !48146 tail call void @llvm.dbg.value(metadata ptr %this, metadata !30, metadata !DIExpression()), !dbg !48147 %call = call i32 @_ZN1A5m_fn1Ev(ptr %8), !dbg !49148 %i.i = getelementptr inbounds %struct.C, ptr %this, i64 0, i32 1, i32 0, !dbg !50149 %18 = ptrtoint ptr %i.i to i64, !dbg !50150 %19 = lshr i64 %18, 3, !dbg !50151 %20 = add i64 %19, 2147450880, !dbg !50152 %21 = inttoptr i64 %20 to ptr, !dbg !50153 %22 = load i8, ptr %21, !dbg !50154 %23 = icmp ne i8 %22, 0, !dbg !50155 br i1 %23, label %24, label %30, !dbg !50156 157; <label>:24 ; preds = %5158 %25 = and i64 %18, 7, !dbg !50159 %26 = add i64 %25, 3, !dbg !50160 %27 = trunc i64 %26 to i8, !dbg !50161 %28 = icmp sge i8 %27, %22, !dbg !50162 br i1 %28, label %29, label %30163 164; <label>:29 ; preds = %24165 call void @__asan_report_store4(i64 %18), !dbg !50166 call void asm sideeffect "", ""()167 unreachable168 169; <label>:30 ; preds = %24, %5170 store i32 0, ptr %i.i, align 4, !dbg !50, !tbaa !41171 store i64 1172321806, ptr %9, !dbg !52172 %31 = icmp ne i64 %6, %0, !dbg !52173 br i1 %31, label %32, label %39, !dbg !52174 175; <label>:32 ; preds = %30176 %33 = add i64 %15, 0, !dbg !52177 %34 = inttoptr i64 %33 to ptr, !dbg !52178 store i64 -723401728380766731, ptr %34, !dbg !52179 %35 = add i64 %6, 56, !dbg !52180 %36 = inttoptr i64 %35 to ptr, !dbg !52181 %37 = load i64, ptr %36, !dbg !52182 %38 = inttoptr i64 %37 to ptr, !dbg !52183 store i8 0, ptr %38, !dbg !52184 br label %42, !dbg !52185 186; <label>:39 ; preds = %30187 %40 = add i64 %15, 0, !dbg !52188 %41 = inttoptr i64 %40 to ptr, !dbg !52189 store i64 0, ptr %41, !dbg !52190 br label %42, !dbg !52191 192; <label>:42 ; preds = %39, %32193 ret void, !dbg !52194}195 196declare i32 @_ZN1A5m_fn1Ev(ptr) #2197 198; Function Attrs: nounwind readnone199declare void @llvm.dbg.value(metadata, metadata, metadata) #3200 201define internal void @asan.module_ctor() {202 tail call void @__asan_init_v3()203 ret void204}205 206declare void @__asan_init_v3()207 208declare void @__asan_report_load1(i64)209 210declare void @__asan_load1(i64)211 212declare void @__asan_report_load2(i64)213 214declare void @__asan_load2(i64)215 216declare void @__asan_report_load4(i64)217 218declare void @__asan_load4(i64)219 220declare void @__asan_report_load8(i64)221 222declare void @__asan_load8(i64)223 224declare void @__asan_report_load16(i64)225 226declare void @__asan_load16(i64)227 228declare void @__asan_report_store1(i64)229 230declare void @__asan_store1(i64)231 232declare void @__asan_report_store2(i64)233 234declare void @__asan_store2(i64)235 236declare void @__asan_report_store4(i64)237 238declare void @__asan_store4(i64)239 240declare void @__asan_report_store8(i64)241 242declare void @__asan_store8(i64)243 244declare void @__asan_report_store16(i64)245 246declare void @__asan_store16(i64)247 248declare void @__asan_report_load_n(i64, i64)249 250declare void @__asan_report_store_n(i64, i64)251 252declare void @__asan_loadN(i64, i64)253 254declare void @__asan_storeN(i64, i64)255 256declare ptr @__asan_memmove(ptr, ptr, i64)257 258declare ptr @__asan_memcpy(ptr, ptr, i64)259 260declare ptr @__asan_memset(ptr, i32, i64)261 262declare void @__asan_handle_no_return()263 264declare void @__sanitizer_cov()265 266declare void @__sanitizer_ptr_cmp(i64, i64)267 268declare void @__sanitizer_ptr_sub(i64, i64)269 270declare i64 @__asan_stack_malloc_0(i64, i64)271 272declare void @__asan_stack_free_0(i64, i64, i64)273 274declare i64 @__asan_stack_malloc_1(i64, i64)275 276declare void @__asan_stack_free_1(i64, i64, i64)277 278declare i64 @__asan_stack_malloc_2(i64, i64)279 280declare void @__asan_stack_free_2(i64, i64, i64)281 282declare i64 @__asan_stack_malloc_3(i64, i64)283 284declare void @__asan_stack_free_3(i64, i64, i64)285 286declare i64 @__asan_stack_malloc_4(i64, i64)287 288declare void @__asan_stack_free_4(i64, i64, i64)289 290declare i64 @__asan_stack_malloc_5(i64, i64)291 292declare void @__asan_stack_free_5(i64, i64, i64)293 294declare i64 @__asan_stack_malloc_6(i64, i64)295 296declare void @__asan_stack_free_6(i64, i64, i64)297 298declare i64 @__asan_stack_malloc_7(i64, i64)299 300declare void @__asan_stack_free_7(i64, i64, i64)301 302declare i64 @__asan_stack_malloc_8(i64, i64)303 304declare void @__asan_stack_free_8(i64, i64, i64)305 306declare i64 @__asan_stack_malloc_9(i64, i64)307 308declare void @__asan_stack_free_9(i64, i64, i64)309 310declare i64 @__asan_stack_malloc_10(i64, i64)311 312declare void @__asan_stack_free_10(i64, i64, i64)313 314declare void @__asan_poison_stack_memory(i64, i64)315 316declare void @__asan_unpoison_stack_memory(i64, i64)317 318declare void @__asan_before_dynamic_init(i64)319 320declare void @__asan_after_dynamic_init()321 322declare void @__asan_register_globals(i64, i64)323 324declare void @__asan_unregister_globals(i64, i64)325 326declare void @__sanitizer_cov_module_init(i64)327 328attributes #0 = { noreturn sanitize_address "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "use-soft-float"="false" }329attributes #1 = { sanitize_address "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "use-soft-float"="false" }330attributes #2 = { "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "use-soft-float"="false" }331attributes #3 = { nounwind readnone }332 333!llvm.dbg.cu = !{!0}334!llvm.module.flags = !{!36, !37}335!llvm.ident = !{!38}336 337!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !3, globals: !2, imports: !2)338!1 = !DIFile(filename: "<stdin>", directory: "/tmp/dbginfo")339!2 = !{}340!3 = !{!4, !14}341!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", line: 10, size: 64, align: 32, file: !5, elements: !6, identifier: "_ZTS1C")342!5 = !DIFile(filename: "incorrect-variable-debug-loc.cpp", directory: "/tmp/dbginfo")343!6 = !{!7, !9, !10}344!7 = !DIDerivedType(tag: DW_TAG_member, name: "j", line: 12, size: 32, align: 32, file: !5, scope: !4, baseType: !8)345!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)346!9 = !DIDerivedType(tag: DW_TAG_member, name: "b", line: 13, size: 32, align: 32, offset: 32, file: !5, scope: !4, baseType: !14)347!10 = !DISubprogram(name: "m_fn3", linkageName: "_ZN1C5m_fn3Ev", line: 11, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 11, file: !5, scope: !4, type: !11)348!11 = !DISubroutineType(types: !12)349!12 = !{null, !13}350!13 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !4)351!14 = !DICompositeType(tag: DW_TAG_structure_type, name: "B", line: 5, size: 32, align: 32, file: !5, elements: !15, identifier: "_ZTS1B")352!15 = !{!16, !17}353!16 = !DIDerivedType(tag: DW_TAG_member, name: "i", line: 7, size: 32, align: 32, file: !5, scope: !14, baseType: !8)354!17 = !DISubprogram(name: "m_fn2", linkageName: "_ZN1B5m_fn2Ev", line: 6, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 6, file: !5, scope: !14, type: !18)355!18 = !DISubroutineType(types: !19)356!19 = !{null, !20}357!20 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !14)358!22 = distinct !DISubprogram(name: "fn1", linkageName: "_Z3fn1v", line: 16, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 16, file: !5, scope: !23, type: !24, retainedNodes: !26)359!23 = !DIFile(filename: "incorrect-variable-debug-loc.cpp", directory: "/tmp/dbginfo")360!24 = !DISubroutineType(types: !25)361!25 = !{!8}362!26 = !{!27}363!27 = !DILocalVariable(name: "A", line: 17, scope: !22, file: !23, type: !4)364!28 = distinct !DISubprogram(name: "m_fn3", linkageName: "_ZN1C5m_fn3Ev", line: 21, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 21, file: !5, scope: !4, type: !11, declaration: !10, retainedNodes: !29)365!29 = !{!30}366!30 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !28, type: !31)367!31 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !4)368!32 = distinct !DISubprogram(name: "m_fn2", linkageName: "_ZN1B5m_fn2Ev", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 6, file: !5, scope: !14, type: !18, declaration: !17, retainedNodes: !33)369!33 = !{!34}370!34 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !32, type: !35)371!35 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !14)372!36 = !{i32 2, !"Dwarf Version", i32 4}373!37 = !{i32 2, !"Debug Info Version", i32 3}374!38 = !{!"clang version 3.5.0 "}375!39 = !DILocation(line: 6, scope: !32, inlinedAt: !40)376!40 = !DILocation(line: 18, scope: !22)377!41 = !{!42, !43, i64 0}378!42 = !{!"struct", !43, i64 0}379!43 = !{!"int", !44, i64 0}380!44 = !{!"omnipotent char", !45, i64 0}381!45 = !{!"Simple C/C++ TBAA"}382!46 = !DILocation(line: 17, scope: !22)383!47 = !DILocation(line: 19, scope: !22)384!48 = !DILocation(line: 0, scope: !28)385!49 = !DILocation(line: 22, scope: !28)386!50 = !DILocation(line: 6, scope: !32, inlinedAt: !51)387!51 = !DILocation(line: 23, scope: !28)388!52 = !DILocation(line: 24, scope: !28)389