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

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 8 02:09:45 PDT 2021


Author: Wang, Pengfei
Date: 2021-10-08T17:09:34+08:00
New Revision: c0f9c7c01561a70974485e0e4a358d6bbdaf3b8e

URL: https://github.com/llvm/llvm-project/commit/c0f9c7c01561a70974485e0e4a358d6bbdaf3b8e
DIFF: https://github.com/llvm/llvm-project/commit/c0f9c7c01561a70974485e0e4a358d6bbdaf3b8e.diff

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

This fixes pr52011.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D111037

Added: 
    

Modified: 
    clang/lib/CodeGen/TargetInfo.cpp
    clang/test/CodeGen/X86/avx512fp16-abi.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index bebadc44725cc..10951a01150a8 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -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);

diff  --git a/clang/test/CodeGen/X86/avx512fp16-abi.c b/clang/test/CodeGen/X86/avx512fp16-abi.c
index 5018567d5bb4d..1144274280557 100644
--- a/clang/test/CodeGen/X86/avx512fp16-abi.c
+++ b/clang/test/CodeGen/X86/avx512fp16-abi.c
@@ -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
+}


        


More information about the cfe-commits mailing list