[cfe-commits] r72636 - in /cfe/trunk: lib/AST/ExprConstant.cpp lib/CodeGen/CGExpr.cpp test/CodeGenCXX/reference-field.cpp
Eli Friedman
eli.friedman at gmail.com
Sat May 30 14:09:44 PDT 2009
Author: efriedma
Date: Sat May 30 16:09:44 2009
New Revision: 72636
URL: http://llvm.org/viewvc/llvm-project?rev=72636&view=rev
Log:
Some small fixes for fields of reference type.
Added:
cfe/trunk/test/CodeGenCXX/reference-field.cpp
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=72636&r1=72635&r2=72636&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat May 30 16:09:44 2009
@@ -231,7 +231,10 @@
FieldDecl *FD = dyn_cast<FieldDecl>(E->getMemberDecl());
if (!FD) // FIXME: deal with other kinds of member expressions
return APValue();
-
+
+ if (FD->getType()->isReferenceType())
+ return APValue();
+
// FIXME: This is linear time.
unsigned i = 0;
for (RecordDecl::field_iterator Field = RD->field_begin(Info.Ctx),
@@ -1047,7 +1050,7 @@
// Get information about the alignment.
unsigned CharSize = Info.Ctx.Target.getCharWidth();
- // FIXME: Why do we ask for the preferred alignment?
+ // __alignof is defined to return the preferred alignment.
return Info.Ctx.getPreferredTypeAlign(T.getTypePtr()) / CharSize;
}
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=72636&r1=72635&r2=72636&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat May 30 16:09:44 2009
@@ -1034,6 +1034,8 @@
llvm::PointerType::get(FieldTy, AS),
"tmp");
}
+ if (Field->getType()->isReferenceType())
+ V = Builder.CreateLoad(V, "tmp");
QualType::GCAttrTypes attr = QualType::GCNone;
if (CGM.getLangOptions().ObjC1 &&
Added: cfe/trunk/test/CodeGenCXX/reference-field.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/reference-field.cpp?rev=72636&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/reference-field.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/reference-field.cpp Sat May 30 16:09:44 2009
@@ -0,0 +1,6 @@
+// RUN: clang-cc -emit-llvm -o - %s -O2 | grep "@_Z1bv"
+
+// Make sure the call to b() doesn't get optimized out.
+extern struct x {char& x,y;}y;
+int b();
+int a() { if (!&y.x) b(); }
More information about the cfe-commits
mailing list