[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] 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] 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: [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
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&id=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 @@
-// C

[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] 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: 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
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 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 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 cas

[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 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 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
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 EXIT_FAIL

[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] 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-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] 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] 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 &Line,
   const FormatToken &Left,
   const FormatToken &Right) {
+  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_pa

[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-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 &&x1 = y1;", getGoogleStyle());
+  verifyFormat("auto const &&x2 = y1;", getLLVMStyle());
+  verifyFormat("auto const &x1 = y2;", getGoogleStyle());
+  verifyFormat("auto const &x2 = y2;", getLLVMStyle());
+  verifyFormat("auto const &x1 = 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)) != (Right.is(T

[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-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-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&id=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] : some

[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

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

Android source is suppressing misc-noexcept-move-constructor warnings
because -fno-exceptions is used and Android does not like to add more
exception specific code.

It's not a big deal for Android to suppress this check one way or the other.
I don't mind reverting it, just curious why a compiler cannot assume noexcept 
under -fno-exceptions.


https://reviews.llvm.org/D34002



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


[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

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

Thanks for providing the ODR reason for Android -fno-exceptions users to change 
source code or suppress this warning themselves.


https://reviews.llvm.org/D34002



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


[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

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

I understood the mentioned ODR issue, which is useful for users to understand 
the compiler choice. For -fno-exceptions users, they should change source code 
to work with mixed cases, or just ignore mixed cases and suppress this warning.


https://reviews.llvm.org/D34002



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


[PATCH] D34633: [clang-tidy] Fix a bug in android-file-open-flag

2017-06-29 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh requested changes to this revision.
chh added a comment.
This revision now requires changes to proceed.

Please update the subject line and summary.
The new diff shows only the renaming of check name and file names.
Were the other changes for format and macro lost or are they
going to be in another change later?


https://reviews.llvm.org/D34633



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


[PATCH] D34633: [clang-tidy] Rename android-file-open-flag and fix a bug

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

I think you also need to change docs/clang-tidy/checks/list.rst.


https://reviews.llvm.org/D34633



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


[PATCH] D34913: [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-06-30 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh accepted this revision.
chh added a comment.
This revision is now accepted and ready to land.

LGTM. If nobody needs this during the long weekend, it's better to submit after 
the long weekend.


Repository:
  rL LLVM

https://reviews.llvm.org/D34913



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


[PATCH] D34114: [clang] A better format for unnecessary packed warning.

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

These warnings are triggered by -Wpadded -Wpacked
or clang-tidy's clang-diagnostic-packed check.
I agree that they should be ignored or suppressed in many cases.
What I am not sure is the amount of real positive cases.

I found it too tedious to suppress one warning per struct field,
and hence liked this CL to consolidate those per-field warnings
into one per struct type. With this change we can use one NOLINT to
suppress all such warnings of a struct type, in the header file.

One alternative for users is to ignore these checks or warnings
for the whole compilation unit. That has the risk of masking
out valid warnings to other packed struct types in the same
compilation unit. Since the types are defined in header files,
these warnings would need to be suppressed in all compilation
units that include those header files.

I am not against removing these warnings completely.
If not removed, I hope that we can consolidate multiple
per-field warnings to one at the struct type level.


Repository:
  rL LLVM

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] D35225: [clang-tidy] add regression test to performance-unnecessary-value-param

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

These tests should be added after https://bugs.llvm.org/show_bug.cgi?id=33734 
is fixed.


https://reviews.llvm.org/D35225



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


[PATCH] D35230: [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

2017-07-10 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.

Fix bug https://bugs.llvm.org/show_bug.cgi?id=33734


https://reviews.llvm.org/D35230

Files:
  lib/Frontend/TextDiagnostic.cpp


Index: lib/Frontend/TextDiagnostic.cpp
===
--- lib/Frontend/TextDiagnostic.cpp
+++ lib/Frontend/TextDiagnostic.cpp
@@ -1052,7 +1052,8 @@
   std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+   unsigned LineNo,
const SourceColumnMap &map,
ArrayRef Hints,
const SourceManager &SM,
@@ -1069,7 +1070,8 @@
   // code contains no newlines and is on the same line as the caret.
   std::pair HintLocInfo
 = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-  if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+  if (FID == HintLocInfo.first &&
+  LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
   StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) 
{
 // Insert the new code into the line just below the code
 // that the user wrote.
@@ -1105,9 +1107,6 @@
 
 PrevHintEndCol =
   HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
-  } else {
-FixItInsertionLine.clear();
-break;
   }
 }
   }
@@ -1222,7 +1221,7 @@
 }
 
 std::string FixItInsertionLine = buildFixItInsertionLine(
-LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
 
 // If the source line is too long for our terminal, select only the
 // "interesting" source region within that line.


Index: lib/Frontend/TextDiagnostic.cpp
===
--- lib/Frontend/TextDiagnostic.cpp
+++ lib/Frontend/TextDiagnostic.cpp
@@ -1052,7 +1052,8 @@
   std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+   unsigned LineNo,
const SourceColumnMap &map,
ArrayRef Hints,
const SourceManager &SM,
@@ -1069,7 +1070,8 @@
   // code contains no newlines and is on the same line as the caret.
   std::pair HintLocInfo
 = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-  if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+  if (FID == HintLocInfo.first &&
+  LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
   StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) {
 // Insert the new code into the line just below the code
 // that the user wrote.
@@ -1105,9 +1107,6 @@
 
 PrevHintEndCol =
   HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
-  } else {
-FixItInsertionLine.clear();
-break;
   }
 }
   }
@@ -1222,7 +1221,7 @@
 }
 
 std::string FixItInsertionLine = buildFixItInsertionLine(
-LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
 
 // If the source line is too long for our terminal, select only the
 // "interesting" source region within that line.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35230: [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

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

See https://reviews.llvm.org/D35225 for a test case.


https://reviews.llvm.org/D35230



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


[PATCH] D35230: [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

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



Comment at: lib/Frontend/TextDiagnostic.cpp:1109-1110
-  } else {
-FixItInsertionLine.clear();
-break;
   }

alexfh wrote:
> Did you figure out why the old code used to give up here? Why does your code 
> just continue?
I don't know. It does not make sense to me for the use cases I think should 
work.
Hints can contain suggested changes for different files and lines.
If those hints can be in any order, resetting FixItInsertLine and break from 
the loop would lose the collected line.



https://reviews.llvm.org/D35230



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


[PATCH] D35225: [clang-tidy] add regression test to performance-unnecessary-value-param

2017-07-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 106064.
chh marked 2 inline comments as done.

https://reviews.llvm.org/D35225

Files:
  test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
  test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
  test/clang-tidy/performance-unnecessary-value-param-header.cpp


Index: test/clang-tidy/performance-unnecessary-value-param-header.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param-header.cpp
+++ test/clang-tidy/performance-unnecessary-value-param-header.cpp
@@ -0,0 +1,18 @@
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- 
-std=c++11 -I %T
+// RUN: diff %T/header.h 
%S/Inputs/performance-unnecessary-value-param/header-fixed.h
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+  return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}
Index: test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
===
--- test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
+++ test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  ABC v1,   ABC v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   ABC v2); // line 15
Index: test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
===
--- test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
+++ test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  const ABC& v1,   const ABC& v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   const ABC& v2); // line 15


Index: test/clang-tidy/performance-unnecessary-value-param-header.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param-header.cpp
+++ test/clang-tidy/performance-unnecessary-value-param-header.cpp
@@ -0,0 +1,18 @@
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- -std=c++11 -I %T
+// RUN: diff %T/header.h %S/Inputs/performance-unnecessary-value-param/header-fixed.h
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+  return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}
Index: test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
===
--- test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
+++ test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  ABC v1,   ABC v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   ABC v2); // line 1

[PATCH] D35230: [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

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



Comment at: lib/Frontend/TextDiagnostic.cpp:1109-1110
-  } else {
-FixItInsertionLine.clear();
-break;
   }

chh wrote:
> alexfh wrote:
> > Did you figure out why the old code used to give up here? Why does your 
> > code just continue?
> I don't know. It does not make sense to me for the use cases I think should 
> work.
> Hints can contain suggested changes for different files and lines.
> If those hints can be in any order, resetting FixItInsertLine and break from 
> the loop would lose the collected line.
> 
I found the old code introduced in https://reviews.llvm.org/rL70656
to fix the problem in https://bugs.llvm.org/show_bug.cgi?id=4084
This change does not have the problem in PR4084.


```
$ cat /tmp/t.c
int f0(char *a, char *b) {
  return ("a" !=
  "b");
}

$ clang -Wall -fsyntax-only /tmp/t.c
/tmp/t.c:2:15: warning: result of comparison against a string literal is 
unspecified (use strncmp instead) [-Wstring-compare]
  return ("a" !=
  ~~~ ^
1 warning generated.

```


https://reviews.llvm.org/D35230



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


[PATCH] D35230: [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

2017-07-12 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307809: [clang] buildFixItInsertionLine should use Hints of 
the same FID and LineNo (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35230?vs=105937&id=106240#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35230

Files:
  cfe/trunk/lib/Frontend/TextDiagnostic.cpp


Index: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
===
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp
@@ -1052,7 +1052,8 @@
   std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+   unsigned LineNo,
const SourceColumnMap &map,
ArrayRef Hints,
const SourceManager &SM,
@@ -1069,7 +1070,8 @@
   // code contains no newlines and is on the same line as the caret.
   std::pair HintLocInfo
 = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-  if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+  if (FID == HintLocInfo.first &&
+  LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
   StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) 
{
 // Insert the new code into the line just below the code
 // that the user wrote.
@@ -1105,9 +1107,6 @@
 
 PrevHintEndCol =
   HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
-  } else {
-FixItInsertionLine.clear();
-break;
   }
 }
   }
@@ -1222,7 +1221,7 @@
 }
 
 std::string FixItInsertionLine = buildFixItInsertionLine(
-LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
 
 // If the source line is too long for our terminal, select only the
 // "interesting" source region within that line.


Index: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
===
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp
@@ -1052,7 +1052,8 @@
   std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+   unsigned LineNo,
const SourceColumnMap &map,
ArrayRef Hints,
const SourceManager &SM,
@@ -1069,7 +1070,8 @@
   // code contains no newlines and is on the same line as the caret.
   std::pair HintLocInfo
 = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-  if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+  if (FID == HintLocInfo.first &&
+  LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
   StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) {
 // Insert the new code into the line just below the code
 // that the user wrote.
@@ -1105,9 +1107,6 @@
 
 PrevHintEndCol =
   HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
-  } else {
-FixItInsertionLine.clear();
-break;
   }
 }
   }
@@ -1222,7 +1221,7 @@
 }
 
 std::string FixItInsertionLine = buildFixItInsertionLine(
-LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
 
 // If the source line is too long for our terminal, select only the
 // "interesting" source region within that line.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35225: [clang-tidy] add regression test to performance-unnecessary-value-param

2017-07-12 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307810: [clang-tidy] add regression test to 
performance-unnecessary-value-param (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35225?vs=106064&id=106241#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35225

Files:
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
  
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp


Index: 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
@@ -0,0 +1,18 @@
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- 
-std=c++11 -I %T
+// RUN: diff %T/header.h 
%S/Inputs/performance-unnecessary-value-param/header-fixed.h
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+  return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}
Index: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
===
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  const ABC& v1,   const ABC& v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   const ABC& v2); // line 15
Index: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
===
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  ABC v1,   ABC v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   ABC v2); // line 15


Index: clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
@@ -0,0 +1,18 @@
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- -std=c++11 -I %T
+// RUN: diff %T/header.h %S/Inputs/performance-unnecessary-value-param/header-fixed.h
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+  return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}
Index:

[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 &Result) 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 &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("creatFn");
-  const SourceManager &SM = *Result.SourceManager;
-
   const std::string &ReplacementText =
-  (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 &Result) override;
 };
Index: clang-tidy/android/CloexecCreatCheck.cpp
===
--- clang-tidy/android/CloexecCreatCheck.cpp
+++ clang-tidy/android/CloexecC

[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 &Result) 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 &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager &SM = *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 &Result) 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 "../uti

[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 &Result) 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 &SM,
- const LangOptions &LangOpts) {
-  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 &Result) {
-  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 &ReplacementText = 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 &Result) override;
 };
Index: clang-tidy/android/CloexecFopenCheck.cpp
===
--- clang-tidy/android/CloexecFopenCheck.cpp
+++ clang-tidy/android

[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] 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 &Result) 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 &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager &SM = *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 &Result) override;
 };
Index: clang-tidy/android/CloexecFopenCheck.cpp
===
--- clang-tidy/android/CloexecFopenCheck.cpp
+++ clang-tidy/and

[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] 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] 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] 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] 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 &Result) 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 &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager &SM = *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 &Result) override;
 };
Index: clang-tidy/android/CloexecOpenCheck.cpp
=

[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 &Result) 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 &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager &SM = *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 &Result) override;
 };
Index: clang-tidy/android/CloexecOpenCheck.cpp

[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&id=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 &Result) {
-  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
-  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
-  const Expr *FlagArg = MatchedCall->getArg(1);
-  SourceManager &SM = *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 &Result,
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 

[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] 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 &Result) 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
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&id=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 &CheckFactories) 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 &Result) 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(

[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&id=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 &Result) 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 &Result) {
+  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 "../Clan

[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&id=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 &Result) 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 &Result) {
+  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-acce

[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&id=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 &Result) 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 CloexecEpollCreateCheck::c

[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] 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] 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] D33103: [clang-tidy] TwineLocalCheck: add param # checking

2017-05-11 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

LGTM. Leave approval to bkramer.


https://reviews.llvm.org/D33103



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


[PATCH] D33430: [clang-tidy] Do not dereference a null BaseType

2017-05-22 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.
Herald added a subscriber: xazax.hun.

Check BaseType before dereference.
Simplified test case is derived from Android Open Source code.


https://reviews.llvm.org/D33430

Files:
  clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
  test/clang-tidy/misc-forwarding-reference-overload.cpp


Index: test/clang-tidy/misc-forwarding-reference-overload.cpp
===
--- test/clang-tidy/misc-forwarding-reference-overload.cpp
+++ test/clang-tidy/misc-forwarding-reference-overload.cpp
@@ -121,3 +121,25 @@
 private:
   Test6(const Test6 &rhs);
 };
+
+// Do not dereference a null BaseType.
+template  class result_of;
+template  class result_of<_Fp(_Args...)> { };
+template  using result_of_t = typename result_of<_Tp>::type;
+
+template  struct __overload;
+template 
+struct __overload<_Tp, _Types...> : __overload<_Types...> {
+  using __overload<_Types...>::operator();
+};
+
+template 
+using __best_match_t = typename 
result_of_t<__overload<_Types...>(_Tp&&)>::type;
+
+template 
+class variant {
+public:
+  template  >
+  constexpr variant(_Arg&& __arg) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+};
Index: clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
===
--- clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
+++ clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
@@ -40,6 +40,8 @@
   if (const auto *Dependent = BaseType->getAs()) {
 BaseType = Dependent->getQualifier()->getAsType();
   }
+  if (!BaseType)
+return false;
   if (CheckTemplate(BaseType->getAs())) {
 return true; // Case: enable_if_t< >.
   } else if (const auto *Elaborated = BaseType->getAs()) {


Index: test/clang-tidy/misc-forwarding-reference-overload.cpp
===
--- test/clang-tidy/misc-forwarding-reference-overload.cpp
+++ test/clang-tidy/misc-forwarding-reference-overload.cpp
@@ -121,3 +121,25 @@
 private:
   Test6(const Test6 &rhs);
 };
+
+// Do not dereference a null BaseType.
+template  class result_of;
+template  class result_of<_Fp(_Args...)> { };
+template  using result_of_t = typename result_of<_Tp>::type;
+
+template  struct __overload;
+template 
+struct __overload<_Tp, _Types...> : __overload<_Types...> {
+  using __overload<_Types...>::operator();
+};
+
+template 
+using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type;
+
+template 
+class variant {
+public:
+  template  >
+  constexpr variant(_Arg&& __arg) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors
+};
Index: clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
===
--- clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
+++ clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
@@ -40,6 +40,8 @@
   if (const auto *Dependent = BaseType->getAs()) {
 BaseType = Dependent->getQualifier()->getAsType();
   }
+  if (!BaseType)
+return false;
   if (CheckTemplate(BaseType->getAs())) {
 return true; // Case: enable_if_t< >.
   } else if (const auto *Elaborated = BaseType->getAs()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33430: [clang-tidy] Do not dereference a null BaseType

2017-05-23 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303645: [clang-tidy] Do not dereference a null BaseType 
(authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D33430?vs=99842&id=99929#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33430

Files:
  clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp


Index: 
clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
@@ -40,6 +40,8 @@
   if (const auto *Dependent = BaseType->getAs()) {
 BaseType = Dependent->getQualifier()->getAsType();
   }
+  if (!BaseType)
+return false;
   if (CheckTemplate(BaseType->getAs())) {
 return true; // Case: enable_if_t< >.
   } else if (const auto *Elaborated = BaseType->getAs()) {
Index: 
clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
@@ -121,3 +121,25 @@
 private:
   Test6(const Test6 &rhs);
 };
+
+// Do not dereference a null BaseType.
+template  class result_of;
+template  class result_of<_Fp(_Args...)> { };
+template  using result_of_t = typename result_of<_Tp>::type;
+
+template  struct __overload;
+template 
+struct __overload<_Tp, _Types...> : __overload<_Types...> {
+  using __overload<_Types...>::operator();
+};
+
+template 
+using __best_match_t = typename 
result_of_t<__overload<_Types...>(_Tp&&)>::type;
+
+template 
+class variant {
+public:
+  template  >
+  constexpr variant(_Arg&& __arg) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a 
forwarding reference can hide the copy and move constructors
+};


Index: clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/ForwardingReferenceOverloadCheck.cpp
@@ -40,6 +40,8 @@
   if (const auto *Dependent = BaseType->getAs()) {
 BaseType = Dependent->getQualifier()->getAsType();
   }
+  if (!BaseType)
+return false;
   if (CheckTemplate(BaseType->getAs())) {
 return true; // Case: enable_if_t< >.
   } else if (const auto *Elaborated = BaseType->getAs()) {
Index: clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-forwarding-reference-overload.cpp
@@ -121,3 +121,25 @@
 private:
   Test6(const Test6 &rhs);
 };
+
+// Do not dereference a null BaseType.
+template  class result_of;
+template  class result_of<_Fp(_Args...)> { };
+template  using result_of_t = typename result_of<_Tp>::type;
+
+template  struct __overload;
+template 
+struct __overload<_Tp, _Types...> : __overload<_Types...> {
+  using __overload<_Types...>::operator();
+};
+
+template 
+using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type;
+
+template 
+class variant {
+public:
+  template  >
+  constexpr variant(_Arg&& __arg) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors
+};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

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

LGTM, leave this to alexfh's approval.


Repository:
  rL LLVM

https://reviews.llvm.org/D34002



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


[PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

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

In https://reviews.llvm.org/D34002#775830, @alexfh wrote:

> IIUC, when `vector` (for a class `T` that has both move and copy 
> constructors) resizes, it will prefer move constructors, but only if they're 
> declared `noexcept`.  This is true even if `-fno-exceptions` is on. So I 
> don't think this check should depend on `-fno-exceptions`.


Should the compiler assume `noexcept` when -fno-exceptions is on?
That means move constructors should be preferred under -fno-exceptions, and 
this check would be unnecessary, right?


https://reviews.llvm.org/D34002



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


[PATCH] D31406: [clang-tidy] Reuse FileID in getLocation

2017-03-30 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 93499.
chh marked an inline comment as done.
chh added a comment.

Use getOrCreateFileID.


https://reviews.llvm.org/D31406

Files:
  clang-tidy/ClangTidy.cpp


Index: clang-tidy/ClangTidy.cpp
===
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -238,7 +238,7 @@
   return SourceLocation();
 
 const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);
-FileID ID = SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
+FileID ID = SourceMgr.getOrCreateFileID(File, SrcMgr::C_User);
 return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
   }
 


Index: clang-tidy/ClangTidy.cpp
===
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -238,7 +238,7 @@
   return SourceLocation();
 
 const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);
-FileID ID = SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
+FileID ID = SourceMgr.getOrCreateFileID(File, SrcMgr::C_User);
 return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31406: [clang-tidy] Reuse FileID in getLocation

2017-03-30 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299119: [clang-tidy] Reuse FileID in getLocation (authored 
by chh).

Changed prior to commit:
  https://reviews.llvm.org/D31406?vs=93499&id=93554#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31406

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


Index: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
@@ -238,7 +238,7 @@
   return SourceLocation();
 
 const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);
-FileID ID = SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
+FileID ID = SourceMgr.getOrCreateFileID(File, SrcMgr::C_User);
 return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
   }
 


Index: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
@@ -238,7 +238,7 @@
   return SourceLocation();
 
 const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);
-FileID ID = SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
+FileID ID = SourceMgr.getOrCreateFileID(File, SrcMgr::C_User);
 return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31406: [clang-tidy] Reuse FileID in getLocation

2017-03-31 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh reopened this revision.
chh added a comment.
This revision is now accepted and ready to land.

This was reverted due to one failed test case clang-tidy/llvm-include-order.cpp 
on Windows:

Assertion failed: EndColNo <= map.getSourceLine().size() && "Invalid range!", 
file 
C:\Buildbot\Slave\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\lib\Frontend\TextDiagnostic.cpp,
 line 999


Repository:
  rL LLVM

https://reviews.llvm.org/D31406



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


[PATCH] D31713: [Basic] getColumnNumber returns location of CR+LF on Windows

2017-04-05 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh created this revision.

When fixing a Clang-Tidy bug in https://reviews.llvm.org/D31406,
http://bugs.llvm.org/show_bug.cgi?id=32402,
reuse of FileID enabled the missing highlightRange function.
Assertion in highlightRange failed because the end-of-range column
number was 2 + the last column of a line on Windows.
This fix is required to enable https://reviews.llvm.org/D31406.


Repository:
  rL LLVM

https://reviews.llvm.org/D31713

Files:
  lib/Basic/SourceManager.cpp


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1144,8 +1144,18 @@
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+const char *Buf = MemBuf->getBufferStart();
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
   const char *Buf = MemBuf->getBufferStart();


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1144,8 +1144,18 @@
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+const char *Buf = MemBuf->getBufferStart();
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
   const char *Buf = MemBuf->getBufferStart();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31713: [Basic] getColumnNumber returns location of CR+LF on Windows

2017-04-06 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 94402.
chh marked an inline comment as done.

https://reviews.llvm.org/D31713

Files:
  lib/Basic/SourceManager.cpp


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1136,19 +1136,28 @@
 return 1;
   }
 
+  const char *Buf = MemBuf->getBufferStart();
   // See if we just calculated the line number for this FilePos and can use
   // that to lookup the start of the line instead of searching for it.
   if (LastLineNoFileIDQuery == FID &&
   LastLineNoContentCache->SourceLineCache != nullptr &&
   LastLineNoResult < LastLineNoContentCache->NumLines) {
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
-  const char *Buf = MemBuf->getBufferStart();
   unsigned LineStart = FilePos;
   while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
 --LineStart;


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1136,19 +1136,28 @@
 return 1;
   }
 
+  const char *Buf = MemBuf->getBufferStart();
   // See if we just calculated the line number for this FilePos and can use
   // that to lookup the start of the line instead of searching for it.
   if (LastLineNoFileIDQuery == FID &&
   LastLineNoContentCache->SourceLineCache != nullptr &&
   LastLineNoResult < LastLineNoContentCache->NumLines) {
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
-  const char *Buf = MemBuf->getBufferStart();
   unsigned LineStart = FilePos;
   while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
 --LineStart;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31713: [Basic] getColumnNumber returns location of CR+LF on Windows

2017-04-06 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299681: [Basic] getColumnNumber returns location of CR+LF on 
Windows (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D31713?vs=94402&id=94410#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31713

Files:
  cfe/trunk/lib/Basic/SourceManager.cpp


Index: cfe/trunk/lib/Basic/SourceManager.cpp
===
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -1136,19 +1136,28 @@
 return 1;
   }
 
+  const char *Buf = MemBuf->getBufferStart();
   // See if we just calculated the line number for this FilePos and can use
   // that to lookup the start of the line instead of searching for it.
   if (LastLineNoFileIDQuery == FID &&
   LastLineNoContentCache->SourceLineCache != nullptr &&
   LastLineNoResult < LastLineNoContentCache->NumLines) {
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
-  const char *Buf = MemBuf->getBufferStart();
   unsigned LineStart = FilePos;
   while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
 --LineStart;


Index: cfe/trunk/lib/Basic/SourceManager.cpp
===
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -1136,19 +1136,28 @@
 return 1;
   }
 
+  const char *Buf = MemBuf->getBufferStart();
   // See if we just calculated the line number for this FilePos and can use
   // that to lookup the start of the line instead of searching for it.
   if (LastLineNoFileIDQuery == FID &&
   LastLineNoContentCache->SourceLineCache != nullptr &&
   LastLineNoResult < LastLineNoContentCache->NumLines) {
 unsigned *SourceLineCache = LastLineNoContentCache->SourceLineCache;
 unsigned LineStart = SourceLineCache[LastLineNoResult - 1];
 unsigned LineEnd = SourceLineCache[LastLineNoResult];
-if (FilePos >= LineStart && FilePos < LineEnd)
+if (FilePos >= LineStart && FilePos < LineEnd) {
+  // LineEnd is the LineStart of the next line.
+  // A line ends with separator LF or CR+LF on Windows.
+  // FilePos might point to the last separator,
+  // but we need a column number at most 1 + the last column.
+  if (FilePos + 1 == LineEnd && FilePos > LineStart) {
+if (Buf[FilePos - 1] == '\r' || Buf[FilePos - 1] == '\n')
+  --FilePos;
+  }
   return FilePos - LineStart + 1;
+}
   }
 
-  const char *Buf = MemBuf->getBufferStart();
   unsigned LineStart = FilePos;
   while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
 --LineStart;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31406: [clang-tidy] Reuse FileID in getLocation

2017-04-06 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299700: [clang-tidy] Reuse FileID in getLocation (authored 
by chh).

Repository:
  rL LLVM

https://reviews.llvm.org/D31406

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


Index: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
@@ -239,7 +239,7 @@
   return SourceLocation();
 
 const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);
-FileID ID = SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
+FileID ID = SourceMgr.getOrCreateFileID(File, SrcMgr::C_User);
 return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
   }
 


Index: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
@@ -239,7 +239,7 @@
   return SourceLocation();
 
 const FileEntry *File = SourceMgr.getFileManager().getFile(FilePath);
-FileID ID = SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
+FileID ID = SourceMgr.getOrCreateFileID(File, SrcMgr::C_User);
 return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[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 &Records;
 };
+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-head

[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 &S) 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 %S/Inputs/

[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 &Records;
 };
+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":"lin

[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 &S) 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/Inpu

[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] 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 &Records;
 };
+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 -checks

[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 &S) 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-tid

[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 &Records;
 };
+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-t

[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 &S) 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/

[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] 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] 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] 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 &Records;
 };
+struct LocFilter {
+  

[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 llvm

[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 &S) 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/t

[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 that

[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 &S) 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-

[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 Sco

[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 fi

[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 &S) 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"

[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] 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
  clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespace

[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 &Records;
 };
+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(MatchFi

[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 &Context) override {
 if (ParsingDone != nullptr) {
   ParsingDone->run();
 }
-Finder->matchAST(Context);
+if (Finder->hasFilter()) {
+  auto SavedScope = Context.getTraversalScope();
+  auto &MyTopDecls = 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))
+TopLev

[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 &Records;
 };
+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: clan

[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] 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] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-19 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 &Context) override {
 if (ParsingDone != nullptr) {
   ParsingDone->run();
 }
-Finder->matchAST(Context);
+if (Finder->hasFilter()) {
+  auto SavedScope = Context.getTraversalScope();
+  auto &MyTopDecls = 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
===
--- clan

  1   2   >