[cfe-commits] r89775 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/member-expressions.cpp

Anders Carlsson andersca at mac.com
Tue Nov 24 08:57:33 PST 2009


Author: andersca
Date: Tue Nov 24 10:57:33 2009
New Revision: 89775

URL: http://llvm.org/viewvc/llvm-project?rev=89775&view=rev
Log:
We always need to emit the base expression of a member expression, even when the member decl refers to an enum. Thanks to Eli for pointing this out!

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGenCXX/member-expressions.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=89775&r1=89774&r2=89775&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Nov 24 10:57:33 2009
@@ -169,9 +169,16 @@
   Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E);
   Value *VisitMemberExpr(MemberExpr *E) { 
     if (const EnumConstantDecl *EC = 
-          dyn_cast<EnumConstantDecl>(E->getMemberDecl()))
+          dyn_cast<EnumConstantDecl>(E->getMemberDecl())) {
+      
+      // We still need to emit the base.
+      if (E->isArrow())
+        CGF.EmitScalarExpr(E->getBase());
+      else
+        CGF.EmitLValue(E->getBase());
       return llvm::ConstantInt::get(VMContext, EC->getInitVal());
-
+    }
+    
     return EmitLoadOfLValue(E);
   }
     

Modified: cfe/trunk/test/CodeGenCXX/member-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-expressions.cpp?rev=89775&r1=89774&r2=89775&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-expressions.cpp Tue Nov 24 10:57:33 2009
@@ -19,9 +19,20 @@
 }
 
 struct A {
+  A();
+  ~A();
   enum E { Foo };
 };
 
+A *g();
+
 void f(A *a) {
-  A::E e = a->Foo;
+  A::E e1 = a->Foo;
+  
+  // CHECK: call %struct.A* @_Z1gv()
+  A::E e2 = g()->Foo;
+  // CHECK: call void @_ZN1AC1Ev(
+  // CHECK: call void @_ZN1AD1Ev(
+  A::E e3 = A().Foo;
 }
+





More information about the cfe-commits mailing list