r219851 - Sema: handle AttributedTypeLocs in C++14 auto deduction

Saleem Abdulrasool compnerd at compnerd.org
Thu Oct 16 15:55:09 PDT 2014


On Wed, Oct 15, 2014 at 3:07 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> On Wed, Oct 15, 2014 at 2:37 PM, Saleem Abdulrasool <compnerd at compnerd.org
> > wrote:
>
>> Author: compnerd
>> Date: Wed Oct 15 16:37:55 2014
>> New Revision: 219851
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=219851&view=rev
>> Log:
>> Sema: handle AttributedTypeLocs in C++14 auto deduction
>>
>> When performing a type deduction from the return type, the FunctionDecl
>> may be
>> attributed with a calling convention.  In such a case, the retrieved type
>> location may be an AttributedTypeLoc.  Performing a
>> castAs<FunctionProtoTypeLoc>
>> on such a type loc would result in an assertion as they are not derived
>> types.
>>
>> Ensure that we correctly handle the attributed type location by looking
>> through
>> it to the modified type loc.
>>
>> Fixes an assertion triggered in C++14 mode.
>>
>> Added:
>>     cfe/trunk/test/Sema/attributed-auto-deduction.cpp
>> Modified:
>>     cfe/trunk/lib/Sema/SemaStmt.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=219851&r1=219850&r2=219851&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Oct 15 16:37:55 2014
>> @@ -2755,8 +2755,11 @@ bool Sema::DeduceFunctionTypeFromReturnE
>>                                              SourceLocation ReturnLoc,
>>                                              Expr *&RetExpr,
>>                                              AutoType *AT) {
>> -  TypeLoc OrigResultType = FD->getTypeSourceInfo()->getTypeLoc().
>> -    IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();
>> +  TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
>> +  if (auto ATL = TL.getAs<AttributedTypeLoc>())
>> +    TL = ATL.getModifiedLoc();
>> +  TypeLoc OrigResultType =
>> +      TL.IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();
>>
>
> Do you need to cope with parens outside the AttributedTypeLoc too? What
> happens if there are multiple attributes here?
>

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.


> Sema::SubstFunctionDeclType and its helper
> NeedsInstantiationAsFunctionType appear to have the same bug.
>

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.


>    QualType Deduced;
>>
>>    if (RetExpr && isa<InitListExpr>(RetExpr)) {
>>
>> Added: cfe/trunk/test/Sema/attributed-auto-deduction.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attributed-auto-deduction.cpp?rev=219851&view=auto
>>
>> ==============================================================================
>> --- cfe/trunk/test/Sema/attributed-auto-deduction.cpp (added)
>> +++ cfe/trunk/test/Sema/attributed-auto-deduction.cpp Wed Oct 15 16:37:55
>> 2014
>> @@ -0,0 +1,10 @@
>> +// RUN: %clang_cc1 -triple armv7 -std=c++14 -x c++ %s -fsyntax-only
>> +// expected-no-diagnostics
>> +
>> +void deduce() {
>> +  auto lambda = [](int i) __attribute__ (( pcs("aapcs") )) {
>> +    return i;
>> +  };
>> +  lambda(42);
>> +}
>> +
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>


-- 
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141016/cdb869c3/attachment.html>


More information about the cfe-commits mailing list