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,13 @@ // CHECK-CPP: define{{.*}} @_Z3fs26shalf2(double {{.*}} return s.a; }; + +#ifndef __cplusplus +struct { + float a; + struct {}; + double b +} pr52011() { + // CHECK-C: define{{.*}} { float, double } @pr52011 +} +#endif