]> granicus.if.org Git - clang/commitdiff
Tip-toe around strict-aliasing violation. Fixes PR4061.
authorDouglas Gregor <dgregor@apple.com>
Tue, 1 Sep 2009 16:13:00 +0000 (16:13 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 1 Sep 2009 16:13:00 +0000 (16:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80674 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h

index afee0f15ca3b39c632844147a40fb35b1bf88d3d..e8c29987b085b0c8f73c526b6ba5f2b2b2114492 100644 (file)
@@ -290,11 +290,13 @@ protected:
   /// default argument.
   struct UninstantiatedDefaultArgument;
 
+  typedef llvm::PointerUnion4<Stmt *, EvaluatedStmt *, 
+                              UnparsedDefaultArgument *, 
+                              UninstantiatedDefaultArgument *> InitType;
+  
   /// \brief The initializer for this variable or, for a ParmVarDecl, the 
   /// C++ default argument.
-  mutable llvm::PointerUnion4<Stmt *, EvaluatedStmt *, 
-                              UnparsedDefaultArgument *, 
-                              UninstantiatedDefaultArgument *> Init;
+  mutable InitType Init;
   
 private:
   // FIXME: This can be packed into the bitfields in Decl.
@@ -368,7 +370,15 @@ public:
   Stmt **getInitAddress() {
     if (EvaluatedStmt *ES = Init.dyn_cast<EvaluatedStmt*>())
       return &ES->Value;
-    return reinterpret_cast<Stmt **>(&Init); // FIXME: ugly hack
+    
+    // This union hack tip-toes around strict-aliasing rules.
+    union {
+      InitType *InitPtr;
+      Stmt **StmtPtr;
+    };
+    
+    InitPtr = &Init;
+    return StmtPtr;
   }
 
   void setInit(ASTContext &C, Expr *I);