[clang] [CIR] Implement constant expression bitfield initialization (PR #162143)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 6 12:34:03 PDT 2025
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 cpp -- clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp clang/test/CIR/CodeGen/constant-inits.cpp
``````````
: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/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index f6a6be13c..82903c6a5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -188,7 +188,7 @@ bool ConstantAggregateBuilder::addBits(llvm::APInt bits, uint64_t offsetInBits,
const ASTContext &astContext = cgm.getASTContext();
const uint64_t charWidth = cgm.getASTContext().getCharWidth();
mlir::Type charTy = cgm.getBuilder().getUIntNTy(charWidth);
-
+
// Offset of where we want the first bit to go within the bits of the
// current char.
unsigned offsetWithinChar = offsetInBits % charWidth;
@@ -312,7 +312,7 @@ std::optional<size_t> ConstantAggregateBuilder::splitAt(CharUnits pos) {
size_t index = iter - elements.begin() - 1;
const Element &elt = elements[index];
-
+
// If we already have an element starting at pos, we're done.
if (elt.offset == pos)
return index;
@@ -336,7 +336,8 @@ bool ConstantAggregateBuilder::split(size_t index, CharUnits hint) {
return false;
}
-void ConstantAggregateBuilder::condense(CharUnits offset, mlir::Type desiredTy) {
+void ConstantAggregateBuilder::condense(CharUnits offset,
+ mlir::Type desiredTy) {
CharUnits desiredSize = getSize(desiredTy);
std::optional<size_t> firstElemToReplace = splitAt(offset);
@@ -361,11 +362,11 @@ void ConstantAggregateBuilder::condense(CharUnits offset, mlir::Type desiredTy)
// Build a new constant from the elements in the range.
SmallVector<Element> subElems(elements.begin() + first,
- elements.begin() + last);
+ elements.begin() + last);
mlir::Attribute replacement =
buildFrom(cgm, subElems, offset, desiredSize,
/*naturalLayout=*/false, desiredTy, false);
-
+
// Replace the range with the condensed constant.
Element newElt(mlir::cast<mlir::TypedAttr>(replacement), offset);
replace(elements, first, last, {newElt});
``````````
</details>
https://github.com/llvm/llvm-project/pull/162143
More information about the cfe-commits
mailing list