[cfe-commits] r72803 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp test/CodeGen/cast-to-union.c
Eli Friedman
eli.friedman at gmail.com
Wed Jun 3 13:45:06 PDT 2009
Author: efriedma
Date: Wed Jun 3 15:45:06 2009
New Revision: 72803
URL: http://llvm.org/viewvc/llvm-project?rev=72803&view=rev
Log:
PR4316: Fix IRGen for cast-to-union extension.
Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/test/CodeGen/cast-to-union.c
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=72803&r1=72802&r2=72803&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed Jun 3 15:45:06 2009
@@ -166,12 +166,12 @@
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(CGF.getContext()),
- true, 0);
- EmitInitializationToLValue(E->getSubExpr(), FieldLoc);
+ if (E->getSubExpr()->getType()->isScalarType()) {
+ QualType PtrTy =
+ CGF.getContext().getPointerType(E->getSubExpr()->getType());
+ llvm::Value *CastPtr = Builder.CreateBitCast(DestPtr,
+ CGF.ConvertType(PtrTy));
+ EmitInitializationToLValue(E->getSubExpr(), LValue::MakeAddr(CastPtr, 0));
return;
}
Modified: cfe/trunk/test/CodeGen/cast-to-union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cast-to-union.c?rev=72803&r1=72802&r2=72803&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/cast-to-union.c (original)
+++ cfe/trunk/test/CodeGen/cast-to-union.c Wed Jun 3 15:45:06 2009
@@ -7,6 +7,7 @@
void foo() {
union u ola = (union u) 351;
+ union u olb = (union u) 1.0;
}
union u w = (union u)2;
More information about the cfe-commits
mailing list