<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">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:0 0 0 .8ex;border-left:1px #ccc 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>Do you need to cope with parens outside the AttributedTypeLoc too? What happens if there are multiple attributes here?</div><div><br></div><div>Sema::SubstFunctionDeclType and its helper NeedsInstantiationAsFunctionType appear to have the same bug.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc 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">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></div></div>