[X86] Check if struct is blank before getting the inner types

This fixes pr52011.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D111037
This commit is contained in:
Wang, Pengfei 2021-10-08 16:01:45 +08:00
parent 48a5a2d1af
commit c0f9c7c015
2 changed files with 44 additions and 0 deletions

View File

@ -3415,6 +3415,9 @@ static llvm::Type *getFPTypeAtOffset(llvm::Type *IRType, unsigned IROffset,
// If this is a struct, recurse into the field at the specified offset.
if (llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) {
if (!STy->getNumContainedTypes())
return nullptr;
const llvm::StructLayout *SL = TD.getStructLayout(STy);
unsigned Elt = SL->getElementContainingOffset(IROffset);
IROffset -= SL->getElementOffset(Elt);

View File

@ -197,3 +197,44 @@ _Float16 fs2(struct shalf2 s) {
// CHECK-CPP: define{{.*}} @_Z3fs26shalf2(double {{.*}}
return s.a;
};
struct fsd {
float a;
struct {};
double b;
};
struct fsd pr52011() {
// CHECK: define{{.*}} { float, double } @
}
struct hsd {
_Float16 a;
struct {};
double b;
};
struct hsd pr52011_2() {
// CHECK: define{{.*}} { half, double } @
}
struct hsf {
_Float16 a;
struct {};
float b;
};
struct hsf pr52011_3() {
// CHECK: define{{.*}} <4 x half> @
}
struct fds {
float a;
double b;
struct {};
};
struct fds pr52011_4() {
// CHECK-C: define{{.*}} { float, double } @pr52011_4
// CHECK-CPP: define{{.*}} void @_Z9pr52011_4v({{.*}} sret
}