aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Zegar <me@piotrzegar.pl>2024-06-06 19:03:37 +0200
committerGitHub <noreply@github.com>2024-06-06 19:03:37 +0200
commit429e5be768c21d208ab688f8dfa1399c04ec5626 (patch)
tree61daebff78ea2c37ba7fb5c3cd07852818d8422b
parent212b78aad41b35df3af33bfffac678b460d467e9 (diff)
downloadllvm-429e5be768c21d208ab688f8dfa1399c04ec5626.zip
llvm-429e5be768c21d208ab688f8dfa1399c04ec5626.tar.gz
llvm-429e5be768c21d208ab688f8dfa1399c04ec5626.tar.bz2
[clang-tidy] Fix crash in readability-container-size-empty (#94527)
Fixed crash caused by call to getCookedLiteral on template user defined literal. Fix base on assert in getCookedLiteral method. Closes #94454
-rw-r--r--clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp9
-rw-r--r--clang-tools-extra/docs/ReleaseNotes.rst1
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp6
3 files changed, 14 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index bbc1b47..bf7a847 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -96,9 +96,14 @@ AST_MATCHER(QualType, isIntegralType) {
AST_MATCHER_P(UserDefinedLiteral, hasLiteral,
clang::ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
- if (const Expr *CookedLiteral = Node.getCookedLiteral()) {
+ const UserDefinedLiteral::LiteralOperatorKind LOK =
+ Node.getLiteralOperatorKind();
+ if (LOK == UserDefinedLiteral::LOK_Template ||
+ LOK == UserDefinedLiteral::LOK_Raw)
+ return false;
+
+ if (const Expr *CookedLiteral = Node.getCookedLiteral())
return InnerMatcher.matches(*CookedLiteral, Finder, Builder);
- }
return false;
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6947cf0..661b2b1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -376,6 +376,7 @@ Changes in existing checks
- Improved :doc:`readability-container-size-empty
<clang-tidy/checks/readability/container-size-empty>` check to prevent false
positives when utilizing ``size`` or ``length`` methods that accept parameter.
+ Fixed crash when facing template user defined literals.
- Improved :doc:`readability-duplicate-include
<clang-tidy/checks/readability/duplicate-include>` check by excluding include
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index ecaf97f..4675527 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -889,3 +889,9 @@ namespace PR88203 {
// CHECK-FIXES: {{^ }}if (s.empty()) {}{{$}}
}
}
+
+namespace PR94454 {
+ template <char...>
+ int operator""_ci() { return 0; }
+ auto eq = 0_ci == 0;
+}