[cfe-commits] r60511 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/AST/ExprCXX.h lib/AST/Expr.cpp lib/AST/ExprCXX.cpp lib/AST/StmtSerialization.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Wed Dec 3 15:17:54 PST 2008
Author: cornedbee
Date: Wed Dec 3 17:17:54 2008
New Revision: 60511
URL: http://llvm.org/viewvc/llvm-project?rev=60511&view=rev
Log:
Fix some type punning errors in SizeOfAlignOf and Typeid AST nodes. This should satisfy compilers and language lawyers alike.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/AST/StmtSerialization.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=60511&r1=60510&r2=60511&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Dec 3 17:17:54 2008
@@ -557,15 +557,23 @@
class SizeOfAlignOfExpr : public Expr {
bool isSizeof : 1; // true if sizeof, false if alignof.
bool isType : 1; // true if operand is a type, false if an expression
- void *Argument;
+ union {
+ void *Ty;
+ Stmt *Ex;
+ } Argument;
SourceLocation OpLoc, RParenLoc;
public:
SizeOfAlignOfExpr(bool issizeof, bool istype, void *argument,
QualType resultType, SourceLocation op,
SourceLocation rp) :
- Expr(SizeOfAlignOfExprClass, resultType),
- isSizeof(issizeof), isType(istype), Argument(argument),
- OpLoc(op), RParenLoc(rp) {}
+ Expr(SizeOfAlignOfExprClass, resultType), isSizeof(issizeof),
+ isType(istype), OpLoc(op), RParenLoc(rp) {
+ if (isType)
+ Argument.Ty = argument;
+ else
+ // argument was an Expr*, so cast it back to that to be safe
+ Argument.Ex = static_cast<Expr*>(argument);
+ }
virtual void Destroy(ASTContext& C);
@@ -573,11 +581,11 @@
bool isArgumentType() const { return isType; }
QualType getArgumentType() const {
assert(isArgumentType() && "calling getArgumentType() when arg is expr");
- return QualType::getFromOpaquePtr(Argument);
+ return QualType::getFromOpaquePtr(Argument.Ty);
}
Expr* getArgumentExpr() const {
assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
- return (Expr *)Argument;
+ return static_cast<Expr*>(Argument.Ex);
}
/// Gets the argument type, or the type of the argument expression, whichever
/// is appropriate.
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=60511&r1=60510&r2=60511&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Wed Dec 3 17:17:54 2008
@@ -193,21 +193,30 @@
class CXXTypeidExpr : public Expr {
private:
bool isTypeOp : 1;
- void *Operand;
+ union {
+ void *Ty;
+ Stmt *Ex;
+ } Operand;
SourceRange Range;
public:
CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) :
- Expr(CXXTypeidExprClass, Ty), isTypeOp(isTypeOp), Operand(op), Range(r) {}
+ Expr(CXXTypeidExprClass, Ty), isTypeOp(isTypeOp), Range(r) {
+ if (isTypeOp)
+ Operand.Ty = op;
+ else
+ // op was an Expr*, so cast it back to that to be safe
+ Operand.Ex = static_cast<Stmt*>(op);
+ }
bool isTypeOperand() const { return isTypeOp; }
QualType getTypeOperand() const {
assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
- return QualType::getFromOpaquePtr(Operand);
+ return QualType::getFromOpaquePtr(Operand.Ty);
}
Expr* getExprOperand() const {
assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
- return static_cast<Expr*>(Operand);
+ return static_cast<Expr*>(Operand.Ex);
}
virtual SourceRange getSourceRange() const {
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=60511&r1=60510&r2=60511&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Dec 3 17:17:54 2008
@@ -1314,12 +1314,12 @@
return child_iterator(T);
return child_iterator();
}
- return child_iterator((Stmt**)&Argument);
+ return child_iterator(&Argument.Ex);
}
Stmt::child_iterator SizeOfAlignOfExpr::child_end() {
if (isArgumentType())
return child_iterator();
- return child_iterator((Stmt**)&Argument + 1);
+ return child_iterator(&Argument.Ex + 1);
}
// ArraySubscriptExpr
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=60511&r1=60510&r2=60511&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Wed Dec 3 17:17:54 2008
@@ -28,10 +28,10 @@
// CXXTypeidExpr - has child iterators if the operand is an expression
Stmt::child_iterator CXXTypeidExpr::child_begin() {
- return isTypeOperand() ? child_iterator() : (Stmt**)&Operand;
+ return isTypeOperand() ? child_iterator() : &Operand.Ex;
}
Stmt::child_iterator CXXTypeidExpr::child_end() {
- return isTypeOperand() ? child_iterator() : (Stmt**)&Operand+1;
+ return isTypeOperand() ? child_iterator() : &Operand.Ex+1;
}
// CXXBoolLiteralExpr
Modified: cfe/trunk/lib/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtSerialization.cpp?rev=60511&r1=60510&r2=60511&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Wed Dec 3 17:17:54 2008
@@ -1394,7 +1394,7 @@
void CXXTypeidExpr::EmitImpl(llvm::Serializer& S) const {
S.Emit(getType());
- S.Emit(isTypeOperand());
+ S.EmitBool(isTypeOperand());
if (isTypeOperand()) {
S.Emit(getTypeOperand());
} else {
More information about the cfe-commits
mailing list