From 77d91743a56850cd32585b9b55f4c875970f942e Mon Sep 17 00:00:00 2001 From: Tanya Lattner Date: Tue, 8 Sep 2009 23:39:56 +0000 Subject: Patch to fix PR4061. git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_26@81284 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index ae1b8bb252..8610000692 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -286,10 +286,12 @@ protected: /// argument. struct UnparsedDefaultArgument; + typedef llvm::PointerUnion3 InitType; + /// \brief The initializer for this variable or, for a ParmVarDecl, the /// C++ default argument. - mutable llvm::PointerUnion3 - Init; + mutable InitType Init; private: // FIXME: This can be packed into the bitfields in Decl. @@ -363,7 +365,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); -- cgit v1.2.3