[cfe-commits] r43258 - in /cfe/trunk: CodeGen/CGExpr.cpp test/CodeGen/struct.c
Devang Patel
dpatel at apple.com
Tue Oct 23 13:28:41 PDT 2007
Author: dpatel
Date: Tue Oct 23 15:28:39 2007
New Revision: 43258
URL: http://llvm.org/viewvc/llvm-project?rev=43258&view=rev
Log:
Handle simple struct member expr.
Added:
cfe/trunk/test/CodeGen/struct.c
Modified:
cfe/trunk/CodeGen/CGExpr.cpp
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=43258&r1=43257&r2=43258&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Tue Oct 23 15:28:39 2007
@@ -101,6 +101,7 @@
return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E));
case Expr::OCUVectorElementExprClass:
return EmitOCUVectorElementExpr(cast<OCUVectorElementExpr>(E));
+ case Expr::MemberExprClass: return EmitMemberExpr(cast<MemberExpr>(E));
}
}
@@ -381,6 +382,36 @@
E->getEncodedElementAccess());
}
+LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
+
+ // FIXME: Handle union members.
+ if (E->getBase()->getType()->getAsUnionType()) {
+ fprintf(stderr, "Unimplemented lvalue expr!\n");
+ E->dump(getContext().SourceMgr);
+ llvm::Type *Ty = llvm::PointerType::get(ConvertType(E->getType()));
+ return LValue::MakeAddr(llvm::UndefValue::get(Ty));
+ }
+
+ LValue BaseLV = EmitLValue(E->getBase());
+ llvm::Value *BaseValue = BaseLV.getAddress();
+
+ FieldDecl *Field = E->getMemberDecl();
+ unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
+ llvm::Value *Idxs[2] = { llvm::Constant::getNullValue(llvm::Type::Int32Ty),
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, idx) };
+ if (E->isArrow()) {
+ QualType PTy = cast<PointerType>(E->getBase()->getType())->getPointeeType();
+ BaseValue = Builder.CreateBitCast(BaseValue,
+ llvm::PointerType::get(ConvertType(PTy)),
+ "tmp");
+ }
+
+ return LValue::MakeAddr(Builder.CreateGEP(BaseValue,Idxs, Idxs + 2, "tmp"));
+
+ // FIXME: If record field does not have one to one match with llvm::StructType
+ // field then apply appropriate masks to select only member field bits.
+}
+
//===--------------------------------------------------------------------===//
// Expression Emission
//===--------------------------------------------------------------------===//
Added: cfe/trunk/test/CodeGen/struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/struct.c?rev=43258&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/struct.c (added)
+++ cfe/trunk/test/CodeGen/struct.c Tue Oct 23 15:28:39 2007
@@ -0,0 +1,39 @@
+// RUN: clang %s -emit-llvm
+
+struct {
+ int x;
+ int y;
+} point;
+
+void fn1() {
+ point.x = 42;
+}
+
+/* Nested member */
+struct {
+ struct {
+ int a;
+ int b;
+ } p1;
+} point2;
+
+void fn2() {
+ point2.p1.a = 42;
+}
+
+/* Indirect reference */
+typedef struct __sf {
+ unsigned char *c;
+ short flags;
+} F;
+
+typedef struct __sf2 {
+ F *ff;
+} F2;
+
+int fn3(F2 *c) {
+ if (c->ff->c >= 0)
+ return 1;
+ else
+ return 0;
+}
More information about the cfe-commits
mailing list