Skip to content

Commit 2936774

Browse files
authored
[Clang][AST][NFC] Add assertion on Init to CompoundLiteralExpr (llvm#152593)
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 88b7915 commit 2936774

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 2 additions & 9 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,19 +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
}
3587-
SourceLocation getEndLoc() const LLVM_READONLY {
3588-
// FIXME: Init should never be null.
3589-
if (!Init)
3590-
return SourceLocation();
3591-
return Init->getEndLoc();
3592-
}
3585+
SourceLocation getEndLoc() const LLVM_READONLY { return Init->getEndLoc(); }
35933586

35943587
static bool classof(const Stmt *T) {
35953588
return T->getStmtClass() == CompoundLiteralExprClass;

0 commit comments

Comments
 (0)