[cfe-commits] r40012 - in /cfe/trunk: AST/Expr.cpp include/clang/AST/Expr.h
Chris Lattner
sabre at nondot.org
Wed Jul 18 11:38:37 PDT 2007
Author: lattner
Date: Wed Jul 18 13:38:36 2007
New Revision: 40012
URL: http://llvm.org/viewvc/llvm-project?rev=40012&view=rev
Log:
implement i-c-e correct evaluation for sizeof/alignof, remove some obsolete fixme's.
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=40012&r1=40011&r2=40012&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Wed Jul 18 13:38:36 2007
@@ -324,32 +324,36 @@
if (Loc) *Loc = Exp->getOperatorLoc();
return false;
case UnaryOperator::Extension:
- return true;
+ return true; // FIXME: this is wrong.
case UnaryOperator::SizeOf:
case UnaryOperator::AlignOf:
// sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc))
return false;
- // FIXME: Evaluate sizeof/alignof.
- Result.zextOrTrunc(32); // FIXME: NOT RIGHT IN GENERAL.
- Result = 1; // FIXME: Obviously bogus
+ // Return the result in the right width.
+ Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()));
+
+ // Get information about the size or align.
+ if (Exp->getOpcode() == UnaryOperator::SizeOf)
+ Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(),
+ Exp->getOperatorLoc());
+ else
+ Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(),
+ Exp->getOperatorLoc());
break;
case UnaryOperator::LNot: {
bool Val = Result != 0;
- Result.zextOrTrunc(32); // FIXME: NOT RIGHT IN GENERAL.
+ Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()));
Result = Val;
break;
}
case UnaryOperator::Plus:
- // FIXME: Do usual unary promotions here!
break;
case UnaryOperator::Minus:
- // FIXME: Do usual unary promotions here!
Result = -Result;
break;
case UnaryOperator::Not:
- // FIXME: Do usual unary promotions here!
Result = ~Result;
break;
}
@@ -361,9 +365,14 @@
if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc))
return false;
- // FIXME: Evaluate sizeof/alignof.
- Result.zextOrTrunc(32); // FIXME: NOT RIGHT IN GENERAL.
- Result = 1; // FIXME: Obviously bogus
+ // Return the result in the right width.
+ Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()));
+
+ // Get information about the size or align.
+ if (Exp->isSizeOf())
+ Result = Ctx.getTypeSize(Exp->getArgumentType(), Exp->getOperatorLoc());
+ else
+ Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc());
break;
}
case BinaryOperatorClass: {
@@ -394,7 +403,6 @@
return false;
}
- // FIXME: These should all do the standard promotions, etc.
switch (Exp->getOpcode()) {
default:
if (Loc) *Loc = getLocStart();
@@ -525,7 +533,6 @@
// Evalute the true one, capture the result.
if (!TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
return false;
- // FIXME: promotions on result.
break;
}
}
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=40012&r1=40011&r2=40012&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Jul 18 13:38:36 2007
@@ -317,6 +317,8 @@
bool isSizeOf() const { return isSizeof; }
QualType getArgumentType() const { return Ty; }
+
+ SourceLocation getOperatorLoc() const { return OpLoc; }
SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); }
virtual void visit(StmtVisitor &Visitor);
More information about the cfe-commits
mailing list