From e5779b993f4f2d5e2c1b84562f5f80adfa73f4df Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Mon, 7 Apr 2025 11:57:46 +0100 Subject: [PATCH] [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/KeyInstructions/coerced-through-memory.c diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 01af35b494c4..a794b884a6fe 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1435,10 +1435,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/KeyInstructions/coerced-through-memory.c b/clang/test/KeyInstructions/coerced-through-memory.c new file mode 100644 index 000000000000..7bdef09b88f5 --- /dev/null +++ b/clang/test/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)