diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -3415,6 +3415,9 @@ // If this is a struct, recurse into the field at the specified offset. if (llvm::StructType *STy = dyn_cast(IRType)) { + if (!STy->getNumContainedTypes()) + return nullptr; + const llvm::StructLayout *SL = TD.getStructLayout(STy); unsigned Elt = SL->getElementContainingOffset(IROffset); IROffset -= SL->getElementOffset(Elt); diff --git a/clang/test/CodeGen/X86/avx512fp16-abi.c b/clang/test/CodeGen/X86/avx512fp16-abi.c --- a/clang/test/CodeGen/X86/avx512fp16-abi.c +++ b/clang/test/CodeGen/X86/avx512fp16-abi.c @@ -197,3 +197,44 @@ // 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 +}