[PATCH] D85193: [clang] Check `expr` inside `InitListChecker::UpdateStructuredListElement()`
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 12:14:04 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3fa0a039ab6f: [clang] Check `expr` inside `InitListChecker::UpdateStructuredListElement()` (authored by ArcsinX).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85193/new/
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,8 @@
+// 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
@@ -1585,10 +1585,7 @@
IList->setInit(Index, ResultExpr);
}
}
- if (hadError)
- ++StructuredIndex;
- else
- UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
+ UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
++Index;
}
@@ -1643,10 +1640,7 @@
if (!VerifyOnly && expr)
IList->setInit(Index, expr);
- if (hadError)
- ++StructuredIndex;
- else
- UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
+ UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
++Index;
}
@@ -1697,11 +1691,7 @@
IList->setInit(Index, ResultExpr);
}
}
- if (hadError)
- ++StructuredIndex;
- else
- UpdateStructuredListElement(StructuredList, StructuredIndex,
- ResultExpr);
+ UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
++Index;
return;
}
@@ -3100,8 +3090,12 @@
if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context,
StructuredIndex, expr)) {
- // This initializer overwrites a previous initializer. Warn.
- diagnoseInitOverride(PrevInit, expr->getSourceRange());
+ // This initializer overwrites a previous initializer.
+ // No need to diagnose when `expr` is nullptr because a more relevant
+ // diagnostic has already been issued and this diagnostic is potentially
+ // noise.
+ if (expr)
+ diagnoseInitOverride(PrevInit, expr->getSourceRange());
}
++StructuredIndex;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85193.285156.patch
Type: text/x-patch
Size: 2183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200812/e4ecd37d/attachment.bin>
More information about the cfe-commits
mailing list