diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-01 16:13:00 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-01 16:13:00 +0000 |
commit | 35f153f8ff4fd6a9b39c077026c3e5cc2c721a82 (patch) | |
tree | fe4deb6cd7b879c0c1fe5ce6328586765caa1a7b | |
parent | 2b8ee6c2994f738e5162ff46b638974870f51662 (diff) |
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
-rw-r--r-- | include/clang/AST/Decl.h | 18 |
1 files changed, 14 insertions, 4 deletions
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<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); |