[cfe-commits] r80439 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/constructor-init-reference.cpp
Eli Friedman
eli.friedman at gmail.com
Sat Aug 29 13:58:20 PDT 2009
Author: efriedma
Date: Sat Aug 29 15:58:20 2009
New Revision: 80439
URL: http://llvm.org/viewvc/llvm-project?rev=80439&view=rev
Log:
Make IRGen for initializing a member reference work correctly.
Added:
cfe/trunk/test/CodeGenCXX/constructor-init-reference.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=80439&r1=80438&r2=80439&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sat Aug 29 15:58:20 2009
@@ -1643,7 +1643,16 @@
FieldType = getContext().getBaseElementType(FieldType);
LoadOfThis = LoadCXXThis();
- LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
+ LValue LHS;
+ if (FieldType->isReferenceType()) {
+ // FIXME: This is really ugly; should be refactored somehow
+ unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
+ llvm::Value *V = Builder.CreateStructGEP(LoadOfThis, idx, "tmp");
+ LHS = LValue::MakeAddr(V, FieldType.getCVRQualifiers(),
+ QualType::GCNone, FieldType.getAddressSpace());
+ } else {
+ LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
+ }
if (FieldType->getAs<RecordType>()) {
if (!Field->isAnonymousStructOrUnion()) {
assert(Member->getConstructor() &&
@@ -1673,8 +1682,13 @@
assert(Member->getNumArgs() == 1 && "Initializer count must be 1 only");
Expr *RhsExpr = *Member->arg_begin();
- llvm::Value *RHS = EmitScalarExpr(RhsExpr, true);
- EmitStoreThroughLValue(RValue::get(RHS), LHS, FieldType);
+ RValue RHS;
+ if (FieldType->isReferenceType())
+ RHS = EmitReferenceBindingToExpr(RhsExpr, FieldType,
+ /*IsInitializer=*/true);
+ else
+ RHS = RValue::get(EmitScalarExpr(RhsExpr, true));
+ EmitStoreThroughLValue(RHS, LHS, FieldType);
}
}
Added: cfe/trunk/test/CodeGenCXX/constructor-init-reference.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-init-reference.cpp?rev=80439&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/constructor-init-reference.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/constructor-init-reference.cpp Sat Aug 29 15:58:20 2009
@@ -0,0 +1,9 @@
+// RUN: clang-cc -emit-llvm -o - %s | grep "store i32\* @x, i32\*\*"
+
+int x;
+class A {
+ int& y;
+ A() : y(x) {}
+};
+A z;
+
More information about the cfe-commits
mailing list