summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-08-29 22:49:32 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-08-29 22:49:32 +0000
commit8823dbc552ec6946027c59ac53510404b98671b6 (patch)
tree9d61df47bc62db4ae00efeca57510cbb66c58aaa /clang/lib
parent7cb9c8a506f3490755db20c0a9298e9caa6fb89d (diff)
downloadbcm5719-llvm-8823dbc552ec6946027c59ac53510404b98671b6.tar.gz
bcm5719-llvm-8823dbc552ec6946027c59ac53510404b98671b6.zip
Refactor InitListChecker to make it a bit clearer that hasError is only
set to true in VerifyOnly mode in cases where it's also set to true when actually building the initializer list. Add FIXMEs for the two cases where that's not true. No functionality change intended. llvm-svn: 370417
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaInit.cpp80
1 files changed, 36 insertions, 44 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 83c475a5f1c..7c33e998036 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1093,49 +1093,32 @@ void InitListChecker::CheckExplicitInitList(const InitializedEntity &Entity,
if (hadError)
return;
- if (Index < IList->getNumInits()) {
+ // Don't complain for incomplete types, since we'll get an error elsewhere.
+ if (Index < IList->getNumInits() && !T->isIncompleteType()) {
// We have leftover initializers
+ bool ExtraInitsIsError = SemaRef.getLangOpts().CPlusPlus ||
+ (SemaRef.getLangOpts().OpenCL && T->isVectorType());
+ hadError = ExtraInitsIsError;
if (VerifyOnly) {
- if (SemaRef.getLangOpts().CPlusPlus ||
- (SemaRef.getLangOpts().OpenCL &&
- IList->getType()->isVectorType())) {
- hadError = true;
- }
return;
- }
-
- if (StructuredIndex == 1 &&
- IsStringInit(StructuredList->getInit(0), T, SemaRef.Context) ==
- SIF_None) {
- unsigned DK = diag::ext_excess_initializers_in_char_array_initializer;
- if (SemaRef.getLangOpts().CPlusPlus) {
- DK = diag::err_excess_initializers_in_char_array_initializer;
- hadError = true;
- }
- // Special-case
+ } else if (StructuredIndex == 1 &&
+ IsStringInit(StructuredList->getInit(0), T, SemaRef.Context) ==
+ SIF_None) {
+ unsigned DK =
+ ExtraInitsIsError
+ ? diag::err_excess_initializers_in_char_array_initializer
+ : diag::ext_excess_initializers_in_char_array_initializer;
SemaRef.Diag(IList->getInit(Index)->getBeginLoc(), DK)
<< IList->getInit(Index)->getSourceRange();
- } else if (!T->isIncompleteType()) {
- // Don't complain for incomplete types, since we'll get an error
- // elsewhere
- QualType CurrentObjectType = StructuredList->getType();
- int initKind =
- CurrentObjectType->isArrayType()? 0 :
- CurrentObjectType->isVectorType()? 1 :
- CurrentObjectType->isScalarType()? 2 :
- CurrentObjectType->isUnionType()? 3 :
- 4;
-
- unsigned DK = diag::ext_excess_initializers;
- if (SemaRef.getLangOpts().CPlusPlus) {
- DK = diag::err_excess_initializers;
- hadError = true;
- }
- if (SemaRef.getLangOpts().OpenCL && initKind == 1) {
- DK = diag::err_excess_initializers;
- hadError = true;
- }
-
+ } else {
+ int initKind = T->isArrayType() ? 0 :
+ T->isVectorType() ? 1 :
+ T->isScalarType() ? 2 :
+ T->isUnionType() ? 3 :
+ 4;
+
+ unsigned DK = ExtraInitsIsError ? diag::err_excess_initializers
+ : diag::ext_excess_initializers;
SemaRef.Diag(IList->getInit(Index)->getBeginLoc(), DK)
<< initKind << IList->getInit(Index)->getSourceRange();
}
@@ -1363,8 +1346,8 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
hadError = true;
else {
ExprRes = SemaRef.DefaultFunctionArrayLvalueConversion(ExprRes.get());
- if (ExprRes.isInvalid())
- hadError = true;
+ if (ExprRes.isInvalid())
+ hadError = true;
}
UpdateStructuredListElement(StructuredList, StructuredIndex,
ExprRes.getAs<Expr>());
@@ -1389,10 +1372,15 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
++StructuredIndex;
} else {
if (!VerifyOnly) {
- // We cannot initialize this element, so let
- // PerformCopyInitialization produce the appropriate diagnostic.
- SemaRef.PerformCopyInitialization(Entity, SourceLocation(), expr,
- /*TopLevelOfInitList=*/true);
+ // We cannot initialize this element, so let PerformCopyInitialization
+ // produce the appropriate diagnostic. We already checked that this
+ // initialization will fail.
+ ExprResult Copy =
+ SemaRef.PerformCopyInitialization(Entity, SourceLocation(), expr,
+ /*TopLevelOfInitList=*/true);
+ (void)Copy;
+ assert(Copy.isInvalid() &&
+ "expected non-aggregate initialization to fail");
}
hadError = true;
++Index;
@@ -1872,6 +1860,8 @@ void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
// enough elements, or if we're performing an array new with an unknown
// bound.
// FIXME: This needs to detect holes left by designated initializers too.
+ // FIXME: Doing this now is wrong; these holes can be filled by later
+ // designated initializers.
if ((maxElementsKnown && elementIndex < maxElements) ||
Entity.isVariableLengthArrayNew())
CheckEmptyInitializable(
@@ -2132,6 +2122,8 @@ void InitListChecker::CheckStructUnionTypes(
if (VerifyOnly && Field != FieldEnd && !DeclType->isUnionType() &&
!Field->getType()->isIncompleteArrayType()) {
// FIXME: Should check for holes left by designated initializers too.
+ // FIXME: Doing this now is wrong; these holes can be filled by later
+ // designated initializers.
for (; Field != FieldEnd && !hadError; ++Field) {
if (!Field->isUnnamedBitfield() && !Field->hasInClassInitializer())
CheckEmptyInitializable(
OpenPOWER on IntegriCloud