Fix some strict-aliasing warnings by using Stmt* instead of Expr* in VariableArrayType, EnumConstantDecl, and VarDecl.

llvm-svn: 51772
This commit is contained in:
Ted Kremenek 2008-05-30 16:14:41 +00:00
parent c9c67157d1
commit 8595668eca
3 changed files with 20 additions and 16 deletions

View File

@ -224,7 +224,7 @@ public:
None, Auto, Register, Extern, Static, PrivateExtern
};
private:
Expr *Init;
Stmt *Init;
// FIXME: This can be packed into the bitfields in Decl.
unsigned SClass : 3;
@ -240,9 +240,9 @@ public:
StorageClass getStorageClass() const { return (StorageClass)SClass; }
const Expr *getInit() const { return Init; }
Expr *getInit() { return Init; }
void setInit(Expr *I) { Init = I; }
const Expr *getInit() const { return (const Expr*) Init; }
Expr *getInit() { return (Expr*) Init; }
void setInit(Expr *I) { Init = (Stmt*) I; }
/// hasLocalStorage - Returns true if a variable with function scope
/// is a non-static local variable.
@ -553,13 +553,13 @@ protected:
/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
/// TagType for the X EnumDecl.
class EnumConstantDecl : public ValueDecl {
Expr *Init; // an integer constant expression
Stmt *Init; // an integer constant expression
llvm::APSInt Val; // The value.
protected:
EnumConstantDecl(DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T, Expr *E,
const llvm::APSInt &V, ScopedDecl *PrevDecl)
: ValueDecl(EnumConstant, DC, L, Id, T, PrevDecl), Init(E), Val(V) {}
: ValueDecl(EnumConstant, DC, L, Id, T, PrevDecl), Init((Stmt*)E), Val(V) {}
virtual ~EnumConstantDecl() {}
public:
@ -571,11 +571,11 @@ public:
virtual void Destroy(ASTContext& C);
const Expr *getInitExpr() const { return Init; }
Expr *getInitExpr() { return Init; }
const Expr *getInitExpr() const { return (const Expr*) Init; }
Expr *getInitExpr() { return (Expr*) Init; }
const llvm::APSInt &getInitVal() const { return Val; }
void setInitExpr(Expr *E) { Init = E; }
void setInitExpr(Expr *E) { Init = (Stmt*) E; }
void setInitVal(const llvm::APSInt &V) { Val = V; }
// Implement isa/cast/dyncast/etc.

View File

@ -37,6 +37,7 @@ namespace clang {
class ObjCProtocolDecl;
class ObjCMethodDecl;
class Expr;
class Stmt;
class SourceLocation;
class PointerLikeType;
class PointerType;
@ -721,17 +722,20 @@ protected:
class VariableArrayType : public ArrayType {
/// SizeExpr - An assignment expression. VLA's are only permitted within
/// a function block.
Expr *SizeExpr;
Stmt *SizeExpr;
VariableArrayType(QualType et, QualType can, Expr *e,
ArraySizeModifier sm, unsigned tq)
: ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {}
: ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
friend class ASTContext; // ASTContext creates these.
virtual void Destroy(ASTContext& C);
public:
const Expr *getSizeExpr() const { return SizeExpr; }
Expr *getSizeExpr() { return SizeExpr; }
const Expr *getSizeExpr() const {
// We use C-style casts instead of cast<> here because we do not wish
// to have a dependency of Type.h on Stmt.h/Expr.h.
return (Expr*) SizeExpr;
}
virtual void getAsStringInternal(std::string &InnerString) const;

View File

@ -104,14 +104,14 @@ StmtIteratorBase::StmtIteratorBase(VariableArrayType* t)
Stmt*& StmtIteratorBase::GetDeclExpr() const {
if (VariableArrayType* VAPtr = getVAPtr()) {
assert (VAPtr->SizeExpr);
return reinterpret_cast<Stmt*&>(VAPtr->SizeExpr);
return VAPtr->SizeExpr;
}
if (VarDecl* VD = dyn_cast<VarDecl>(decl)) {
assert (VD->Init);
return reinterpret_cast<Stmt*&>(VD->Init);
return VD->Init;
}
EnumConstantDecl* ECD = cast<EnumConstantDecl>(decl);
return reinterpret_cast<Stmt*&>(ECD->Init);
return ECD->Init;
}