[cfe-commits] r80674 - /cfe/trunk/include/clang/AST/Decl.h
Douglas Gregor
dgregor at apple.com
Tue Sep 1 09:13:00 PDT 2009
Author: dgregor
Date: Tue Sep 1 11:13:00 2009
New Revision: 80674
URL: http://llvm.org/viewvc/llvm-project?rev=80674&view=rev
Log:
Tip-toe around strict-aliasing violation. Fixes PR4061.
Modified:
cfe/trunk/include/clang/AST/Decl.h
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=80674&r1=80673&r2=80674&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Sep 1 11:13:00 2009
@@ -290,11 +290,13 @@
/// 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 @@
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);
More information about the cfe-commits
mailing list