Skip to content

Commit bbdd6c1

Browse files
committed
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. llvm-svn: 219851
1 parent 4c879be commit bbdd6c1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

clang/lib/Sema/SemaStmt.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,8 +2755,11 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
27552755
SourceLocation ReturnLoc,
27562756
Expr *&RetExpr,
27572757
AutoType *AT) {
2758-
TypeLoc OrigResultType = FD->getTypeSourceInfo()->getTypeLoc().
2759-
IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();
2758+
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
2759+
if (auto ATL = TL.getAs<AttributedTypeLoc>())
2760+
TL = ATL.getModifiedLoc();
2761+
TypeLoc OrigResultType =
2762+
TL.IgnoreParens().castAs<FunctionProtoTypeLoc>().getReturnLoc();
27602763
QualType Deduced;
27612764

27622765
if (RetExpr && isa<InitListExpr>(RetExpr)) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -triple armv7 -std=c++14 -x c++ %s -fsyntax-only
2+
// expected-no-diagnostics
3+
4+
void deduce() {
5+
auto lambda = [](int i) __attribute__ (( pcs("aapcs") )) {
6+
return i;
7+
};
8+
lambda(42);
9+
}
10+

0 commit comments

Comments
 (0)