aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenTBAA.cpp
diff options
context:
space:
mode:
authorJulian Nagele <j.nagele@apple.com>2024-04-05 15:26:41 +0100
committerGitHub <noreply@github.com>2024-04-05 15:26:41 +0100
commitf905935ff96da4c04d2a6bf431340fd16e3a14ea (patch)
tree0802e0a76dc93495e86f9cc43f66e8c26c36ee0a /clang/lib/CodeGen/CodeGenTBAA.cpp
parent3c3e0e556fd768897d003fffa9e2308de982d4ae (diff)
downloadllvm-f905935ff96da4c04d2a6bf431340fd16e3a14ea.zip
llvm-f905935ff96da4c04d2a6bf431340fd16e3a14ea.tar.gz
llvm-f905935ff96da4c04d2a6bf431340fd16e3a14ea.tar.bz2
Fix tbaa.struct metadata for bitfields using big endian. (#87753)
When generating tbaa.struct metadata we treat multiple adjacent bitfields as a single "field", with one corresponding entry in the metadata. At the moment this is achieved by adding an entry for the first bitfield in the run using its StorageSize and skipping the remaining bitfields. The problem is that "first" is determined by checking that the Offset of the field in the run is 0, which breaks for big endian. PR: https://github.com/llvm/llvm-project/pull/87753
Diffstat (limited to 'clang/lib/CodeGen/CodeGenTBAA.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenTBAA.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp
index a1e14c5..837bf72 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -22,6 +22,7 @@
#include "clang/AST/Mangle.h"
#include "clang/AST/RecordLayout.h"
#include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/LLVMContext.h"
@@ -319,7 +320,13 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
// base type.
if ((*i)->isBitField()) {
const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
- if (Info.Offset != 0)
+ // For big endian targets the first bitfield in the consecutive run is
+ // at the most-significant end; see CGRecordLowering::setBitFieldInfo
+ // for more information.
+ bool IsBE = Context.getTargetInfo().isBigEndian();
+ bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
+ : Info.Offset == 0;
+ if (!IsFirst)
continue;
unsigned CurrentBitFieldSize = Info.StorageSize;
uint64_t Size =