Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3326,7 +3326,8 @@ static void BuildFlattenedTypeList(QualType BaseTy,

llvm::SmallVector<QualType, 16> FieldTypes;
for (const auto *FD : RD->fields())
FieldTypes.push_back(FD->getType());
if (!FD->isUnnamedBitField())
FieldTypes.push_back(FD->getType());
// Reverse the newly added sub-range.
std::reverse(FieldTypes.begin(), FieldTypes.end());
llvm::append_range(WorkList, FieldTypes);
Expand Down Expand Up @@ -4171,6 +4172,8 @@ class InitListTransformer {
while (!RecordDecls.empty()) {
CXXRecordDecl *RD = RecordDecls.pop_back_val();
for (auto *FD : RD->fields()) {
if (FD->isUnnamedBitField())
continue;
DeclAccessPair Found = DeclAccessPair::make(FD, FD->getAccess());
DeclarationNameInfo NameInfo(FD->getDeclName(), E->getBeginLoc());
ExprResult Res = S.BuildFieldReferenceExpr(
Expand Down Expand Up @@ -4220,7 +4223,8 @@ class InitListTransformer {
while (!RecordDecls.empty()) {
CXXRecordDecl *RD = RecordDecls.pop_back_val();
for (auto *FD : RD->fields())
Inits.push_back(generateInitListsImpl(FD->getType()));
if (!FD->isUnnamedBitField())
Inits.push_back(generateInitListsImpl(FD->getType()));
}
}
auto *NewInit = new (Ctx) InitListExpr(Ctx, Inits.front()->getBeginLoc(),
Expand Down
26 changes: 26 additions & 0 deletions clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ struct SlicyBits {
int W : 8;
};

struct Unnamed {
int A;
int : 8;
};

// Case 1: Extraneous braces get ignored in literal instantiation.
// CHECK-LABEL: define hidden void @_Z5case1v(
// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 1 [[AGG_RESULT:%.*]]) #[[ATTR0:[0-9]+]] {
Expand Down Expand Up @@ -959,3 +964,24 @@ int case17Helper(int x) {
void case17() {
int2 X = {case17Helper(0), case17Helper(1)};
}

// InitList with Struct with unnamed bitfield on LHS
// CHECK-LABEL: case18
// CHECK: [[U:%.*]] = alloca %struct.Unnamed, align 1
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[U]], ptr align 1 {{.*}}, i32 5, i1 false)
void case18() {
Unnamed U = {1};
}

// InitList with Struct with unnamed bitfield on RHS
// CHECK-LABEL: case19
// CHECK: [[TI:%.*]] = alloca %struct.TwoInts, align 1
// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw %struct.TwoInts, ptr [[TI]], i32 0, i32 0
// CHECK-NEXT: [[A:%.*]] = getelementptr inbounds nuw %struct.Unnamed, ptr %U, i32 0, i32 0
// CHECK-NEXT: [[L:%.*]] = load i32, ptr [[A]], align 1
// CHECK-NEXT: store i32 [[L]], ptr [[Z]], align 1
// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw %struct.TwoInts, ptr [[TI]], i32 0, i32 1
// CHECK-NEXT: store i32 1, ptr [[W]], align 1
void case19(Unnamed U) {
TwoInts TI = {U, 1};
}