[cfe-commits] r89705 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/member-expressions.cpp
Anders Carlsson
andersca at mac.com
Mon Nov 23 13:56:42 PST 2009
Author: andersca
Date: Mon Nov 23 15:56:41 2009
New Revision: 89705
URL: http://llvm.org/viewvc/llvm-project?rev=89705&view=rev
Log:
Don't try to treat an enum constant as an lvalue.
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=89705&r1=89704&r2=89705&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Nov 23 15:56:41 2009
@@ -167,7 +167,14 @@
Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E);
- Value *VisitMemberExpr(Expr *E) { return EmitLoadOfLValue(E); }
+ Value *VisitMemberExpr(MemberExpr *E) {
+ if (const EnumConstantDecl *EC =
+ dyn_cast<EnumConstantDecl>(E->getMemberDecl()))
+ return llvm::ConstantInt::get(VMContext, EC->getInitVal());
+
+ return EmitLoadOfLValue(E);
+ }
+
Value *VisitExtVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); }
Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
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=89705&r1=89704&r2=89705&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-expressions.cpp Mon Nov 23 15:56:41 2009
@@ -17,3 +17,11 @@
}
}
+
+struct A {
+ enum E { Foo };
+};
+
+void f(A *a) {
+ A::E e = a->Foo;
+}
More information about the cfe-commits
mailing list