Skip to content

Commit c0f9c7c

Browse files
committed
[X86] Check if struct is blank before getting the inner types
This fixes pr52011. Reviewed By: LuoYuanke Differential Revision: https://reviews.llvm.org/D111037
1 parent 48a5a2d commit c0f9c7c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,9 @@ static llvm::Type *getFPTypeAtOffset(llvm::Type *IRType, unsigned IROffset,
34153415

34163416
// If this is a struct, recurse into the field at the specified offset.
34173417
if (llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) {
3418+
if (!STy->getNumContainedTypes())
3419+
return nullptr;
3420+
34183421
const llvm::StructLayout *SL = TD.getStructLayout(STy);
34193422
unsigned Elt = SL->getElementContainingOffset(IROffset);
34203423
IROffset -= SL->getElementOffset(Elt);

clang/test/CodeGen/X86/avx512fp16-abi.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,44 @@ _Float16 fs2(struct shalf2 s) {
197197
// CHECK-CPP: define{{.*}} @_Z3fs26shalf2(double {{.*}}
198198
return s.a;
199199
};
200+
201+
struct fsd {
202+
float a;
203+
struct {};
204+
double b;
205+
};
206+
207+
struct fsd pr52011() {
208+
// CHECK: define{{.*}} { float, double } @
209+
}
210+
211+
struct hsd {
212+
_Float16 a;
213+
struct {};
214+
double b;
215+
};
216+
217+
struct hsd pr52011_2() {
218+
// CHECK: define{{.*}} { half, double } @
219+
}
220+
221+
struct hsf {
222+
_Float16 a;
223+
struct {};
224+
float b;
225+
};
226+
227+
struct hsf pr52011_3() {
228+
// CHECK: define{{.*}} <4 x half> @
229+
}
230+
231+
struct fds {
232+
float a;
233+
double b;
234+
struct {};
235+
};
236+
237+
struct fds pr52011_4() {
238+
// CHECK-C: define{{.*}} { float, double } @pr52011_4
239+
// CHECK-CPP: define{{.*}} void @_Z9pr52011_4v({{.*}} sret
240+
}

0 commit comments

Comments
 (0)