This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG6c78703e3abc: [AST] Fix the incorrect auto-keyword loc for constrained auto type loc. (authored by hokein).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D117009/new/ https://reviews.llvm.org/D117009 Files: clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp clang/lib/Parse/ParseDecl.cpp clang/unittests/AST/SourceLocationTest.cpp Index: clang/unittests/AST/SourceLocationTest.cpp =================================================================== --- clang/unittests/AST/SourceLocationTest.cpp +++ clang/unittests/AST/SourceLocationTest.cpp @@ -247,6 +247,14 @@ Verifier.expectRange(1, 1, 1, 14); EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())), Lang_CXX14)); + + const char *Code = + R"cpp(template <typename T> concept C = true; +C auto abc(); +)cpp"; + // Should include "C auto" tokens. + Verifier.expectRange(2, 1, 2, 3); // token range. + EXPECT_TRUE(Verifier.match(Code, typeLoc(loc(autoType())), Lang_CXX20)); } TEST(TypeLoc, LongDoubleRange) { Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -3582,7 +3582,7 @@ isInvalid = DS.SetTypeSpecType(TST_decltype_auto, Loc, PrevSpec, DiagID, TemplateId, Policy); } else { - isInvalid = DS.SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, + isInvalid = DS.SetTypeSpecType(TST_auto, AutoLoc, PrevSpec, DiagID, TemplateId, Policy); } break; Index: clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp @@ -285,31 +285,6 @@ return {}; } - // If the return type is a constrained 'auto', we need to include the token - // after the concept. Unfortunately, the source range of an AutoTypeLoc, if it - // is constrained, does not include the 'auto'. - // FIXME: fix the AutoTypeLoc location in clang. - auto ATL = ReturnLoc.getAs<AutoTypeLoc>(); - if (ATL && ATL.isConstrained() && !ATL.isDecltypeAuto()) { - SourceLocation End = - expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM); - SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM); - - // Extend the ReturnTypeRange until the last token before the function - // name. - std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(End); - StringRef File = SM.getBufferData(Loc.first); - const char *TokenBegin = File.data() + Loc.second; - Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(), - TokenBegin, File.end()); - Token T; - SourceLocation LastTLoc = End; - while (!Lexer.LexFromRawLexer(T) && - SM.isBeforeInTranslationUnit(T.getLocation(), BeginNameF)) { - LastTLoc = T.getLocation(); - } - ReturnTypeRange.setEnd(LastTLoc); - } // If the return type has no local qualifiers, it's source range is accurate. if (!hasAnyNestedLocalQualifiers(F.getReturnType()))
Index: clang/unittests/AST/SourceLocationTest.cpp =================================================================== --- clang/unittests/AST/SourceLocationTest.cpp +++ clang/unittests/AST/SourceLocationTest.cpp @@ -247,6 +247,14 @@ Verifier.expectRange(1, 1, 1, 14); EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())), Lang_CXX14)); + + const char *Code = + R"cpp(template <typename T> concept C = true; +C auto abc(); +)cpp"; + // Should include "C auto" tokens. + Verifier.expectRange(2, 1, 2, 3); // token range. + EXPECT_TRUE(Verifier.match(Code, typeLoc(loc(autoType())), Lang_CXX20)); } TEST(TypeLoc, LongDoubleRange) { Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -3582,7 +3582,7 @@ isInvalid = DS.SetTypeSpecType(TST_decltype_auto, Loc, PrevSpec, DiagID, TemplateId, Policy); } else { - isInvalid = DS.SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID, + isInvalid = DS.SetTypeSpecType(TST_auto, AutoLoc, PrevSpec, DiagID, TemplateId, Policy); } break; Index: clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp @@ -285,31 +285,6 @@ return {}; } - // If the return type is a constrained 'auto', we need to include the token - // after the concept. Unfortunately, the source range of an AutoTypeLoc, if it - // is constrained, does not include the 'auto'. - // FIXME: fix the AutoTypeLoc location in clang. - auto ATL = ReturnLoc.getAs<AutoTypeLoc>(); - if (ATL && ATL.isConstrained() && !ATL.isDecltypeAuto()) { - SourceLocation End = - expandIfMacroId(ReturnLoc.getSourceRange().getEnd(), SM); - SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM); - - // Extend the ReturnTypeRange until the last token before the function - // name. - std::pair<FileID, unsigned> Loc = SM.getDecomposedLoc(End); - StringRef File = SM.getBufferData(Loc.first); - const char *TokenBegin = File.data() + Loc.second; - Lexer Lexer(SM.getLocForStartOfFile(Loc.first), LangOpts, File.begin(), - TokenBegin, File.end()); - Token T; - SourceLocation LastTLoc = End; - while (!Lexer.LexFromRawLexer(T) && - SM.isBeforeInTranslationUnit(T.getLocation(), BeginNameF)) { - LastTLoc = T.getLocation(); - } - ReturnTypeRange.setEnd(LastTLoc); - } // If the return type has no local qualifiers, it's source range is accurate. if (!hasAnyNestedLocalQualifiers(F.getReturnType()))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits