[cfe-commits] r44879 - in /cfe/trunk: CodeGen/CGExpr.cpp test/CodeGen/union.c
Devang Patel
dpatel at apple.com
Tue Dec 11 13:33:16 PST 2007
Author: dpatel
Date: Tue Dec 11 15:33:16 2007
New Revision: 44879
URL: http://llvm.org/viewvc/llvm-project?rev=44879&view=rev
Log:
Match union field type when member expression is u->x
Modified:
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGen/union.c
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=44879&r1=44878&r2=44879&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Tue Dec 11 15:33:16 2007
@@ -387,16 +387,24 @@
LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
+ bool isUnion = false;
Expr *BaseExpr = E->getBase();
llvm::Value *BaseValue = NULL;
// If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar.
- if (E->isArrow())
+ if (E->isArrow()) {
BaseValue = EmitScalarExpr(BaseExpr);
+ const PointerType *PTy =
+ cast<PointerType>(BaseExpr->getType().getCanonicalType());
+ if (PTy->getPointeeType()->isUnionType())
+ isUnion = true;
+ }
else {
LValue BaseLV = EmitLValue(BaseExpr);
// FIXME: this isn't right for bitfields.
BaseValue = BaseLV.getAddress();
+ if (BaseExpr->getType()->isUnionType())
+ isUnion = true;
}
FieldDecl *Field = E->getMemberDecl();
@@ -409,7 +417,7 @@
llvm::Value *V = Builder.CreateGEP(BaseValue,Idxs, Idxs + 2, "tmp");
// Match union field type.
- if (BaseExpr->getType()->isUnionType()) {
+ if (isUnion) {
const llvm::Type * FieldTy = ConvertType(Field->getType());
const llvm::PointerType * BaseTy =
cast<llvm::PointerType>(BaseValue->getType());
Modified: cfe/trunk/test/CodeGen/union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/union.c?rev=44879&r1=44878&r2=44879&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/union.c (original)
+++ cfe/trunk/test/CodeGen/union.c Tue Dec 11 15:33:16 2007
@@ -1,6 +1,6 @@
// RUN: clang %s -emit-llvm
-union {
+union u_tag {
int a;
float b;
} u;
@@ -9,6 +9,10 @@
u.b = 11;
}
+float get_b(union u_tag *my_u) {
+ return my_u->b;
+}
+
int f2( float __x ) {
union{
float __f;
More information about the cfe-commits
mailing list