[cfe-commits] r51772 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/Type.h lib/AST/StmtIterator.cpp

Ted Kremenek kremenek at apple.com
Fri May 30 09:14:41 PDT 2008


Author: kremenek
Date: Fri May 30 11:14:41 2008
New Revision: 51772

URL: http://llvm.org/viewvc/llvm-project?rev=51772&view=rev
Log:
Fix some strict-aliasing warnings by using Stmt* instead of Expr* in VariableArrayType, EnumConstantDecl, and VarDecl.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/StmtIterator.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=51772&r1=51771&r2=51772&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri May 30 11:14:41 2008
@@ -224,7 +224,7 @@
     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 @@
   
   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 @@
 /// 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 @@
   
   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.

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=51772&r1=51771&r2=51772&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri May 30 11:14:41 2008
@@ -37,6 +37,7 @@
   class ObjCProtocolDecl;
   class ObjCMethodDecl;
   class Expr;
+  class Stmt;
   class SourceLocation;
   class PointerLikeType;
   class PointerType;
@@ -721,17 +722,20 @@
 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;
   

Modified: cfe/trunk/lib/AST/StmtIterator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtIterator.cpp?rev=51772&r1=51771&r2=51772&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtIterator.cpp (original)
+++ cfe/trunk/lib/AST/StmtIterator.cpp Fri May 30 11:14:41 2008
@@ -104,14 +104,14 @@
 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;
 }





More information about the cfe-commits mailing list