[PATCH] D91601: [clang-tidy] Fix an abseil-redundant-strcat-calls crash on 0-parameter StrCat().

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 17 01:29:12 PST 2020


hokein created this revision.
hokein added a reviewer: gribozavr2.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.
hokein requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91601

Files:
  clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-redundant-strcat-calls.cpp
@@ -121,6 +121,7 @@
   AlphaNum &operator=(const AlphaNum &);
 };
 
+string StrCat();
 string StrCat(const AlphaNum &A);
 string StrCat(const AlphaNum &A, const AlphaNum &B);
 string StrCat(const AlphaNum &A, const AlphaNum &B, const AlphaNum &C);
@@ -182,6 +183,9 @@
   StrAppend(&S, StrCat(1, 2, 3, 4, 5), StrCat(6, 7, 8, 9, 10));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple calls to 'absl::StrCat' can be flattened into a single call
   // CHECK-FIXES: StrAppend(&S, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+  StrCat(1, StrCat());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple calls to 'absl::StrCat' can be flattened into a single call
 }
 
 void Negatives() {
Index: clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
@@ -47,6 +47,8 @@
 };
 
 void RemoveCallLeaveArgs(const CallExpr* Call, StrCatCheckResult* CheckResult) {
+  if (Call->getNumArgs() == 0)
+    return;
   // Remove 'Foo('
   CheckResult->Hints.push_back(
       FixItHint::CreateRemoval(CharSourceRange::getCharRange(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91601.305697.patch
Type: text/x-patch
Size: 1543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201117/96a57fde/attachment-0001.bin>


More information about the cfe-commits mailing list