]> granicus.if.org Git - clang/commitdiff
Some small fixes for fields of reference type.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 30 May 2009 21:09:44 +0000 (21:09 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 30 May 2009 21:09:44 +0000 (21:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72636 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
lib/CodeGen/CGExpr.cpp
test/CodeGenCXX/reference-field.cpp [new file with mode: 0644]

index 4ad2bec53bcc8f3caed8de69d772504ba12b0fe2..50fdcfd6eb2b6e1cfb5874ca8a89bf703a66cfab 100644 (file)
@@ -231,7 +231,10 @@ APValue LValueExprEvaluator::VisitMemberExpr(MemberExpr *E) {
   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 @@ unsigned IntExprEvaluator::GetAlignOfType(QualType T) {
   // 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;
 }
 
index 3d07403b07fb12b2cd096db3c05754bf7811a233..12a8002de310517abea8adbbd86d8d3aec287806 100644 (file)
@@ -1034,6 +1034,8 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
                               llvm::PointerType::get(FieldTy, AS), 
                               "tmp");
   }
+  if (Field->getType()->isReferenceType())
+    V = Builder.CreateLoad(V, "tmp");
 
   QualType::GCAttrTypes attr = QualType::GCNone;
   if (CGM.getLangOptions().ObjC1 &&
diff --git a/test/CodeGenCXX/reference-field.cpp b/test/CodeGenCXX/reference-field.cpp
new file mode 100644 (file)
index 0000000..88d4c1f
--- /dev/null
@@ -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(); }