Skip to content

Commit d7c1848

Browse files
committed
[Clang][AST][NFC] Add assertion on Init to CompoundLiteralExpr
Static analysis complained that: child_range(&Init, &Init+1); in the children member function was potentially out of bounds. This is false b/c it is forming an iterator range but it would be invalid if Init was a nullptr. I add an assertion in the constructor for this and remove to FIXME checks that are related to this. I checked the various usages and we always valid the argument is not nullptr.
1 parent ca52d9b commit d7c1848

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,6 +3548,7 @@ class CompoundLiteralExpr : public Expr {
35483548
QualType T, ExprValueKind VK, Expr *init, bool fileScope)
35493549
: Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary),
35503550
LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {
3551+
assert(Init && "Init is a nullptr");
35513552
setDependence(computeDependence(this));
35523553
}
35533554

@@ -3577,17 +3578,11 @@ class CompoundLiteralExpr : public Expr {
35773578
APValue &getStaticValue() const;
35783579

35793580
SourceLocation getBeginLoc() const LLVM_READONLY {
3580-
// FIXME: Init should never be null.
3581-
if (!Init)
3582-
return SourceLocation();
35833581
if (LParenLoc.isInvalid())
35843582
return Init->getBeginLoc();
35853583
return LParenLoc;
35863584
}
35873585
SourceLocation getEndLoc() const LLVM_READONLY {
3588-
// FIXME: Init should never be null.
3589-
if (!Init)
3590-
return SourceLocation();
35913586
return Init->getEndLoc();
35923587
}
35933588

0 commit comments

Comments
 (0)