diff options
author | Chris Lattner <sabre@nondot.org> | 2007-12-18 07:15:40 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-12-18 07:15:40 +0000 |
commit | 65383479cb2caf0f136f58fecdbdbaf9c497b7a1 (patch) | |
tree | b21f67f9c2ab406e1c8f2eab8e1d6014c210e0ce | |
parent | d52a4578144ab2887912e52eabec58a857a44adb (diff) |
Fix the location we emit the "not a constant" error for this:
int foo() {
typedef int x[foo()];
static int y = sizeof(x);
}
previously we'd emit it on the typedef, which made not sense at all.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45154 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | AST/Expr.cpp | 16 | ||||
-rw-r--r-- | test/Sema/vla.c | 7 |
2 files changed, 19 insertions, 4 deletions
diff --git a/AST/Expr.cpp b/AST/Expr.cpp index f4f89001f2..e814d58328 100644 --- a/AST/Expr.cpp +++ b/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/test/Sema/vla.c b/test/Sema/vla.c new file mode 100644 index 0000000000..c1e0e20e63 --- /dev/null +++ b/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}} +} + |