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 | 20aad334c769067e8df889d7d36b53e73e714091 (patch) | |
| tree | 2fad05ffb6fa38e2d228c6df1362985db4ede05f | |
| parent | 6d2d1b67ca90486c546e896d7fd1642ce86b09ce (diff) | |
| download | bcm5719-llvm-20aad334c769067e8df889d7d36b53e73e714091.tar.gz bcm5719-llvm-20aad334c769067e8df889d7d36b53e73e714091.zip | |
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.
llvm-svn: 45154
| -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}} +} + |

