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).
This commit is contained in:
liuke 2021-10-13 12:29:36 -04:00 committed by Aaron Ballman
parent 24c9016574
commit ea72b55b5c
2 changed files with 7 additions and 0 deletions

View File

@ -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());
}

View File

@ -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
}