[llvm-branch-commits] [clang] [KeyInstr][Clang] Bitfield atom (PR #134648)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Apr 7 06:49:09 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134648.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+2-1) 
- (added) clang/test/KeyInstructions/bitfield.cpp (+13) 


``````````diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 7408c498b3a1a..a5e113a1a4397 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2614,7 +2614,8 @@ void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
   }
 
   // Write the new value back out.
-  Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, SrcVal);
 
   // Return the new value of the bit-field, if requested.
   if (Result) {
diff --git a/clang/test/KeyInstructions/bitfield.cpp b/clang/test/KeyInstructions/bitfield.cpp
new file mode 100644
index 0000000000000..0586050ba8397
--- /dev/null
+++ b/clang/test/KeyInstructions/bitfield.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
+
+struct S { int a:3; };
+
+void foo(int x, S s) {
+// CHECK: %bf.set = or i8 %bf.clear, %bf.value, !dbg [[G1R2:!.*]]
+// CHECK: store i8 %bf.set, ptr %s, align 4, !dbg [[G1R1:!.*]]
+  s.a = x;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)

``````````

</details>


https://github.com/llvm/llvm-project/pull/134648


More information about the llvm-branch-commits mailing list