<div dir="ltr">Hi Richard,<div><br></div><div>Would you mind if I merged this into the 3.9 branch? :)</div><div><br></div><div>Thanks,</div><div>George</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 11, 2016 at 9:12 PM, George Burgess IV via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: gbiv<br>
Date: Thu Aug 11 23:12:31 2016<br>
New Revision: 278471<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278471&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=278471&view=rev</a><br>
Log:<br>
[Sema] Fix a crash on variadic enable_if functions.<br>
<br>
Currently, when trying to evaluate an enable_if condition, we try to<br>
evaluate all arguments a user passes to a function. Given that we can't<br>
use variadic arguments from said condition anyway, not converting them<br>
is a reasonable thing to do. So, this patch makes us ignore any varargs<br>
when attempting to check an enable_if condition.<br>
<br>
We'd crash because, in order to convert an argument, we need its<br>
ParmVarDecl. Variadic arguments don't have ParmVarDecls.<br>
<br>
Modified:<br>
cfe/trunk/lib/Sema/<wbr>SemaOverload.cpp<br>
cfe/trunk/test/Sema/enable_if.<wbr>c<br>
cfe/trunk/test/SemaCXX/enable_<wbr>if.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaOverload.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=278471&r1=278470&r2=278471&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaOverload.cpp?rev=278471&<wbr>r1=278470&r2=278471&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaOverload.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaOverload.cpp Thu Aug 11 23:12:31 2016<br>
@@ -5974,8 +5974,12 @@ EnableIfAttr *Sema::CheckEnableIf(Functi<br>
SmallVector<Expr *, 16> ConvertedArgs;<br>
bool InitializationFailed = false;<br>
<br>
+ // Ignore any variadic parameters. Converting them is pointless, since the<br>
+ // user can't refer to them in the enable_if condition.<br>
+ unsigned ArgSizeNoVarargs = std::min(Function->param_size(<wbr>), Args.size());<br>
+<br>
// Convert the arguments.<br>
- for (unsigned I = 0, E = Args.size(); I != E; ++I) {<br>
+ for (unsigned I = 0; I != ArgSizeNoVarargs; ++I) {<br>
ExprResult R;<br>
if (I == 0 && !MissingImplicitThis && isa<CXXMethodDecl>(Function) &&<br>
!cast<CXXMethodDecl>(Function)<wbr>->isStatic() &&<br>
<br>
Modified: cfe/trunk/test/Sema/enable_if.<wbr>c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enable_if.c?rev=278471&r1=278470&r2=278471&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/Sema/<wbr>enable_if.c?rev=278471&r1=<wbr>278470&r2=278471&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Sema/enable_if.<wbr>c (original)<br>
+++ cfe/trunk/test/Sema/enable_if.<wbr>c Thu Aug 11 23:12:31 2016<br>
@@ -149,4 +149,25 @@ void PR27122_ext() {<br>
regular_enable_if(1, 2); // expected-error{{too many arguments}}<br>
regular_enable_if(); // expected-error{{too few arguments}}<br>
}<br>
+<br>
+// We had a bug where we'd crash upon trying to evaluate varargs.<br>
+void variadic_enable_if(int a, ...) __attribute__((enable_if(a, ""))); // expected-note 6 {{disabled}}<br>
+void variadic_test() {<br>
+ variadic_enable_if(1);<br>
+ variadic_enable_if(1, 2);<br>
+ variadic_enable_if(1, "c", 3);<br>
+<br>
+ variadic_enable_if(0); // expected-error{{no matching}}<br>
+ variadic_enable_if(0, 2); // expected-error{{no matching}}<br>
+ variadic_enable_if(0, "c", 3); // expected-error{{no matching}}<br>
+<br>
+ int m;<br>
+ variadic_enable_if(1);<br>
+ variadic_enable_if(1, m);<br>
+ variadic_enable_if(1, m, "c");<br>
+<br>
+ variadic_enable_if(0); // expected-error{{no matching}}<br>
+ variadic_enable_if(0, m); // expected-error{{no matching}}<br>
+ variadic_enable_if(0, m, 3); // expected-error{{no matching}}<br>
+}<br>
#endif<br>
<br>
Modified: cfe/trunk/test/SemaCXX/enable_<wbr>if.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enable_if.cpp?rev=278471&r1=278470&r2=278471&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/enable_if.cpp?rev=<wbr>278471&r1=278470&r2=278471&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/enable_<wbr>if.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/enable_<wbr>if.cpp Thu Aug 11 23:12:31 2016<br>
@@ -417,3 +417,26 @@ template <int N> constexpr int callTempl<br>
constexpr int B = callTemplated<0>(); // expected-error{{initialized by a constant expression}} expected-error@-2{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note@-9{{candidate disabled}}<br>
static_assert(callTemplated<1><wbr>() == 1, "");<br>
}<br>
+<br>
+namespace variadic {<br>
+void foo(int a, int b = 0, ...) __attribute__((enable_if(a && b, ""))); // expected-note 6{{disabled}}<br>
+<br>
+void testFoo() {<br>
+ foo(1, 1);<br>
+ foo(1, 1, 2);<br>
+ foo(1, 1, 2, 3);<br>
+<br>
+ foo(1, 0); // expected-error{{no matching}}<br>
+ foo(1, 0, 2); // expected-error{{no matching}}<br>
+ foo(1, 0, 2, 3); // expected-error{{no matching}}<br>
+<br>
+ int m;<br>
+ foo(1, 1);<br>
+ foo(1, 1, m);<br>
+ foo(1, 1, m, 3);<br>
+<br>
+ foo(1, 0); // expected-error{{no matching}}<br>
+ foo(1, 0, m); // expected-error{{no matching}}<br>
+ foo(1, 0, m, 3); // expected-error{{no matching}}<br>
+}<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>