<div dir="ltr">On Wed, Oct 15, 2014 at 3:07 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Wed, Oct 15, 2014 at 2:37 PM, Saleem Abdulrasool <span dir="ltr"><<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: compnerd<br>
Date: Wed Oct 15 16:37:55 2014<br>
New Revision: 219851<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=219851&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=219851&view=rev</a><br>
Log:<br>
Sema: handle AttributedTypeLocs in C++14 auto deduction<br>
<br>
When performing a type deduction from the return type, the FunctionDecl may be<br>
attributed with a calling convention.  In such a case, the retrieved type<br>
location may be an AttributedTypeLoc.  Performing a castAs<FunctionProtoTypeLoc><br>
on such a type loc would result in an assertion as they are not derived types.<br>
<br>
Ensure that we correctly handle the attributed type location by looking through<br>
it to the modified type loc.<br>
<br>
Fixes an assertion triggered in C++14 mode.<br>
<br>
Added:<br>
    cfe/trunk/test/Sema/attributed-auto-deduction.cpp<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaStmt.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=219851&r1=219850&r2=219851&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=219851&r1=219850&r2=219851&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Oct 15 16:37:55 2014<br>
@@ -2755,8 +2755,11 @@ bool Sema::DeduceFunctionTypeFromReturnE<br>
                                             SourceLocation ReturnLoc,<br>
                                             Expr *&RetExpr,<br>
                                             AutoType *AT) {<br>
-  TypeLoc OrigResultType = FD->getTypeSourceInfo()->getTypeLoc().<br>
-    IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();<br>
+  TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();<br>
+  if (auto ATL = TL.getAs<AttributedTypeLoc>())<br>
+    TL = ATL.getModifiedLoc();<br>
+  TypeLoc OrigResultType =<br>
+      TL.IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();<br></blockquote><div><br></div></div></div><div>Do you need to cope with parens outside the AttributedTypeLoc too? What happens if there are multiple attributes here?</div></div></div></div></blockquote><div><br></div><div>AFAIK, thats not allowed.  But, added to future-proof it a bit.  Yes, multiple attributes are a problem still, good point.  There was another case where the void inference without a return would also fail.  Addressed these comments in SVN r219974.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Sema::SubstFunctionDeclType and its helper NeedsInstantiationAsFunctionType appear to have the same bug.</div></div></div></div></blockquote><div><br></div><div>Yes, those have a related issue, but cannot cause the issue to appear yet.  Ill wait for you to reinstate SVN r217995 before trying to see if I can reproduce the issue.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
   QualType Deduced;<br>
<br>
   if (RetExpr && isa<InitListExpr>(RetExpr)) {<br>
<br>
Added: cfe/trunk/test/Sema/attributed-auto-deduction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attributed-auto-deduction.cpp?rev=219851&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attributed-auto-deduction.cpp?rev=219851&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/attributed-auto-deduction.cpp (added)<br>
+++ cfe/trunk/test/Sema/attributed-auto-deduction.cpp Wed Oct 15 16:37:55 2014<br>
@@ -0,0 +1,10 @@<br>
+// RUN: %clang_cc1 -triple armv7 -std=c++14 -x c++ %s -fsyntax-only<br>
+// expected-no-diagnostics<br>
+<br>
+void deduce() {<br>
+  auto lambda = [](int i) __attribute__ (( pcs("aapcs") )) {<br>
+    return i;<br>
+  };<br>
+  lambda(42);<br>
+}<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">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></span></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org
</div></div>