diff options
| author | Devang Patel <dpatel@apple.com> | 2007-12-11 21:33:16 +0000 |
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2007-12-11 21:33:16 +0000 |
| commit | fe2419aac49879f08eddc8917171b943dbe571ad (patch) | |
| tree | 6abebfe07df7e0118eeadf3993ab6e3b0a196295 /CodeGen/CGExpr.cpp | |
| parent | 7a9d49fd2bfac00e905b361ba76d26ab5b6c3b09 (diff) | |
Match union field type when member expression is u->x
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44879 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CGExpr.cpp')
| -rw-r--r-- | CodeGen/CGExpr.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp index 5026c83433..ab5d05969e 100644 --- a/CodeGen/CGExpr.cpp +++ b/CodeGen/CGExpr.cpp @@ -387,16 +387,24 @@ EmitOCUVectorElementExpr(const OCUVectorElementExpr *E) { 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 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { 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()); |
