forked from OSchip/llvm-project
[clang] Check `expr` inside `InitListChecker::UpdateStructuredListElement()`
- Prevent nullptr-deference at try to emit warning for invalid `expr` - Simplify `InitListChecker::UpdateStructuredListElement()` usages. We do not need to check `expr` and increment `StructuredIndex` (for invalid `expr`) before the call anymore. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D85193
This commit is contained in:
parent
d6f0600c96
commit
3fa0a039ab
|
@ -1585,9 +1585,6 @@ void InitListChecker::CheckScalarType(const InitializedEntity &Entity,
|
|||
IList->setInit(Index, ResultExpr);
|
||||
}
|
||||
}
|
||||
if (hadError)
|
||||
++StructuredIndex;
|
||||
else
|
||||
UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
|
||||
++Index;
|
||||
}
|
||||
|
@ -1643,9 +1640,6 @@ void InitListChecker::CheckReferenceType(const InitializedEntity &Entity,
|
|||
if (!VerifyOnly && expr)
|
||||
IList->setInit(Index, expr);
|
||||
|
||||
if (hadError)
|
||||
++StructuredIndex;
|
||||
else
|
||||
UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
|
||||
++Index;
|
||||
}
|
||||
|
@ -1697,11 +1691,7 @@ void InitListChecker::CheckVectorType(const InitializedEntity &Entity,
|
|||
IList->setInit(Index, ResultExpr);
|
||||
}
|
||||
}
|
||||
if (hadError)
|
||||
++StructuredIndex;
|
||||
else
|
||||
UpdateStructuredListElement(StructuredList, StructuredIndex,
|
||||
ResultExpr);
|
||||
UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
|
||||
++Index;
|
||||
return;
|
||||
}
|
||||
|
@ -3100,7 +3090,11 @@ void InitListChecker::UpdateStructuredListElement(InitListExpr *StructuredList,
|
|||
|
||||
if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context,
|
||||
StructuredIndex, expr)) {
|
||||
// This initializer overwrites a previous initializer. Warn.
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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, {}};
|
Loading…
Reference in New Issue