diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-05-30 16:14:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-05-30 16:14:41 +0000 |
commit | b3064041583eb134fbf56906728bf752bc65b572 (patch) | |
tree | 16f4444fb395db3cee19e9e1c0952d726f113cda | |
parent | cfb313bd56fb935c54544489d71d77364fd312db (diff) |
Fix some strict-aliasing warnings by using Stmt* instead of Expr* in VariableArrayType, EnumConstantDecl, and VarDecl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51772 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Decl.h | 18 | ||||
-rw-r--r-- | include/clang/AST/Type.h | 12 | ||||
-rw-r--r-- | lib/AST/StmtIterator.cpp | 6 |
3 files changed, 20 insertions, 16 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index a90ebdd47d..e3d83af420 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -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. diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 313c28951d..5cefb7843f 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -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; diff --git a/lib/AST/StmtIterator.cpp b/lib/AST/StmtIterator.cpp index 61b8e0f9c5..0e5c0995a5 100644 --- a/lib/AST/StmtIterator.cpp +++ b/lib/AST/StmtIterator.cpp @@ -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; } |