[clang] [clang][CodeGen] Add TBAA for bit-field accesses (PR #226806)

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 09:50:33 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions c,cpp -- clang/test/CodeGen/tbaa-bitfield-access.c clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CodeGenTBAA.cpp clang/test/CodeGen/tbaa-struct.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index bea3a8096..f51ca0af0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3074,8 +3074,7 @@ void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
   // and mask together with source before storing.
   if (StorageSize != Info.Size) {
     assert(StorageSize > Info.Size && "Invalid bitfield size.");
-    auto *Load =
-        Builder.CreateLoad(Ptr, Dst.isVolatileQualified(), "bf.load");
+    auto *Load = Builder.CreateLoad(Ptr, Dst.isVolatileQualified(), "bf.load");
     CGM.DecorateInstructionWithTBAA(Load, Dst.getTBAAInfo());
     llvm::Value *Val = Load;
 
@@ -3104,8 +3103,8 @@ void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
     // of the container. The two accesses are not atomic.
     if (Dst.isVolatileQualified() && CodeGenUtils::isAAPCS(CGM.getTarget()) &&
         CGM.getCodeGenOpts().ForceAAPCSBitfieldLoad)
-      CGM.DecorateInstructionWithTBAA(
-          Builder.CreateLoad(Ptr, true, "bf.load"), Dst.getTBAAInfo());
+      CGM.DecorateInstructionWithTBAA(Builder.CreateLoad(Ptr, true, "bf.load"),
+                                      Dst.getTBAAInfo());
   }
 
   // Write the new value back out.
@@ -6030,8 +6029,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, const FieldDecl *field,
       if (FieldTBAAInfo.BaseType)
         FieldTBAAInfo.Offset += Info.StorageOffset.getQuantity();
       FieldTBAAInfo.AccessType = CGM.getTBAATypeInfo(getContext().CharTy);
-      FieldTBAAInfo.Size =
-          getContext().toCharUnitsFromBits(SS).getQuantity();
+      FieldTBAAInfo.Size = getContext().toCharUnitsFromBits(SS).getQuantity();
     }
     LValueBaseInfo FieldBaseInfo(BaseInfo.getAlignmentSource());
     return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo,
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8e7e202af..813a23550 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -578,9 +578,8 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
           continue;
         BitFieldStorageUnits.emplace_back(Offset, Size);
       } else {
-        TypeNode = isValidBaseType(FieldQTy)
-                       ? getValidBaseTypeInfo(FieldQTy)
-                       : getTypeInfo(FieldQTy);
+        TypeNode = isValidBaseType(FieldQTy) ? getValidBaseTypeInfo(FieldQTy)
+                                             : getTypeInfo(FieldQTy);
         uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
         Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
         Size = Context.getTypeSizeInChars(FieldQTy).getQuantity();

``````````

</details>


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


More information about the cfe-commits mailing list