[clang-tools-extra] ea72b55 - bugprone-argument-comment: SourceLocation valid judgment avoid emitting coredump in isInSystemHeader

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 13 09:31:11 PDT 2021


Author: liuke
Date: 2021-10-13T12:31:02-04:00
New Revision: ea72b55b5c7c281cb21bb7bd50e6e039ca63dfe8

URL: https://github.com/llvm/llvm-project/commit/ea72b55b5c7c281cb21bb7bd50e6e039ca63dfe8
DIFF: https://github.com/llvm/llvm-project/commit/ea72b55b5c7c281cb21bb7bd50e6e039ca63dfe8.diff

LOG: bugprone-argument-comment: SourceLocation valid judgment avoid emitting coredump in isInSystemHeader

If the Node has an invalid location, it will trigger assert in
isInSystemHeader(...).

void test() {
  __builtin_va_list __args;
  // __builtin_va_list has no defination in any source file and its
  // CXXConstructorDecl has invalid sourcelocation
}
coredump with "Assertion `Loc.isValid() && "Can't get file
characteristic of invalid loc!"' failed." in
getFileCharacteristic(SourceLocation).

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
    clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index c36fb60b6d3d6..3836e4cf3990d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -24,6 +24,8 @@ AST_MATCHER(Decl, isFromStdNamespaceOrSystemHeader) {
   if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext())
     if (D->isStdNamespace())
       return true;
+  if (Node.getLocation().isInvalid())
+    return false;
   return Node.getASTContext().getSourceManager().isInSystemHeader(
       Node.getLocation());
 }

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp
index cb4eac84c6916..22dcd74b5c4fd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment.cpp
@@ -151,3 +151,8 @@ void test() {
   my_system_header_function(/*not_arg=*/1);
 }
 } // namespace system_header
+
+void testInvalidSlocCxxConstructExpr() {
+  __builtin_va_list __args;
+  // __builtin_va_list has no defination in any source file
+} 


        


More information about the cfe-commits mailing list