Commit bbdd6c13 authored by Saleem Abdulrasool's avatar Saleem Abdulrasool
Browse files

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
parent 4c879bed
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -2755,8 +2755,11 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
                                            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)) {
+10 −0
Original line number Diff line number Diff line
// 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);
}