From: Douglas Gregor Date: Tue, 1 Sep 2009 16:13:00 +0000 (+0000) Subject: Tip-toe around strict-aliasing violation. Fixes PR4061. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=35f153f8ff4fd6a9b39c077026c3e5cc2c721a82;p=clang Tip-toe around strict-aliasing violation. Fixes PR4061. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80674 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index afee0f15ca..e8c29987b0 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -290,11 +290,13 @@ protected: /// default argument. struct UninstantiatedDefaultArgument; + typedef llvm::PointerUnion4 InitType; + /// \brief The initializer for this variable or, for a ParmVarDecl, the /// C++ default argument. - mutable llvm::PointerUnion4 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()) return &ES->Value; - return reinterpret_cast(&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);