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

Pengfei Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 3 23:24:31 PDT 2021


pengfei created this revision.
pengfei added reviewers: dyung, LuoYuanke.
pengfei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes pr52011.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111037

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


Index: clang/test/CodeGen/X86/avx512fp16-abi.c
===================================================================
--- clang/test/CodeGen/X86/avx512fp16-abi.c
+++ 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
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ 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<llvm::StructType>(IRType)) {
+    if (!STy->getNumContainedTypes())
+      return nullptr;
+
     const llvm::StructLayout *SL = TD.getStructLayout(STy);
     unsigned Elt = SL->getElementContainingOffset(IROffset);
     IROffset -= SL->getElementOffset(Elt);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111037.376807.patch
Type: text/x-patch
Size: 1035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211004/490f9f6e/attachment.bin>


More information about the cfe-commits mailing list