diff options
| -rw-r--r-- | clang/AST/Expr.cpp | 16 | ||||
| -rw-r--r-- | clang/test/Sema/vla.c | 7 |
2 files changed, 19 insertions, 4 deletions
diff --git a/clang/AST/Expr.cpp b/clang/AST/Expr.cpp index f4f89001f2b..e814d58328a 100644 --- a/clang/AST/Expr.cpp +++ b/clang/AST/Expr.cpp @@ -468,8 +468,10 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { case UnaryOperator::SizeOf: case UnaryOperator::AlignOf: // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. - if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc)) + if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) { + if (Loc) *Loc = Exp->getOperatorLoc(); return false; + } return true; case UnaryOperator::LNot: case UnaryOperator::Plus: @@ -481,8 +483,10 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const { case SizeOfAlignOfTypeExprClass: { const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); // alignof always evaluates to a constant. - if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc)) + if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) { + if (Loc) *Loc = Exp->getOperatorLoc(); return false; + } return true; } case BinaryOperatorClass: { @@ -612,8 +616,10 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, case UnaryOperator::SizeOf: case UnaryOperator::AlignOf: // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2. - if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc)) + if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) { + if (Loc) *Loc = Exp->getOperatorLoc(); return false; + } // Return the result in the right width. Result.zextOrTrunc( @@ -654,8 +660,10 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, case SizeOfAlignOfTypeExprClass: { const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this); // alignof always evaluates to a constant. - if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc)) + if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) { + if (Loc) *Loc = Exp->getOperatorLoc(); return false; + } // Return the result in the right width. Result.zextOrTrunc( diff --git a/clang/test/Sema/vla.c b/clang/test/Sema/vla.c new file mode 100644 index 00000000000..c1e0e20e63a --- /dev/null +++ b/clang/test/Sema/vla.c @@ -0,0 +1,7 @@ +// RUN: clang %s -verify -fsyntax-only + +int test1() { + typedef int x[test1()]; // vla + static int y = sizeof(x); // expected-error {{not constant}} +} + |

