aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2021-01-06 06:46:01 -0800
committerErich Keane <erich.keane@intel.com>2021-01-06 07:17:12 -0800
commit3fa6cedb6be809092f8a8b27e63bd4f6dc526a08 (patch)
treeb41e7d76ac5b855eb3a1d019272c1bb279d505b8 /clang/lib/Sema/SemaInit.cpp
parent0c41b1c9f93c09966b87126820d3cf41d8eebbf9 (diff)
downloadllvm-3fa6cedb6be809092f8a8b27e63bd4f6dc526a08.zip
llvm-3fa6cedb6be809092f8a8b27e63bd4f6dc526a08.tar.gz
llvm-3fa6cedb6be809092f8a8b27e63bd4f6dc526a08.tar.bz2
Fix MaterializeTemporaryExpr's type when its an incomplete array.
Like the VarDecl that gets its type updated based on an init-list, this patch corrects the MaterializeTemporaryExpr's type to make sure it isn't creating an incomplete type, which leads to a handful of CodeGen crashes (see PR 47636). Based on @rsmith 's comments on D88236 Differential Revision: https://reviews.llvm.org/D88298
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r--clang/lib/Sema/SemaInit.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b5f31bf..38f6a59 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -8200,9 +8200,21 @@ ExprResult InitializationSequence::Perform(Sema &S,
if (S.CheckExceptionSpecCompatibility(CurInit.get(), DestType))
return ExprError();
+ QualType MTETy = Step->Type;
+
+ // When this is an incomplete array type (such as when this is
+ // initializing an array of unknown bounds from an init list), use THAT
+ // type instead so that we propogate the array bounds.
+ if (MTETy->isIncompleteArrayType() &&
+ !CurInit.get()->getType()->isIncompleteArrayType() &&
+ S.Context.hasSameType(
+ MTETy->getPointeeOrArrayElementType(),
+ CurInit.get()->getType()->getPointeeOrArrayElementType()))
+ MTETy = CurInit.get()->getType();
+
// Materialize the temporary into memory.
MaterializeTemporaryExpr *MTE = S.CreateMaterializeTemporaryExpr(
- Step->Type, CurInit.get(), Entity.getType()->isLValueReferenceType());
+ MTETy, CurInit.get(), Entity.getType()->isLValueReferenceType());
CurInit = MTE;
// If we're extending this temporary to automatic storage duration -- we