[clang] 2767ff4 - [CIR][NFC] Upstream computeVolatileBitfields (#145414)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 24 07:38:07 PDT 2025
Author: Andres-Salamanca
Date: 2025-06-24T09:38:02-05:00
New Revision: 2767ff49955fc3749d79738820285f152fb55ee9
URL: https://github.com/llvm/llvm-project/commit/2767ff49955fc3749d79738820285f152fb55ee9
DIFF: https://github.com/llvm/llvm-project/commit/2767ff49955fc3749d79738820285f152fb55ee9.diff
LOG: [CIR][NFC] Upstream computeVolatileBitfields (#145414)
This PR upstreams functionality for computing volatile bitfields when
the target follows the AAPCS ABI. The implementation matches the one in
the incubator, so no tests are included as the feature is not yet fully
implemented (NYI).
Added:
Modified:
clang/include/clang/CIR/MissingFeatures.h
clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h
index d8e45d02cd2a0..3ba363772316c 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -241,6 +241,7 @@ struct MissingFeatures {
static bool builtinCallF128() { return false; }
static bool builtinCallMathErrno() { return false; }
static bool nonFineGrainedBitfields() { return false; }
+ static bool armComputeVolatileBitfields() { return false; }
// Missing types
static bool dataMemberType() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
index faeee88bba3c6..349c6e75ce36c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
@@ -79,6 +79,7 @@ struct CIRRecordLowering final {
/// Inserts padding everywhere it's needed.
void insertPadding();
+ void computeVolatileBitfields();
void accumulateBases(const CXXRecordDecl *cxxRecordDecl);
void accumulateVPtrs();
void accumulateFields();
@@ -86,6 +87,10 @@ struct CIRRecordLowering final {
accumulateBitFields(RecordDecl::field_iterator field,
RecordDecl::field_iterator fieldEnd);
+ bool isAAPCS() const {
+ return astContext.getTargetInfo().getABI().starts_with("aapcs");
+ }
+
CharUnits bitsToCharUnits(uint64_t bitOffset) {
return astContext.toCharUnitsFromBits(bitOffset);
}
@@ -239,7 +244,7 @@ void CIRRecordLowering::setBitFieldInfo(const FieldDecl *fd,
void CIRRecordLowering::lower() {
if (recordDecl->isUnion()) {
lowerUnion();
- assert(!cir::MissingFeatures::bitfields());
+ computeVolatileBitfields();
return;
}
@@ -253,7 +258,7 @@ void CIRRecordLowering::lower() {
accumulateBases(cxxRecordDecl);
if (members.empty()) {
appendPaddingBytes(size);
- assert(!cir::MissingFeatures::bitfields());
+ computeVolatileBitfields();
return;
}
assert(!cir::MissingFeatures::recordLayoutVirtualBases());
@@ -271,6 +276,7 @@ void CIRRecordLowering::lower() {
calculateZeroInit();
fillOutputFields();
+ computeVolatileBitfields();
}
void CIRRecordLowering::fillOutputFields() {
@@ -754,6 +760,30 @@ void CIRRecordLowering::lowerUnion() {
packed = true;
}
+/// The AAPCS that defines that, when possible, bit-fields should
+/// be accessed using containers of the declared type width:
+/// When a volatile bit-field is read, and its container does not overlap with
+/// any non-bit-field member or any zero length bit-field member, its container
+/// must be read exactly once using the access width appropriate to the type of
+/// the container. When a volatile bit-field is written, and its container does
+/// not overlap with any non-bit-field member or any zero-length bit-field
+/// member, its container must be read exactly once and written exactly once
+/// using the access width appropriate to the type of the container. The two
+/// accesses are not atomic.
+///
+/// Enforcing the width restriction can be disabled using
+/// -fno-aapcs-bitfield-width.
+void CIRRecordLowering::computeVolatileBitfields() {
+ if (!isAAPCS() ||
+ !cirGenTypes.getCGModule().getCodeGenOpts().AAPCSBitfieldWidth)
+ return;
+
+ for ([[maybe_unused]] auto &I : bitFields) {
+ assert(!cir::MissingFeatures::armComputeVolatileBitfields());
+ cirGenTypes.getCGModule().errorNYI("NYI AAPCS bit-fields");
+ }
+}
+
void CIRRecordLowering::accumulateBases(const CXXRecordDecl *cxxRecordDecl) {
// If we've got a primary virtual base, we need to add it with the bases.
if (astRecordLayout.isPrimaryBaseVirtual()) {
More information about the cfe-commits
mailing list