Skip to content

Commit 556fcef

Browse files
committed
[TBAA] Skip all bitfields when generating !tbaa.struct metadata.
At the moment, clang generates what I believe are incorrect !tbaa.struct fields for named bitfields. At the moment, the base type size is used for named bifields (e.g. sizeof(int)) instead of the bifield width per field. This results in overalpping fields in !tbaa.struct metadata. This causes incorrect results when extracting individual copied fields from !tbaa.struct as in added in dc85719. This patch fixes that by skipping all bitfields, not only unnamed ones (note that CollectFields has a TODO to support bitfields). As bitfields specify their widths in bits, while !tbaa metadata uses bytes for sizes and offsets, I don't think we would be able to generate correct metadata for them in general. If this understanding is correct, I can also extend the verifier to check that !tbaa.struct fields aren't overlapping. Fixes llvm#82586
1 parent 7110147 commit 556fcef

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

clang/lib/CodeGen/CodeGenTBAA.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset,
298298
unsigned idx = 0;
299299
for (RecordDecl::field_iterator i = RD->field_begin(),
300300
e = RD->field_end(); i != e; ++i, ++idx) {
301-
if ((*i)->isZeroSize(Context) || (*i)->isUnnamedBitfield())
301+
if ((*i)->isZeroSize(Context) || (*i)->isBitField())
302302
continue;
303303
uint64_t Offset = BaseOffset +
304304
Layout.getFieldOffset(idx) / Context.getCharWidth();

clang/test/CodeGen/tbaa-struct.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void copy8(NamedBitfields *a1, NamedBitfields *a2) {
130130
// CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}}
131131
// CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]}
132132
// CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]}
133-
// CHECK-OLD: [[TS6]] = !{i64 0, i64 4, [[TAG_INT]], i64 1, i64 4, [[TAG_INT]], i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]}
133+
// CHECK-OLD: [[TS6]] = !{i64 2, i64 1, [[TAG_CHAR]], i64 8, i64 8, [[TAG_DOUBLE:!.+]]}
134134
// CHECK-OLD: [[TAG_DOUBLE]] = !{[[DOUBLE:!.+]], [[DOUBLE]], i64 0}
135135
// CHECK-OLD [[DOUBLE]] = !{!"double", [[CHAR]], i64 0}
136136

0 commit comments

Comments
 (0)