diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index d02f2ad09d2f1..18135384021e8 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -945,6 +945,7 @@ void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init, isa(Init) || isa(Init) || isa(Init)) { auto *I = Builder.CreateStore(Init, Loc, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); if (IsAutoInit) I->addAnnotationMetadata("auto-init"); return; @@ -1188,6 +1189,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy(); if (canDoSingleStore) { auto *I = Builder.CreateStore(constant, Loc, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); if (IsAutoInit) I->addAnnotationMetadata("auto-init"); return; @@ -1200,6 +1202,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) { auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); + if (IsAutoInit) I->addAnnotationMetadata("auto-init"); @@ -1224,6 +1228,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, } auto *I = Builder.CreateMemSet( Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); if (IsAutoInit) I->addAnnotationMetadata("auto-init"); return; @@ -1270,6 +1275,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc, createUnnamedGlobalForMemcpyFrom( CGM, D, Builder, constant, Loc.getAlignment()), SizeVal, isVolatile); + addInstToCurrentSourceAtom(I, nullptr); + if (IsAutoInit) I->addAnnotationMetadata("auto-init"); } diff --git a/clang/test/DebugInfo/KeyInstructions/init-agg.cpp b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp new file mode 100644 index 0000000000000..5446aae155d63 --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp @@ -0,0 +1,48 @@ + +// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only -gno-column-info -emit-llvm -o - -ftrivial-auto-var-init=pattern \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// The implicit-check-not is important; we don't want the GEPs created for the +// store locations to be included in the atom group. + +int g; +void a() { +// CHECK: _Z1av() +// CHECK: call void @llvm.memcpy{{.*}}%A, {{.*}}@__const._Z1av.A{{.*}}, !dbg [[G1R1:!.*]] + int A[] = { 1, 2, 3 }; + +// CHECK: call void @llvm.memcpy{{.*}}%B, {{.*}}@__const._Z1av.B{{.*}}, !dbg [[G2R1:!.*]] +// CHECK-NEXT: store i32 1, ptr %B{{.*}}, !dbg [[G2R1:!.*]] +// CHECK-NEXT: %arrayinit.element = getelementptr {{.*}}, ptr %B, i64 1, !dbg [[B_LINE:!.*]] +// CHECK-NEXT: store i32 2, ptr %arrayinit.element{{.*}}, !dbg [[G2R1]] +// CHECK-NEXT: %arrayinit.element1 = getelementptr {{.*}}, ptr %B, i64 2, !dbg [[B_LINE]] +// CHECK-NEXT: %0 = load i32, ptr @g{{.*}}, !dbg [[G2R2:!.*]] +// CHECK-NEXT: store i32 %0, ptr %arrayinit.element1{{.*}}, !dbg [[G2R1]] + int B[] = { 1, 2, g }; + +// CHECK: call void @llvm.memset{{.*}}%big{{.*}} !dbg [[G3R1:!.*]] +// CHECK-NEXT: %1 = getelementptr {{.*}}, ptr %big, i32 0, i32 0, !dbg [[big_LINE:!.*]] +// CHECK-NEXT: store i8 97, ptr %1{{.*}}, !dbg [[G3R1]] +// CHECK-NEXT: %2 = getelementptr {{.*}}, ptr %big, i32 0, i32 1, !dbg [[big_LINE]] +// CHECK-NEXT: store i8 98, ptr %2{{.*}}, !dbg [[G3R1]] +// CHECK-NEXT: %3 = getelementptr {{.*}}, ptr %big, i32 0, i32 2, !dbg [[big_LINE]] +// CHECK-NEXT: store i8 99, ptr %3{{.*}}, !dbg [[G3R1]] +// CHECK-NEXT: %4 = getelementptr {{.*}}, ptr %big, i32 0, i32 3, !dbg [[big_LINE]] +// CHECK: store i8 100, ptr %4{{.*}} !dbg [[G3R1]] + char big[65536] = { 'a', 'b', 'c', 'd' }; + +// CHECK: call void @llvm.memset{{.*}}%arr{{.*}}, !dbg [[G4R1:!.*]] + char arr[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, }; + +// CHECK: store i8 -86, ptr %uninit{{.*}}, !dbg [[G5R1:!.*]], !annotation + char uninit; // -ftrivial-auto-var-init=pattern +} + +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[B_LINE]] = !DILocation(line: 21, scope: ![[#]]) +// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) +// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) +// CHECK: [[big_LINE]] = !DILocation(line: 32, scope: ![[#]]) +// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)