https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/163483
>From 2372be22d2c0c8fd493f80661bcef5701464ea9e Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <[email protected]> Date: Tue, 14 Oct 2025 22:08:13 -0300 Subject: [PATCH] [clang] fix parsing of late parsed attributes with delayed template parsing Besides ignoring the attribute, this would also cause a memory leak. --- clang/docs/ReleaseNotes.rst | 3 ++- clang/lib/Parse/Parser.cpp | 4 ++++ clang/test/Parser/DelayedTemplateParsing.cpp | 13 +++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index db2b0f6fd5027..e4a66fad29c83 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -424,7 +424,8 @@ Bug Fixes to Attribute Support (#GH141504) and on types returned from indirect calls (#GH142453). - Fixes some late parsed attributes, when applied to function definitions, not being parsed in function try blocks, and some situations where parsing of the function body - is skipped, such as error recovery and code completion. (#GH153551) + is skipped, such as error recovery, code completion, and msvc-compatible delayed + template parsing. (#GH153551) - Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with ``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520) - Fix a crash when the function name is empty in the `swift_name` attribute. (#GH157075) diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index bbff627d46600..21b3191ac4d2c 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1285,6 +1285,10 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, D.complete(DP); D.getMutableDeclSpec().abort(); + if (LateParsedAttrs) + ParseLexedAttributeList(*LateParsedAttrs, DP, /*EnterScope=*/false, + /*OnDefinition=*/true); + if (SkipFunctionBodies && (!DP || Actions.canSkipFunctionBody(DP)) && trySkippingFunctionBody()) { BodyScope.Exit(); diff --git a/clang/test/Parser/DelayedTemplateParsing.cpp b/clang/test/Parser/DelayedTemplateParsing.cpp index bcd286ae04492..ba0d71ba2f0a0 100644 --- a/clang/test/Parser/DelayedTemplateParsing.cpp +++ b/clang/test/Parser/DelayedTemplateParsing.cpp @@ -43,10 +43,10 @@ void undeclared() } -template <class T> void foo5() {} //expected-note {{previous definition is here}} +template <class T> void foo5() {} //expected-note {{previous definition is here}} template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}} - + namespace PR11931 { @@ -195,3 +195,12 @@ template <typename> struct PR38460_2 { } }; template struct PR38460_2<int>; + +namespace LateParsedAttrs { + template <class> + void f() __attribute__((__diagnose_if__(true, "foo", "error"))) {} + // expected-note@-1 {{from 'diagnose_if' attribute on 'f<int>'}} + void g() { + f<int>(); // expected-error {{foo}} + } +} // namespace LateParsedAttrs _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
