diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2009-01-15 20:14:33 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2009-01-15 20:14:33 +0000 |
commit | 7e91627301b05cd8f2324795e19d87a62f444c31 (patch) | |
tree | c7d9329ed35ee8dec8dbc0d7e45ba76a3703df0b | |
parent | e1deaac73379eeb9864215c7979f6005ebd74cef (diff) |
add codegen support to union casts
init of static vars still not working. I'll get back to it tomorrow or so
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62278 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 15 | ||||
-rw-r--r-- | test/CodeGen/cast-to-union.c | 10 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 7571149b5a..5e36751fb7 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -74,6 +74,7 @@ public: // Operators. // case Expr::UnaryOperatorClass: // case Expr::CastExprClass: + void VisitCStyleCastExpr(CStyleCastExpr *E); void VisitImplicitCastExpr(ImplicitCastExpr *E); void VisitCallExpr(const CallExpr *E); void VisitStmtExpr(const StmtExpr *E); @@ -127,6 +128,18 @@ void AggExprEmitter::EmitAggLoadOfLValue(const Expr *E) { // Visitor Methods //===----------------------------------------------------------------------===// +void AggExprEmitter::VisitCStyleCastExpr(CStyleCastExpr *E) { + // GCC union extension + if (E->getType()->isUnionType()) { + RecordDecl *SD = E->getType()->getAsRecordType()->getDecl(); + LValue FieldLoc = CGF.EmitLValueForField(DestPtr, *SD->field_begin(), true, 0); + EmitInitializationToLValue(E->getSubExpr(), FieldLoc); + return; + } + + Visit(E->getSubExpr()); +} + void AggExprEmitter::VisitImplicitCastExpr(ImplicitCastExpr *E) { assert(CGF.getContext().typesAreCompatible( E->getSubExpr()->getType().getUnqualifiedType(), @@ -467,7 +480,7 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // Unions only initialize one field. // (things can get weird with designators, but they aren't // supported yet.) - if (E->getType()->isUnionType()) + if (isUnion) break; } } diff --git a/test/CodeGen/cast-to-union.c b/test/CodeGen/cast-to-union.c new file mode 100644 index 0000000000..3f339041eb --- /dev/null +++ b/test/CodeGen/cast-to-union.c @@ -0,0 +1,10 @@ +// RUN: clang -emit-llvm < %s | grep "store i32 351, i32*" + +union u { int i; }; + +void foo() { + union u ola = (union u) 351; +} + +// FIXME: not working yet +// union u w = (union u)2; |