From: Eli Friedman Date: Sat, 30 May 2009 21:09:44 +0000 (+0000) Subject: Some small fixes for fields of reference type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2be586108bb401019647791feca19ea03fd477ce;p=clang Some small fixes for fields of reference type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72636 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 4ad2bec53b..50fdcfd6eb 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -231,7 +231,10 @@ APValue LValueExprEvaluator::VisitMemberExpr(MemberExpr *E) { FieldDecl *FD = dyn_cast(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; } diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 3d07403b07..12a8002de3 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -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 index 0000000000..88d4c1f37e --- /dev/null +++ b/test/CodeGenCXX/reference-field.cpp @@ -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(); }