From: Fariborz Jahanian Date: Mon, 25 Jan 2010 18:30:26 +0000 (+0000) Subject: Fix a code gen. bug involving compiling global references. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7c00eda7f21ef89cfec48fa90b743a403b89d4b;p=clang Fix a code gen. bug involving compiling global references. (fixes radar 7574896). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94434 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp index 47773a0d69..2d473de47c 100644 --- a/lib/CodeGen/CGDeclCXX.cpp +++ b/lib/CodeGen/CGDeclCXX.cpp @@ -80,8 +80,8 @@ void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D, EmitDeclInit(*this, D, DeclPtr); return; } - - ErrorUnsupported(Init, "global variable that binds to a reference"); + RValue RV = EmitReferenceBindingToExpr(Init, T, /*IsInitializer=*/true); + EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, T); } void diff --git a/test/CodeGenCXX/reference-init.cpp b/test/CodeGenCXX/reference-init.cpp index 6c2c6a3016..61ae2daffd 100644 --- a/test/CodeGenCXX/reference-init.cpp +++ b/test/CodeGenCXX/reference-init.cpp @@ -14,3 +14,8 @@ namespace PR5911 { int iarr[] = { 1 }; int test() { return f(iarr); } } + +// radar 7574896 +struct Foo { int foo; }; +Foo& ignoreSetMutex = *(new Foo); +