Skip to content

Commit 323df6b

Browse files
committed
avoid unnamed bit fields when initializing
1 parent 7c861bc commit 323df6b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,7 +3326,8 @@ static void BuildFlattenedTypeList(QualType BaseTy,
33263326

33273327
llvm::SmallVector<QualType, 16> FieldTypes;
33283328
for (const auto *FD : RD->fields())
3329-
FieldTypes.push_back(FD->getType());
3329+
if (!FD->isUnnamedBitField())
3330+
FieldTypes.push_back(FD->getType());
33303331
// Reverse the newly added sub-range.
33313332
std::reverse(FieldTypes.begin(), FieldTypes.end());
33323333
llvm::append_range(WorkList, FieldTypes);
@@ -4171,6 +4172,8 @@ class InitListTransformer {
41714172
while (!RecordDecls.empty()) {
41724173
CXXRecordDecl *RD = RecordDecls.pop_back_val();
41734174
for (auto *FD : RD->fields()) {
4175+
if (FD->isUnnamedBitField())
4176+
continue;
41744177
DeclAccessPair Found = DeclAccessPair::make(FD, FD->getAccess());
41754178
DeclarationNameInfo NameInfo(FD->getDeclName(), E->getBeginLoc());
41764179
ExprResult Res = S.BuildFieldReferenceExpr(
@@ -4220,7 +4223,8 @@ class InitListTransformer {
42204223
while (!RecordDecls.empty()) {
42214224
CXXRecordDecl *RD = RecordDecls.pop_back_val();
42224225
for (auto *FD : RD->fields())
4223-
Inits.push_back(generateInitListsImpl(FD->getType()));
4226+
if (!FD->isUnnamedBitField())
4227+
Inits.push_back(generateInitListsImpl(FD->getType()));
42244228
}
42254229
}
42264230
auto *NewInit = new (Ctx) InitListExpr(Ctx, Inits.front()->getBeginLoc(),

clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ struct SlicyBits {
4545
int W : 8;
4646
};
4747

48+
struct Unnamed {
49+
int A;
50+
int : 8;
51+
};
52+
4853
// Case 1: Extraneous braces get ignored in literal instantiation.
4954
// CHECK-LABEL: define hidden void @_Z5case1v(
5055
// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 1 [[AGG_RESULT:%.*]]) #[[ATTR0:[0-9]+]] {
@@ -959,3 +964,24 @@ int case17Helper(int x) {
959964
void case17() {
960965
int2 X = {case17Helper(0), case17Helper(1)};
961966
}
967+
968+
// InitList with Struct with unnamed bitfield on LHS
969+
// CHECK-LABEL: case18
970+
// CHECK: [[U:%.*]] = alloca %struct.Unnamed, align 1
971+
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[U]], ptr align 1 {{.*}}, i32 5, i1 false)
972+
void case18() {
973+
Unnamed U = {1};
974+
}
975+
976+
// InitList with Struct with unnamed bitfield on RHS
977+
// CHECK-LABEL: case19
978+
// CHECK: [[TI:%.*]] = alloca %struct.TwoInts, align 1
979+
// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw %struct.TwoInts, ptr [[TI]], i32 0, i32 0
980+
// CHECK-NEXT: [[A:%.*]] = getelementptr inbounds nuw %struct.Unnamed, ptr %U, i32 0, i32 0
981+
// CHECK-NEXT: [[L:%.*]] = load i32, ptr [[A]], align 1
982+
// CHECK-NEXT: store i32 [[L]], ptr [[Z]], align 1
983+
// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw %struct.TwoInts, ptr [[TI]], i32 0, i32 1
984+
// CHECK-NEXT: store i32 1, ptr [[W]], align 1
985+
void case19(Unnamed U) {
986+
TwoInts TI = {U, 1};
987+
}

0 commit comments

Comments
 (0)