-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Add bitfield offset calculation for big-endian targets #145067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clangir Author: None (Andres-Salamanca) ChangesThis PR updates the bitfield offset calculation to correctly handle big-endian architectures. Full diff: https://github.com/llvm/llvm-project/pull/145067.diff 3 Files Affected:
diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h
index e0b2959f374f8..d8e45d02cd2a0 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -150,7 +150,6 @@ struct MissingFeatures {
static bool cxxabiAppleARM64CXXABI() { return false; }
static bool cxxabiStructorImplicitParam() { return false; }
static bool isDiscreteBitFieldABI() { return false; }
- static bool isBigEndian() { return false; }
// Address class
static bool addressOffset() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
index 8dbf1b36a93b2..d2fb4b711b0c2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
@@ -228,7 +228,8 @@ void CIRRecordLowering::setBitFieldInfo(const FieldDecl *fd,
// out as packed bits within an integer-sized unit, we can imagine the bits
// counting from the most-significant-bit instead of the
// least-significant-bit.
- assert(!cir::MissingFeatures::isBigEndian());
+ if (dataLayout.isBigEndian())
+ info.offset = info.storageSize - (info.offset + info.size);
info.volatileStorageSize = 0;
info.volatileOffset = 0;
diff --git a/clang/test/CIR/CodeGen/bitfields_be.c b/clang/test/CIR/CodeGen/bitfields_be.c
new file mode 100644
index 0000000000000..149e9c9ac33ff
--- /dev/null
+++ b/clang/test/CIR/CodeGen/bitfields_be.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple aarch64_be-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
+
+typedef struct {
+ int a : 4;
+ int b : 11;
+ int c : 17;
+} S;
+S s;
+
+// CIR: !rec_S = !cir.record<struct "S" {!u32i}>
+// LLVM: %struct.S = type { i32 }
+// OGCG: %struct.S = type { i32 }
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see this done Incrementally, LGTM.
@Andres-Salamanca Are you expecting the test to be failing? Here is what I am seeing:
|
Hey! Sorry about the failing test I just pushed 2767ff4 without rebasing first, so it didn't pick up the recent changes. That's why we're getting the NYI AAPCS bit-fields error in bitfields_be.c. I'll clean this up now going to remove the error emission and just leave a NYI marker so it behaves as a missing feature, not a hard failure. |
This PR addresses the error mentioned in #145067 (comment), which occurs on ARM when handling an unsupported bit-field case. The patch removes the error and replaces it with an assert, marking the missing feature.
…e (#145560) This PR addresses the error mentioned in llvm/llvm-project#145067 (comment), which occurs on ARM when handling an unsupported bit-field case. The patch removes the error and replaces it with an assert, marking the missing feature.
) This PR addresses the error mentioned in llvm#145067 (comment), which occurs on ARM when handling an unsupported bit-field case. The patch removes the error and replaces it with an assert, marking the missing feature.
This PR updates the bitfield offset calculation to correctly handle big-endian architectures.