I think this change broke bootstrap builds with C++11 and -Werror enabled.<br><br>lib/VMCore/Verifier.cpp:116:14: error: variable 'PreVerifyID' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]<br>
static char &PreVerifyID = PreVerifier::ID;<br><br><div class="gmail_quote">On Fri, Oct 19, 2012 at 6:38 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Fri Oct 19 20:38:33 2012<br>
New Revision: 166361<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=166361&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=166361&view=rev</a><br>
Log:<br>
DR1472: A reference isn't odr-used if it has preceding initialization,<br>
initialized by a reference constant expression.<br>
<br>
Our odr-use modeling still needs work here: we don't yet implement the 'set of<br>
potential results of an expression' DR.<br>
<br>
Modified:<br>
cfe/trunk/lib/CodeGen/CGExpr.cpp<br>
cfe/trunk/lib/Sema/SemaExpr.cpp<br>
cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp<br>
cfe/trunk/test/CodeGenCXX/for-range.cpp<br>
cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp<br>
cfe/trunk/test/SemaCXX/lambda-expressions.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=166361&r1=166360&r2=166361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=166361&r1=166360&r2=166361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Oct 19 20:38:33 2012<br>
@@ -1695,6 +1695,21 @@<br>
CharUnits Alignment = getContext().getDeclAlign(ND);<br>
QualType T = E->getType();<br>
<br>
+ // A DeclRefExpr for a reference initialized by a constant expression can<br>
+ // appear without being odr-used. Directly emit the constant initializer.<br>
+ if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {<br>
+ const Expr *Init = VD->getAnyInitializer(VD);<br>
+ if (Init && !isa<ParmVarDecl>(VD) && VD->getType()->isReferenceType() &&<br>
+ VD->isUsableInConstantExpressions(getContext()) &&<br>
+ VD->checkInitIsICE()) {<br>
+ llvm::Constant *Val =<br>
+ CGM.EmitConstantValue(*VD->evaluateValue(), VD->getType(), this);<br>
+ assert(Val && "failed to emit reference constant expression");<br>
+ // FIXME: Eventually we will want to emit vector element references.<br>
+ return MakeAddrLValue(Val, T, Alignment);<br>
+ }<br>
+ }<br>
+<br>
// FIXME: We should be able to assert this for FunctionDecls as well!<br>
// FIXME: We should be able to assert this for all DeclRefExprs, not just<br>
// those with a valid source location.<br>
@@ -1705,7 +1720,7 @@<br>
if (ND->hasAttr<WeakRefAttr>()) {<br>
const ValueDecl *VD = cast<ValueDecl>(ND);<br>
llvm::Constant *Aliasee = CGM.GetWeakRefReference(VD);<br>
- return MakeAddrLValue(Aliasee, E->getType(), Alignment);<br>
+ return MakeAddrLValue(Aliasee, T, Alignment);<br>
}<br>
<br>
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {<br>
@@ -1733,9 +1748,8 @@<br>
}<br>
<br>
assert(isa<BlockDecl>(CurCodeDecl) && E->refersToEnclosingLocal());<br>
- CharUnits alignment = getContext().getDeclAlign(VD);<br>
return MakeAddrLValue(GetAddrOfBlockDecl(VD, isBlockVariable),<br>
- E->getType(), alignment);<br>
+ T, Alignment);<br>
}<br>
<br>
assert(V && "DeclRefExpr not entered in LocalDeclMap?");<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=166361&r1=166360&r2=166361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=166361&r1=166360&r2=166361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Oct 19 20:38:33 2012<br>
@@ -11010,20 +11010,21 @@<br>
}<br>
}<br>
<br>
- // Per C++11 [basic.def.odr], a variable is odr-used "unless it is<br>
- // an object that satisfies the requirements for appearing in a<br>
- // constant expression (5.19) and the lvalue-to-rvalue conversion (4.1)<br>
+ // Per C++11 [basic.def.odr], a variable is odr-used "unless it satisfies<br>
+ // the requirements for appearing in a constant expression (5.19) and, if<br>
+ // it is an object, the lvalue-to-rvalue conversion (4.1)<br>
// is immediately applied." We check the first part here, and<br>
// Sema::UpdateMarkingForLValueToRValue deals with the second part.<br>
// Note that we use the C++11 definition everywhere because nothing in<br>
- // C++03 depends on whether we get the C++03 version correct. This does not<br>
- // apply to references, since they are not objects.<br>
+ // C++03 depends on whether we get the C++03 version correct. The second<br>
+ // part does not apply to references, since they are not objects.<br>
const VarDecl *DefVD;<br>
- if (E && !isa<ParmVarDecl>(Var) && !Var->getType()->isReferenceType() &&<br>
+ if (E && !isa<ParmVarDecl>(Var) &&<br>
Var->isUsableInConstantExpressions(SemaRef.Context) &&<br>
- Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE())<br>
- SemaRef.MaybeODRUseExprs.insert(E);<br>
- else<br>
+ Var->getAnyInitializer(DefVD) && DefVD->checkInitIsICE()) {<br>
+ if (!Var->getType()->isReferenceType())<br>
+ SemaRef.MaybeODRUseExprs.insert(E);<br>
+ } else<br>
MarkVarDeclODRUsed(SemaRef, Var, Loc);<br>
}<br>
<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=166361&r1=166360&r2=166361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=166361&r1=166360&r2=166361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Fri Oct 19 20:38:33 2012<br>
@@ -432,11 +432,7 @@<br>
// CHECK: call void @_ZN13InitFromConst7consumeIRKNS_1SEEEvT_(%"struct.InitFromConst::S"* @_ZN13InitFromConstL1sE)<br>
consume<const S&>(s);<br>
<br>
- // FIXME CHECK-NOT: call void @_ZN13InitFromConst7consumeIRKNS_1SEEEvT_(%"struct.InitFromConst::S"* @_ZN13InitFromConstL1sE)<br>
- // There's no lvalue-to-rvalue conversion here, so 'r' is odr-used, and<br>
- // we're permitted to emit a load of it. This seems likely to be a defect<br>
- // in the standard. If we start emitting a direct reference to 's', update<br>
- // this test.<br>
+ // CHECK: call void @_ZN13InitFromConst7consumeIRKNS_1SEEEvT_(%"struct.InitFromConst::S"* @_ZN13InitFromConstL1sE)<br>
consume<const S&>(r);<br>
<br>
// CHECK: call void @_ZN13InitFromConst7consumeIPKNS_1SEEEvT_(%"struct.InitFromConst::S"* @_ZN13InitFromConstL1sE)<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/for-range.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/for-range.cpp?rev=166361&r1=166360&r2=166361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/for-range.cpp?rev=166361&r1=166360&r2=166361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/for-range.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/for-range.cpp Fri Oct 19 20:38:33 2012<br>
@@ -40,7 +40,7 @@<br>
// CHECK-NOT: 5begin<br>
// CHECK-NOT: 3end<br>
// CHECK: getelementptr {{.*}}, i32 0<br>
- // CHECK: getelementptr {{.*}}, i64 5<br>
+ // CHECK: getelementptr {{.*}}, i64 1, i64 0<br>
// CHECK: br label %[[COND:.*]]<br>
<br>
// CHECK: [[COND]]:<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp?rev=166361&r1=166360&r2=166361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp?rev=166361&r1=166360&r2=166361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp Fri Oct 19 20:38:33 2012<br>
@@ -71,6 +71,15 @@<br>
int (*fp)(int, int) = [](int x, int y){ return x + y; };<br>
}<br>
<br>
+static int k;<br>
+int g() {<br>
+ int &r = k;<br>
+ // CHECK: define internal i32 @"_ZZ1gvENK3$_6clEv"(<br>
+ // CHECK-NOT: }<br>
+ // CHECK: load i32* @_ZL1k,<br>
+ return [] { return r; } ();<br>
+};<br>
+<br>
// CHECK: define internal i32 @"_ZZ1fvEN3$_58__invokeEii"<br>
// CHECK: store i32<br>
// CHECK-NEXT: store i32<br>
<br>
Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=166361&r1=166360&r2=166361&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=166361&r1=166360&r2=166361&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Fri Oct 19 20:38:33 2012<br>
@@ -83,12 +83,15 @@<br>
const int h = a; // expected-note {{declared}}<br>
[]() { return h; }; // expected-error {{variable 'h' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}}<br>
<br>
- // The exemption for variables which can appear in constant expressions<br>
- // applies only to objects (and not to references).<br>
- // FIXME: This might be a bug in the standard.<br>
- static int i;<br>
- constexpr int &ref_i = i; // expected-note {{declared}}<br>
+ // References can appear in constant expressions if they are initialized by<br>
+ // reference constant expressions.<br>
+ int i;<br>
+ int &ref_i = i; // expected-note {{declared}}<br>
[] { return ref_i; }; // expected-error {{variable 'ref_i' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}}<br>
+<br>
+ static int j;<br>
+ int &ref_j = j;<br>
+ [] { return ref_j; }; // ok<br>
}<br>
}<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>~Craig<br>