[PATCH] D85193: [clang] Do not use an invalid expression to update the initializer.
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 4 04:49:31 PDT 2020
ArcsinX created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ArcsinX requested review of this revision.
This patch prevents `InitListChecker::UpdateStructuredListElement()` call with `expr == nullptr` which could cause a crash.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85193
Files:
clang/lib/Sema/SemaInit.cpp
clang/test/Sema/init-invalid-struct-array.c
Index: clang/test/Sema/init-invalid-struct-array.c
===================================================================
--- /dev/null
+++ clang/test/Sema/init-invalid-struct-array.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct S {
+ Unknown u; // expected-error {{unknown type name 'Unknown'}}
+ int i;
+};
+// Should not crash
+struct S s[] = {
+ [0].i = 0,
+ [1].i = 1,
+ { }
+};
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1378,9 +1378,9 @@
ExprResult Result = Seq.Perform(SemaRef, TmpEntity, Kind, expr);
if (Result.isInvalid())
hadError = true;
-
- UpdateStructuredListElement(StructuredList, StructuredIndex,
- Result.getAs<Expr>());
+ else
+ UpdateStructuredListElement(StructuredList, StructuredIndex,
+ Result.getAs<Expr>());
} else if (!Seq) {
hadError = true;
} else if (StructuredList) {
@@ -1436,8 +1436,9 @@
if (ExprRes.isInvalid())
hadError = true;
}
- UpdateStructuredListElement(StructuredList, StructuredIndex,
- ExprRes.getAs<Expr>());
+ if (!hadError)
+ UpdateStructuredListElement(StructuredList, StructuredIndex,
+ ExprRes.getAs<Expr>());
++Index;
return;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85193.282869.patch
Type: text/x-patch
Size: 1517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200804/482644ec/attachment-0001.bin>
More information about the cfe-commits
mailing list