r219851 - Sema: handle AttributedTypeLocs in C++14 auto deduction
Richard Smith
richard at metafoo.co.uk
Wed Oct 15 15:07:52 PDT 2014
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?
Sema::SubstFunctionDeclType and its helper NeedsInstantiationAsFunctionType
appear to have the same bug.
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141015/2a716b3b/attachment.html>
More information about the cfe-commits
mailing list