[PATCH] D107323: [clang-tidy] Add skip-headers; use skipLocation and setTraversalScope

2021-08-18 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 367331.
chh added a comment.

fix windows test failure


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107323/new/

https://reviews.llvm.org/D107323

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-pass-by-value/header.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-command-line-macros.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/google-upgrade-googletest-case.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-1.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/include/clang/Frontend/MultiplexConsumer.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocationFilter

2021-08-18 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 367330.
chh added a comment.

fix windows test failure


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-pass-by-value/header.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-command-line-macros.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/google-upgrade-googletest-case.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-1.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || 

[PATCH] D107323: [clang-tidy] Add skip-headers; use skipLocation and setTraversalScope

2021-08-18 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 367120.
chh edited the summary of this revision.
chh added a comment.

Factor out LocationFilter; improve more tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107323/new/

https://reviews.llvm.org/D107323

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-pass-by-value/header.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-command-line-macros.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/google-upgrade-googletest-case.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-1.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/include/clang/Frontend/MultiplexConsumer.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocationFilter

2021-08-18 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 367117.
chh retitled this revision from "[clang-tidy] New feature --skip-headers, part 
1, LocFilter" to "[clang-tidy] New feature --skip-headers, part 1, 
LocationFilter".
chh edited the summary of this revision.
chh added a comment.

Factor out LocationFilter; improve more test cases.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-pass-by-value/header.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-macro-usage-command-line-macros.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/google-upgrade-googletest-case.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-1.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 

[PATCH] D107323: [clang-tidy] Add skip-headers; use skipLocation and setTraversalScope

2021-08-02 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.
Herald added subscribers: kbarton, xazax.hun, nemanjai.
chh requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

[clang-tidy] Add skip-headers; use skipLocation and setTraversalScope

- This depends on https://reviews.llvm.org/D104071.
- This new feature has impacts similar to --header-filter and --system-headers.
  - Clang-tidy by default checks header files, reports the number of warnings 
found in header files but not those warning messages.
  - With --header-filter, clang-tidy shows warnings in selected header files, 
but not system header files.
  - With --system-headers, clang-tidy shows also warnings in system header 
files.
  - With --skip-headers, clang-tidy does not check header files, and does not 
know or count warnings in header files. However, if --header-filter or 
--system-headers are used, those header files will be checked and warnings be 
counted and displayed.
- For users who do not need to know the number of not-shown warnings in header 
files, this feature saves maybe 60% to 80% of clang-tidy run-time, by skipping 
checks of header files. When building Android system with clang-tidy, repeated 
checks on commonly included header files in multiple compilation units took 
significant part of build time, which could be saved by this new feature.
- Note that this is not the same as PCH, which usually saves parsing time, but 
not semantic checks or code generation time.
- This part 1 implementation only affects the MatchFinder-based checks, not the 
PPCallback-based or the static analyzer checks. Follow up changes could make 
the other checks to skip header files and save more time.
- Add a --show-all-warnings flag. It is hidden, not shown by --help. When it is 
used, ClangTidyDiagnosticConsumer::checkFilters will not suppress any 
diagnostic message. This is useful to find tidy checks that have not yet 
handled the --skip-headers flag.
- Implementation Methods:
  - Add a shared LocFilter to Tidy's MatchFinderOptions.
  - In MatchASTVisitor::TraverseDecl, skip a DeclNode if the MatchFinderOptions 
has a LocFilter that decides to skip the DeclNode location.
  - LocFilter::skipLocation checks if a location should not be checked.
  - Use simple cache of the last skipped/accepted FileID in LocFilter to 
minimize the overhead of skipLocation.
  - Add an AllFileFinder for checks that need to match all source files.
- ForwardDeclarationNamespaceCheck is registered as an AllFileCheck, to 
avoid missing valid warnings on main source files.
- UnusedUsingDeclsCheck is registered as an AllFileCheck, to avoid 
incorrect warnings on main source files.
- Their diag functions call ClangTidyCheck::skipLocation to skip 
diagnostics on header files.
  - Depending on new changes to set/getTraversalScope in 
https://reviews.llvm.org/D104071, the AST was modified to exclude header file 
top-level Decls during the call to MatchFinder's ASTConsumer's 
HandleTranslationUnit.
- AllFileFinder's and static analyzer's AST consumers are still called with 
the unmodified full AST.
- ClangTidyASTConsumer overrides two member functions of MultiplexConsumer 
and accesses the Consumers data member.
  - in HandleTopLevelDecl to collect filtered Decls.
  - in HandleTranslationUnit to call get/setTraversalScope before calling 
the Finder ASTConcumser, which calls matchAST.
- Tests:
  - Add skip-headers*.cpp tests to show the effects of new flags.
  - Add bugprone-forward-declaration-namespace-header.cpp test to show how 
AllFileMatchFinder-based checks can depend on header Decls.
  - Add new test cases into misc-unused-using-decls.cpp.
  - Extend some clang-tidy checker tests to make sure that --skip-headers skips 
checks/warnings in the header files: google-namespaces.cpp 
modernize-pass-by-value-header.cpp
  - Add runs with --skip-headers in some clang-tidy checker tests to make sure 
that the option does not hide warnings in the main file:
- about 18 other clang-tools-extra/test/clang-tidy/checkers/*.cpp
  - Some tests were added --skip-headers=0 flag to get expected warning 
messages in test header files: checkers/abseil-no-internal-dependencies.cpp 
checkers/abseil-upgrade-duration-conversions.cpp checkers/google-namespaces.cpp 
infrastructure/file-filter-symlinks.cpp infrastructure/file-filter.cpp 
infrastructure/line-filter.cpp


https://reviews.llvm.org/D107323

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocFilter

2021-07-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

This is enhanced implementation over D98710 , 
to handle the new found failed test cases.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 362704.
chh added a comment.

sync to the latest source; apply clang-format; add new skip-headers-4.cpp test


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocFilter

2021-07-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 362702.
chh added a comment.

sync to the latest source; apply clang-format; add new skip-headers-4.cpp test;
skip modernize-use-nullptr warnings in header files in UseNullptrCheck.cpp


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-4.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1232,6 +1234,13 @@
   if (!StmtNode) {
 return true;
   }
+  // When a function call is in the main file or wanted header 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocFilter

2021-07-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 362262.
chh added a comment.

apply clang-format


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1232,6 +1234,13 @@
   if (!StmtNode) {
 return true;
   }
+  // When a function call is in the main file or wanted header files,
+  // the call site maybe in the Decl that is not to be skipped.
+  // But the statements of the called function or parameter default expressions
+  // should be skipped. So here we need to call skipLocation here.
+  if (Options.Filter && Options.Filter->skipLocation(StmtNode->getBeginLoc()))
+return true;
+
   bool 

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 362239.
chh edited the summary of this revision.
chh added a comment.

Add new test cases into misc-unused-using-decls.cpp.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocFilter

2021-07-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 362216.
chh edited the summary of this revision.
chh added a comment.

- Use clang-format layout in ClangTidy.cpp and ClangTidyModule.h.
- Fix misc-unused-using-decls false-positive warning from --skip-headers.
  - UnusedUsingDeclsCheck is now registered as an AllFileCheck.
  - Add new test cases into misc-unused-using-decls.cpp.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/unused-using-decls.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1232,6 +1234,13 @@
   if (!StmtNode) {
 return true;
   }
+  // When a function call is in the main file or wanted header files,
+  // the call site maybe in the Decl 

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-26 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 361871.
chh added a comment.

add skip-headers-3.cpp test to show that checking only Decl locations is not 
enough to skip some warnings in header files


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
 
 #include "header1.h"
 // CHECK-NOT: header1.h:{{.*}} warning
Index: 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocFilter

2021-07-26 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 361870.
chh added a comment.

add skip-headers-3.cpp test to show that checking only Decl locations is not 
enough to skip some warnings in header files


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/c1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-3.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1232,6 +1234,13 @@
   if (!StmtNode) {
 return true;
   }
+  // When a function call is in the main file or wanted header files,
+  // the call site maybe in the Decl that is not to be skipped.
+  // But the statements of the called function or parameter default expressions
+  // should be skipped. So here we need to call skipLocation here.
+  if (Options.Filter && Options.Filter->skipLocation(StmtNode->getBeginLoc()))
+return true;
+
   bool ScopedTraversal = TraversingASTNodeNotSpelledInSource ||
  TraversingASTChildrenNotSpelledInSource;
 
@@ -1454,5 +1463,7 @@
   return 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, LocFilter

2021-07-23 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 361295.
chh retitled this revision from "[clang-tidy] New feature --skip-headers, part 
1, skip Decls" to "[clang-tidy] New feature --skip-headers, part 1, LocFilter".
chh edited the summary of this revision.
chh added a comment.

Add an AllFileFinder for checks that need to match all source files.
ForwardDeclarationNamespaceCheck is registered as an AllFileCheck,


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipLocation(DeclNode->getLocation()))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,7 @@
   return llvm::None;
 }
 
+MatchFinder::MatchFinderOptions::LocFilter::~LocFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,18 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct LocFilter {
+  

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-22 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Some Android developers and legacy code care less about clang-tidy warnings.
Newer developers spend a lot of time to get lint-free new code.
So Android source tree has a lot of clang-tidy flags like
header-filter, checks, and warnings-as-errors to select checks
for different modules. People are even asking for new features like
making header-filter to accept a list of regexp like the checks flag.

If a new change to header-filter or skip-headers lose existing valid warnings,
maybe it will be perfectly acceptable to some but not to people who want to
make code lint-free. To them, these changes are regressions.
A clang-tidy check's owner would not like to lose capability for
some minor performance gain, either.

bugprone-forward-declaration-namespace is just one valid warning found
in a couple of days. Android tree is huge and has disabled many checks,
so we won't know the impact to all checks any time soon. 
If we have a mechanism to keep any special checks from the impact,
like the PPCallback-based checks, it will be much safer to release 
the first phase skip-headers and know that we can fix any bad impact quickly.

I am trying such a mechanism to support "see-all-file" MatchFinder-based checks.
Those checks will be very few, so skip-headers still saves a lot of runtime.
After more tests, I will upload it to D98709 .

Please note that I added a new test skip-headers-2.cpp.
It is extremely simplified, but reflects the need to check a top-level
Decl and ignore warnings in included nested Decls in other files.
If we implement skip-headers based on only top-level Decls,
we won't be able to support such a use case.
In D98709 , we check/skip not only top-level 
Decls.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106516: to run test only

2021-07-21 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 360688.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106516/new/

https://reviews.llvm.org/D106516

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/include/clang/Frontend/MultiplexConsumer.h


Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -10,6 +10,8 @@
 //  multiplex ASTConsumer and SemaConsumer messages to many consumers.
 //
 
//===--===//
+//
+// To run all tests.
 
 #ifndef LLVM_CLANG_FRONTEND_MULTIPLEXCONSUMER_H
 #define LLVM_CLANG_FRONTEND_MULTIPLEXCONSUMER_H
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -37,6 +37,8 @@
 //
 
//===--===//
 
+// To run all tests.
+//
 #ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
 #define LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
 
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -14,6 +14,8 @@
 ///
 
//===--===//
 
+// Check with latest clang/llvm tests.
+
 #include "ClangTidy.h"
 #include "ClangTidyCheck.h"
 #include "ClangTidyDiagnosticConsumer.h"


Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -10,6 +10,8 @@
 //  multiplex ASTConsumer and SemaConsumer messages to many consumers.
 //
 //===--===//
+//
+// To run all tests.
 
 #ifndef LLVM_CLANG_FRONTEND_MULTIPLEXCONSUMER_H
 #define LLVM_CLANG_FRONTEND_MULTIPLEXCONSUMER_H
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -37,6 +37,8 @@
 //
 //===--===//
 
+// To run all tests.
+//
 #ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
 #define LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
 
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -14,6 +14,8 @@
 ///
 //===--===//
 
+// Check with latest clang/llvm tests.
+
 #include "ClangTidy.h"
 #include "ClangTidyCheck.h"
 #include "ClangTidyDiagnosticConsumer.h"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106516: to run test only

2021-07-21 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.
chh requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

DO NOT SUBMIT.
Only to run tests.


https://reviews.llvm.org/D106516

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp


Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -14,6 +14,8 @@
 ///
 
//===--===//
 
+// Check with latest clang/llvm tests.
+
 #include "ClangTidy.h"
 #include "ClangTidyCheck.h"
 #include "ClangTidyDiagnosticConsumer.h"


Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -14,6 +14,8 @@
 ///
 //===--===//
 
+// Check with latest clang/llvm tests.
+
 #include "ClangTidy.h"
 #include "ClangTidyCheck.h"
 #include "ClangTidyDiagnosticConsumer.h"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-21 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 360651.
chh edited the summary of this revision.
chh added a comment.

Add one more skip-headers-2.cpp test, which shows desired check at a top-level 
Decl but not at nested Decl. Checking locations of only top-level Decls will 
miss the opportunity to skip nested Decls.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
 
 #include "header1.h"
 // CHECK-NOT: header1.h:{{.*}} warning
Index: 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, skip Decls

2021-07-21 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 360649.
chh edited the summary of this revision.
chh added a comment.

Add one more skip-headers-2.cpp test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/a.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers-2.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipDecl(DeclNode))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,8 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,19 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct DeclFilter {
+  virtual bool skipDecl(const Decl *) = 0;
+  virtual bool skipLocation(SourceLocation) = 0;
+  virtual ~DeclFilter();
+};
 
 /// Enables per-check timers.
 ///
 /// It prints a report after match.
 llvm::Optional CheckProfiling;
+
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- 

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-20 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 360339.
chh edited the summary of this revision.
chh added a comment.

Add bugprone-forward-declaration-namespace-header.cpp test to
show that MatchFinder-based checks can also depend on header Decls.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
 
 #include "header1.h"
 // CHECK-NOT: header1.h:{{.*}} warning
Index: clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
@@ -1,14 +1,14 @@
-// RUN: clang-tidy 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, skip Decls

2021-07-20 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 360336.
chh edited the summary of this revision.
chh added a comment.

Add bugprone-forward-declaration-namespace-header.cpp test; fix some coding 
style warnings.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/bugprone-forward-declaration-namespace/b.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipDecl(DeclNode))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,8 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,19 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct DeclFilter {
+  virtual bool skipDecl(const Decl *) = 0;
+  virtual bool skipLocation(SourceLocation) = 0;
+  virtual ~DeclFilter();
+};
 
 /// Enables per-check timers.
 ///
 /// It prints a report after match.
 llvm::Optional CheckProfiling;
+
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy 

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-19 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Sam,

The latest tested change contained one of your suggestions:

  using setTraversalScope for all consumers in the
  ClangTidyASTConsumer::HandleTranslationUnit

It is good to pass all existing tests,
although not a proof of correctness yet.

The failed libarcher.* tests have been there for days.
We can be sure that those are unrelated to this change.

We still have some different views of the purpose and requirements of
these new flags, skip-headers and show-all-warnings. That's why it is
important to describe them correctly in the summary.
We can try to include more use cases or applications now or later,
however, the following has been our requirement for a successful story
for the first Android deployment:

  --skip-headers should work correctly, even if not at optimal speed.
  
  Correctness means no more or fewer "displayed" warnings with or without
  this flag, although it could report fewer "suppressed" header file warnings.

For desired performance gain, experiment data showed that it is more than
enough to get savings from only MatchFinder-based checks.

We are less critical on "implementation" methods, code complexity, or 
efficiency.
Using set/getTraversalScope or not, cutting Decls in advance or on the fly,
cutting only top-level Decls or all Decls at any level, are all acceptable
alternatives if they produce the same "displayed" warnings as before.

Please also take a look of https://reviews.llvm.org/D98709,
which skips Decls at all levels on-the-fly.
That is a different implementation with 50% less changes in ClangTidy.cpp
than this one. The changes in other files are identical or tiny.
It is a little slower, but D98709  is smaller 
and simpler to maintain,
and it limits the impact to only MatchFinder, not static analyzer.

Now the bad news is that when tested against the whole Android source, 
I found failed cases, which are missing clang-tidy warning messages
by both implementations.

The missed warnings were bugprone-forward-declaration-namespace.
There could be other misses undetected.
According to bugprone/ForwardDeclarationNamespaceCheck.cpp,
it's a MatchFinder-based check that can report warning on
Decl in the main file, but the check needs Decls in an
included file. For this kind of checks, skipping their
matchers for Decls in header files is wrong.
This is similar to what we found before that some checks
need the root TranslationUnit node in AST, so we have to
change set/getTraversalScope to keep the root node.

Now we realized that we cannot simply skip or cut out Decls
of headers files for ALL MatchFinder-based checks. Some checks
or some of their matchers need to see ALL Decls in ALL source files.

I will try to update this D98710  and D98709 
 with new test cases
to show the failed bugprone-forward-declaration-namespace checks.
Then, I will try some implementation changes to work also for
those tidy checks.  The implementation probably won't be as simple
as this one to cut all top-level header file Decls for all checks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, setTraversalScope

2021-07-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 359532.
chh retitled this revision from "[clang-tidy] New feature --skip-headers, part 
1, (tested as default)" to "[clang-tidy] New feature --skip-headers, part 1, 
setTraversalScope".
chh edited the summary of this revision.
chh added a comment.

--skip-headers is set to false by default;
many tidy tests runs are augmented with explicit --skip-headers or 
--skip-headers=0
to test this feature as on or off.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
 
 #include "header1.h"
 // CHECK-NOT: header1.h:{{.*}} warning
Index: clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
@@ -1,14 +1,14 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, part 1, skip Decls

2021-07-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 359531.
chh retitled this revision from "[clang-tidy] New feature --skip-headers, 
(tested as default)" to "[clang-tidy] New feature --skip-headers, part 1, skip 
Decls".
chh edited the summary of this revision.
chh added a comment.

--skip-headers is set to false by default;
many tidy tests runs are augmented with explicit --skip-headers or 
--skip-headers=0
to test this feature as on or off.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipDecl(DeclNode))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,8 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,19 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct DeclFilter {
+  virtual bool skipDecl(Decl *) = 0;
+  virtual bool skipLocation(SourceLocation) = 0;
+  virtual ~DeclFilter();
+};
 
 /// Enables per-check timers.
 ///
 /// It prints a report after match.
 llvm::Optional CheckProfiling;
+
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1, (tested as default)

2021-07-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 359506.
chh retitled this revision from "[clang-tidy] New feature --skip-headers, part 
1" to "[clang-tidy] New feature --skip-headers, part 1, (tested as default)".
chh edited the summary of this revision.
chh added a comment.

to test skip-headers as default, do not submit;
show that setTraversalScope failed some static analyzer checks,
see #if 0 comments in ClangTidy.cpp.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
 
 #include "header1.h"
 // CHECK-NOT: header1.h:{{.*}} warning
Index: clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
@@ -1,14 +1,14 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter -isystem 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, (tested as default)

2021-07-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 359461.
chh edited the summary of this revision.
chh added a comment.

only coding style changes in clang-tidy files, to match other alternative 
implementation


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipDecl(DeclNode))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,8 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,19 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct DeclFilter {
+  virtual bool skipDecl(Decl *) = 0;
+  virtual bool skipLocation(SourceLocation) = 0;
+  virtual ~DeclFilter();
+};
 
 /// Enables per-check timers.
 ///
 /// It prints a report after match.
 llvm::Optional CheckProfiling;
+
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"line-filter.cpp","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy --skip-headers=0 

[PATCH] D98709: [clang-tidy] New feature --skip-headers, (tested as default)

2021-07-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 359271.
chh retitled this revision from "[clang-tidy] Add --skip-headers, part 1" to 
"[clang-tidy] New feature --skip-headers, (tested as default)".
chh edited the summary of this revision.
chh added a comment.

sync with latest source, update more tests to test skip-headers as default


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipDecl(DeclNode))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,8 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,19 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct DeclFilter {
+  virtual bool skipDecl(Decl *) = 0;
+  virtual bool skipLocation(SourceLocation) = 0;
+  virtual ~DeclFilter();
+};
 
 /// Enables per-check timers.
 ///
 /// It prints a report after match.
 llvm::Optional CheckProfiling;
+
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
Index: clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 

[PATCH] D98710: [clang-tidy] New feature --skip-headers, part 1

2021-07-13 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Sam, the revision summary is updated. Could you review it again?

The new summary would clarify a few points:

- This --skip-headers is a new feature, not just a transparent run-time saving. 
It should be used carefully with header-filter and system-headers, and 
similarly handled in IO.mapOptional.
- It's not PCH.
- It uses set/getTraversalScope as an implementation method, but the goal of 
skip-headers is not to limit clang-tidy to see only non-header Decls.
- Improvements on PPCallback-based and static analyzer checks could be in 
follow up changes. The gain might not be as large as the MatchFinder-based 
checks and the implementation could be more complicated than using 
set/getTraversalScope.

I am glad that with your help on set/getTraversalScope, 
many part of this revision has become much simpler.
I am looking forward to applying this new feature, even with only part 1, 
to save very significant Android build time, but I am also extremely cautious
not to combine many risky changes into one big revision.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:310
+struct DeclFilter {
+  DeclFilter(ClangTidyContext , SourceManager )
+  : Context(Ctx), Sources(SM) {

sammccall wrote:
> Ctx is ultimately unused, just take the regex instead?
Context is used in skipFileID.




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:514
+  for (auto  : Consumers) {
+if (hasFilter() && Consumer.get() == FinderASTConsumerPtr) {
+  // Modify AST before calling the Finder's ASTConsumer.

sammccall wrote:
> This adds significant conceptual complexity and possible runtime costs to 
> guard against the possibility that the static analyzer would not be 
> compatible with simply setting the traversal scope.
> 
> Please do not do this. It may appear that you're cheaply eliminating a class 
> of bugs, but complexity is not cheap, and in the long run can also introduce 
> bugs. Instead investigate whether this is a real problem and why.
> 
> If it's not then `Context.setTraversalScope()` + 
> `MultiplexingASTConsumer::HandleTranslationUnit` is enough here, and 
> `FinderASTConsumerPtr` can go away.
For this first step implementation of skip-headers, could we limit the risk and 
impact to only AST MatchFinder based checks? If it works fine, we can add more 
performance improvements, handle PPCallback-based checks, and static analyzer 
checks. We can turn skip-headers to default or revert any follow up step.

At this time, we only know that PPCallback-based checks can save some more time 
with skip-headers, but do not know if any static analyzer check can benefit 
from skip-headers easily. In other words, we are sure to deliver big saving of 
runtime for clang-tidy users that do not enable static analyzer checks, but not 
sure about static analyzer check users.

The overhead and complexity of set/getTraversalScope and checking filters will 
be on the users of skip-header, but not on the static analyzer checkers.

If we apply the same change to AST for all consumers, the saving of code 
complexity is smaller than the risk of impact to static analyzer checks, and 
the saving of runtime is also much smaller than the already saved time in 
MatchFinder.




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:473
+MatchFinder::matchAST(Context);
+Context.setTraversalScope(SavedScope);
+  } else {

sammccall wrote:
> chh wrote:
> > sammccall wrote:
> > > Is restoring the traversal scope strictly needed by the static analyzer? 
> > > I would expect not, but I might be wrong.
> > I think it is safer to assume low or acceptable overhead in 
> > get/setTraversalScope and keep the impact only to the MatchFinder consumer, 
> > rather than depending on static analyzer working now or in the future with 
> > the changed AST.
> > 
> > I think it is safer to assume low or acceptable overhead in 
> > get/setTraversalScope
> We have reasons to believe this is not cheap. The first usage of getParent() 
> after changing traversal scope incurs a full AST traversal.
> 
> > rather than depending on static analyzer working now or in the future with 
> > the changed AST.
> 
> There are a fairly small number of reasons that setTraversalScope could break 
> static analyzer at this point, and I think they're all going to cause the 
> static analyzer to be slow when used with PCHes. However the static 
> analyzer's implementation and comments say that it goes to effort to be fast 
> with PCHes. So I do believe this is a more stable assumption, and in the long 
> run we may be able to simplify its implementation.
Okay, won't assume low overhead in set/getTraversalScope.
So far their impact is limited to skip-headers, which in this step is limited 
to only MatchFinder. Please see also my reply in the other comment.




Comment at: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp:99
 IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
 IO.mapOptional("UseColor", Options.UseColor);
   }

sammccall wrote:
> Maybe an explicit comment that ShowAllHeaders, SkipHeaders are 
> runtime/optimization options that are configured at the command-line only, 
> and therefore not mapped here
Why SystemHeaders is not mapped?
I agree that ShowAllWarnings is not important here,
but SkipHeaders seems as important to be included here as HeaderFilterRegex and 
SystemHeaders.




Comment at: clang-tools-extra/clang-tidy/ClangTidyOptions.h:84
+  /// and system files when --system-headers is used.
+  llvm::Optional SkipHeaders;
+

sammccall wrote:
> This is easy to confuse with e.g. HeaderFilterRegex and SystemHeaders, which 
> control policy rather than just implementation strategy.
> I'd suggest calling this something like `PruneTraversal` which hints at the 
> implementation strategy it controls but most importantly that it's *not* 
> about whether 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 357824.
chh marked 7 inline comments as done.
chh added a comment.

sync up latest clang/llvm source; more format/style changes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:no_hint -implicit-check-not="{{warning|error}}:"
+//
+// --show-all-warnings reports all warnings, even without --header-filters
+// RUN: clang-tidy %s -checks='*' --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='.*' is like --show-all-warnings
+// RUN: clang-tidy %s -checks='*' --header-filter='.*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='header1.h' shows only warnings in header1.h
+// RUN: clang-tidy %s -checks='*' --header-filter='header1.h' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN1,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// The main purpose of --show-all-warnings is to debug --skip-headers.
+// When used together, no warnings should be reported from header files.
+// RUN: clang-tidy %s -checks='*' --skip-headers --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,NO_HINT
+// later:  -implicit-check-not="{{warning|error}}:"
+//
+// use --skip-headers and --header-filter='header2.h'
+// 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-05 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 356589.
chh edited the summary of this revision.
chh added a comment.

No more change to or derivation from MatchFinder, but override two member 
functions in MultiplexConsumer.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/Frontend/MultiplexConsumer.h

Index: clang/include/clang/Frontend/MultiplexConsumer.h
===
--- clang/include/clang/Frontend/MultiplexConsumer.h
+++ clang/include/clang/Frontend/MultiplexConsumer.h
@@ -77,8 +77,9 @@
   void InitializeSema(Sema ) override;
   void ForgetSema() override;
 
-private:
+protected:
   std::vector> Consumers; // Owns these.
+private:
   std::unique_ptr MutationListener;
   std::unique_ptr DeserializationListener;
 };
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:no_hint -implicit-check-not="{{warning|error}}:"
+//
+// --show-all-warnings reports all warnings, even without --header-filters
+// RUN: clang-tidy %s -checks='*' --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='.*' is like --show-all-warnings
+// RUN: clang-tidy %s -checks='*' --header-filter='.*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='header1.h' shows only warnings in header1.h
+// RUN: clang-tidy %s -checks='*' --header-filter='header1.h' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN1,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// The main purpose of --show-all-warnings is to debug --skip-headers.
+// When used together, no warnings should be reported from header files.
+// RUN: clang-tidy %s -checks='*' --skip-headers --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,NO_HINT
+// later:  -implicit-check-not="{{warning|error}}:"
+//
+// use 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-02 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 356321.
chh added a comment.

fix clang-format coding style issue


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h

Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -141,7 +141,7 @@
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
 
   /// Adds a matcher to execute when running over the AST.
   ///
@@ -196,7 +196,7 @@
   /// @}
 
   /// Finds all matches in the given AST.
-  void matchAST(ASTContext );
+  virtual void matchAST(ASTContext );
 
   /// Registers a callback to notify the end of parsing.
   ///
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:no_hint -implicit-check-not="{{warning|error}}:"
+//
+// --show-all-warnings reports all warnings, even without --header-filters
+// RUN: clang-tidy %s -checks='*' --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='.*' is like --show-all-warnings
+// RUN: clang-tidy %s -checks='*' --header-filter='.*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='header1.h' shows only warnings in header1.h
+// RUN: clang-tidy %s -checks='*' --header-filter='header1.h' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN1,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// The main purpose of --show-all-warnings is to debug --skip-headers.
+// When used together, no warnings should be reported from header files.
+// RUN: clang-tidy %s -checks='*' --skip-headers --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,NO_HINT
+// 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-02 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 356319.
chh marked an inline comment as done.
chh added a comment.

fix clang-format name style issue


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h

Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -141,7 +141,7 @@
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
 
   /// Adds a matcher to execute when running over the AST.
   ///
@@ -196,7 +196,7 @@
   /// @}
 
   /// Finds all matches in the given AST.
-  void matchAST(ASTContext );
+  virtual void matchAST(ASTContext );
 
   /// Registers a callback to notify the end of parsing.
   ///
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:no_hint -implicit-check-not="{{warning|error}}:"
+//
+// --show-all-warnings reports all warnings, even without --header-filters
+// RUN: clang-tidy %s -checks='*' --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='.*' is like --show-all-warnings
+// RUN: clang-tidy %s -checks='*' --header-filter='.*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='header1.h' shows only warnings in header1.h
+// RUN: clang-tidy %s -checks='*' --header-filter='header1.h' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN1,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// The main purpose of --show-all-warnings is to debug --skip-headers.
+// When used together, no warnings should be reported from header files.
+// RUN: clang-tidy %s -checks='*' --skip-headers --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-02 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh marked an inline comment as done and an inline comment as not done.
chh added a comment.

Last build tests were green. Let's see if the new updated diff still passes all 
the tests.

Looks like all choices have some risk/overhead in future maintenance and we 
need to pick one with the least cost.
I think cloning classes is most expensive and risky to keep future 
compatibility.
Adding a new subclass or optional members into existing class are more 
conventional solutions.




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:473
+MatchFinder::matchAST(Context);
+Context.setTraversalScope(SavedScope);
+  } else {

sammccall wrote:
> Is restoring the traversal scope strictly needed by the static analyzer? I 
> would expect not, but I might be wrong.
I think it is safer to assume low or acceptable overhead in 
get/setTraversalScope and keep the impact only to the MatchFinder consumer, 
rather than depending on static analyzer working now or in the future with the 
changed AST.




Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:144
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
+

sammccall wrote:
> Matchfinder specifically says "not intended to be subclassed".
Do you know the reason it cannot have subclass?
All our current implementation choices need to change its matchAST behavior, 
either by overriding it, or changing the AST before it, or skip Decl in the 
recursive walk of AST.
For any reason not to have subclass, changing AST outside matchAST seems 
riskier than changing inside matchAST in a child class.




Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:147
+  /// Inside a MatchASTConsumer, handles all top level Decl.
+  virtual bool HandleTopLevelDecl(DeclGroupRef DG);
 

sammccall wrote:
> This function doesn't make sense at this layer - calling it does nothing and 
> the class is intended to be used directly, not to be subclassed. And 
> MatchFinder itself doesn't "consume" top-level decls - that's an ASTConsumer 
> concern.
> 
> I understand you use it here as a hook to listen for decls seen by the 
> MatchFinder::newASTConsumer().
> Better would be to pass a HandleTopLevelDecl callback to newASTConsumer() 
> instead.
> But given that MatchFinderASTConsumer is completely trivial and can be built 
> on the public MatchFinder API, better still would just be to reimplement it 
> with the unusual functionality ClangTidy needs.
Please review the updated diff. Now HandleTopLevelDecl is all in clang-tidy.
For both the MultiplexConsumer and MatchFinder, I think it is more feasible to 
resolve all subclass issues now and maintain the inheritance relation than 
making clone implementations and trying to maintain the same behavior in the 
future.



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-02 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 356307.
chh marked an inline comment as done.
chh edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h

Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -141,7 +141,7 @@
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
 
   /// Adds a matcher to execute when running over the AST.
   ///
@@ -196,7 +196,7 @@
   /// @}
 
   /// Finds all matches in the given AST.
-  void matchAST(ASTContext );
+  virtual void matchAST(ASTContext );
 
   /// Registers a callback to notify the end of parsing.
   ///
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:no_hint -implicit-check-not="{{warning|error}}:"
+//
+// --show-all-warnings reports all warnings, even without --header-filters
+// RUN: clang-tidy %s -checks='*' --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='.*' is like --show-all-warnings
+// RUN: clang-tidy %s -checks='*' --header-filter='.*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN_BOTH,MAIN,NO_HINT
+//
+// --header-filter='header1.h' shows only warnings in header1.h
+// RUN: clang-tidy %s -checks='*' --header-filter='header1.h' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,WARN1,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// The main purpose of --show-all-warnings is to debug --skip-headers.
+// When used together, no warnings should be reported from header files.
+// RUN: clang-tidy %s -checks='*' --skip-headers --show-all-warnings -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-07-01 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 355827.
chh added a comment.

with clang-format suggested change


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1306,6 +1306,10 @@
MatchFinder::ParsingDoneTestCallback *ParsingDone)
   : Finder(Finder), ParsingDone(ParsingDone) {}
 
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+return Finder->HandleTopLevelDecl(DG);
+  }
+
 private:
   void HandleTranslationUnit(ASTContext ) override {
 if (ParsingDone != nullptr) {
@@ -1434,6 +1438,8 @@
   Visitor.match(Node);
 }
 
+bool MatchFinder::HandleTopLevelDecl(DeclGroupRef) { return true; }
+
 void MatchFinder::matchAST(ASTContext ) {
   internal::MatchASTVisitor Visitor(, Options);
   Visitor.set_active_ast_context();
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -141,7 +141,10 @@
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
+
+  /// Inside a MatchASTConsumer, handles all top level Decl.
+  virtual bool HandleTopLevelDecl(DeclGroupRef DG);
 
   /// Adds a matcher to execute when running over the AST.
   ///
@@ -196,7 +199,7 @@
   /// @}
 
   /// Finds all matches in the given AST.
-  void matchAST(ASTContext );
+  virtual void matchAST(ASTContext );
 
   /// Registers a callback to notify the end of parsing.
   ///
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:no_hint 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-30 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

I reproduced the ClangdTests::TargetDeclTest.Concept failure locally without 
this change,
using llvm git commit 0c400e8953 
. Will 
wait for upstream fix of the failed tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-30 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 355699.
chh edited the summary of this revision.
chh added a comment.

Move almost all changes to MatchFinder into ClangTidy.cpp.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1306,6 +1306,10 @@
MatchFinder::ParsingDoneTestCallback *ParsingDone)
   : Finder(Finder), ParsingDone(ParsingDone) {}
 
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+return Finder->HandleTopLevelDecl(DG);
+  }
+
 private:
   void HandleTranslationUnit(ASTContext ) override {
 if (ParsingDone != nullptr) {
@@ -1434,6 +1438,10 @@
   Visitor.match(Node);
 }
 
+bool MatchFinder::HandleTopLevelDecl(DeclGroupRef) {
+  return true;
+}
+
 void MatchFinder::matchAST(ASTContext ) {
   internal::MatchASTVisitor Visitor(, Options);
   Visitor.set_active_ast_context();
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -141,7 +141,10 @@
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
-  ~MatchFinder();
+  virtual ~MatchFinder();
+
+  /// Inside a MatchASTConsumer, handles all top level Decl.
+  virtual bool HandleTopLevelDecl(DeclGroupRef DG);
 
   /// Adds a matcher to execute when running over the AST.
   ///
@@ -196,7 +199,7 @@
   /// @}
 
   /// Finds all matches in the given AST.
-  void matchAST(ASTContext );
+  virtual void matchAST(ASTContext );
 
   /// Registers a callback to notify the end of parsing.
   ///
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy %s -checks='*' --skip-headers -- \
+// RUN: 2>&1 | FileCheck %s 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:431
+bool DeclFilter::skipLocation(SourceLocation Location) {
+  // do not skip non-file locations
+  if (!Location.isValid())

sammccall wrote:
> this comment didn't match the next line.
> Did you intend to check Location.isFile() instead?
I just wanted to make sure that we can get valid FileID.
Updated the comment.





Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:434
+return false;
+  auto FID = Sources.getDecomposedExpansionLoc(Location).first;
+  // Quick check against last checked results.

sammccall wrote:
> sammccall wrote:
> > maybe add a comment explaning why the expansion loc is chosen?
> note that this means we're going to traverse up the macro expansion edges 
> even if we're hitting the cache. You may want to cache under the original 
> file ID instead?
This is to match the ClangTidyDiagnosticConsumer::checkFilters.
Do you think some other get*Location method should be used in both places?




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:434
+return false;
+  auto FID = Sources.getDecomposedExpansionLoc(Location).first;
+  // Quick check against last checked results.

chh wrote:
> sammccall wrote:
> > sammccall wrote:
> > > maybe add a comment explaning why the expansion loc is chosen?
> > note that this means we're going to traverse up the macro expansion edges 
> > even if we're hitting the cache. You may want to cache under the original 
> > file ID instead?
> This is to match the ClangTidyDiagnosticConsumer::checkFilters.
> Do you think some other get*Location method should be used in both places?
> 
I would rather explore various cache performance improvements in follow up CLs.
In my performance tests, current simple check of LastAcceptedFileID and 
LastSkippedFileID already has very high hit rate due to sequential check of 
Decls in the included header files. More caching improvements should produce 
relatively smaller difference, which will be shown/visible easier in their own 
small change CLs.




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:436
+  // Quick check against last checked results.
+  if (FID == LastSkippedFileID)
+return true;

sammccall wrote:
> caching all results in a DenseMap seems likely to perform 
> better, no?
I am sure most calls hit the last FileID. For the missed calls, I was planning 
to add other caching mechanism in skipFileID function. That could be in follow 
up CLs with more accurate measurements to compare the overhead vs hit rate.




Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:148
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };

sammccall wrote:
> hokein wrote:
> > chh wrote:
> > > sammccall wrote:
> > > > I don't think the filter belongs here.
> > > > The design of traversal scope is that it's a property of the AST that 
> > > > affects all traversals, so it shouldn't be a configuration property of 
> > > > particular traversals like ASTMatchFinder.
> > > > 
> > > > There's a question of what to do about `MatchFinder::newASTConsumer()`, 
> > > > which runs the finder immediately after an AST is created, and so 
> > > > covers the point at which we might set a scope. There are several good 
> > > > options, e.g.:
> > > >  - Don't provide any facility for setting traversal scope when 
> > > > newASTConsumer() is used - it's not commonly needed, and the 
> > > > ASTConsumer is trivial to reimplement where that's actually needed
> > > >  - Accept an optional `function` which should run 
> > > > just before matching starts
> > > > 
> > > > This seems a bit subtle, but the difference between having this in 
> > > > MatchFinder proper vs just in newASTConsumer() is important I think, 
> > > > precisely because it's common to run the matchers directly on an 
> > > > existing AST.
> > > > 
> > > I have some similar concerns too.
> > > 
> > > clangd calls MatchFinder::matchAST explicitly after setTraversalScope,
> > > but clang-tidy uses MultiplexConsumer and MatchFinder::newASTConsumer
> > > is just one of the two consumers.
> > > (1) I am not sure if it would be safe or even work to make big changes in
> > > ClangTidy.cpp's CreateASTConsumer to call MatchFinder::matchAST 
> > > explicitly.
> > > (2) Similarly, I wonder if setTraversalScope will work for both 
> > > MatchFinder
> > > and other consumers in the same MultiplexConsumer.
> > > 
> > > Could you check if my current change to MatchFinder::HandleTranslationUnit
> > > is right, especially in the saving/restoring of traversal scope?
> > > 
> > > I am assuming that each consumer in a MultiplexConsumer will have its own
> > > chance to HandleTranslationUnit and HandleTopLevelDecl.
> > > If that's correct, it seems to me that changing those two handlers in
> > > MatchFinder is 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 354737.
chh marked 7 inline comments as done.
chh added a comment.

update some comments and sync again with the latest clang/llvm source


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1306,12 +1306,25 @@
MatchFinder::ParsingDoneTestCallback *ParsingDone)
   : Finder(Finder), ParsingDone(ParsingDone) {}
 
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+Finder->HandleTopLevelDecl(DG);
+return true;
+  }
+
 private:
   void HandleTranslationUnit(ASTContext ) override {
 if (ParsingDone != nullptr) {
   ParsingDone->run();
 }
-Finder->matchAST(Context);
+if (Finder->hasFilter()) {
+  auto SavedScope = Context.getTraversalScope();
+  auto  = Finder->getTraversalScope();
+  Context.setTraversalScope(MyTopDecls);
+  Finder->matchAST(Context);
+  Context.setTraversalScope(SavedScope);
+} else {
+  Finder->matchAST(Context);
+}
   }
 
   MatchFinder *Finder;
@@ -1454,5 +1467,44 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
+template 
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  if (const auto *TD = dyn_cast(D))
+return TD->getTemplateSpecializationKind() == Kind;
+  return false;
+}
+
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  return isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind);
+}
+
+bool isImplicitTemplateInstantiation(const NamedDecl *D) {
+  return isTemplateSpecializationKind(D, TSK_ImplicitInstantiation);
+}
+
+void MatchFinder::HandleTopLevelDecl(DeclGroupRef DG) {
+  if (hasFilter()) {
+for (Decl *D : DG) {
+  if (const NamedDecl *ND = dyn_cast(D))
+if (isImplicitTemplateInstantiation(ND))
+  continue;
+
+  // ObjCMethodDecl are not actually top-level decls.
+  if (isa(D))
+continue;
+
+  if (!Options.Filter->skipDecl(D))
+TopLevelDecls.push_back(D);
+}
+  }
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-20 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.h:31
+
+struct DeclFilter : public OptionsDeclFilter {
+  DeclFilter(ClangTidyContext , SourceManager )

sammccall wrote:
> The layering in clang-tidy is... not particularly great or clear, but there 
> is a distinction between driver-y type code (the clang-tidy application) vs 
> the checks themselves.
> 
> As I understand our plan, this filter is "just" a way to configure the 
> traversal scope before running, i.e. what information the AST will expose to 
> the checks.
> That is, this is a driver concern and should not be visible to the checks - 
> probably should go in `ClangTidy.h` or even just `ClangTidy.cpp` as part of 
> the `ClangTidyASTConsumer`. My litmus test here is that we do have other 
> drivers (at least clangd that I know of), and they shouldn't be 
> seeing/reusing this mechanism, and so neither should checks.
> 
> (Similarly if we do something with PP in the future, hopefully this can 
> *also* be transparent to checks)
> 
> 
Thanks. Moved this class to ClangTidy.cpp.




Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:148
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };

sammccall wrote:
> I don't think the filter belongs here.
> The design of traversal scope is that it's a property of the AST that affects 
> all traversals, so it shouldn't be a configuration property of particular 
> traversals like ASTMatchFinder.
> 
> There's a question of what to do about `MatchFinder::newASTConsumer()`, which 
> runs the finder immediately after an AST is created, and so covers the point 
> at which we might set a scope. There are several good options, e.g.:
>  - Don't provide any facility for setting traversal scope when 
> newASTConsumer() is used - it's not commonly needed, and the ASTConsumer is 
> trivial to reimplement where that's actually needed
>  - Accept an optional `function` which should run just 
> before matching starts
> 
> This seems a bit subtle, but the difference between having this in 
> MatchFinder proper vs just in newASTConsumer() is important I think, 
> precisely because it's common to run the matchers directly on an existing AST.
> 
I have some similar concerns too.

clangd calls MatchFinder::matchAST explicitly after setTraversalScope,
but clang-tidy uses MultiplexConsumer and MatchFinder::newASTConsumer
is just one of the two consumers.
(1) I am not sure if it would be safe or even work to make big changes in
ClangTidy.cpp's CreateASTConsumer to call MatchFinder::matchAST explicitly.
(2) Similarly, I wonder if setTraversalScope will work for both MatchFinder
and other consumers in the same MultiplexConsumer.

Could you check if my current change to MatchFinder::HandleTranslationUnit
is right, especially in the saving/restoring of traversal scope?

I am assuming that each consumer in a MultiplexConsumer will have its own
chance to HandleTranslationUnit and HandleTopLevelDecl.
If that's correct, it seems to me that changing those two handlers in
MatchFinder is right for clang-tidy. Then they will need the optional
MatchFinder::MatchFinderOptions::DeclFilter.




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-20 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 353224.
chh marked an inline comment as done.
chh edited the summary of this revision.
chh added a comment.

Sync up; moved DeclFilter to ClangTidy.cpp.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1306,12 +1306,25 @@
MatchFinder::ParsingDoneTestCallback *ParsingDone)
   : Finder(Finder), ParsingDone(ParsingDone) {}
 
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+Finder->HandleTopLevelDecl(DG);
+return true;
+  }
+
 private:
   void HandleTranslationUnit(ASTContext ) override {
 if (ParsingDone != nullptr) {
   ParsingDone->run();
 }
-Finder->matchAST(Context);
+if (Finder->hasFilter()) {
+  auto SavedScope = Context.getTraversalScope();
+  auto  = Finder->getTraversalScope();
+  Context.setTraversalScope(MyTopDecls);
+  Finder->matchAST(Context);
+  Context.setTraversalScope(SavedScope);
+} else {
+  Finder->matchAST(Context);
+}
   }
 
   MatchFinder *Finder;
@@ -1454,5 +1467,44 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
+template 
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  if (const auto *TD = dyn_cast(D))
+return TD->getTemplateSpecializationKind() == Kind;
+  return false;
+}
+
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  return isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind);
+}
+
+bool isImplicitTemplateInstantiation(const NamedDecl *D) {
+  return isTemplateSpecializationKind(D, TSK_ImplicitInstantiation);
+}
+
+void MatchFinder::HandleTopLevelDecl(DeclGroupRef DG) {
+  if (hasFilter()) {
+for (Decl *D : DG) {
+  if (const NamedDecl *ND = dyn_cast(D))
+if (isImplicitTemplateInstantiation(ND))
+  continue;
+
+  // ObjCMethodDecl are not actually top-level decls.
+  if (isa(D))
+continue;
+
+  if (!Options.Filter->skipDecl(D))
+TopLevelDecls.push_back(D);
+}
+  }
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Friendly ping reviewers. Now this change can pass all clang-tidy tests.
Please feel free to comment and/or add other reviewers. Thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98618: [clang-tidy] Add --skip-headers, part 1 (with TopLevelDecl bit)

2021-06-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Please review https://reviews.llvm.org/D98710, which uses get/setTraversalScope 
instead of adding a TopLevelDecl bit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98618/new/

https://reviews.llvm.org/D98618

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98709: [clang-tidy] Add --skip-headers, part 1

2021-06-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 351617.
chh retitled this revision from "clang-tidy skip-headers; Alt#1; fewer changes" 
to "[clang-tidy] Add --skip-headers, part 1".
chh edited the summary of this revision.
chh added a comment.
Herald added subscribers: cfe-commits, xazax.hun.

sync with latest clang/llvm


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98709/new/

https://reviews.llvm.org/D98709

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipDecl(DeclNode))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,8 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,19 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct DeclFilter {
+  virtual bool skipDecl(Decl *) = 0;
+  virtual bool skipLocation(SourceLocation) = 0;
+  virtual ~DeclFilter();
+};
 
 /// Enables per-check timers.
 ///
 /// It prints a report after match.
 llvm::Optional CheckProfiling;
+
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };
 
   MatchFinder(MatchFinderOptions Options = MatchFinderOptions());
Index: clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
@@ -0,0 +1,54 @@
+// Test --skip-headers, --show-all-warnings, and --header-filter.
+// TODO: when skip-headers implementation is complete, add back
+//  -implicit-check-not="{{warning|error}}:"
+// and use no_hint instead of hint
+//
+// Default shows no warning in .h files, and give HINT to use --header-filter
+// RUN: clang-tidy %s -checks='*' -- \
+// RUN: 2>&1 | FileCheck %s -check-prefixes WARN,MAIN,HINT
+// later:-implicit-check-not="{{warning|error}}:"
+//
+// --skip-headers skips included files; finds only warnings in the main file.
+// RUN: clang-tidy 

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1

2021-06-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 351616.
chh retitled this revision from "WIP; clang-tidy skip-headers; Alt#2; need more 
changes" to "[clang-tidy] Add --skip-headers, part 1".
chh edited the summary of this revision.
chh added a comment.
Herald added subscribers: cfe-commits, xazax.hun.

sync with latest clang/llvm


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98710/new/

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1306,12 +1306,25 @@
MatchFinder::ParsingDoneTestCallback *ParsingDone)
   : Finder(Finder), ParsingDone(ParsingDone) {}
 
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+Finder->HandleTopLevelDecl(DG);
+return true;
+  }
+
 private:
   void HandleTranslationUnit(ASTContext ) override {
 if (ParsingDone != nullptr) {
   ParsingDone->run();
 }
-Finder->matchAST(Context);
+if (Finder->hasFilter()) {
+  auto SavedScope = Context.getTraversalScope();
+  auto  = Finder->getTraversalScope();
+  Context.setTraversalScope(MyTopDecls);
+  Finder->matchAST(Context);
+  Context.setTraversalScope(SavedScope);
+} else {
+  Finder->matchAST(Context);
+}
   }
 
   MatchFinder *Finder;
@@ -1454,5 +1467,44 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
+template 
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  if (const auto *TD = dyn_cast(D))
+return TD->getTemplateSpecializationKind() == Kind;
+  return false;
+}
+
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  return isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind);
+}
+
+bool isImplicitTemplateInstantiation(const NamedDecl *D) {
+  return isTemplateSpecializationKind(D, TSK_ImplicitInstantiation);
+}
+
+void MatchFinder::HandleTopLevelDecl(DeclGroupRef DG) {
+  if (hasFilter()) {
+for (Decl *D : DG) {
+  if (const NamedDecl *ND = dyn_cast(D))
+if (isImplicitTemplateInstantiation(ND))
+  continue;
+
+  // ObjCMethodDecl are not actually top-level decls.
+  if (isa(D))
+continue;
+
+  if (!Options.Filter->skipDecl(D))
+

[PATCH] D98618: [clang-tidy] Add --skip-headers, part 1

2021-06-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 351615.
chh added a comment.
Herald added a subscriber: cfe-commits.

sync with latest clang/llvm


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98618/new/

https://reviews.llvm.org/D98618

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/Parse/ParseAST.cpp

Index: clang/lib/Parse/ParseAST.cpp
===
--- clang/lib/Parse/ParseAST.cpp
+++ clang/lib/Parse/ParseAST.cpp
@@ -159,14 +159,20 @@
   // If we got a null return and something *was* parsed, ignore it.  This
   // is due to a top-level semicolon, an action override, or a parse error
   // skipping something.
-  if (ADecl && !Consumer->HandleTopLevelDecl(ADecl.get()))
-return;
+  if (ADecl) {
+for (Decl *D : ADecl.get())
+  D->setTopLevelDecl();
+if (!Consumer->HandleTopLevelDecl(ADecl.get()))
+  return;
+  }
 }
   }
 
   // Process any TopLevelDecls generated by #pragma weak.
-  for (Decl *D : S.WeakTopLevelDecls())
+  for (Decl *D : S.WeakTopLevelDecls()) {
+D->setTopLevelDecl();
 Consumer->HandleTopLevelDecl(DeclGroupRef(D));
+  }
 
   Consumer->HandleTranslationUnit(S.getASTContext());
 
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1202,6 +1202,8 @@
   if (!DeclNode) {
 return true;
   }
+  if (Options.Filter && Options.Filter->skipDecl(DeclNode))
+return true;
 
   bool ScopedTraversal =
   TraversingASTNodeNotSpelledInSource || DeclNode->isImplicit();
@@ -1454,5 +1456,8 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -133,11 +133,19 @@
   /// Per bucket timing information.
   llvm::StringMap 
 };
+struct DeclFilter {
+  virtual bool skipDecl(Decl *) = 0;
+  virtual bool skipLocation(SourceLocation) = 0;
+  virtual ~DeclFilter();
+};
 
 /// Enables per-check timers.
 ///
 /// It prints a report after match.
 llvm::Optional CheckProfiling;
+
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };
 
   

[PATCH] D45454: Add llvm_gcov_flush to be called outside a shared library

2018-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT336019: [profile] Add llvm_gcov_flush to be called outside 
a shared library (authored by chh, committed by ).
Herald added a subscriber: Sanitizers.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,12 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call for any linked .so file.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {
Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL || dlerror() == NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and 
func2.shared\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;


Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,12 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call for any linked .so file.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {
Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL || dlerror() == NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and func2.shared\n");
+return 

[PATCH] D45454: Add llvm_gcov_flush to be called outside a shared library

2018-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 153576.
chh marked an inline comment as done.

https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL || dlerror() == NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and 
func2.shared\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,12 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call for any linked .so file.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL || dlerror() == NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and func2.shared\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,12 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call for any linked .so file.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {

[PATCH] D45454: Add llvm_gcov_flush to be called outside a shared library

2018-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: test/profile/Inputs/instrprof-dlopen-dlclose-main.c:20
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");

srhines wrote:
> Should also clear dlerror() before this call and check that dlerror() 
> returned a non-NULL pointer indicating that this search failed.
Look up of __gcov_flush is expected to fail because it's hidden.
Other places checks for returned value and report dlerror() messages.



https://reviews.llvm.org/D45454



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45454: Add llvm_gcov_flush to be called outside a shared library

2018-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 153573.
chh added a comment.

check dlerror() where it shouldn't be NULL


https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL || dlerror() == NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and 
func2.shared\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,14 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call. In that case, it dumps profile data of a .so file.
+// If it is called directly inside a .so file, the unified copy of
+// llvm_gcov_flush might dump data of other .so file or the main module.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL || dlerror() == NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and func2.shared\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,14 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call. In that case, it 

[PATCH] D45454: Add llvm_gcov_flush to be called outside a shared library

2018-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 153569.
chh marked an inline comment as done.
chh added a comment.

Added calls to dlerror() before other dl* functions.


https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", 
dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and 
func2.shared\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,14 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call. In that case, it dumps profile data of a .so file.
+// If it is called directly inside a .so file, the unified copy of
+// llvm_gcov_flush might dump data of other .so file or the main module.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -10,12 +10,42 @@
 return EXIT_FAILURE;
   }
 
+  dlerror();
   void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
   if (f2_handle == NULL) {
 fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
   }
 
+  dlerror();
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  dlerror();
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared': %s\n", dlerror());
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and func2.shared\n");
+return EXIT_FAILURE;
+  }
+
+  dlerror();
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,14 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call. In that 

[PATCH] D45454: Add llvm_gcov_flush to be called outside a shared library

2018-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Marco, latest patch does not change __gcov_flush, which is also hidden in 
libgcov.
Android coverage test programs have depended on an earlier compiler-rt that did 
not hide __gcov_flush.
If that's the only use case broken by recent change of compiler-rt, which hide 
__gcov_flush,
I think it is okay to keep compiler-rt the same as it is now.
Adding a visible llvm_gcov_flush will allow Android coverage test program to 
use it and dump system .so profiling data,
from the main test program.
Keeping an hidden __gcov_flush has the purpose that David mentioned earlier, to 
let each .so file dump its own profiling data.


https://reviews.llvm.org/D45454



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45454: Add llvm_gcov_flush to be called outside a shared library

2018-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 153532.
chh retitled this revision from "Make __gcov_flush visible outside a shared 
library" to "Add llvm_gcov_flush to be called outside a shared library".
chh edited the summary of this revision.
chh added a comment.

Now keep __gcov_flush hidden as libgcov; add llvm_gcov_flush to call from 
outside of .so files.


https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,31 @@
 return EXIT_FAILURE;
   }
 
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared'\n");
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared'\n");
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and 
func2.shared\n");
+return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,14 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call. In that case, it dumps profile data of a .so file.
+// If it is called directly inside a .so file, the unified copy of
+// llvm_gcov_flush might dump data of other .so file or the main module.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,31 @@
 return EXIT_FAILURE;
   }
 
+  void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (gcov_flush != NULL) {
+fprintf(stderr, "__gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func.shared'\n");
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared'\n");
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same llvm_gcov_flush found in func.shared and func2.shared\n");
+return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,6 +527,10 @@
   }
 }
 
+// __gcov_flush is hidden. When called in a .so file,
+// it dumps profile data of the calling .so file.
+// If a main program needs to dump profile data of each linked
+// .so files, it should use dlsym to find and call llvm_gcov_flush.
 COMPILER_RT_VISIBILITY
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
@@ -537,6 +541,14 @@
   }
 }
 
+// llvm_gcov_flush is not hidden for a program to use dlsym to
+// find and call. In that case, it dumps profile data of a .so file.
+// If it is called directly inside a .so file, the unified copy of
+// llvm_gcov_flush might dump data of other .so file or the main module.
+void llvm_gcov_flush() {
+  __gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {
___
cfe-commits mailing list

[PATCH] D45454: Make __gcov_flush visible outside a shared library

2018-06-26 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 152957.
chh edited the summary of this revision.

https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,31 @@
 return EXIT_FAILURE;
   }
 
+  void (*llvm_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (llvm_flush != NULL) {
+fprintf(stderr, "llvm_gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func.shared'\n");
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func2.shared'\n");
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same __gcov_flush found in func.shared and 
func2.shared\n");
+return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,16 +527,28 @@
   }
 }
 
+// llvm_gcov_flush is like __gcov_flush, but invisible outside a .so file.
+// It should be used inside a .so file to flush its own profile data.
 COMPILER_RT_VISIBILITY
-void __gcov_flush() {
+void llvm_gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
 
   while (curr) {
 curr->fn();
 curr = curr->next;
   }
 }
 
+// Keep __gcov_flush visible to be compatible with old gcov users
+// who call dlsym to find and call __gcov_flush in .so files.
+// In that use case, the expected bahavior is to flush profile data
+// for each .so file.
+// When called directly inside a .so file, the unified __gcov_flush
+// would flush the main program profile data.
+void __gcov_flush() {
+  llvm_gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,31 @@
 return EXIT_FAILURE;
   }
 
+  void (*llvm_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
+  if (llvm_flush != NULL) {
+fprintf(stderr, "llvm_gcov_flush should not be visible in func.shared'\n");
+return EXIT_FAILURE;
+  }
+
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func.shared'\n");
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func2.shared'\n");
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same __gcov_flush found in func.shared and func2.shared\n");
+return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,16 +527,28 @@
   }
 }
 
+// llvm_gcov_flush is like __gcov_flush, but invisible outside a .so file.
+// It should be used inside a .so file to flush its own profile data.
 COMPILER_RT_VISIBILITY
-void __gcov_flush() {
+void llvm_gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
 
   while (curr) {
 curr->fn();
 curr = curr->next;
   }
 }
 
+// Keep __gcov_flush visible to be compatible with old gcov users
+// who call dlsym to find and call __gcov_flush in .so files.
+// In that use case, the expected bahavior is to flush profile data
+// for each .so file.
+// When called directly inside a .so file, the unified __gcov_flush
+// would flush the main program profile data.
+void __gcov_flush() {
+  llvm_gcov_flush();
+}
+
 COMPILER_RT_VISIBILITY
 void llvm_delete_flush_function_list(void) {
   while (flush_fn_head) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45454: Make __gcov_flush visible outside a shared library

2018-06-25 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

In https://reviews.llvm.org/D45454#1142197, @marco-c wrote:

> In https://reviews.llvm.org/D45454#1070884, @belleyb wrote:
>
> > @chh I had a chance to try out your proposed changes. It's not causing us 
> > any trouble. In fact, `__gcov_flush()` is not even used at all (at least in 
> > LLVM 5.0.1).. I can recompile llvm, compiler_rt and clang and re-run all 
> > the tests with `__gcov_flush` commented out! No problem.
> >
> > I would suggest adding a bit more documentation to `__gcov_flush()`, thus 
> > describing what those "special cases" are...
>
>
> __gcov_flush is only used if you actually call it (it's needed for example if 
> you want to profile only part of your program).
>
> In GCC, __gcov_flush is not hidden, so perhaps we should do the same to keep 
> the same behavior? I've also submitted https://reviews.llvm.org/D48538, which 
> is making __gcov_flush flush counters for all shared libraries (like GCC 
> does, with the same caveat: 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83879).


I have no problem keeping these functions compatible with GCC.
My earlier proposal and David's comment in the mailing list seemed to be lost 
and not showing here.
So, let me summarize the case here. This change should make `__gcov_flush` not 
hidden as before in GCC,
but earlier change made it hidden as well as other `llvm_gov_*` functions.
Could we have both `__gov_flush` and `llvm_gov_flush` functions, one unhidden 
and one hidden?


https://reviews.llvm.org/D45454



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2018-04-30 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.
Herald added a subscriber: llvm-commits.

FYI, Android NDK has another use case in 
https://github.com/android-ndk/ndk/issues/680.
It would be nice to have clang-tidy recognize the response file.


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43689: [analyzer] Disable constructor inlining when lifetime extension through fields occurs.

2018-04-18 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

This change caused an assertion failure in ExprEngineCXX.cpp:
https://bugs.llvm.org/show_bug.cgi?id=37166


Repository:
  rC Clang

https://reviews.llvm.org/D43689



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45454: Make __gcov_flush visible outside a shared library

2018-04-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Yes, calling `__gcov_flush` within .so files are different,
but it's a revert of https://reviews.llvm.org/D38124.
I think  https://bugs.llvm.org/show_bug.cgi?id=27224
can be fixed by hiding only llvm_gcda_* functions,
without any change to `__gcov_flush`.

(1) Before https://reviews.llvm.org/D38124:

- Calling `__gcov_flush` within .so or main function dumps to main gcda file.
- Android's dlsym() lookup/call of `__gcov_flush` dumps to .so file specific 
gcda files.

(2) After https://reviews.llvm.org/D38124:

- Android's dlsym() cannot find/call `__gcov_flush`.
- Calling `__gcov_flush` from main works as in (1).
- Calling `__gcov_flush` from .so works differently; it will dump to .so 
specific gcda file, not the main one.

(3) With this change, we revert `__gcov_flush` behavior back to (1).

Is there any application that needs to call `__gcov_flush` within .so
and expects the output to .so specific gcda file like in (2)?
I think the behavior of (1) is more desirable.
If a main program wants to dump to .so specific gcda file, like Android,
it can use dlsym() to look up .so specific `__gcov_flush`.


https://reviews.llvm.org/D45454



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45454: Make __gcov_flush visible outside a shared library

2018-04-10 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

If we use the unit test case, call `__gcov_flush` from the main function,
and dump static variables in GCDAProfiling.c, we can see that `__gcov_flush`
is resolved to the same copy for func.shared, func2.shared, and main.
However, when `__gcov_flush` is called from main and from f1_flush and f2_flush,
they use different copies of static variables defined in GCDAProfiling.c.
The "flush_fn_head" and its flush functions are different, so 3 calls of
`__gcov_flush` will flush to 3 different output files:

  instrprof-dlopen-func.gcda
  instrprof-dlopen-func2.gcda
  instrprof-dlopen-dlclose-main.gcda

This keeps current Android use cases working as before `__gcov_flush` is hidden.
Is there other use case that could be broken by this change?


https://reviews.llvm.org/D45454



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45454: Make __gcov_flush visible outside a shared library

2018-04-09 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.
chh added reviewers: sylvestre.ledru, davidxl, rnk, void.

__gcov_flush is not called from other functions in GCDAProfiling.c,
but have been used by Android, which needs an interface function
to flush profile data of multiple .so files.

See https://bugs.llvm.org/show_bug.cgi?id=27224#c5


https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,25 @@
 return EXIT_FAILURE;
   }
 
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func.shared'\n");
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func2.shared'\n");
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same __gcov_flush found in func.shared and 
func2.shared\n");
+return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,7 +527,7 @@
   }
 }
 
-COMPILER_RT_VISIBILITY
+// Keep __gcov_flush visible for special use cases.
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
 


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,25 @@
 return EXIT_FAILURE;
   }
 
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (f1_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func.shared'\n");
+return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
+  if (f2_flush == NULL) {
+fprintf(stderr, "unable to find __gcov_flush in func2.shared'\n");
+return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+fprintf(stderr, "Same __gcov_flush found in func.shared and func2.shared\n");
+return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
 fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
 return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,7 +527,7 @@
   }
 }
 
-COMPILER_RT_VISIBILITY
+// Keep __gcov_flush visible for special use cases.
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43965: [Driver] Pass -f[no-]emulated-tls and set up ExplicitEmulatedTLS

2018-03-01 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326499: [Driver] Pass -f[no-]emulated-tls and set up 
ExplicitEmulatedTLS (authored by chh, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43965?vs=136601=136608#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43965

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/Driver/emulated-tls.cpp

Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -3937,13 +3937,9 @@
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
-  // Emulated TLS is enabled by default on Android and OpenBSD, and can be enabled
-  // manually with -femulated-tls.
-  bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isOSOpenBSD() ||
-Triple.isWindowsCygwinEnvironment();
-  if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
-   EmulatedTLSDefault))
-CmdArgs.push_back("-femulated-tls");
+  Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
+  options::OPT_fno_emulated_tls);
+
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa(JA) || Output.getType() != types::TY_PP_Asm)
 Args.AddLastArg(CmdArgs, options::OPT_fzvector);
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -942,8 +942,12 @@
 }
   }
 
-  Opts.EmulatedTLS =
-  Args.hasFlag(OPT_femulated_tls, OPT_fno_emulated_tls, false);
+  if (Args.getLastArg(OPT_femulated_tls) ||
+  Args.getLastArg(OPT_fno_emulated_tls)) {
+Opts.ExplicitEmulatedTLS = true;
+Opts.EmulatedTLS =
+Args.hasFlag(OPT_femulated_tls, OPT_fno_emulated_tls, false);
+  }
 
   if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
 StringRef Name = A->getValue();
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -433,6 +433,7 @@
   Options.DataSections = CodeGenOpts.DataSections;
   Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
   Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
+  Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
   Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
 
Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def
@@ -69,7 +69,8 @@
 CODEGENOPT(EmitGcovArcs  , 1, 0) ///< Emit coverage data files, aka. GCDA.
 CODEGENOPT(EmitGcovNotes , 1, 0) ///< Emit coverage "notes" files, aka GCNO.
 CODEGENOPT(EmitOpenCLArgMetadata , 1, 0) ///< Emit OpenCL kernel arg metadata.
-CODEGENOPT(EmulatedTLS   , 1, 0) ///< Set when -femulated-tls is enabled.
+CODEGENOPT(EmulatedTLS   , 1, 0) ///< Set by default or -f[no-]emulated-tls.
+CODEGENOPT(ExplicitEmulatedTLS , 1, 0) ///< Set if -f[no-]emulated-tls is used.
 /// \brief Embed Bitcode mode (off/all/bitcode/marker).
 ENUM_CODEGENOPT(EmbedBitcode, EmbedBitcodeKind, 2, Embed_Off)
 CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard variables
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -815,7 +815,7 @@
   HelpText<"Emit all declarations, even if unused">;
 def femulated_tls : Flag<["-"], "femulated-tls">, Group, Flags<[CC1Option]>,
   HelpText<"Use emutls functions to access thread_local variables">;
-def fno_emulated_tls : Flag<["-"], "fno-emulated-tls">, Group;
+def fno_emulated_tls : Flag<["-"], "fno-emulated-tls">, Group, Flags<[CC1Option]>;
 def fencoding_EQ : Joined<["-"], "fencoding=">, Group;
 def ferror_limit_EQ : Joined<["-"], "ferror-limit=">, Group, Flags<[CoreOption]>;
 def fexceptions : Flag<["-"], "fexceptions">, Group, Flags<[CC1Option]>,
Index: cfe/trunk/test/Driver/emulated-tls.cpp
===
--- cfe/trunk/test/Driver/emulated-tls.cpp
+++ cfe/trunk/test/Driver/emulated-tls.cpp
@@ -1,7 +1,42 @@
-// 

[PATCH] D43965: [Driver] Pass -f[no-]emulated-tls and set up ExplicitEmulatedTLS

2018-03-01 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Martin, thanks for finding this problem.
Please review/accept my new change if it passes your tests.
After this and https://reviews.llvm.org/D42999, the default emulated TLS mode 
should only be decided in
llvm/trunk/include/llvm/ADT/Triple.h hasDefaultEmulatedTLS().


https://reviews.llvm.org/D43965



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43965: [Driver] Pass -f[no-]emulated-tls and set up ExplicitEmulatedTLS

2018-03-01 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 136601.
chh retitled this revision from "[CodeGen] Force the backend to follow clang's 
EmulatedTLS flag" to "[Driver] Pass -f[no-]emulated-tls and set up 
ExplicitEmulatedTLS".
chh edited the summary of this revision.
chh added a reviewer: srhines.

https://reviews.llvm.org/D43965

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/emulated-tls.cpp

Index: test/Driver/emulated-tls.cpp
===
--- test/Driver/emulated-tls.cpp
+++ test/Driver/emulated-tls.cpp
@@ -1,7 +1,42 @@
-// Cygwin and OpenBSD use emutls. Clang should pass -femulated-tls to cc1
-// and cc1 should pass EmulatedTLS to LLVM CodeGen.
-// FIXME: Add more targets here to use emutls.
-// RUN: %clang -### -std=c++11 -target i686-pc-cygwin %s 2>&1 | FileCheck %s
-// RUN: %clang -### -std=c++11 -target i686-pc-openbsd %s 2>&1 | FileCheck %s
+// Android, Cygwin and OpenBSD use emutls by default.
+// Clang should pass -femulated-tls or -fno-emulated-tls to cc1 if they are used,
+// and cc1 should set up EmulatedTLS and ExplicitEmulatedTLS to LLVM CodeGen.
+//
+// RUN: %clang -### -target arm-linux-androideabi %s 2>&1 \
+// RUN: | FileCheck -check-prefix=DEFAULT %s
+// RUN: %clang -### -target arm-linux-gnu %s 2>&1 \
+// RUN: | FileCheck -check-prefix=DEFAULT %s
+// RUN: %clang -### -target i686-pc-cygwin %s 2>&1 \
+// RUN: | FileCheck -check-prefix=DEFAULT %s
+// RUN: %clang -### -target i686-pc-openbsd %s 2>&1 \
+// RUN: | FileCheck -check-prefix=DEFAULT %s
 
-// CHECK: "-cc1" {{.*}}"-femulated-tls"
+// RUN: %clang -### -target arm-linux-androideabi -fno-emulated-tls -femulated-tls %s 2>&1 \
+// RUN: | FileCheck -check-prefix=EMU %s
+// RUN: %clang -### -target arm-linux-gnu %s -fno-emulated-tls -femulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=EMU %s
+// RUN: %clang -### -target i686-pc-cygwin %s -fno-emulated-tls -femulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=EMU %s
+// RUN: %clang -### -target i686-pc-openbsd %s -fno-emulated-tls -femulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=EMU %s
+
+// RUN: %clang -### -target arm-linux-androideabi -femulated-tls -fno-emulated-tls %s 2>&1 \
+// RUN: | FileCheck -check-prefix=NOEMU %s
+// RUN: %clang -### -target arm-linux-gnu %s -femulated-tls -fno-emulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=NOEMU %s
+// RUN: %clang -### -target i686-pc-cygwin %s -femulated-tls -fno-emulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=NOEMU %s
+// RUN: %clang -### -target i686-pc-openbsd %s -femulated-tls -fno-emulated-tls 2>&1 \
+// RUN: | FileCheck -check-prefix=NOEMU %s
+
+
+// Default without -f[no-]emulated-tls, will be decided by the target triple.
+// DEFAULT-NOT: "-cc1" {{.*}}"-femulated-tls"
+// DEFAULT-NOT: "-cc1" {{.*}}"-fno-emulated-tls"
+
+// Explicit and last -f[no-]emulated-tls flag will be passed to cc1.
+// EMU: "-cc1" {{.*}}"-femulated-tls"
+// EMU-NOT: "-cc1" {{.*}}"-fno-emulated-tls"
+
+// NOEMU: "-cc1" {{.*}}"-fno-emulated-tls"
+// NOEMU-NOT: "-cc1" {{.*}}"-femulated-tls"
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -942,8 +942,12 @@
 }
   }
 
-  Opts.EmulatedTLS =
-  Args.hasFlag(OPT_femulated_tls, OPT_fno_emulated_tls, false);
+  if (Args.getLastArg(OPT_femulated_tls) ||
+  Args.getLastArg(OPT_fno_emulated_tls)) {
+Opts.ExplicitEmulatedTLS = true;
+Opts.EmulatedTLS =
+Args.hasFlag(OPT_femulated_tls, OPT_fno_emulated_tls, false);
+  }
 
   if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
 StringRef Name = A->getValue();
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3937,13 +3937,9 @@
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
-  // Emulated TLS is enabled by default on Android and OpenBSD, and can be enabled
-  // manually with -femulated-tls.
-  bool EmulatedTLSDefault = Triple.isAndroid() || Triple.isOSOpenBSD() ||
-Triple.isWindowsCygwinEnvironment();
-  if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
-   EmulatedTLSDefault))
-CmdArgs.push_back("-femulated-tls");
+  Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
+  options::OPT_fno_emulated_tls);
+
   // AltiVec-like language extensions aren't relevant for assembling.
   if (!isa(JA) || Output.getType() != types::TY_PP_Asm)
 Args.AddLastArg(CmdArgs, options::OPT_fzvector);
Index: lib/CodeGen/BackendUtil.cpp

[PATCH] D43965: [CodeGen] Force the backend to follow clang's EmulatedTLS flag

2018-03-01 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh commandeered this revision.
chh edited reviewers, added: mstorsjo; removed: chh.
chh added a comment.

I will upload a different fix soon.
We should set ExplicitEmulatedTLS only when -f[no-]emulated-tls flag is found 
at command line.
Any front-end should only pass the flag and let backend decide the default 
based on target.


Repository:
  rC Clang

https://reviews.llvm.org/D43965



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35743: [clang-format] Adjust space around &/&& of structured bindings

2017-09-26 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314264: [clang-format] Adjust space around &/&& of 
structured bindings (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35743?vs=116201=116744#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35743

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -342,10 +342,10 @@
 bool ColonFound = false;
 
 unsigned BindingIncrease = 1;
-if (Left->is(TT_Unknown)) {
-  if (Left->isCppStructuredBinding(Style)) {
-Left->Type = TT_StructuredBindingLSquare;
-  } else if (StartsObjCMethodExpr) {
+if (Left->isCppStructuredBinding(Style)) {
+  Left->Type = TT_StructuredBindingLSquare;
+} else if (Left->is(TT_Unknown)) {
+  if (StartsObjCMethodExpr) {
 Left->Type = TT_ObjCMethodExpr;
   } else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
  Contexts.back().ContextKind == tok::l_brace &&
@@ -2515,6 +2515,14 @@
   TT_TemplateOpener));
   if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
 return Style.SpacesInAngles;
+  // Space before TT_StructuredBindingLSquare.
+  if (Right.is(TT_StructuredBindingLSquare))
+return !Left.isOneOf(tok::amp, tok::ampamp) ||
+   Style.PointerAlignment != FormatStyle::PAS_Right;
+  // Space before & or && following a TT_StructuredBindingLSquare.
+  if (Right.Next && Right.Next->is(TT_StructuredBindingLSquare) &&
+  Right.isOneOf(tok::amp, tok::ampamp))
+return Style.PointerAlignment != FormatStyle::PAS_Left;
   if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) ||
   (Left.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) &&
!Right.is(tok::r_paren)))
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -11579,24 +11579,59 @@
   EXPECT_EQ("auto const volatile [a, b] = f();",
 format("auto  const   volatile[a, b] = f();"));
   EXPECT_EQ("auto [a, b, c] = f();", format("auto   [  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto & [a, b, c] = f();",
+  EXPECT_EQ("auto &[a, b, c] = f();",
 format("auto   &[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto && [a, b, c] = f();",
+  EXPECT_EQ("auto &&[a, b, c] = f();",
 format("auto   &&[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto const & [a, b] = f();", format("auto  const&[a, b] = f();"));
-  EXPECT_EQ("auto const volatile && [a, b] = f();",
+  EXPECT_EQ("auto const &[a, b] = f();", format("auto  const&[a, b] = f();"));
+  EXPECT_EQ("auto const volatile &&[a, b] = f();",
 format("auto  const  volatile  &&[a, b] = f();"));
-  EXPECT_EQ("auto && [a, b] = f();", format("auto  &&[a, b] = f();"));
+  EXPECT_EQ("auto const &&[a, b] = f();", format("auto  const   &&  [a, b] = f();"));
+  EXPECT_EQ("const auto &[a, b] = f();", format("const  auto  &  [a, b] = f();"));
+  EXPECT_EQ("const auto volatile &&[a, b] = f();",
+format("const  auto   volatile  &&[a, b] = f();"));
+  EXPECT_EQ("volatile const auto &&[a, b] = f();",
+format("volatile  const  auto   &&[a, b] = f();"));
+  EXPECT_EQ("const auto &&[a, b] = f();", format("const  auto  &&  [a, b] = f();"));
 
   // Make sure we don't mistake structured bindings for lambdas.
-  verifyFormat("auto [a, b]{A * i};");
-  verifyFormat("auto const [a, b]{A * i};");
-  verifyFormat("auto const && [a, b]{A * i};");
+  FormatStyle PointerMiddle = getLLVMStyle();
+  PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle;
+  verifyFormat("auto [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto [a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto [a3, b]{A * i};", PointerMiddle);
+  verifyFormat("auto const [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const [a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const [a3, b]{A * i};", PointerMiddle);
+  verifyFormat("auto const& [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const &[a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const & [a3, b]{A * i};", PointerMiddle);
+  verifyFormat("auto const&& [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const &&[a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const && [a3, b]{A * i};", PointerMiddle);
+
+  EXPECT_EQ("for (const auto &&[a, b] : some_range) {\n}",
+format("for (const auto   &&   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto &[a, b] : some_range) {\n}",
+format("for (const auto   &   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto [a, b] : 

[PATCH] D35743: [clang-format] Adjust space around &/&& of structured bindings

2017-09-25 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

ping.


https://reviews.llvm.org/D35743



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35743: [clang-format] Adjust space around &/&& of structured bindings

2017-09-21 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 116201.
chh marked 2 inline comments as done.
chh edited the summary of this revision.

https://reviews.llvm.org/D35743

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11579,24 +11579,59 @@
   EXPECT_EQ("auto const volatile [a, b] = f();",
 format("auto  const   volatile[a, b] = f();"));
   EXPECT_EQ("auto [a, b, c] = f();", format("auto   [  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto & [a, b, c] = f();",
+  EXPECT_EQ("auto &[a, b, c] = f();",
 format("auto   &[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto && [a, b, c] = f();",
+  EXPECT_EQ("auto &&[a, b, c] = f();",
 format("auto   &&[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto const & [a, b] = f();", format("auto  const&[a, b] = f();"));
-  EXPECT_EQ("auto const volatile && [a, b] = f();",
+  EXPECT_EQ("auto const &[a, b] = f();", format("auto  const&[a, b] = f();"));
+  EXPECT_EQ("auto const volatile &&[a, b] = f();",
 format("auto  const  volatile  &&[a, b] = f();"));
-  EXPECT_EQ("auto && [a, b] = f();", format("auto  &&[a, b] = f();"));
+  EXPECT_EQ("auto const &&[a, b] = f();", format("auto  const   &&  [a, b] = f();"));
+  EXPECT_EQ("const auto &[a, b] = f();", format("const  auto  &  [a, b] = f();"));
+  EXPECT_EQ("const auto volatile &&[a, b] = f();",
+format("const  auto   volatile  &&[a, b] = f();"));
+  EXPECT_EQ("volatile const auto &&[a, b] = f();",
+format("volatile  const  auto   &&[a, b] = f();"));
+  EXPECT_EQ("const auto &&[a, b] = f();", format("const  auto  &&  [a, b] = f();"));
 
   // Make sure we don't mistake structured bindings for lambdas.
-  verifyFormat("auto [a, b]{A * i};");
-  verifyFormat("auto const [a, b]{A * i};");
-  verifyFormat("auto const && [a, b]{A * i};");
+  FormatStyle PointerMiddle = getLLVMStyle();
+  PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle;
+  verifyFormat("auto [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto [a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto [a3, b]{A * i};", PointerMiddle);
+  verifyFormat("auto const [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const [a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const [a3, b]{A * i};", PointerMiddle);
+  verifyFormat("auto const& [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const &[a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const & [a3, b]{A * i};", PointerMiddle);
+  verifyFormat("auto const&& [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const &&[a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const && [a3, b]{A * i};", PointerMiddle);
+
+  EXPECT_EQ("for (const auto &&[a, b] : some_range) {\n}",
+format("for (const auto   &&   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto &[a, b] : some_range) {\n}",
+format("for (const auto   &   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto [a, b] : some_range) {\n}",
+format("for (const auto[a, b] : some_range) {\n}"));
+  EXPECT_EQ("auto [x, y](expr);", format("auto[x,y]  (expr);"));
+  EXPECT_EQ("auto &[x, y](expr);", format("auto  &  [x,y]  (expr);"));
+  EXPECT_EQ("auto &&[x, y](expr);", format("auto  &&  [x,y]  (expr);"));
+  EXPECT_EQ("auto const &[x, y](expr);", format("auto  const  &  [x,y]  (expr);"));
+  EXPECT_EQ("auto const &&[x, y](expr);", format("auto  const  &&  [x,y]  (expr);"));
+  EXPECT_EQ("auto [x, y]{expr};", format("auto[x,y] {expr};"));
+  EXPECT_EQ("auto const &[x, y]{expr};", format("auto  const  &  [x,y]  {expr};"));
+  EXPECT_EQ("auto const &&[x, y]{expr};", format("auto  const  &&  [x,y]  {expr};"));
 
   format::FormatStyle Spaces = format::getLLVMStyle();
   Spaces.SpacesInSquareBrackets = true;
   verifyFormat("auto [ a, b ] = f();", Spaces);
-  verifyFormat("auto && [ a, b ] = f();", Spaces);
+  verifyFormat("auto &&[ a, b ] = f();", Spaces);
+  verifyFormat("auto &[ a, b ] = f();", Spaces);
+  verifyFormat("auto const &&[ a, b ] = f();", Spaces);
+  verifyFormat("auto const &[ a, b ] = f();", Spaces);
 }
 
 } // end namespace
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -342,10 +342,10 @@
 bool ColonFound = false;
 
 unsigned BindingIncrease = 1;
-if (Left->is(TT_Unknown)) {
-  if (Left->isCppStructuredBinding(Style)) {
-Left->Type = TT_StructuredBindingLSquare;
-  } else if (StartsObjCMethodExpr) {
+if (Left->isCppStructuredBinding(Style)) {
+  Left->Type = TT_StructuredBindingLSquare;
+} else if (Left->is(TT_Unknown)) {
+  if (StartsObjCMethodExpr) {
 Left->Type = TT_ObjCMethodExpr;
   } else if (Style.Language 

[PATCH] D35743: [clang-format] Adjust space around &/&& of structured bindings

2017-09-20 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 116092.
chh edited the summary of this revision.

https://reviews.llvm.org/D35743

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11579,24 +11579,58 @@
   EXPECT_EQ("auto const volatile [a, b] = f();",
 format("auto  const   volatile[a, b] = f();"));
   EXPECT_EQ("auto [a, b, c] = f();", format("auto   [  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto & [a, b, c] = f();",
+  EXPECT_EQ("auto &[a, b, c] = f();",
 format("auto   &[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto && [a, b, c] = f();",
+  EXPECT_EQ("auto &&[a, b, c] = f();",
 format("auto   &&[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto const & [a, b] = f();", format("auto  const&[a, b] = f();"));
-  EXPECT_EQ("auto const volatile && [a, b] = f();",
+  EXPECT_EQ("auto const &[a, b] = f();", format("auto  const&[a, b] = f();"));
+  EXPECT_EQ("auto const volatile &&[a, b] = f();",
 format("auto  const  volatile  &&[a, b] = f();"));
-  EXPECT_EQ("auto && [a, b] = f();", format("auto  &&[a, b] = f();"));
+  EXPECT_EQ("auto const &&[a, b] = f();", format("auto  const   &&  [a, b] = f();"));
+  EXPECT_EQ("const auto &[a, b] = f();", format("const  auto  &  [a, b] = f();"));
+  EXPECT_EQ("const auto volatile &&[a, b] = f();",
+format("const  auto   volatile  &&[a, b] = f();"));
+  EXPECT_EQ("volatile const auto &&[a, b] = f();",
+format("volatile  const  auto   &&[a, b] = f();"));
+  EXPECT_EQ("const auto &&[a, b] = f();", format("const  auto  &&  [a, b] = f();"));
 
   // Make sure we don't mistake structured bindings for lambdas.
   verifyFormat("auto [a, b]{A * i};");
   verifyFormat("auto const [a, b]{A * i};");
-  verifyFormat("auto const && [a, b]{A * i};");
+  verifyFormat("auto const& [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const &[a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const&& [a1, b]{A * i};", getGoogleStyle());
+  verifyFormat("auto const &&[a2, b]{A * i};", getLLVMStyle());
+  verifyFormat("auto const & = y1;", getGoogleStyle());
+  verifyFormat("auto const & = y1;", getLLVMStyle());
+  verifyFormat("auto const  = y2;", getGoogleStyle());
+  verifyFormat("auto const  = y2;", getLLVMStyle());
+  verifyFormat("auto const  = y2;", getGoogleStyle());
+  verifyFormat("auto const *x1, *x2;", getGoogleStyle());
+  verifyFormat("auto const *x3, *x4;", getLLVMStyle());
+
+  EXPECT_EQ("for (const auto &&[a, b] : some_range) {\n}",
+format("for (const auto   &&   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto &[a, b] : some_range) {\n}",
+format("for (const auto   &   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto [a, b] : some_range) {\n}",
+format("for (const auto[a, b] : some_range) {\n}"));
+  EXPECT_EQ("auto [x, y](expr);", format("auto[x,y]  (expr);"));
+  EXPECT_EQ("auto &[x, y](expr);", format("auto  &  [x,y]  (expr);"));
+  EXPECT_EQ("auto &&[x, y](expr);", format("auto  &&  [x,y]  (expr);"));
+  EXPECT_EQ("auto const &[x, y](expr);", format("auto  const  &  [x,y]  (expr);"));
+  EXPECT_EQ("auto const &&[x, y](expr);", format("auto  const  &&  [x,y]  (expr);"));
+  EXPECT_EQ("auto [x, y]{expr};", format("auto[x,y] {expr};"));
+  EXPECT_EQ("auto const &[x, y]{expr};", format("auto  const  &  [x,y]  {expr};"));
+  EXPECT_EQ("auto const &&[x, y]{expr};", format("auto  const  &&  [x,y]  {expr};"));
 
   format::FormatStyle Spaces = format::getLLVMStyle();
   Spaces.SpacesInSquareBrackets = true;
   verifyFormat("auto [ a, b ] = f();", Spaces);
-  verifyFormat("auto && [ a, b ] = f();", Spaces);
+  verifyFormat("auto &&[ a, b ] = f();", Spaces);
+  verifyFormat("auto &[ a, b ] = f();", Spaces);
+  verifyFormat("auto const &&[ a, b ] = f();", Spaces);
+  verifyFormat("auto const &[ a, b ] = f();", Spaces);
 }
 
 } // end namespace
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -342,10 +342,10 @@
 bool ColonFound = false;
 
 unsigned BindingIncrease = 1;
-if (Left->is(TT_Unknown)) {
-  if (Left->isCppStructuredBinding(Style)) {
-Left->Type = TT_StructuredBindingLSquare;
-  } else if (StartsObjCMethodExpr) {
+if (Left->isCppStructuredBinding(Style)) {
+  Left->Type = TT_StructuredBindingLSquare;
+} else if (Left->is(TT_Unknown)) {
+  if (StartsObjCMethodExpr) {
 Left->Type = TT_ObjCMethodExpr;
   } else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
  Contexts.back().ContextKind == tok::l_brace &&
@@ -2513,6 +2513,14 @@
   TT_TemplateOpener));
   if ((Left.is(TT_TemplateOpener)) != 

[PATCH] D37132: [clang-format] Add support for C++17 structured bindings.

2017-09-18 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Please review  https://reviews.llvm.org/D35743.
I uploaded there a new diff that should fix the spaces around & and && tokens.
Thanks.


https://reviews.llvm.org/D37132



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35743: [clang-format] Adjust space around &/&& of structured bindings

2017-09-18 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 115741.

https://reviews.llvm.org/D35743

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11577,19 +11577,43 @@
   EXPECT_EQ("auto const volatile [a, b] = f();",
 format("auto  const   volatile[a, b] = f();"));
   EXPECT_EQ("auto [a, b, c] = f();", format("auto   [  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto & [a, b, c] = f();",
+  EXPECT_EQ("auto& [a, b, c] = f();",
 format("auto   &[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto && [a, b, c] = f();",
+  EXPECT_EQ("auto&& [a, b, c] = f();",
 format("auto   &&[  a  ,  b,c   ] = f();"));
-  EXPECT_EQ("auto const & [a, b] = f();", format("auto  const&[a, b] = f();"));
-  EXPECT_EQ("auto const volatile && [a, b] = f();",
+  EXPECT_EQ("auto const& [a, b] = f();", format("auto  const&[a, b] = f();"));
+  EXPECT_EQ("auto const volatile&& [a, b] = f();",
 format("auto  const  volatile  &&[a, b] = f();"));
-  EXPECT_EQ("auto && [a, b] = f();", format("auto  &&[a, b] = f();"));
+  EXPECT_EQ("auto const&& [a, b] = f();", format("auto  const   &&  [a, b] = 
f();"));
+  EXPECT_EQ("const auto& [a, b] = f();", format("const  auto  &  [a, b] = 
f();"));
+  EXPECT_EQ("const auto volatile&& [a, b] = f();",
+format("const  auto   volatile  &&[a, b] = f();"));
+  EXPECT_EQ("volatile const auto&& [a, b] = f();",
+format("volatile  const  auto   &&[a, b] = f();"));
+  EXPECT_EQ("const auto&& [a, b] = f();", format("const  auto  &&  [a, b] = 
f();"));
+
+  EXPECT_EQ("for (const auto&& [a, b] : some_range) {\n}",
+format("for (const auto   &&   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto& [a, b] : some_range) {\n}",
+format("for (const auto   &   [a, b] : some_range) {\n}"));
+  EXPECT_EQ("for (const auto [a, b] : some_range) {\n}",
+format("for (const auto[a, b] : some_range) {\n}"));
+  EXPECT_EQ("auto [x, y](expr);", format("auto[x,y]  (expr);"));
+  EXPECT_EQ("auto& [x, y](expr);", format("auto  &  [x,y]  (expr);"));
+  EXPECT_EQ("auto&& [x, y](expr);", format("auto  &&  [x,y]  (expr);"));
+  EXPECT_EQ("auto const& [x, y](expr);", format("auto  const  &  [x,y]  
(expr);"));
+  EXPECT_EQ("auto const&& [x, y](expr);", format("auto  const  &&  [x,y]  
(expr);"));
+  EXPECT_EQ("auto [x, y] { expr };", format("auto[x,y] {expr};"));
+  EXPECT_EQ("auto const& [x, y] { expr };", format("auto  const  &  [x,y]  
{expr};"));
+  EXPECT_EQ("auto const&& [x, y] { expr };", format("auto  const  &&  [x,y]  
{expr};"));
 
   format::FormatStyle Spaces = format::getLLVMStyle();
   Spaces.SpacesInSquareBrackets = true;
   verifyFormat("auto [ a, b ] = f();", Spaces);
-  verifyFormat("auto && [ a, b ] = f();", Spaces);
+  verifyFormat("auto&& [ a, b ] = f();", Spaces);
+  verifyFormat("auto& [ a, b ] = f();", Spaces);
+  verifyFormat("auto const&& [ a, b ] = f();", Spaces);
+  verifyFormat("auto const& [ a, b ] = f();", Spaces);
 }
 
 } // end namespace
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -353,10 +353,10 @@
 bool ColonFound = false;
 
 unsigned BindingIncrease = 1;
-if (Left->is(TT_Unknown)) {
-  if (isCppStructuredBinding(Left)) {
-Left->Type = TT_StructuredBindingLSquare;
-  } else if (StartsObjCMethodExpr) {
+if (isCppStructuredBinding(Left)) {
+  Left->Type = TT_StructuredBindingLSquare;
+} else if (Left->is(TT_Unknown)) {
+  if (StartsObjCMethodExpr) {
 Left->Type = TT_ObjCMethodExpr;
   } else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
  Contexts.back().ContextKind == tok::l_brace &&
@@ -2193,6 +2193,10 @@
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine ,
   const FormatToken ,
   const FormatToken ) {
+  if (Right.is(TT_StructuredBindingLSquare))
+return true;
+  if (Right.Next && Right.Next->is(TT_StructuredBindingLSquare))
+return false;
   if (Left.is(tok::kw_return) && Right.isNot(tok::semi))
 return true;
   if (Style.ObjCSpaceAfterProperty && Line.Type == LT_ObjCProperty &&
@@ -2522,7 +2526,8 @@
   tok::kw___super, TT_TemplateCloser, 
TT_TemplateOpener));
   if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
 return Style.SpacesInAngles;
-  if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) ||
+  if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren) &&
+   !(Right.Next && Right.Next->is(TT_StructuredBindingLSquare))) ||
   (Left.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) &&
!Right.is(tok::r_paren)))
 

[PATCH] D37132: [clang-format] Add support for C++17 structured bindings.

2017-09-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Thanks for this change.
Could you take a look of https://reviews.llvm.org/D35743 too?

This outputs a space before and after "&" or "&&", like this

  "auto & [...",  "auto && [..."

Could we remove one of the space to a format like the following?

  "auto& [...",  "auto&& [..."


https://reviews.llvm.org/D37132



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35743: [clang-format] Handle Structured binding declaration in C++17

2017-09-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

ping.


https://reviews.llvm.org/D35743



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35367: [clang-tidy] Add a close-on-exec check on epoll_create() in Android module.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: clang-tidy/android/CloexecEpollCreateCheck.cpp:27-31
+  replaceFunc(Result, /*WarningMsg=*/
+  "prefer epoll_create() to epoll_create1() "
+  "because epoll_create1() allows "
+  "EPOLL_CLOEXEC", /*FixMsg=*/
+  "epoll_create1(EPOLL_CLOEXEC)");

alexfh wrote:
> nit: Please remove argument comments, they don't add any useful information.
Done.



Repository:
  rL LLVM

https://reviews.llvm.org/D35367



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35367: [clang-tidy] Add a close-on-exec check on epoll_create() in Android module.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311029: [clang-tidy] Add a close-on-exec check on 
epoll_create() in Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35367?vs=110751=111386#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35367

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-epoll-create.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-epoll-create.cpp

Index: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
@@ -7,6 +7,7 @@
   CloexecCheck.cpp
   CloexecCreatCheck.cpp
   CloexecEpollCreate1Check.cpp
+  CloexecEpollCreateCheck.cpp
   CloexecDupCheck.cpp
   CloexecFopenCheck.cpp
   CloexecInotifyInit1Check.cpp
Index: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
@@ -14,6 +14,7 @@
 #include "CloexecAcceptCheck.h"
 #include "CloexecCreatCheck.h"
 #include "CloexecEpollCreate1Check.h"
+#include "CloexecEpollCreateCheck.h"
 #include "CloexecDupCheck.h"
 #include "CloexecFopenCheck.h"
 #include "CloexecInotifyInit1Check.h"
@@ -37,6 +38,8 @@
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck(
 "android-cloexec-epoll-create1");
+CheckFactories.registerCheck(
+"android-cloexec-epoll-create");
 CheckFactories.registerCheck("android-cloexec-dup");
 CheckFactories.registerCheck("android-cloexec-fopen");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecEpollCreateCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// epoll_create() is better to be replaced by epoll_create1().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-epoll-create.html
+class CloexecEpollCreateCheck : public CloexecCheck {
+public:
+  CloexecEpollCreateCheck(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreateCheck.cpp
@@ -0,0 +1,36 @@
+//===--- CloexecEpollCreateCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecEpollCreateCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecEpollCreateCheck::registerMatchers(MatchFinder *Finder) {
+  registerMatchersImpl(
+  Finder, functionDecl(returns(isInteger()), hasName("epoll_create"),
+   hasParameter(0, hasType(isInteger();
+}
+
+void 

[PATCH] D35365: [clang-tidy] Add a close-on-exec check on epoll_create1() in Android module.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311028: [clang-tidy] Add a close-on-exec check on 
epoll_create1() in Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35365?vs=110752=111385#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35365

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-epoll-create1.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-epoll-create1.cpp

Index: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
@@ -6,6 +6,7 @@
   CloexecAcceptCheck.cpp
   CloexecCheck.cpp
   CloexecCreatCheck.cpp
+  CloexecEpollCreate1Check.cpp
   CloexecDupCheck.cpp
   CloexecFopenCheck.cpp
   CloexecInotifyInit1Check.cpp
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.h
@@ -0,0 +1,35 @@
+//===--- CloexecEpollCreate1Check.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses epoll_create1() without using the EPOLL_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-epoll-create1.html
+class CloexecEpollCreate1Check : public CloexecCheck {
+public:
+  CloexecEpollCreate1Check(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecEpollCreate1Check.cpp
@@ -0,0 +1,33 @@
+//===--- CloexecEpollCreate1Check.cpp - clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecEpollCreate1Check.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecEpollCreate1Check::registerMatchers(MatchFinder *Finder) {
+  registerMatchersImpl(
+  Finder, functionDecl(returns(isInteger()), hasName("epoll_create1"),
+   hasParameter(0, hasType(isInteger();
+}
+
+void CloexecEpollCreate1Check::check(const MatchFinder::MatchResult ) {
+  insertMacroFlag(Result, /*MarcoFlag=*/"EPOLL_CLOEXEC", /*ArgPos=*/0);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "CloexecAccept4Check.h"
 #include "CloexecAcceptCheck.h"
 #include "CloexecCreatCheck.h"
+#include "CloexecEpollCreate1Check.h"
 #include "CloexecDupCheck.h"
 #include "CloexecFopenCheck.h"
 #include "CloexecInotifyInit1Check.h"
@@ -34,6 +35,8 @@
 CheckFactories.registerCheck("android-cloexec-accept4");
 CheckFactories.registerCheck("android-cloexec-accept");
 

[PATCH] D35363: [clang-tidy] Add a close-on-exec check on accept4() in Android module.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311027: [clang-tidy] Add a close-on-exec check on accept4() 
in Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35363?vs=110755=111383#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35363

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-accept4.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-accept4.cpp

Index: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
+  CloexecAccept4Check.cpp
   CloexecAcceptCheck.cpp
   CloexecCheck.cpp
   CloexecCreatCheck.cpp
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.h
@@ -0,0 +1,35 @@
+//===--- CloexecAccept4Check.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses accept4() without using the SOCK_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-accept4.html
+class CloexecAccept4Check : public CloexecCheck {
+public:
+  CloexecAccept4Check(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecAccept4Check.cpp
@@ -0,0 +1,40 @@
+//===--- CloexecAccept4Check.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecAccept4Check.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecAccept4Check::registerMatchers(MatchFinder *Finder) {
+  auto SockAddrPointerType =
+  hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr";
+  auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t";
+
+  registerMatchersImpl(Finder,
+   functionDecl(returns(isInteger()), hasName("accept4"),
+hasParameter(0, hasType(isInteger())),
+hasParameter(1, SockAddrPointerType),
+hasParameter(2, SockLenPointerType),
+hasParameter(3, hasType(isInteger();
+}
+
+void CloexecAccept4Check::check(const MatchFinder::MatchResult ) {
+  insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/3);
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include 

[PATCH] D35362: [clang-tidy] Add a close-on-exec check on accept() in Android module.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311024: [clang-tidy] Add a close-on-exec check on accept() 
in Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35362?vs=111377=111378#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35362

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-accept.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-accept.cpp

Index: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
+  CloexecAcceptCheck.cpp
   CloexecCheck.cpp
   CloexecCreatCheck.cpp
   CloexecDupCheck.cpp
Index: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CloexecAcceptCheck.h"
 #include "CloexecCreatCheck.h"
 #include "CloexecDupCheck.h"
 #include "CloexecFopenCheck.h"
@@ -29,6 +30,7 @@
 class AndroidModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
+CheckFactories.registerCheck("android-cloexec-accept");
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-dup");
 CheckFactories.registerCheck("android-cloexec-fopen");
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecAcceptCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// accept() is better to be replaced by accept4().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-accept.html
+class CloexecAcceptCheck : public CloexecCheck {
+public:
+  CloexecAcceptCheck(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecAcceptCheck.cpp
@@ -0,0 +1,47 @@
+//===--- CloexecAcceptCheck.cpp - clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecAcceptCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecAcceptCheck::registerMatchers(MatchFinder *Finder) {
+  auto SockAddrPointerType =
+  hasType(pointsTo(recordDecl(isStruct(), hasName("sockaddr";
+  auto SockLenPointerType = hasType(pointsTo(namedDecl(hasName("socklen_t";
+
+  registerMatchersImpl(Finder,
+   functionDecl(returns(isInteger()), hasName("accept"),
+hasParameter(0, hasType(isInteger())),
+ 

[PATCH] D35362: [clang-tidy] Add a close-on-exec check on accept() in Android module.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 111377.

https://reviews.llvm.org/D35362

Files:
  clang-tidy/android/AndroidTidyModule.cpp
  clang-tidy/android/CMakeLists.txt
  clang-tidy/android/CloexecAcceptCheck.cpp
  clang-tidy/android/CloexecAcceptCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/android-cloexec-accept.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/android-cloexec-accept.cpp

Index: test/clang-tidy/android-cloexec-accept.cpp
===
--- test/clang-tidy/android-cloexec-accept.cpp
+++ test/clang-tidy/android-cloexec-accept.cpp
@@ -0,0 +1,28 @@
+// RUN: %check_clang_tidy %s android-cloexec-accept %t
+
+struct sockaddr {};
+typedef int socklen_t;
+#define NULL 0
+
+extern "C" int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+
+void f() {
+  accept(0, NULL, NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer accept4() to accept() because accept4() allows SOCK_CLOEXEC [android-cloexec-accept]
+  // CHECK-FIXES: accept4(0, NULL, NULL, SOCK_CLOEXEC);
+}
+
+namespace i {
+int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+void g() {
+  accept(0, NULL, NULL);
+}
+} // namespace i
+
+class C {
+public:
+  int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
+  void h() {
+accept(0, NULL, NULL);
+  }
+};
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -4,6 +4,7 @@
 =
 
 .. toctree::
+   android-cloexec-accept
android-cloexec-creat
android-cloexec-dup
android-cloexec-fopen
Index: docs/clang-tidy/checks/android-cloexec-accept.rst
===
--- docs/clang-tidy/checks/android-cloexec-accept.rst
+++ docs/clang-tidy/checks/android-cloexec-accept.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - android-cloexec-accept
+
+android-cloexec-accept
+==
+
+The usage of ``accept()`` is not recommended, it's better to use ``accept4()``.
+Without this flag, an opened sensitive file descriptor would remain open across
+a fork+exec to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  accept(sockfd, addr, addrlen);
+
+  // becomes
+
+  accept4(sockfd, addr, addrlen, SOCK_CLOEXEC);
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -70,6 +70,11 @@
   ``AllowConditionalIntegerCasts`` -> ``AllowIntegerConditions``,
   ``AllowConditionalPointerCasts`` -> ``AllowPointerConditions``.
 
+- New `android-cloexec-accept
+  `_ check
+
+  Detects usage of ``accept()``.
+
 - New `android-cloexec-dup
   `_ check
 
Index: clang-tidy/android/CloexecAcceptCheck.h
===
--- clang-tidy/android/CloexecAcceptCheck.h
+++ clang-tidy/android/CloexecAcceptCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecAcceptCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// accept() is better to be replaced by accept4().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-accept.html
+class CloexecAcceptCheck : public CloexecCheck {
+public:
+  CloexecAcceptCheck(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
Index: clang-tidy/android/CloexecAcceptCheck.cpp
===
--- clang-tidy/android/CloexecAcceptCheck.cpp
+++ clang-tidy/android/CloexecAcceptCheck.cpp
@@ -0,0 +1,47 @@
+//===--- CloexecAcceptCheck.cpp - clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include 

[PATCH] D35362: [clang-tidy] Add a close-on-exec check on accept() in Android module.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh commandeered this revision.
chh added a reviewer: yawanng.
chh added inline comments.



Comment at: clang-tidy/android/CloexecAcceptCheck.cpp:42
+  "prefer accept4() to accept() because accept4() allows SOCK_CLOEXEC",
+  /*FixMsg=*/ReplacementText);
+}

alexfh wrote:
> Two minor issues here:
> 1. `FixMsg` name is misleading, specifically the "Msg" part, since it's not a 
> message.
> 2. there's no need to use an argument comment, where it's clear what the 
> actual argument's meaning is. E.g. `ReplacementText` is pretty clear on its 
> own. As is the warning message above.
Done.


https://reviews.llvm.org/D35362



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36761: [clang-tidy] Use CloexecCheck as base class.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311020: [clang-tidy] Use CloexecCheck as base class. 
(authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D36761?vs=111372=111373#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36761

Files:
  clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
  clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.h
  clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.h
  clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.h
  clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h

Index: clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
@@ -8,7 +8,6 @@
 //===--===//
 
 #include "CloexecSocketCheck.h"
-#include "../utils/ASTUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -21,35 +20,16 @@
 static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
 
 void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
-   hasName("socket"),
-   hasParameter(0, hasType(isInteger())),
-   hasParameter(1, hasType(isInteger())),
-   hasParameter(2, hasType(isInteger(
-  .bind("funcDecl")))
-  .bind("socketFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(isInteger()),
+hasName("socket"),
+hasParameter(0, hasType(isInteger())),
+hasParameter(1, hasType(isInteger())),
+hasParameter(2, hasType(isInteger();
 }
 
 void CloexecSocketCheck::check(const MatchFinder::MatchResult ) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager  = *Result.SourceManager;
-
-  if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
- Result.Context->getLangOpts(), SOCK_CLOEXEC))
-return;
-
-  SourceLocation EndLoc =
-  Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
- Result.Context->getLangOpts());
-
-  diag(EndLoc, "%0 should use %1 where possible")
-  << FD << SOCK_CLOEXEC
-  << FixItHint::CreateInsertion(EndLoc,
-(Twine(" | ") + SOCK_CLOEXEC).str());
+  insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
 }
 
 } // namespace android
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
@@ -90,6 +90,12 @@
   /// Helper function to get the spelling of a particular argument.
   StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult ,
int N) const;
+
+  /// Binding name of the FuncDecl of a function call.
+  static constexpr char FuncDeclBindingStr[] = "funcDecl";
+
+  /// Binding name of the function call expression.
+  static constexpr char FuncBindingStr[] = "func";
 };
 
 } // namespace android
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
@@ -20,10 +20,6 @@
 namespace android {
 
 namespace {
-
-const char *const FuncDeclBindingStr = "funcDecl";
-const char *const FuncBindingStr = "func";
-
 // Helper function to form the correct string mode for Type3.
 // Build the replace text. If it's string constant, add  directly in the
 // end of the string. Else, add .
@@ -41,6 +37,10 @@
 }
 } // namespace
 
+constexpr char CloexecCheck::FuncDeclBindingStr[];
+
+constexpr char CloexecCheck::FuncBindingStr[];
+
 void CloexecCheck::registerMatchersImpl(
 MatchFinder *Finder, internal::Matcher Function) {
   // We assume all the checked 

[PATCH] D36761: [clang-tidy] Use CloexecCheck as base class.

2017-08-16 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 111372.
chh marked 3 inline comments as done.

https://reviews.llvm.org/D36761

Files:
  clang-tidy/android/CloexecCheck.cpp
  clang-tidy/android/CloexecCheck.h
  clang-tidy/android/CloexecCreatCheck.cpp
  clang-tidy/android/CloexecCreatCheck.h
  clang-tidy/android/CloexecFopenCheck.cpp
  clang-tidy/android/CloexecFopenCheck.h
  clang-tidy/android/CloexecOpenCheck.cpp
  clang-tidy/android/CloexecOpenCheck.h
  clang-tidy/android/CloexecSocketCheck.cpp
  clang-tidy/android/CloexecSocketCheck.h

Index: clang-tidy/android/CloexecSocketCheck.h
===
--- clang-tidy/android/CloexecSocketCheck.h
+++ clang-tidy/android/CloexecSocketCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,10 +20,10 @@
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
-class CloexecSocketCheck : public ClangTidyCheck {
+class CloexecSocketCheck : public CloexecCheck {
 public:
   CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecSocketCheck.cpp
===
--- clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tidy/android/CloexecSocketCheck.cpp
@@ -8,7 +8,6 @@
 //===--===//
 
 #include "CloexecSocketCheck.h"
-#include "../utils/ASTUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -21,35 +20,16 @@
 static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
 
 void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
-   hasName("socket"),
-   hasParameter(0, hasType(isInteger())),
-   hasParameter(1, hasType(isInteger())),
-   hasParameter(2, hasType(isInteger(
-  .bind("funcDecl")))
-  .bind("socketFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(isInteger()),
+hasName("socket"),
+hasParameter(0, hasType(isInteger())),
+hasParameter(1, hasType(isInteger())),
+hasParameter(2, hasType(isInteger();
 }
 
 void CloexecSocketCheck::check(const MatchFinder::MatchResult ) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager  = *Result.SourceManager;
-
-  if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
- Result.Context->getLangOpts(), SOCK_CLOEXEC))
-return;
-
-  SourceLocation EndLoc =
-  Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
- Result.Context->getLangOpts());
-
-  diag(EndLoc, "%0 should use %1 where possible")
-  << FD << SOCK_CLOEXEC
-  << FixItHint::CreateInsertion(EndLoc,
-(Twine(" | ") + SOCK_CLOEXEC).str());
+  insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
 }
 
 } // namespace android
Index: clang-tidy/android/CloexecOpenCheck.h
===
--- clang-tidy/android/CloexecOpenCheck.h
+++ clang-tidy/android/CloexecOpenCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -25,10 +25,10 @@
 ///
 /// Only the symbolic 'O_CLOEXEC' macro definition is checked, not the concrete
 /// value.
-class CloexecOpenCheck : public ClangTidyCheck {
+class CloexecOpenCheck : public CloexecCheck {
 public:
   CloexecOpenCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecOpenCheck.cpp
===
--- 

[PATCH] D36761: [clang-tidy] Use CloexecCheck as base class.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 111243.
chh edited the summary of this revision.

https://reviews.llvm.org/D36761

Files:
  clang-tidy/android/CloexecCheck.cpp
  clang-tidy/android/CloexecCheck.h
  clang-tidy/android/CloexecCreatCheck.cpp
  clang-tidy/android/CloexecCreatCheck.h
  clang-tidy/android/CloexecFopenCheck.cpp
  clang-tidy/android/CloexecFopenCheck.h
  clang-tidy/android/CloexecOpenCheck.cpp
  clang-tidy/android/CloexecOpenCheck.h
  clang-tidy/android/CloexecSocketCheck.cpp
  clang-tidy/android/CloexecSocketCheck.h

Index: clang-tidy/android/CloexecSocketCheck.h
===
--- clang-tidy/android/CloexecSocketCheck.h
+++ clang-tidy/android/CloexecSocketCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,10 +20,10 @@
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
-class CloexecSocketCheck : public ClangTidyCheck {
+class CloexecSocketCheck : public CloexecCheck {
 public:
   CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecSocketCheck.cpp
===
--- clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tidy/android/CloexecSocketCheck.cpp
@@ -8,7 +8,6 @@
 //===--===//
 
 #include "CloexecSocketCheck.h"
-#include "../utils/ASTUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -21,35 +20,16 @@
 static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
 
 void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
-   hasName("socket"),
-   hasParameter(0, hasType(isInteger())),
-   hasParameter(1, hasType(isInteger())),
-   hasParameter(2, hasType(isInteger(
-  .bind("funcDecl")))
-  .bind("socketFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(isInteger()),
+hasName("socket"),
+hasParameter(0, hasType(isInteger())),
+hasParameter(1, hasType(isInteger())),
+hasParameter(2, hasType(isInteger();
 }
 
 void CloexecSocketCheck::check(const MatchFinder::MatchResult ) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager  = *Result.SourceManager;
-
-  if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
- Result.Context->getLangOpts(), SOCK_CLOEXEC))
-return;
-
-  SourceLocation EndLoc =
-  Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
- Result.Context->getLangOpts());
-
-  diag(EndLoc, "%0 should use %1 where possible")
-  << FD << SOCK_CLOEXEC
-  << FixItHint::CreateInsertion(EndLoc,
-(Twine(" | ") + SOCK_CLOEXEC).str());
+  insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
 }
 
 } // namespace android
Index: clang-tidy/android/CloexecOpenCheck.h
===
--- clang-tidy/android/CloexecOpenCheck.h
+++ clang-tidy/android/CloexecOpenCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -25,10 +25,10 @@
 ///
 /// Only the symbolic 'O_CLOEXEC' macro definition is checked, not the concrete
 /// value.
-class CloexecOpenCheck : public ClangTidyCheck {
+class CloexecOpenCheck : public CloexecCheck {
 public:
   CloexecOpenCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecOpenCheck.cpp
===
--- 

[PATCH] D36755: [clang-tidy] Use CloexecCheck as base class of CloexecCreatCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh abandoned this revision.
chh added a comment.

Included in https://reviews.llvm.org/D36761.


https://reviews.llvm.org/D36755



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36756: [clang-tidy] Use CloexecCheck as base class of CloexecSocketCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh abandoned this revision.
chh added a comment.

Included in https://reviews.llvm.org/D36761.


https://reviews.llvm.org/D36756



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36759: [clang-tidy] Use CloexecCheck as base class of CloexecFopenCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh abandoned this revision.
chh added a comment.

Included in  https://reviews.llvm.org/D36761.


https://reviews.llvm.org/D36759



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36759: [clang-tidy] Use CloexecCheck as base class of CloexecFopenCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Okay, 3 changes are combined into https://reviews.llvm.org/D36761.


https://reviews.llvm.org/D36759



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36761: [clang-tidy] Use CloexecCheck as base class.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.

Simplify registerMatchers and check functions in CloexecCreatCheck,
CloexecSocketCheck, and CloexecFopenCheck.


https://reviews.llvm.org/D36761

Files:
  clang-tidy/android/CloexecCreatCheck.cpp
  clang-tidy/android/CloexecCreatCheck.h
  clang-tidy/android/CloexecFopenCheck.cpp
  clang-tidy/android/CloexecFopenCheck.h
  clang-tidy/android/CloexecSocketCheck.cpp
  clang-tidy/android/CloexecSocketCheck.h

Index: clang-tidy/android/CloexecSocketCheck.h
===
--- clang-tidy/android/CloexecSocketCheck.h
+++ clang-tidy/android/CloexecSocketCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,10 +20,10 @@
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
-class CloexecSocketCheck : public ClangTidyCheck {
+class CloexecSocketCheck : public CloexecCheck {
 public:
   CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecSocketCheck.cpp
===
--- clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tidy/android/CloexecSocketCheck.cpp
@@ -8,7 +8,6 @@
 //===--===//
 
 #include "CloexecSocketCheck.h"
-#include "../utils/ASTUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -21,35 +20,16 @@
 static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
 
 void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
-   hasName("socket"),
-   hasParameter(0, hasType(isInteger())),
-   hasParameter(1, hasType(isInteger())),
-   hasParameter(2, hasType(isInteger(
-  .bind("funcDecl")))
-  .bind("socketFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(isInteger()),
+hasName("socket"),
+hasParameter(0, hasType(isInteger())),
+hasParameter(1, hasType(isInteger())),
+hasParameter(2, hasType(isInteger();
 }
 
 void CloexecSocketCheck::check(const MatchFinder::MatchResult ) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager  = *Result.SourceManager;
-
-  if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
- Result.Context->getLangOpts(), SOCK_CLOEXEC))
-return;
-
-  SourceLocation EndLoc =
-  Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
- Result.Context->getLangOpts());
-
-  diag(EndLoc, "%0 should use %1 where possible")
-  << FD << SOCK_CLOEXEC
-  << FixItHint::CreateInsertion(EndLoc,
-(Twine(" | ") + SOCK_CLOEXEC).str());
+  insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
 }
 
 } // namespace android
Index: clang-tidy/android/CloexecFopenCheck.h
===
--- clang-tidy/android/CloexecFopenCheck.h
+++ clang-tidy/android/CloexecFopenCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -23,10 +23,10 @@
 /// constant propagation.
 ///
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-fopen.html
-class CloexecFopenCheck : public ClangTidyCheck {
+class CloexecFopenCheck : public CloexecCheck {
 public:
   CloexecFopenCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecFopenCheck.cpp
===
--- clang-tidy/android/CloexecFopenCheck.cpp
+++ 

[PATCH] D36759: [clang-tidy] Use CloexecCheck as base class of CloexecFopenCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Eugene, do you mean combining this one,  https://reviews.llvm.org/D36756, and 
https://reviews.llvm.org/D36755 into one?
I don't mind either way.


https://reviews.llvm.org/D36759



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36759: [clang-tidy] Use CloexecCheck as base class of CloexecFopenCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.

Simplify registerMatchers and check functions in CloexecFopenCheck.


https://reviews.llvm.org/D36759

Files:
  clang-tidy/android/CloexecFopenCheck.cpp
  clang-tidy/android/CloexecFopenCheck.h


Index: clang-tidy/android/CloexecFopenCheck.h
===
--- clang-tidy/android/CloexecFopenCheck.h
+++ clang-tidy/android/CloexecFopenCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -23,10 +23,10 @@
 /// constant propagation.
 ///
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-fopen.html
-class CloexecFopenCheck : public ClangTidyCheck {
+class CloexecFopenCheck : public CloexecCheck {
 public:
   CloexecFopenCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecFopenCheck.cpp
===
--- clang-tidy/android/CloexecFopenCheck.cpp
+++ clang-tidy/android/CloexecFopenCheck.cpp
@@ -18,55 +18,17 @@
 namespace tidy {
 namespace android {
 
-namespace {
-static const char MODE = 'e';
-
-// Build the replace text. If it's string constant, add 'e' directly in the end
-// of the string. Else, add "e".
-std::string BuildReplaceText(const Expr *Arg, const SourceManager ,
- const LangOptions ) {
-  if (Arg->getLocStart().isMacroID())
-return (Lexer::getSourceText(
-CharSourceRange::getTokenRange(Arg->getSourceRange()), SM,
-LangOpts) +
-" \"" + Twine(MODE) + "\"")
-.str();
-
-  StringRef SR = cast(Arg->IgnoreParenCasts())->getString();
-  return ("\"" + SR + Twine(MODE) + "\"").str();
-}
-} // namespace
-
 void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) {
   auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
-
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(asString("FILE *")),
-   hasName("fopen"),
-   hasParameter(0, CharPointerType),
-   hasParameter(1, CharPointerType))
-  .bind("funcDecl")))
-  .bind("fopenFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(asString("FILE *")),
+hasName("fopen"),
+hasParameter(0, CharPointerType),
+hasParameter(1, CharPointerType)));
 }
 
 void CloexecFopenCheck::check(const MatchFinder::MatchResult ) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("fopenFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *ModeArg = MatchedCall->getArg(1);
-
-  // Check if the 'e' may be in the mode string.
-  const auto *ModeStr = dyn_cast(ModeArg->IgnoreParenCasts());
-  if (!ModeStr || (ModeStr->getString().find(MODE) != StringRef::npos))
-return;
-
-  const std::string  = BuildReplaceText(
-  ModeArg, *Result.SourceManager, Result.Context->getLangOpts());
-
-  diag(ModeArg->getLocStart(), "use %0 mode 'e' to set O_CLOEXEC")
-  << FD
-  << FixItHint::CreateReplacement(ModeArg->getSourceRange(),
-  ReplacementText);
+  insertStringFlag(Result, 'e', 1);
 }
 
 } // namespace android


Index: clang-tidy/android/CloexecFopenCheck.h
===
--- clang-tidy/android/CloexecFopenCheck.h
+++ clang-tidy/android/CloexecFopenCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -23,10 +23,10 @@
 /// constant propagation.
 ///
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-fopen.html
-class CloexecFopenCheck : public ClangTidyCheck {
+class CloexecFopenCheck : public CloexecCheck {
 public:
   CloexecFopenCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecFopenCheck.cpp
===
--- clang-tidy/android/CloexecFopenCheck.cpp
+++ clang-tidy/android/CloexecFopenCheck.cpp
@@ -18,55 +18,17 @@
 

[PATCH] D36756: [clang-tidy] Use CloexecCheck as base class of CloexecSocketCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.

Simplify registerMatchers and check functions in CloexecSocketCheck.


https://reviews.llvm.org/D36756

Files:
  clang-tidy/android/CloexecSocketCheck.cpp
  clang-tidy/android/CloexecSocketCheck.h


Index: clang-tidy/android/CloexecSocketCheck.h
===
--- clang-tidy/android/CloexecSocketCheck.h
+++ clang-tidy/android/CloexecSocketCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,10 +20,10 @@
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
-class CloexecSocketCheck : public ClangTidyCheck {
+class CloexecSocketCheck : public CloexecCheck {
 public:
   CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecSocketCheck.cpp
===
--- clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tidy/android/CloexecSocketCheck.cpp
@@ -8,7 +8,6 @@
 
//===--===//
 
 #include "CloexecSocketCheck.h"
-#include "../utils/ASTUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -21,35 +20,16 @@
 static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
 
 void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
-   hasName("socket"),
-   hasParameter(0, hasType(isInteger())),
-   hasParameter(1, hasType(isInteger())),
-   hasParameter(2, hasType(isInteger(
-  .bind("funcDecl")))
-  .bind("socketFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(isInteger()),
+hasName("socket"),
+hasParameter(0, hasType(isInteger())),
+hasParameter(1, hasType(isInteger())),
+hasParameter(2, hasType(isInteger();
 }
 
 void CloexecSocketCheck::check(const MatchFinder::MatchResult ) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager  = *Result.SourceManager;
-
-  if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
- Result.Context->getLangOpts(), SOCK_CLOEXEC))
-return;
-
-  SourceLocation EndLoc =
-  Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
- Result.Context->getLangOpts());
-
-  diag(EndLoc, "%0 should use %1 where possible")
-  << FD << SOCK_CLOEXEC
-  << FixItHint::CreateInsertion(EndLoc,
-(Twine(" | ") + SOCK_CLOEXEC).str());
+  insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
 }
 
 } // namespace android


Index: clang-tidy/android/CloexecSocketCheck.h
===
--- clang-tidy/android/CloexecSocketCheck.h
+++ clang-tidy/android/CloexecSocketCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,10 +20,10 @@
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
-class CloexecSocketCheck : public ClangTidyCheck {
+class CloexecSocketCheck : public CloexecCheck {
 public:
   CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecSocketCheck.cpp
===
--- clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tidy/android/CloexecSocketCheck.cpp
@@ -8,7 +8,6 @@
 //===--===//
 
 #include "CloexecSocketCheck.h"
-#include "../utils/ASTUtils.h"
 

[PATCH] D36755: [clang-tidy] Use CloexecCheck as base class of CloexecCreatCheck.

2017-08-15 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.

Simplify registerMatchers and check functions in CloexecCreatCheck.


https://reviews.llvm.org/D36755

Files:
  clang-tidy/android/CloexecCreatCheck.cpp
  clang-tidy/android/CloexecCreatCheck.h


Index: clang-tidy/android/CloexecCreatCheck.h
===
--- clang-tidy/android/CloexecCreatCheck.h
+++ clang-tidy/android/CloexecCreatCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,10 +20,10 @@
 /// Find the usage of creat() and redirect user to use open().
 
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-creat.html
-class CloexecCreatCheck : public ClangTidyCheck {
+class CloexecCreatCheck : public CloexecCheck {
 public:
   CloexecCreatCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecCreatCheck.cpp
===
--- clang-tidy/android/CloexecCreatCheck.cpp
+++ clang-tidy/android/CloexecCreatCheck.cpp
@@ -10,7 +10,6 @@
 #include "CloexecCreatCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -21,37 +20,22 @@
 void CloexecCreatCheck::registerMatchers(MatchFinder *Finder) {
   auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
   auto MODETType = hasType(namedDecl(hasName("mode_t")));
-
-  Finder->addMatcher(
-  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
-   hasName("creat"),
-   hasParameter(0, CharPointerType),
-   hasParameter(1, MODETType))
-  .bind("funcDecl")))
-  .bind("creatFn"),
-  this);
+  registerMatchersImpl(Finder,
+   functionDecl(isExternC(), returns(isInteger()),
+hasName("creat"),
+hasParameter(0, CharPointerType),
+hasParameter(1, MODETType)));
 }
 
 void CloexecCreatCheck::check(const MatchFinder::MatchResult ) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("creatFn");
-  const SourceManager  = *Result.SourceManager;
-
   const std::string  =
-  (Twine("open (") +
-   Lexer::getSourceText(CharSourceRange::getTokenRange(
-MatchedCall->getArg(0)->getSourceRange()),
-SM, Result.Context->getLangOpts()) +
+  (Twine("open (") + getSpellingArg(Result, 0) +
", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, " +
-   Lexer::getSourceText(CharSourceRange::getTokenRange(
-MatchedCall->getArg(1)->getSourceRange()),
-SM, Result.Context->getLangOpts()) +
-   ")")
+   getSpellingArg(Result, 1) + ")")
   .str();
-
-  diag(MatchedCall->getLocStart(),
-   "prefer open() to creat() because open() allows O_CLOEXEC")
-  << FixItHint::CreateReplacement(MatchedCall->getSourceRange(),
-  ReplacementText);
+  replaceFunc(Result,
+  "prefer open() to creat() because open() allows O_CLOEXEC",
+  ReplacementText);
 }
 
 } // namespace android


Index: clang-tidy/android/CloexecCreatCheck.h
===
--- clang-tidy/android/CloexecCreatCheck.h
+++ clang-tidy/android/CloexecCreatCheck.h
@@ -10,7 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
 
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -20,10 +20,10 @@
 /// Find the usage of creat() and redirect user to use open().
 
 /// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-creat.html
-class CloexecCreatCheck : public ClangTidyCheck {
+class CloexecCreatCheck : public CloexecCheck {
 public:
   CloexecCreatCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : CloexecCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 };
Index: clang-tidy/android/CloexecCreatCheck.cpp
===
--- clang-tidy/android/CloexecCreatCheck.cpp
+++ clang-tidy/android/CloexecCreatCheck.cpp
@@ -10,7 +10,6 @@
 

[PATCH] D35743: [clang-format] Handle Structured binding declaration in C++17

2017-08-14 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

Daniel, Manuel, I will take over this CL since Yan has finished his internship 
at Google.,
Yan's latest patch to tryToParseLambda looks acceptable to me.
I think it should take care of new kw_auto in additional to kw_new, ke_delete, 
etc.

Could you suggest if there is any better way to handle the new syntax?
Thanks.


https://reviews.llvm.org/D35743



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35368: [clang-tidy] Add a close-on-exec check on inotify_init1() in Android module.

2017-08-14 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310863: [clang-tidy] Add a close-on-exec check on 
inotify_init1() in Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35368?vs=110750=111033#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35368

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInit1Check.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInit1Check.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-inotify-init1.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-inotify-init1.cpp

Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -98,6 +98,12 @@
   Ensures that all exception will be instances of ``std::exception`` and classes 
   that are derived from it.
 
+- New `android-cloexec-inotify-init1
+  `_ check
+
+  Checks if the required file flag ``IN_CLOEXEC`` is present in the argument of
+  ``inotify_init1()``.
+
 - New `readability-static-accessed-through-instance
   `_ check
 
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
@@ -8,6 +8,7 @@
android-cloexec-dup
android-cloexec-fopen
android-cloexec-inotify-init
+   android-cloexec-inotify-init1
android-cloexec-memfd-create
android-cloexec-open
android-cloexec-socket
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-inotify-init1.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-inotify-init1.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-inotify-init1.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - android-cloexec-inotify-init1
+
+android-cloexec-inotify-init1
+=
+
+``inotify_init1()`` should include ``IN_CLOEXEC`` in its type argument to avoid the
+file descriptor leakage. Without this flag, an opened sensitive file would
+remain open across a fork+exec to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  inotify_init1(IN_NONBLOCK);
+
+  // becomes
+
+  inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
Index: clang-tools-extra/trunk/test/clang-tidy/android-cloexec-inotify-init1.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/android-cloexec-inotify-init1.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/android-cloexec-inotify-init1.cpp
@@ -0,0 +1,64 @@
+// RUN: %check_clang_tidy %s android-cloexec-inotify-init1 %t
+
+#define IN_NONBLOCK 1
+#define __O_CLOEXEC 3
+#define IN_CLOEXEC __O_CLOEXEC
+#define TEMP_FAILURE_RETRY(exp) \
+  ({\
+int _rc;\
+do {\
+  _rc = (exp);  \
+} while (_rc == -1);\
+  })
+
+extern "C" int inotify_init1(int flags);
+
+void a() {
+  inotify_init1(IN_NONBLOCK);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: 'inotify_init1' should use IN_CLOEXEC where possible [android-cloexec-inotify-init1]
+  // CHECK-FIXES: inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
+  TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK));
+  // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: 'inotify_init1'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
+}
+
+void f() {
+  inotify_init1(0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'inotify_init1'
+  // CHECK-FIXES: inotify_init1(IN_CLOEXEC);
+  TEMP_FAILURE_RETRY(inotify_init1(0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: 'inotify_init1'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(inotify_init1(IN_CLOEXEC));
+
+  int flag = 1;
+  inotify_init1(flag);
+  TEMP_FAILURE_RETRY(inotify_init1(flag));
+}
+
+namespace i {
+int inotify_init1(int flags);
+
+void d() {
+  inotify_init1(IN_NONBLOCK);
+  TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK));
+}
+
+} // namespace i
+
+void e() {
+  inotify_init1(IN_CLOEXEC);
+  TEMP_FAILURE_RETRY(inotify_init1(IN_CLOEXEC));
+  inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
+  TEMP_FAILURE_RETRY(inotify_init1(IN_NONBLOCK | IN_CLOEXEC));
+}
+
+class G {
+public:
+  int inotify_init1(int flags);
+  void d() {
+inotify_init1(IN_CLOEXEC);
+

[PATCH] D35370: [clang-tidy] Add a close-on-exec check on inotify_init() in Android module.

2017-08-14 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310861: [clang-tidy] Add a close-on-exec check on 
inotify_init() in Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35370?vs=110749=111028#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35370

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-inotify-init.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-inotify-init.cpp

Index: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "CloexecCreatCheck.h"
 #include "CloexecDupCheck.h"
 #include "CloexecFopenCheck.h"
+#include "CloexecInotifyInitCheck.h"
 #include "CloexecMemfdCreateCheck.h"
 #include "CloexecOpenCheck.h"
 #include "CloexecSocketCheck.h"
@@ -30,6 +31,8 @@
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-dup");
 CheckFactories.registerCheck("android-cloexec-fopen");
+CheckFactories.registerCheck(
+"android-cloexec-inotify-init");
 CheckFactories.registerCheck(
 "android-cloexec-memfd-create");
 CheckFactories.registerCheck("android-cloexec-open");
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecInotifyInitCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// inotify_init() is better to be replaced by inotify_init1().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-inotify-init.html
+class CloexecInotifyInitCheck : public CloexecCheck {
+public:
+  CloexecInotifyInitCheck(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
@@ -0,0 +1,34 @@
+//===--- CloexecInotifyInitCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecInotifyInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecInotifyInitCheck::registerMatchers(MatchFinder *Finder) {
+  registerMatchersImpl(
+  Finder, functionDecl(returns(isInteger()), hasName("inotify_init")));
+}
+
+void CloexecInotifyInitCheck::check(const MatchFinder::MatchResult ) {
+  replaceFunc(Result, /*WarningMsg=*/
+  "prefer inotify_init() to inotify_init1() "
+  "because inotify_init1() allows IN_CLOEXEC",
+  /*FixMsg=*/"inotify_init1(IN_CLOEXEC)");
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt

[PATCH] D35364: [clang-tidy] Add a close-on-exec check on dup() in Android module.

2017-08-14 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310858: [clang-tidy] Add a close-on-exec check on dup() in 
Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35364?vs=110753=111021#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35364

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
  clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp

Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -70,6 +70,11 @@
   ``AllowConditionalIntegerCasts`` -> ``AllowIntegerConditions``,
   ``AllowConditionalPointerCasts`` -> ``AllowPointerConditions``.
 
+- New `android-cloexec-dup
+  `_ check
+
+  Detects usage of ``dup()``.
+
 - New `android-cloexec-memfd_create
   `_ check
 
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - android-cloexec-dup
+
+android-cloexec-dup
+===
+
+The usage of ``dup()`` is not recommended, it's better to use ``fcntl()``,
+which can set the close-on-exec flag. Otherwise, an opened sensitive file would
+remain open across a fork+exec to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  int fd = dup(oldfd);
+
+  // becomes
+
+  int fd = fcntl(oldfd, F_DUPFD_CLOEXEC);
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
@@ -5,6 +5,7 @@
 
 .. toctree::
android-cloexec-creat
+   android-cloexec-dup
android-cloexec-fopen
android-cloexec-memfd-create
android-cloexec-open
Index: clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s android-cloexec-dup %t
+
+extern "C" int dup(int oldfd);
+void f() {
+  dup(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer fcntl() to dup() because fcntl() allows F_DUPFD_CLOEXEC [android-cloexec-dup]
+  // CHECK-FIXES: fcntl(1, F_DUPFD_CLOEXEC);
+  int oldfd = 0;
+  dup(oldfd);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer
+  // CHECK-FIXES: fcntl(oldfd, F_DUPFD_CLOEXEC);
+}
+
+namespace i {
+int dup(int oldfd);
+void g() {
+  dup(0);
+  int oldfd = 1;
+  dup(oldfd);
+}
+} // namespace i
+
+class C {
+public:
+  int dup(int oldfd);
+  void h() {
+dup(0);
+int oldfd = 1;
+dup(oldfd);
+  }
+};
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
@@ -0,0 +1,38 @@
+//===--- CloexecDupCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecDupCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecDupCheck::registerMatchers(MatchFinder *Finder) {
+  registerMatchersImpl(Finder,
+   functionDecl(returns(isInteger()), hasName("dup"),
+hasParameter(0, hasType(isInteger();
+}
+
+void CloexecDupCheck::check(const MatchFinder::MatchResult ) {
+  const std::string  =
+  (Twine("fcntl(") + getSpellingArg(Result, 0) + ", 

[PATCH] D34114: [clang] Change the condition of unnecessary packed warning

2017-07-28 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

LGTM.
rsmith, srhines, akyrtzi, rtrieu, do you have any comment?


https://reviews.llvm.org/D34114



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34114: [clang] Change the condition of unnecessary packed warning

2017-07-28 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: lib/AST/RecordLayoutBuilder.cpp:1887
+// greater than the one after packing.
+if (Packed && UnpackedAlignment <= Alignment)
   Diag(D->getLocation(), diag::warn_unnecessary_packed)

chh wrote:
> With this change, UnpackedSize is unused and caused a warning about 
> unused-but-set-variable. Please use it or remove the variable.
> 
> I think UnpackedSizeInBits should be used somehow in the condition, because 
> bit fields can be affected by the packed attribute. Please add a few unit 
> test cases with bit fields. For example, the following cases showed that S21 
> is affected by packed, but got a wrong "unnecessary" warning after this 
> change.
> 
> 
> ```
> struct S21 {
>   unsigned char a:6;
>   unsigned char b:6;
> } __attribute__((packed, aligned(1)));
> struct S22 {
>   unsigned char a:6;
>   unsigned char b:6;
> } __attribute__((aligned(1)));
> struct S23 {
>   unsigned char a:6;
>   unsigned char b:6;
> };
> 
> ```
> Warnings:
> 
> ```
>   padding size of 'S21' with 4 bits to alignment boundary
>   packed attribute is unnecessary for 'S21'
>   padding struct 'S22' with 2 bits to align 'b'
>   padding size of 'S22' with 2 bits to alignment boundary
>   padding struct 'S23' with 2 bits to align 'b'
>   padding size of 'S23' with 2 bits to alignment boundary
> 
> ```
> 
I am still getting warning about unused-but-set-variable UnpackedSize.




Comment at: lib/AST/RecordLayoutBuilder.cpp:636
+  /// \brief the flag of field offset changing due to packed attribute.
+  bool IsFieldOffsetChangedWithPacked;
+

s/IsFieldOffsetChangedWithPacked/HasPackedField/




Comment at: lib/AST/RecordLayoutBuilder.cpp:1985
+ // If the offset of any field changed due to packed, then the packed is not
+ // necessary.
+ if (isPacked && Offset != UnpackedOffset) {

"then packed is not necessary" is incorrect.
Maybe this comment can be removed since the code is clear enough.




Comment at: test/CodeGenCXX/warn-padded-packed.cpp:152
+void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*, 
S14*, S15*,
+   S16*, S17*, S18*, S19*, S20*, S21*, S22*, S23*, S24*, S25*, S26*, 
S27*){}

Please wrap line 150, 151, 152 to less than 80 chars per line.
The only exceptions in this file are the 'expected-warning' lines.
 


https://reviews.llvm.org/D34114



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34114: [clang] Change the condition of unnecessary packed warning

2017-07-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: lib/AST/RecordLayoutBuilder.cpp:1887
+// greater than the one after packing.
+if (Packed && UnpackedAlignment <= Alignment)
   Diag(D->getLocation(), diag::warn_unnecessary_packed)

With this change, UnpackedSize is unused and caused a warning about 
unused-but-set-variable. Please use it or remove the variable.

I think UnpackedSizeInBits should be used somehow in the condition, because bit 
fields can be affected by the packed attribute. Please add a few unit test 
cases with bit fields. For example, the following cases showed that S21 is 
affected by packed, but got a wrong "unnecessary" warning after this change.


```
struct S21 {
  unsigned char a:6;
  unsigned char b:6;
} __attribute__((packed, aligned(1)));
struct S22 {
  unsigned char a:6;
  unsigned char b:6;
} __attribute__((aligned(1)));
struct S23 {
  unsigned char a:6;
  unsigned char b:6;
};

```
Warnings:

```
  padding size of 'S21' with 4 bits to alignment boundary
  packed attribute is unnecessary for 'S21'
  padding struct 'S22' with 2 bits to align 'b'
  padding size of 'S22' with 2 bits to alignment boundary
  padding struct 'S23' with 2 bits to align 'b'
  padding size of 'S23' with 2 bits to alignment boundary

```



https://reviews.llvm.org/D34114



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34114: [clang] Change the condition of unnecessary packed warning

2017-07-26 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: lib/AST/RecordLayoutBuilder.cpp:1888
-if (Packed && UnpackedAlignment > CharUnits::One() && 
-getSize() == UnpackedSize)
   Diag(D->getLocation(), diag::warn_unnecessary_packed)

Why not keeping the (getSize() == UnpackedSize) condition?



https://reviews.llvm.org/D34114



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >