summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-01 16:13:00 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-01 16:13:00 +0000
commit770a532fa12142c4625a972b2e4c4bd60cbf2261 (patch)
treeaa2d85691e9a8d9883e180a4a0589a90a47e3b21
parent69b10fd2c5aad82caeee42769753942e930ba9d4 (diff)
downloadbcm5719-llvm-770a532fa12142c4625a972b2e4c4bd60cbf2261.tar.gz
bcm5719-llvm-770a532fa12142c4625a972b2e4c4bd60cbf2261.zip
Tip-toe around strict-aliasing violation. Fixes PR4061.
llvm-svn: 80674
-rw-r--r--clang/include/clang/AST/Decl.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index afee0f15ca3..e8c29987b08 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/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);
OpenPOWER on IntegriCloud