https://github.com/PiotrZSL updated https://github.com/llvm/llvm-project/pull/92019
>From 5f0302b0d1c34d13b566aa6f992568005a47fac0 Mon Sep 17 00:00:00 2001 From: Piotr Zegar <m...@piotrzegar.pl> Date: Mon, 13 May 2024 19:47:44 +0000 Subject: [PATCH 1/2] [clang-tidy] Fix crash in modernize-use-constraints Improved modernize-use-constraints check by fixing a crash that occurred in some scenarios and excluded system headers from analysis. Problem were with DependentNameTypeLoc having null type location as getQualifierLoc().getTypeLoc(). Fixes #91872 --- .../modernize/UseConstraintsCheck.cpp | 4 +++ clang-tools-extra/docs/ReleaseNotes.rst | 4 +++ .../checks/modernize/use-constraints.rst | 4 +++ .../checkers/modernize/use-constraints.cpp | 32 +++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp index 6d7d1d6b87c60..d9fab64050adb 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp @@ -41,6 +41,8 @@ AST_MATCHER(FunctionDecl, hasOtherDeclarations) { void UseConstraintsCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( functionTemplateDecl( + // Skip external libraries included as system headers + unless(isExpansionInSystemHeader()), has(functionDecl(unless(hasOtherDeclarations()), isDefinition(), hasReturnTypeLoc(typeLoc().bind("return"))) .bind("function"))) @@ -57,6 +59,8 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) { return std::nullopt; } TheType = Dep.getQualifierLoc().getTypeLoc(); + if (TheType.isNull()) + return std::nullopt; } if (const auto SpecializationLoc = diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index fc976ce3a33d5..91b24f654112f 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -306,6 +306,10 @@ Changes in existing checks don't remove parentheses used in ``sizeof`` calls when they have array index accesses as arguments. +- Improved :doc:`modernize-use-constraints + <clang-tidy/checks/modernize/use-constraints>` check by fixing a crash that + occurred in some scenarios and excluded system headers from analysis. + - Improved :doc:`modernize-use-nullptr <clang-tidy/checks/modernize/use-nullptr>` check to include support for C23, which also has introduced the ``nullptr`` keyword. diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst index be62dd5823d55..a8b31b80e580b 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst @@ -68,3 +68,7 @@ The tool will replace the above code with, // The tool will not emit a diagnostic or attempt to replace the code. template <typename T, std::enable_if_t<T::some_trait, int> = 0> struct my_class {}; + +.. note:: + + System headers are not analyzed by this check. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp index 3ec44be8a1c8c..3bcd5cd74024e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp @@ -724,3 +724,35 @@ void not_last_param() { } } // namespace enable_if_trailing_type_parameter + + +// Issue fixes: + +namespace PR91872 { + +enum expression_template_option { value1, value2 }; + +template <typename T> struct number_category { + static const int value = 0; +}; + +constexpr int number_kind_complex = 1; + +template <typename T, expression_template_option ExpressionTemplates> +struct number { + using type = T; +}; + +template <typename T> struct component_type { + using type = T; +}; + +template <class T, expression_template_option ExpressionTemplates> +inline typename std::enable_if< + number_category<T>::value == number_kind_complex, + component_type<number<T, ExpressionTemplates>>>::type::type +abs(const number<T, ExpressionTemplates> &v) { + return {}; +} + +} >From fd5fa3e94ade53bfa78850879f3dfa287697277b Mon Sep 17 00:00:00 2001 From: Piotr Zegar <m...@piotrzegar.pl> Date: Tue, 14 May 2024 19:18:06 +0200 Subject: [PATCH 2/2] Update clang-tools-extra/docs/ReleaseNotes.rst Co-authored-by: Congcong Cai <congcongcai0...@163.com> --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 91b24f654112f..e30b7bc3cd22d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -308,7 +308,7 @@ Changes in existing checks - Improved :doc:`modernize-use-constraints <clang-tidy/checks/modernize/use-constraints>` check by fixing a crash that - occurred in some scenarios and excluded system headers from analysis. + occurred in some scenarios and excluding system headers from analysis. - Improved :doc:`modernize-use-nullptr <clang-tidy/checks/modernize/use-nullptr>` check to include support for C23, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits