[cfe-commits] r45154 - in /cfe/trunk: AST/Expr.cpp test/Sema/vla.c
Chris Lattner
sabre at nondot.org
Mon Dec 17 23:15:40 PST 2007
Author: lattner
Date: Tue Dec 18 01:15:40 2007
New Revision: 45154
URL: http://llvm.org/viewvc/llvm-project?rev=45154&view=rev
Log:
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.
Added:
cfe/trunk/test/Sema/vla.c
Modified:
cfe/trunk/AST/Expr.cpp
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=45154&r1=45153&r2=45154&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Tue Dec 18 01:15:40 2007
@@ -468,8 +468,10 @@
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 @@
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 @@
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 @@
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(
Added: cfe/trunk/test/Sema/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vla.c?rev=45154&view=auto
==============================================================================
--- cfe/trunk/test/Sema/vla.c (added)
+++ cfe/trunk/test/Sema/vla.c Tue Dec 18 01:15:40 2007
@@ -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}}
+}
+
More information about the cfe-commits
mailing list