r219851 - Sema: handle AttributedTypeLocs in C++14 auto deduction
Saleem Abdulrasool
compnerd at compnerd.org
Wed Oct 15 14:37:55 PDT 2014
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();
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);
+}
+
More information about the cfe-commits
mailing list