From c86b6c7c5dc66619a52c2ec61eaf571df932449f Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 7 Apr 2025 08:59:09 +0100 Subject: [PATCH 1/9] [KeyInstr][Clang] Coerced store atoms This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. The Key Instructions project is introduced, including a "quick summary" section at the top which adds context for this PR, here: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed. The Clang-side work is demoed here: https://github.com/llvm/llvm-project/pull/130943 --- clang/lib/CodeGen/CGCall.cpp | 3 ++- .../test/DebugInfo/KeyInstructions/coerced.c | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 clang/test/DebugInfo/KeyInstructions/coerced.c diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index bd920a2e3f2dd..11e9441f8c69e 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1432,7 +1432,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst, for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { Address EltPtr = Builder.CreateStructGEP(Dst, i); llvm::Value *Elt = Builder.CreateExtractValue(Src, i); - Builder.CreateStore(Elt, EltPtr, DstIsVolatile); + auto *I = Builder.CreateStore(Elt, EltPtr, DstIsVolatile); + addInstToCurrentSourceAtom(I, Elt); } } else { Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile); diff --git a/clang/test/DebugInfo/KeyInstructions/coerced.c b/clang/test/DebugInfo/KeyInstructions/coerced.c new file mode 100644 index 0000000000000..0e2a6464bb906 --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/coerced.c @@ -0,0 +1,24 @@ +// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target x86_64-unknown-linux \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target x86_64-unknown-linux \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +typedef struct { + void* a; + void* b; +} Struct; + +Struct get(); +void store() { + // CHECK: %1 = extractvalue { ptr, ptr } %call, 0, !dbg [[G1R2:!.*]] + // CHECK: store ptr %1, ptr {{.*}}, !dbg [[G1R1:!.*]] + // CHECK: %3 = extractvalue { ptr, ptr } %call, 1, !dbg [[G1R2]] + // CHECK: store ptr %3, ptr {{.*}}, !dbg [[G1R1:!.*]] + Struct s = get(); + // CHECK: ret void, !dbg [[G2R1:!.*]] +} + +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) From c02e47c9973397ace3ea45d995628c9deb0a0a94 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 7 Apr 2025 10:23:55 +0100 Subject: [PATCH 2/9] [KeyInstr][Clang] Coerced to int atom --- clang/lib/CodeGen/CGCall.cpp | 3 +- .../test/DebugInfo/KeyInstructions/coerced.c | 34 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 11e9441f8c69e..4faa36da5e274 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1436,7 +1436,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst, addInstToCurrentSourceAtom(I, Elt); } } else { - Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile); + auto * I = Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile); + addInstToCurrentSourceAtom(I, Src); } } else if (SrcTy->isIntegerTy()) { // If the source is a simple integer, coerce it directly. diff --git a/clang/test/DebugInfo/KeyInstructions/coerced.c b/clang/test/DebugInfo/KeyInstructions/coerced.c index 0e2a6464bb906..db570719689fd 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced.c @@ -1,24 +1,40 @@ // RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target x86_64-unknown-linux \ -// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank --check-prefixes=CHECK,CHECK-CXX // RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target x86_64-unknown-linux \ -// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank --check-prefixes=CHECK,CHECK-C typedef struct { void* a; void* b; } Struct; - Struct get(); -void store() { - // CHECK: %1 = extractvalue { ptr, ptr } %call, 0, !dbg [[G1R2:!.*]] - // CHECK: store ptr %1, ptr {{.*}}, !dbg [[G1R1:!.*]] - // CHECK: %3 = extractvalue { ptr, ptr } %call, 1, !dbg [[G1R2]] - // CHECK: store ptr %3, ptr {{.*}}, !dbg [[G1R1:!.*]] + +void test() { +// CHECK: %1 = extractvalue { ptr, ptr } %call, 0, !dbg [[G1R2:!.*]] +// CHECK: store ptr %1, ptr {{.*}}, !dbg [[G1R1:!.*]] +// CHECK: %3 = extractvalue { ptr, ptr } %call, 1, !dbg [[G1R2]] +// CHECK: store ptr %3, ptr {{.*}}, !dbg [[G1R1:!.*]] Struct s = get(); - // CHECK: ret void, !dbg [[G2R1:!.*]] +// CHECK: ret void, !dbg [[G2R1:!.*]] +} + +typedef struct { int i; } Int; +Int getInt(void); + +// CHECK-C: @test2 +// CHECK-CXX: @_Z5test2v +void test2() { +// CHECK: %call = call i32 @{{(_Z6)?}}getInt{{v?}}(), !dbg [[T2_G1R2:!.*]] +// CHECK: [[gep:%.*]] = getelementptr inbounds nuw %struct.Int, ptr %i, i32 0, i32 0 +// CHECK: store i32 %call, ptr [[gep]]{{.*}}, !dbg [[T2_G1R1:!.*]] + Int i = getInt(); +// CHECK: ret void, !dbg [[T2_G2R1:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[T2_G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[T2_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[T2_G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) From 15f4bd9811411431dda43dc9ae600754b3fdd655 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 7 Apr 2025 10:51:49 +0100 Subject: [PATCH 3/9] [KeyInstr][Clang] Coerced ptr to int atom --- clang/lib/CodeGen/CGCall.cpp | 3 ++- .../DebugInfo/KeyInstructions/coerced-ptr.c | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 clang/test/DebugInfo/KeyInstructions/coerced-ptr.c diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4faa36da5e274..771185d162673 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1424,7 +1424,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst, SrcSize == CGM.getDataLayout().getTypeAllocSize(Dst.getElementType())) { // If the value is supposed to be a pointer, convert it before storing it. Src = CoerceIntOrPtrToIntOrPtr(Src, Dst.getElementType(), *this); - Builder.CreateStore(Src, Dst, DstIsVolatile); + auto *I = Builder.CreateStore(Src, Dst, DstIsVolatile); + addInstToCurrentSourceAtom(I, Src); } else if (llvm::StructType *STy = dyn_cast(Src->getType())) { // Prefer scalar stores to first-class aggregate stores. diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c new file mode 100644 index 0000000000000..4face4bc78a88 --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c @@ -0,0 +1,21 @@ +// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target x86_64-windows-msvc \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target x86_64-windows-msvc \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +typedef struct { int *p; } Ptr; +Ptr getPtr(); +void f() { +// CHECK: %call = call i64{{.*}}, !dbg [[G1R3:!.*]] +// CHECK: [[gep:%.*]] = getelementptr inbounds nuw %struct.Ptr, ptr %p, i32 0, i32 0 +// CHECK: [[i2p:%.*]] = inttoptr i64 %call to ptr, !dbg [[G1R2:!.*]] +// CHECK: store ptr [[i2p]], ptr [[gep]], align 8, !dbg [[G1R1:!.*]] + Ptr p = getPtr(); +// CHECK: ret void, !dbg [[G2R1:!.*]] +} + +// CHECK: [[G1R3]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 3) +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) From e32d57fbd2be084cc3461338659e90c9d6c5262e Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 7 Apr 2025 11:31:25 +0100 Subject: [PATCH 4/9] [KeyInstr][Clang] Coerce packed struct atom --- clang/lib/CodeGen/CGCall.cpp | 3 ++- .../KeyInstructions/coerced-packed.c | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 clang/test/DebugInfo/KeyInstructions/coerced-packed.c diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 771185d162673..3996bef110dac 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1444,7 +1444,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst, // If the source is a simple integer, coerce it directly. llvm::Type *DstIntTy = Builder.getIntNTy(DstSize.getFixedValue() * 8); Src = CoerceIntOrPtrToIntOrPtr(Src, DstIntTy, *this); - Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile); + auto *I = Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile); + addInstToCurrentSourceAtom(I, Src); } else { // Otherwise do coercion through memory. This is stupid, but // simple. diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-packed.c b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c new file mode 100644 index 0000000000000..476d3f742cec2 --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c @@ -0,0 +1,22 @@ +// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target arm64-apple-ios11 \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target arm64-apple-ios11 \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +typedef struct { + char a; + int x; +} __attribute((packed)) S; + +S getS(); +void f() { +// CHECK: [[call:%.*]] = call i40{{.*}}getS{{.*}}, !dbg [[G1R2:!.*]] +// CHECK: store i40 [[call]], ptr %s, align 1, !dbg [[G1R1:!.*]] + S s = getS(); +// CHECK: ret void, !dbg [[G2R1:!.*]] +} + +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) From 20ba846606753dd772b784102f31ee1bf1b1ce26 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 7 Apr 2025 11:57:46 +0100 Subject: [PATCH 5/9] [KeyInstr][Clang] Coerce through memory atom --- clang/lib/CodeGen/CGCall.cpp | 9 ++++--- .../KeyInstructions/coerced-through-memory.c | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 3996bef110dac..0e9d8a0b93b65 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1459,10 +1459,11 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst, RawAddress Tmp = CreateTempAllocaForCoercion(*this, SrcTy, Dst.getAlignment()); Builder.CreateStore(Src, Tmp); - Builder.CreateMemCpy(Dst.emitRawPointer(*this), - Dst.getAlignment().getAsAlign(), Tmp.getPointer(), - Tmp.getAlignment().getAsAlign(), - Builder.CreateTypeSize(IntPtrTy, DstSize)); + auto *I = Builder.CreateMemCpy( + Dst.emitRawPointer(*this), Dst.getAlignment().getAsAlign(), + Tmp.getPointer(), Tmp.getAlignment().getAsAlign(), + Builder.CreateTypeSize(IntPtrTy, DstSize)); + addInstToCurrentSourceAtom(I, Src); } } diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c new file mode 100644 index 0000000000000..7bdef09b88f5a --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c @@ -0,0 +1,26 @@ +// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target aarch64-windows-msvc \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target aarch64-windows-msvc \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +typedef struct { + short a; + int b; + short c; +} S; + +S getS(void); + +void f() { +// CHECK: %call = call [2 x i64] {{.*}}getS{{.*}}(), !dbg [[G1R2:!.*]] +//// Note: The store to the tmp alloca isn't part of the atom. +// CHECK: store [2 x i64] %call, ptr %tmp.coerce, align 8 +// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %s, ptr align 8 %tmp.coerce, i64 12, i1 false), !dbg [[G1R1:!.*]] + S s = getS(); +// CHECK: ret void, !dbg [[G2R1:!.*]] +} + +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) From 5b9da397ff336dde25af59fee5ed06990bac8f53 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Wed, 21 May 2025 17:16:03 +0100 Subject: [PATCH 6/9] cc1 --- clang/test/DebugInfo/KeyInstructions/coerced-packed.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/coerced-ptr.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/coerced.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-packed.c b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c index 476d3f742cec2..d3e86c5ec9e39 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-packed.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c @@ -1,7 +1,7 @@ -// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target arm64-apple-ios11 \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target arm64-apple-ios11 \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target arm64-apple-ios11 \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target arm64-apple-ios11 \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef struct { diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c index 4face4bc78a88..6f5cdf677a996 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c @@ -1,7 +1,7 @@ -// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target x86_64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target x86_64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef struct { int *p; } Ptr; diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c index 7bdef09b88f5a..7560b500e0fcc 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c @@ -1,7 +1,7 @@ -// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target aarch64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target aarch64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target aarch64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target aarch64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef struct { diff --git a/clang/test/DebugInfo/KeyInstructions/coerced.c b/clang/test/DebugInfo/KeyInstructions/coerced.c index db570719689fd..a02c6c90ec77a 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced.c @@ -1,7 +1,7 @@ -// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - -target x86_64-unknown-linux \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-unknown-linux \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank --check-prefixes=CHECK,CHECK-CXX -// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - -target x86_64-unknown-linux \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-unknown-linux \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank --check-prefixes=CHECK,CHECK-C typedef struct { From 85b030c57ad1c7ffee408206525891d64fca13e6 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Tue, 3 Jun 2025 09:13:33 +0100 Subject: [PATCH 7/9] remove ret atoms: coming in later patch --- clang/test/DebugInfo/KeyInstructions/coerced-packed.c | 2 -- clang/test/DebugInfo/KeyInstructions/coerced-ptr.c | 2 -- clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c | 2 -- clang/test/DebugInfo/KeyInstructions/coerced.c | 4 ---- 4 files changed, 10 deletions(-) diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-packed.c b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c index d3e86c5ec9e39..5963935b9ca44 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-packed.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c @@ -14,9 +14,7 @@ void f() { // CHECK: [[call:%.*]] = call i40{{.*}}getS{{.*}}, !dbg [[G1R2:!.*]] // CHECK: store i40 [[call]], ptr %s, align 1, !dbg [[G1R1:!.*]] S s = getS(); -// CHECK: ret void, !dbg [[G2R1:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c index 6f5cdf677a996..054f9f3f46270 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c @@ -12,10 +12,8 @@ void f() { // CHECK: [[i2p:%.*]] = inttoptr i64 %call to ptr, !dbg [[G1R2:!.*]] // CHECK: store ptr [[i2p]], ptr [[gep]], align 8, !dbg [[G1R1:!.*]] Ptr p = getPtr(); -// CHECK: ret void, !dbg [[G2R1:!.*]] } // CHECK: [[G1R3]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 3) // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c index 7560b500e0fcc..e0d072ba9f356 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c @@ -18,9 +18,7 @@ void f() { // CHECK: store [2 x i64] %call, ptr %tmp.coerce, align 8 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %s, ptr align 8 %tmp.coerce, i64 12, i1 false), !dbg [[G1R1:!.*]] S s = getS(); -// CHECK: ret void, !dbg [[G2R1:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) diff --git a/clang/test/DebugInfo/KeyInstructions/coerced.c b/clang/test/DebugInfo/KeyInstructions/coerced.c index a02c6c90ec77a..e284e7fa412c3 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced.c @@ -16,7 +16,6 @@ void test() { // CHECK: %3 = extractvalue { ptr, ptr } %call, 1, !dbg [[G1R2]] // CHECK: store ptr %3, ptr {{.*}}, !dbg [[G1R1:!.*]] Struct s = get(); -// CHECK: ret void, !dbg [[G2R1:!.*]] } typedef struct { int i; } Int; @@ -29,12 +28,9 @@ void test2() { // CHECK: [[gep:%.*]] = getelementptr inbounds nuw %struct.Int, ptr %i, i32 0, i32 0 // CHECK: store i32 %call, ptr [[gep]]{{.*}}, !dbg [[T2_G1R1:!.*]] Int i = getInt(); -// CHECK: ret void, !dbg [[T2_G2R1:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) // CHECK: [[T2_G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[T2_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[T2_G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) From 158bf4e39865236c8d77cdd828c0054d40d2c69b Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Tue, 3 Jun 2025 09:15:54 +0100 Subject: [PATCH 8/9] fix RUN lines --- clang/test/DebugInfo/KeyInstructions/coerced-packed.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/coerced-ptr.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/coerced.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-packed.c b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c index 5963935b9ca44..90ec8420b0d8c 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-packed.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-packed.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target arm64-apple-ios11 \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple arm64-apple-ios11 \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target arm64-apple-ios11 \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple arm64-apple-ios11 \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef struct { diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c index 054f9f3f46270..0002e9051220b 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-ptr.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple x86_64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple x86_64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef struct { int *p; } Ptr; diff --git a/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c index e0d072ba9f356..98361aa9806ef 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced-through-memory.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target aarch64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple aarch64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target aarch64-windows-msvc \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple aarch64-windows-msvc \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef struct { diff --git a/clang/test/DebugInfo/KeyInstructions/coerced.c b/clang/test/DebugInfo/KeyInstructions/coerced.c index e284e7fa412c3..b5a254fb641c9 100644 --- a/clang/test/DebugInfo/KeyInstructions/coerced.c +++ b/clang/test/DebugInfo/KeyInstructions/coerced.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-unknown-linux \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple x86_64-unknown-linux \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank --check-prefixes=CHECK,CHECK-CXX -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s %clang_cc1-debug-info-kind=line-tables-only -emit-llvm -o - -target x86_64-unknown-linux \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - -triple x86_64-unknown-linux \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank --check-prefixes=CHECK,CHECK-C typedef struct { From e82a363f74bea9ba12d3804f4c055eda8657c437 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Tue, 3 Jun 2025 09:16:15 +0100 Subject: [PATCH 9/9] clang-format --- clang/lib/CodeGen/CGCall.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 0e9d8a0b93b65..a7e571ec465c2 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1437,14 +1437,16 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst, addInstToCurrentSourceAtom(I, Elt); } } else { - auto * I = Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile); + auto *I = + Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile); addInstToCurrentSourceAtom(I, Src); } } else if (SrcTy->isIntegerTy()) { // If the source is a simple integer, coerce it directly. llvm::Type *DstIntTy = Builder.getIntNTy(DstSize.getFixedValue() * 8); Src = CoerceIntOrPtrToIntOrPtr(Src, DstIntTy, *this); - auto *I = Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile); + auto *I = + Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile); addInstToCurrentSourceAtom(I, Src); } else { // Otherwise do coercion through memory. This is stupid, but