From c25359bdebc67e0f48c96a468fd665d6a6130219 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams Date: Thu, 3 Apr 2025 17:00:09 +0100 Subject: [PATCH] [KeyInstr][Clang] Member initalization atom 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/CGClass.cpp | 1 + clang/test/KeyInstructions/init-member.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 clang/test/KeyInstructions/init-member.cpp diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 98c93b5bb488..8ef795bfee41 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1338,6 +1338,7 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD, assert(!Member->isBaseInitializer()); assert(Member->isAnyMemberInitializer() && "Delegating initializer on non-delegating constructor"); + ApplyAtomGroup Grp(getDebugInfo()); CM.addMemberInitializer(Member); } CM.finish(); diff --git a/clang/test/KeyInstructions/init-member.cpp b/clang/test/KeyInstructions/init-member.cpp new file mode 100644 index 000000000000..60949bd8a604 --- /dev/null +++ b/clang/test/KeyInstructions/init-member.cpp @@ -0,0 +1,22 @@ +// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \ +// RUN: | FileCheck %s + +struct B { + float y; +}; + +class Cls { + public: + int x = 1; + B b = {5.f}; +}; + +void fun() { + Cls c; +} + +// CHECK: store i32 1, ptr %x{{.*}}, !dbg [[G1R1:!.*]] +// CHECK: store float 5.000000e+00, ptr %y{{.*}}, !dbg [[G2R1:!.*]] + +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)