[PATCH] D100968: Update shebang for clang-format-diff script to python3.

2021-04-22 Thread Paula Toth via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71e80386d0fe: Update shebang for clang-format-diff script to 
python3. (authored by PaulkaToast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100968

Files:
  clang/tools/clang-format/clang-format-diff.py


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 #===- clang-format-diff.py - ClangFormat Diff Reformatter *- python 
-*--===#
 #


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 #===- clang-format-diff.py - ClangFormat Diff Reformatter *- python -*--===#
 #
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100968: Update shebang for clang-format-diff script to python3.

2021-04-21 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

In D100968#2705598 , @MaskRay wrote:

>> On newer Linux distributions
>
> Different distributions have different strategies migrating the 
> /usr/bin/python symlink. Debian and its derivatives provide python-is-python2 
> and python-is-python3. If neither is installed, the user gets no 
> `/usr/bin/python`.
>
> LG with this clarified.

Thank you, added to the change description for more context. (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100968

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


[PATCH] D100968: Update shebang for clang-format-diff script to python3.

2021-04-21 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added reviewers: MaskRay, DavidSpickett.
PaulkaToast requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

On newer Linux distributions that don't have python2, the clang-format-diff 
script and consequently `arc diff` is failing with python not found error.  
Since we require python greater than 3.6 as part of llvm prerequisites 
(https://llvm.org/docs/GettingStarted.html#software), let's go ahead and update 
this shebang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100968

Files:
  clang/tools/clang-format/clang-format-diff.py


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 #===- clang-format-diff.py - ClangFormat Diff Reformatter *- python 
-*--===#
 #


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 #===- clang-format-diff.py - ClangFormat Diff Reformatter *- python -*--===#
 #
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78890: [clang-tidy] Add check callee-namespace.

2020-04-28 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 260805.
PaulkaToast marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78890

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
@@ -0,0 +1,42 @@
+// RUN: %check_clang_tidy %s llvmlibc-callee-namespace %t
+
+namespace __llvm_libc {
+namespace nested {
+void nested_func() {}
+} // namespace nested
+void libc_api_func() {}
+} // namespace __llvm_libc
+
+// Emulate a function from the public headers like string.h
+void libc_api_func() {}
+
+namespace __llvm_libc {
+void Test() {
+  // Allow calls with the fully qualified name.
+  __llvm_libc::libc_api_func();
+  __llvm_libc::nested::nested_func();
+  void (*qualifiedPtr)(void) = __llvm_libc::libc_api_func;
+  qualifiedPtr();
+
+  // Should not trigger on compiler provided function calls.
+  (void)__builtin_abs(-1);
+
+  // Bare calls are allowed as long as they resolve to the correct namespace.
+  libc_api_func();
+  nested::nested_func();
+  void (*barePtr)(void) = __llvm_libc::libc_api_func;
+  barePtr();
+
+  // Disallow calling into global namespace for implemented entrypoints.
+  ::libc_api_func();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'libc_api_func' must resolve to a function declared within the '__llvm_libc' namespace
+  // CHECK-MESSAGES: :11:6: note: resolves to this declaration
+
+  // Disallow indirect references to functions in global namespace.
+  void (*badPtr)(void) = ::libc_api_func;
+  badPtr();
+  // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: 'libc_api_func' must resolve to a function declared within the '__llvm_libc' namespace
+  // CHECK-MESSAGES: :11:6: note: resolves to this declaration
+}
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - llvmlibc-callee-namespace
+
+llvmlibc-callee-namespace
+
+
+Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
+.. code-block:: c++
+
+namespace __llvm_libc {
+
+// Allow calls with the fully qualified name.
+__llvm_libc::strlen("hello");
+
+// Allow calls to compiler provided functions.
+(void)__builtin_abs(-1);
+
+// Bare calls are allowed as long as they resolve to the correct namespace.
+strlen("world");
+
+// Disallow calling into functions in the global namespace.
+::strlen("!");
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-callee-namespace `_,
`llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-callee-namespace
+  ` check.
+
+  Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
 - New :doc:`llvmlibc-implementation-in-namespace
   ` check.
 
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CalleeNamespaceCheck.h"
 #include "ImplementationInNamespaceCheck.h"
 #include 

[PATCH] D78890: [clang-tidy] Add check callee-namespace.

2020-04-28 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added inline comments.



Comment at: clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp:52-53
+
+  diag(FuncDecl->getLocation(),
+   "currently resolves to: ", clang::DiagnosticIDs::Note);
+}

aaron.ballman wrote:
> PaulkaToast wrote:
> > aaron.ballman wrote:
> > > This diagnostic seems a bit strange -- I would expect some text after the 
> > > colon.
> > I was trying mimic the clang's previous definition diagnostic. e.g. : 
> > https://godbolt.org/z/V4tKr-
> > Although the colon does seem to confusing so I removed it.
> Ah, thank you for the explanation. I think I would word it `resolves to this 
> declaration` (or something along those lines) to be a bit less grammatically 
> ambiguous. When the diagnostic ends in "to", I assume there's a part of the 
> diagnostic missing and I wonder "to what?"
I agree with this, thanks for the insight (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78890



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


[PATCH] D78890: [clang-tidy] Add check callee-namespace.

2020-04-28 Thread Paula Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8683f5de5352: [clang-tidy] Add check callee-namespace. 
(authored by PaulkaToast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78890

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
@@ -0,0 +1,42 @@
+// RUN: %check_clang_tidy %s llvmlibc-callee-namespace %t
+
+namespace __llvm_libc {
+namespace nested {
+void nested_func() {}
+} // namespace nested
+void libc_api_func() {}
+} // namespace __llvm_libc
+
+// Emulate a function from the public headers like string.h
+void libc_api_func() {}
+
+namespace __llvm_libc {
+void Test() {
+  // Allow calls with the fully qualified name.
+  __llvm_libc::libc_api_func();
+  __llvm_libc::nested::nested_func();
+  void (*qualifiedPtr)(void) = __llvm_libc::libc_api_func;
+  qualifiedPtr();
+
+  // Should not trigger on compiler provided function calls.
+  (void)__builtin_abs(-1);
+
+  // Bare calls are allowed as long as they resolve to the correct namespace.
+  libc_api_func();
+  nested::nested_func();
+  void (*barePtr)(void) = __llvm_libc::libc_api_func;
+  barePtr();
+
+  // Disallow calling into global namespace for implemented entrypoints.
+  ::libc_api_func();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'libc_api_func' must resolve to a function declared within the '__llvm_libc' namespace
+  // CHECK-MESSAGES: :11:6: note: resolves to this declaration
+
+  // Disallow indirect references to functions in global namespace.
+  void (*badPtr)(void) = ::libc_api_func;
+  badPtr();
+  // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: 'libc_api_func' must resolve to a function declared within the '__llvm_libc' namespace
+  // CHECK-MESSAGES: :11:6: note: resolves to this declaration
+}
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - llvmlibc-callee-namespace
+
+llvmlibc-callee-namespace
+
+
+Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
+.. code-block:: c++
+
+namespace __llvm_libc {
+
+// Allow calls with the fully qualified name.
+__llvm_libc::strlen("hello");
+
+// Allow calls to compiler provided functions.
+(void)__builtin_abs(-1);
+
+// Bare calls are allowed as long as they resolve to the correct namespace.
+strlen("world");
+
+// Disallow calling into functions in the global namespace.
+::strlen("!");
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-callee-namespace `_,
`llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-callee-namespace
+  ` check.
+
+  Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
 - New :doc:`llvmlibc-implementation-in-namespace
   ` check.
 
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CalleeNamespaceCheck.h"
 

[PATCH] D78890: [clang-tidy] Add check callee-namespace.

2020-04-27 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added inline comments.



Comment at: clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp:22-23
+const DeclContext *getOutermostNamespace(const DeclContext *Decl) {
+  if (Decl->isTranslationUnit())
+return Decl;
+  if (Decl->getParent() && Decl->getParent()->isTranslationUnit())

aaron.ballman wrote:
> Under what circumstances could the translation unit be passed in as the 
> declaration? I think this code can just be removed.
Actually you are totally right. This case would never occur, thanks (:



Comment at: clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp:30-31
+void CalleeNamespaceCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(functionDecl().bind("func"))).bind("call-site"), this);
+}

aaron.ballman wrote:
> Do you also want to catch binding of function pointers? e.g.,
> ```
> float (*fp)(float) = sinf;
> ```
I hadn't considered function pointers, does seem like a good thing to catch 
though. Modified the matches to catch this case as well. Thank you!



Comment at: clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp:52-53
+
+  diag(FuncDecl->getLocation(),
+   "currently resolves to: ", clang::DiagnosticIDs::Note);
+}

aaron.ballman wrote:
> This diagnostic seems a bit strange -- I would expect some text after the 
> colon.
I was trying mimic the clang's previous definition diagnostic. e.g. : 
https://godbolt.org/z/V4tKr-
Although the colon does seem to confusing so I removed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78890



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


[PATCH] D78890: [clang-tidy] Add check callee-namespace.

2020-04-27 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 260524.
PaulkaToast marked 8 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78890

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
@@ -0,0 +1,42 @@
+// RUN: %check_clang_tidy %s llvmlibc-callee-namespace %t
+
+namespace __llvm_libc {
+namespace nested {
+void nested_func() {}
+} // namespace nested
+void libc_api_func() {}
+} // namespace __llvm_libc
+
+// Emulate a function from the public headers like string.h
+void libc_api_func() {}
+
+namespace __llvm_libc {
+void Test() {
+  // Allow calls with the fully qualified name.
+  __llvm_libc::libc_api_func();
+  __llvm_libc::nested::nested_func();
+  void (*qualifiedPtr)(void) = __llvm_libc::libc_api_func;
+  qualifiedPtr();
+
+  // Should not trigger on compiler provided function calls.
+  (void)__builtin_abs(-1);
+
+  // Bare calls are allowed as long as they resolve to the correct namespace.
+  libc_api_func();
+  nested::nested_func();
+  void (*barePtr)(void) = __llvm_libc::libc_api_func;
+  barePtr();
+
+  // Disallow calling into global namespace for implemented entrypoints.
+  ::libc_api_func();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'libc_api_func' must resolve to a function declared within the '__llvm_libc' namespace
+  // CHECK-MESSAGES: :11:6: note: currently resolves to
+
+  // Disallow indirect references to functions in global namespace.
+  void (*badPtr)(void) = ::libc_api_func;
+  badPtr();
+  // CHECK-MESSAGES: :[[@LINE-2]]:26: warning: 'libc_api_func' must resolve to a function declared within the '__llvm_libc' namespace
+  // CHECK-MESSAGES: :11:6: note: currently resolves to
+}
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - llvmlibc-callee-namespace
+
+llvmlibc-callee-namespace
+
+
+Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
+.. code-block:: c++
+
+namespace __llvm_libc {
+
+// Allow calls with the fully qualified name.
+__llvm_libc::strlen("hello");
+
+// Allow calls to compiler provided functions.
+(void)__builtin_abs(-1);
+
+// Bare calls are allowed as long as they resolve to the correct namespace.
+strlen("world");
+
+// Disallow calling into functions in the global namespace.
+::strlen("!");
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-callee-namespace `_,
`llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-callee-namespace
+  ` check.
+
+  Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
 - New :doc:`llvmlibc-implementation-in-namespace
   ` check.
 
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CalleeNamespaceCheck.h"
 #include "ImplementationInNamespaceCheck.h"
 #include "RestrictSystemLibcHeadersCheck.h"
 
@@ 

[PATCH] D78890: [clang-tidy] Add check callee-namespace.

2020-04-27 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 260218.
PaulkaToast marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78890

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
@@ -0,0 +1,32 @@
+// RUN: %check_clang_tidy %s llvmlibc-callee-namespace %t
+
+namespace __llvm_libc {
+namespace nested {
+void nested_func() {}
+} // namespace nested
+void libc_api_func() {}
+} // namespace __llvm_libc
+
+// Emulate a function from the public headers like string.h
+void libc_api_func() {}
+
+namespace __llvm_libc {
+void Test() {
+  // Allow calls with the fully qualified name.
+  __llvm_libc::libc_api_func();
+  __llvm_libc::nested::nested_func();
+
+  // Should not trigger on compiler provided function calls.
+  (void)__builtin_abs(-1);
+
+  // Bare calls are allowed as long as they resolve to the correct namespace.
+  libc_api_func();
+  nested::nested_func();
+
+  // Disallow calling into global namespace for implemented entrypoints.
+  ::libc_api_func();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'libc_api_func' must call to internal implementation in `__llvm_libc` namespace
+  // CHECK-MESSAGES: :11:6: note: currently resolves to:
+}
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - llvmlibc-callee-namespace
+
+llvmlibc-callee-namespace
+
+
+Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
+.. code-block:: c++
+
+namespace __llvm_libc {
+
+// Allow calls with the fully qualified name.
+__llvm_libc::strlen("hello");
+
+// Allow calls to compiler provided functions.
+(void)__builtin_abs(-1);
+
+// Bare calls are allowed as long as they resolve to the correct namespace.
+strlen("world");
+
+// Disallow calling into functions in the global namespace.
+::strlen("!");
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-callee-namespace `_,
`llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-callee-namespace
+  ` check.
+
+  Checks all calls resolve to functions within ``__llvm_libc`` namespace.
+
 - New :doc:`llvmlibc-implementation-in-namespace
   ` check.
 
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CalleeNamespaceCheck.h"
 #include "ImplementationInNamespaceCheck.h"
 #include "RestrictSystemLibcHeadersCheck.h"
 
@@ -19,6 +20,8 @@
 class LLVMLibcModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
+CheckFactories.registerCheck(
+"llvmlibc-callee-namespace");
 CheckFactories.registerCheck(
 "llvmlibc-implementation-in-namespace");
 CheckFactories.registerCheck(
Index: clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h
===

[PATCH] D78890: [clang-tidy] Add check callee-namespace.

2020-04-26 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added reviewers: aaron.ballman, njames93.
PaulkaToast added projects: clang-tools-extra, libc-project.
Herald added subscribers: cfe-commits, xazax.hun, mgorny.
Herald added a project: clang.

This check will ensure that all calls to functions resolve to one inside the 
`__llvm_libc` namespace.

This is done to ensure that if we include a public header then we don't 
accidentally call into the a function within the global namespace.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78890

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp
@@ -0,0 +1,32 @@
+// RUN: %check_clang_tidy %s llvmlibc-callee-namespace %t
+
+namespace __llvm_libc {
+namespace nested {
+void nested_func() {}
+} // namespace nested
+void libc_api_func() {}
+} // namespace __llvm_libc
+
+// Emulate a function from the public headers like string.h
+void libc_api_func() {}
+
+namespace __llvm_libc {
+void Test() {
+  // Allow calls with the fully qualified name.
+  __llvm_libc::libc_api_func();
+  __llvm_libc::nested::nested_func();
+
+  // Should not trigger on compiler provided function calls.
+  (void)__builtin_abs(-1);
+
+  // Bare calls are allowed as long as they resolve to the correct namespace.
+  libc_api_func();
+  nested::nested_func();
+
+  // Disallow calling into global namespace for implemented entrypoints.
+  ::libc_api_func();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'libc_api_func' must call to internal implementation in `__llvm_libc` namespace
+  // CHECK-MESSAGES: :11:6: note: currently resolves to:
+}
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - llvmlibc-callee-namespace
+
+llvmlibc-callee-namespace
+
+
+Checks all calls resolve to functions within __llvm_libc namespace.
+
+.. code-block:: c++
+
+namespace __llvm_libc {
+
+// Allow calls with the fully qualified name.
+__llvm_libc::strlen("hello");
+
+// Allow calls to compiler provided functions.
+(void)__builtin_abs(-1);
+
+// Bare calls are allowed as long as they resolve to the correct namespace.
+strlen("world");
+
+// Disallow calling into functions in the global namespace.
+::strlen("!");
+
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-callee-namespace `_,
`llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-callee-namespace
+  ` check.
+
+  Checks all calls resolve to functions within __llvm_libc namespace.
+
 - New :doc:`llvmlibc-implementation-in-namespace
   ` check.
 
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
@@ -9,6 +9,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CalleeNamespaceCheck.h"
 #include "ImplementationInNamespaceCheck.h"
 #include "RestrictSystemLibcHeadersCheck.h"
 
@@ -19,6 +20,8 @@
 class LLVMLibcModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
+

[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-04-06 Thread Paula Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG00a57558978d: [clang-tidy] Add check 
llvmlibc-implementation-in-namespace. (authored by PaulkaToast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t
+
+#define MACRO_A "defining macros outside namespace is valid"
+
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared within the '__llvm_libc' namespace
+struct StructC {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be declared within the '__llvm_libc' namespace
+char *VarD = MACRO_A;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared within the '__llvm_libc' namespace
+typedef int typeE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be declared within the '__llvm_libc' namespace
+void funcF() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be declared within the '__llvm_libc' namespace
+
+namespace namespaceG {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '__llvm_libc' needs to be the outermost namespace
+namespace __llvm_libc{
+namespace namespaceH {
+class ClassB;
+} // namespace namespaceH
+struct StructC {};
+} // namespace __llvm_libc
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+} // namespace namespaceG
+
+// Wrapped in correct namespace.
+namespace __llvm_libc {
+// Namespaces within __llvim_libc namespace allowed.
+namespace namespaceI {
+class ClassB;
+} // namespace namespaceI
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+extern "C" void extern_funcJ() {}
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
@@ -0,0 +1,28 @@
+.. title:: clang-tidy - llvmlibc-implementation-in-namespace
+
+llvmlibc-implementation-in-namespace
+
+
+Checks that all declarations in the llvm-libc implementation are within the
+correct namespace.
+
+.. code-block:: c++
+
+// Correct: implementation inside the correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+// Namespaces within __llvm_libc namespace are allowed.
+namespace inner{
+int localVar = 0;
+}
+// Functions with C linkage are allowed.
+extern "C" void str_fuzz(){}
+}
+
+// Incorrect: implementation not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+
+// Incorrect: outer most namespace is not correct.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-implementation-in-namespace
+  ` check.
+
+  Checks all llvm-libc implementation is within the correct namespace.
+
 - New :doc:`llvmlibc-restrict-system-libc-headers
   ` check.
 
Index: 

[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-04-06 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp:21
+  Finder->addMatcher(
+  decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
+  .bind("child_of_translation_unit"),

aaron.ballman wrote:
> This skips linkage spec declarations, but are there other declarations that 
> should be similarly skipped? For instance `static_assert` declarations?
I believe that linkage is the only exception needed, static_asserts and all 
other declarations should also be within the namespace. 



Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp:33-34
+
+  if (isa(MatchedDecl)) {
+const auto *NS = cast(MatchedDecl);
+if (NS->getName() != RequiredNamespace) {

aaron.ballman wrote:
> Instead of doing an `isa<>` followed by a `cast<>`, the more common pattern 
> is to do:
> ```
> if (const auto *NS = dyn_cast(MatchedDecl)) {
> ```
Ah thank you this looks much nicer!



Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp:42
+  diag(MatchedDecl->getLocation(),
+   "Please wrap implentation in '%0' namespace.")
+  << RequiredNamespace;

aaron.ballman wrote:
> They also aren't grammatically correct sentences, so the capital P and period 
> should both go. While this definitely gets points for politeness, I think a 
> more typical diagnostic might be: `declaration must be declared within the 
> '%0' namespace`
ah, alright, good call. (:



Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h:35
+private:
+  std::string RequiredNamespace;
+};

aaron.ballman wrote:
> njames93 wrote:
> > This can be made const
> Will there only ever be a single namespace? Or should this be a list (for 
> instance, a main namespace and a details namespace)?
There will only be this one namespace.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst:32-35
+.. option:: RequiredNamespace
+
+The namespace that llvm-libc implementations must be wrapped in. The 
default
+is `__llvm_libc`.

aaron.ballman wrote:
> Given that this check is specific to llvm-libc, why is the option needed at 
> all?
I was concerned that maybe there would be a desire to make the check 
generalized, however it does seem quite specific so I will take your advice. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818



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


[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-04-06 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 255277.
PaulkaToast marked 13 inline comments as done.
PaulkaToast added a comment.

Addressed njames's and aaron's comments. (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t
+
+#define MACRO_A "defining macros outside namespace is valid"
+
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared within the '__llvm_libc' namespace
+struct StructC {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be declared within the '__llvm_libc' namespace
+char *VarD = MACRO_A;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be declared within the '__llvm_libc' namespace
+typedef int typeE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be declared within the '__llvm_libc' namespace
+void funcF() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be declared within the '__llvm_libc' namespace
+
+namespace namespaceG {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '__llvm_libc' needs to be the outermost namespace
+namespace __llvm_libc{
+namespace namespaceH {
+class ClassB;
+} // namespace namespaceH
+struct StructC {};
+} // namespace __llvm_libc
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+} // namespace namespaceG
+
+// Wrapped in correct namespace.
+namespace __llvm_libc {
+// Namespaces within __llvim_libc namespace allowed.
+namespace namespaceI {
+class ClassB;
+} // namespace namespaceI
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+extern "C" void extern_funcJ() {}
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
@@ -0,0 +1,28 @@
+.. title:: clang-tidy - llvmlibc-implementation-in-namespace
+
+llvmlibc-implementation-in-namespace
+
+
+Checks that all declarations in the llvm-libc implementation are within the
+correct namespace.
+
+.. code-block:: c++
+
+// Correct: implementation inside the correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+// Namespaces within __llvm_libc namespace are allowed.
+namespace inner{
+int localVar = 0;
+}
+// Functions with C linkage are allowed.
+extern "C" void str_fuzz(){}
+}
+
+// Incorrect: implementation not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+
+// Incorrect: outer most namespace is not correct.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-implementation-in-namespace
+  ` check.
+
+  Checks all llvm-libc implementation is within the correct namespace.
+
 - New :doc:`llvmlibc-restrict-system-libc-headers
   ` check.
 
Index: 

[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-04-01 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 254376.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t
+
+#define MACRO_A "defining macros outside namespace is valid"
+
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Please wrap implentation in '__llvm_libc' namespace.
+struct StructC {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: Please wrap implentation in '__llvm_libc' namespace.
+char *VarD = MACRO_A;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Please wrap implentation in '__llvm_libc' namespace.
+typedef int typeE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Please wrap implentation in '__llvm_libc' namespace.
+void funcF() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Please wrap implentation in '__llvm_libc' namespace.
+
+namespace namespaceG {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '__llvm_libc' needs to be the outermost namespace.
+namespace __llvm_libc{
+namespace namespaceH {
+class ClassB;
+} // namespace namespaceH
+struct StructC {};
+} // namespace __llvm_libc
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+} // namespace namespaceG
+
+// Wrapped in correct namespace.
+namespace __llvm_libc {
+// Namespaces within __llvim_libc namespace allowed.
+namespace namespaceI {
+class ClassB;
+} // namespace namespaceI
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+extern "C" void extern_funcJ() {}
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - llvmlibc-implementation-in-namespace
+
+llvmlibc-implementation-in-namespace
+
+
+Checks all llvm-libc implementation is within the correct namespace.
+
+.. code-block:: c++
+
+// Correct: implementation inside the correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+// Namespaces within __llvm_libc namespace are allowed.
+namespace inner{
+int localVar = 0;
+}
+// Functions with C linkage are allowed.
+extern "C" void str_fuzz(){}
+}
+
+// Incorrect: implementation not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+
+// Incorrect: outer most namespace is not correct.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
+
+Options
+---
+
+.. option:: RequiredNamespace
+
+The namespace that llvm-libc implementations must be wrapped in. The default
+is `__llvm_libc`.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-implementation-in-namespace
+  ` check.
+
+  Checks all llvm-libc implementation is within the correct namespace.
+
 - New :doc:`llvmlibc-restrict-system-libc-headers
   ` check.
 
Index: clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp

[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-03-31 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

Friendly Ping @njames93 (:
Any other changes needed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818



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


[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-03-27 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast marked 3 inline comments as done.
PaulkaToast added a comment.

In D76818#1943781 , @njames93 wrote:

> If you want to make it a general check, you should consider making the 
> default module options set the correct namespace
> RequiredNamespace


Changed the check a bit so I'm not sure if pulling it out is still something 
desired, if so what module do you recommend this should live under?




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp:6
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: CXXRecord is not defined in a 
namespace, please wrap implentation in '__llvm_libc' namespace.
+struct StructC {};

njames93 wrote:
> Small nit : Not a fan of the diagnostic saying `CXX Record`. Maybe a pain but 
> `getDeclKindName` isn't the best to expose to users. 
Removed getDeclKindName as recommended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818



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


[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-03-27 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 253250.
PaulkaToast added a comment.

Updated to handle nested namespaces, exclude C linkages functions,  and made 
check language specific. (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76818

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
@@ -0,0 +1,38 @@
+// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t
+
+#define MACRO_A "defining macros outside namespace is valid"
+
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Please wrap implentation in '__llvm_libc' namespace.
+struct StructC {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: Please wrap implentation in '__llvm_libc' namespace.
+char *VarD = MACRO_A;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Please wrap implentation in '__llvm_libc' namespace.
+typedef int typeE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Please wrap implentation in '__llvm_libc' namespace.
+void funcF() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Please wrap implentation in '__llvm_libc' namespace.
+
+namespace namespaceG {
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: '__llvm_libc' needs to be the outermost namespace.
+namespace namespaceH {
+class ClassB;
+} // namespace namespaceH
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+} // namespace namespaceG
+
+// Wrapped in correct namespace.
+namespace __llvm_libc {
+// Namespaces within __llvim_libc namespace allowed.
+namespace namespaceI {
+class ClassB;
+} // namespace namespaceI
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+extern "C" void extern_funcJ() {}
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - llvmlibc-implementation-in-namespace
+
+llvmlibc-implementation-in-namespace
+
+
+Checks all llvm-libc implementation is within the correct namespace.
+
+.. code-block:: c++
+
+// Correct: implementation inside the correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+// Namespaces within __llvm_libc namespace are allowed.
+namespace inner{
+int localVar = 0;
+}
+// Functions with C linkage are allowed.
+extern "C" void str_fuzz(){}
+}
+
+// Incorrect: implementation not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+
+// Incorrect: outer most namespace is not correct.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
+
+Options
+---
+
+.. option:: RequiredNamespace
+
+The namespace that llvm-libc implementations must be wrapped in. The default
+is `__llvm_libc`.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-implementation-in-namespace
+  ` check.
+
+  Checks all llvm-libc implementation is within the correct namespace.
+
 - New :doc:`llvmlibc-restrict-system-libc-headers
   ` check.
 
Index: 

[PATCH] D76744: [clang-tidy] Add check to ensure llvm-libc implementations are defined in correct namespace.

2020-03-25 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast marked 3 inline comments as done.
PaulkaToast added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/EntrypointNamespaceCheck.cpp:67
+  if (Result.SourceManager->getFilename(MatchedDecl->getLocation())
+  .endswith(".h"))
+return;

njames93 wrote:
> Is there a rule that all libc implementation headers must have the extension 
> `.h`. If not there is `utils::FileExtensionSet` that could be used.
> Alternatively you could just check to see if the SourceLocation is in the 
> main file
> `if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation())`
Thanks for this! I incorporated your recommendations in the new patch. (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76744



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


[PATCH] D76744: [clang-tidy] Add check to ensure llvm-libc implementations are defined in correct namespace.

2020-03-25 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast abandoned this revision.
PaulkaToast added a comment.

Abandoning for a more generalized check. D76818 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76744



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


[PATCH] D76818: [clang-tidy] Add check llvmlibc-implementation-in-namespace.

2020-03-25 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added reviewers: alexfh, aaron.ballman, hokein, njames93.
PaulkaToast added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, MaskRay, xazax.hun, mgorny.
Herald added a project: clang.

This check makes sure all llvm-libc implementations falls within the 
`__llvm_libc` namespace.

The check is quite general, lots of projects do this by conversion to avoid 
pollution. Not sure if there is a desire to put this in a different module?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76818

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t
+
+#define MACRO_A "defining macros outside namespace is valid"
+
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: CXXRecord is not defined in a namespace, please wrap implentation in '__llvm_libc' namespace.
+struct StructC {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: CXXRecord is not defined in a namespace, please wrap implentation in '__llvm_libc' namespace.
+char *VarD = MACRO_A;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Var is not defined in a namespace, please wrap implentation in '__llvm_libc' namespace.
+typedef int typeE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Typedef is not defined in a namespace, please wrap implentation in '__llvm_libc' namespace.
+void funcF() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Function is not defined in a namespace, please wrap implentation in '__llvm_libc' namespace.
+
+namespace namespace_g {
+class ClassB;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: CXXRecord is defined in namespace 'namespace_g', should be in '__llvm_libc' namespace.
+struct StructC {};
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: CXXRecord is defined in namespace 'namespace_g', should be in '__llvm_libc' namespace.
+char *VarD = MACRO_A;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Var is defined in namespace 'namespace_g', should be in '__llvm_libc' namespace.
+typedef int typeE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Typedef is defined in namespace 'namespace_g', should be in '__llvm_libc' namespace.
+void funcF() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Function is defined in namespace 'namespace_g', should be in '__llvm_libc' namespace.
+} // namespace namespace_g
+
+// Wrapped in correct namespace.
+namespace __llvm_libc {
+class ClassB;
+struct StructC {};
+char *VarD = MACRO_A;
+typedef int typeE;
+void funcF() {}
+} // namespace __llvm_libc
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst
@@ -0,0 +1,29 @@
+.. title:: clang-tidy - llvmlibc-implementation-in-namespace
+
+llvmlibc-implementation-in-namespace
+
+
+Checks all llvm-libc implementation is within the correct namespace.
+
+.. code-block:: c++
+
+// Correct: implementation inside the correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
+
+// Incorrect: implementation not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+
+// Incorrect: implementation inside an incorrect namespace.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
+
+Options
+---
+
+.. option:: RequiredNamespace
+
+The namespace that llvm-libc implementations must be wrapped in. The default
+is `__llvm_libc`.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-implementation-in-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"

[PATCH] D76744: [clang-tidy] Add check to ensure llvm-libc implementations are defined in correct namespace.

2020-03-24 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, MaskRay, xazax.hun, mgorny.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76744

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/EntrypointNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/EntrypointNamespaceCheck.h
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/llvmlibc-entrypoint-namespace.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc-entrypoint-namespace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-entrypoint-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-entrypoint-namespace.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s llvmlibc-entrypoint-namespace %t
+
+#define LLVM_LIBC_ENTRYPOINT(name) name
+#define SOMETHING_ELSE(name) name
+
+// use of entrypoint macro with correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(correct_entrypoint)(char *param) {}
+} // namespace __llvm_libc
+
+// different macros are ignored.
+namespace something_else {
+void SOMETHING_ELSE(different_macro)(char *param) {}
+} // namespace something_else
+
+// Not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(missing_namespace)(char *param) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: function 'missing_namespace' is not defined in a namespace, please wrap implentation in '__llvm_libc' namespace.
+
+// Inside incorrect namespace.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(incorrect_namespace)(char *param) {}
+} // namespace something_else
+// CHECK-MESSAGES: :[[@LINE-2]]:27: warning: function 'incorrect_namespace' is defined in namespace 'something_else', should be in '__llvm_libc' namespace.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-entrypoint-namespace.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-entrypoint-namespace.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - llvmlibc-entrypoint-namespace
+
+llvmlibc-entrypoint-namespace
+=
+
+Finds where llvm-libc entrypoint macro is called and checks that it is wrapped
+in the correct namespace.
+
+.. code-block:: c++
+
+// Correct: entrypoint inside correct namespace.
+namespace __llvm_libc {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
+
+// Incorrect: entrypoint not in a namespace.
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+
+// Incorrect: entrypoint inside incorrect namespace.
+namespace something_else {
+void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
+}
+
+Options
+---
+
+.. option:: EntrypointMacro
+
+The name of the macro used when defining llvm-libc implementations. The
+default is `LLVM_LIBC_ENTRYPOINT`.
+
+.. option:: RequiredNamespace
+
+The namespace that llvm-libc implementations must be wrapped in. The default
+is `__llvm_libc`.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -188,6 +188,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-entrypoint-namespace `_,
`llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -92,7 +92,7 @@
 
   Finds ``cnd_wait``, ``cnd_timedwait``, ``wait``, ``wait_for``, or
   ``wait_until`` function calls when the function is not invoked from a loop
-  that checks whether a condition predicate holds or the function has a 
+  that checks whether a condition predicate holds or the function has a
   condition parameter.
 
 - New :doc:`bugprone-reserved-identifier
@@ -113,6 +113,12 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-entrypoint-namespace
+  ` check.
+
+  Finds where llvm-libc entrypoint macro is called and checks that it is wrapped
+  in the correct namespace.
+
 - New :doc:`llvmlibc-restrict-system-libc-headers
   ` check.
 
@@ -156,7 +162,7 @@
 ^^
 
 - Improved :doc:`readability-qualified-auto
-  ` check now supports a 
+  ` 

[PATCH] D76393: Allow remapping the sysroot with -fdebug-prefix-map.

2020-03-20 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

This seems to be causing a failure in our buildbot 
, mind taking a look? (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76393



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


[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-20 Thread Paula Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG556b917fffcf: [clang-tidy] Merge common code between 
llvmlibc-restrict-system-libc-headers… (authored by PaulkaToast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76395

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -3,11 +3,11 @@
 // RUN:   -resource-dir %S/Inputs/llvmlibc/resource
 
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed
 #include "string.h"
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed
 #include "stdatomic.h"
 #include 
 // Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
-// RUN:   -- -header-filter=.* \
-// RUN:   -- -I %S/Inputs/llvmlibc \
-// RUN:   -isystem %S/Inputs/llvmlibc/system \
-// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
-
-#include "transitive.h"
-// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
+++ /dev/null
@@ -1 +0,0 @@
-#include 
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -18,3 +18,18 @@
 whose ``dirent`` struct has slightly different field ordering than llvm-libc.
 While this will compile successfully, this can cause issues during runtime
 because they are ABI incompatible.
+
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma separated glob list of allowed include
+   filenames. Similar to the -checks glob list for running clang-tidy itself,
+   the two wildcard characters are `*` and `-`, to include and exclude globs,
+   respectively. The default is `-*`, which disallows all includes.
+
+   This can be used to allow known safe includes such as Linux development
+   headers. See :doc:`portability-restrict-system-includes
+   ` for more
+   details.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,7 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
-   `llvmlibc-restrict-system-libc-headers `_,
+   `llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
Index: clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
===
--- 

[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-20 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 251713.
PaulkaToast marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76395

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -3,11 +3,11 @@
 // RUN:   -resource-dir %S/Inputs/llvmlibc/resource
 
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed
 #include "string.h"
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed
 #include "stdatomic.h"
 #include 
 // Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
-// RUN:   -- -header-filter=.* \
-// RUN:   -- -I %S/Inputs/llvmlibc \
-// RUN:   -isystem %S/Inputs/llvmlibc/system \
-// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
-
-#include "transitive.h"
-// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
+++ /dev/null
@@ -1 +0,0 @@
-#include 
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -18,3 +18,18 @@
 whose ``dirent`` struct has slightly different field ordering than llvm-libc.
 While this will compile successfully, this can cause issues during runtime
 because they are ABI incompatible.
+
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma separated glob list of allowed include
+   filenames. Similar to the -checks glob list for running clang-tidy itself,
+   the two wildcard characters are `*` and `-`, to include and exclude globs,
+   respectively. The default is `-*`, which disallows all includes.
+
+   This can be used to allow known safe includes such as Linux development
+   headers. See :doc:`portability-restrict-system-includes
+   ` for more
+   details.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,7 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
-   `llvmlibc-restrict-system-libc-headers `_,
+   `llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
Index: clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
===
--- clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
+++ 

[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-20 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76395



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


[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-18 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 251233.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76395

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -3,11 +3,11 @@
 // RUN:   -resource-dir %S/Inputs/llvmlibc/resource
 
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed
 #include "string.h"
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed
 #include "stdatomic.h"
 #include 
 // Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
-// RUN:   -- -header-filter=.* \
-// RUN:   -- -I %S/Inputs/llvmlibc \
-// RUN:   -isystem %S/Inputs/llvmlibc/system \
-// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
-
-#include "transitive.h"
-// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
+++ /dev/null
@@ -1 +0,0 @@
-#include 
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -18,3 +18,18 @@
 whose ``dirent`` struct has slightly different field ordering than llvm-libc.
 While this will compile successfully, this can cause issues during runtime
 because they are ABI incompatible.
+
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma separated glob list of allowed include
+   filenames. Similar to the -checks glob list for running clang-tidy itself,
+   the two wildcard characters are `*` and `-`, to include and exclude globs,
+   respectively. The default is `-*`, which disallows all includes.
+
+   This can be used to whitelist known safe includes such as Linux development
+   headers. See :doc:`portability-restrict-system-includes
+   ` for more
+   details.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,7 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
-   `llvmlibc-restrict-system-libc-headers `_,
+   `llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
Index: clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
===
--- clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
+++ clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
@@ -23,9 +23,10 @@
 /// 

[PATCH] D76395: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes

2020-03-18 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added a reviewer: aaron.ballman.
PaulkaToast added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, MaskRay, xazax.hun, mgorny.
Herald added a project: clang.

Made llvmlibc::RestrictSystemLibcHeadersCheck a subclass of 
protability::RestrictSystemIncludesCheck to re-use common code between the two. 
This also adds the ability to white list linux development headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76395

Files:
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -3,11 +3,11 @@
 // RUN:   -resource-dir %S/Inputs/llvmlibc/resource
 
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed
 #include 
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed
 #include "string.h"
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed
 #include "stdatomic.h"
 #include 
 // Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
-// RUN:   -- -header-filter=.* \
-// RUN:   -- -I %S/Inputs/llvmlibc \
-// RUN:   -isystem %S/Inputs/llvmlibc/system \
-// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
-
-#include "transitive.h"
-// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
+++ /dev/null
@@ -1 +0,0 @@
-#include 
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -18,3 +18,18 @@
 whose ``dirent`` struct has slightly different field ordering than llvm-libc.
 While this will compile successfully, this can cause issues during runtime
 because they are ABI incompatible.
+
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma separated glob list of allowed include
+   filenames. Similar to the -checks glob list for running clang-tidy itself,
+   the two wildcard characters are `*` and `-`, to include and exclude globs,
+   respectively. The default is `-*`, which disallows all includes.
+
+   This can be used to whitelist known safe includes such as Linux development
+   headers. See :doc:`portability-restrict-system-includes
+   ` for more
+   details.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,7 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
-   `llvmlibc-restrict-system-libc-headers `_,
+   `llvmlibc-restrict-system-libc-headers `_, "Yes"
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
Index: 

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-12 Thread Paula Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb41cc619866: [clang-tidy] Add module for llvm-libc and 
restrict-system-libc-header-check. (authored by PaulkaToast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/resource/include/stdatomic.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/resource/include/stddef.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/stdio.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/stdlib.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -- -isystem %S/Inputs/llvmlibc/system \
+// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,8 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc \
+// RUN:   -isystem %S/Inputs/llvmlibc/system \
+// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part 

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-11 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 249802.
PaulkaToast added a comment.

Mocked the header files so that we don't experience failures due to differences 
in systems. Mind taking a quick look @aaron.ballman?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/resource/include/stdatomic.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/resource/include/stddef.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/stdio.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/stdlib.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -- -isystem %S/Inputs/llvmlibc/system \
+// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,8 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc \
+// RUN:   -isystem %S/Inputs/llvmlibc/system \
+// RUN:   -resource-dir %S/Inputs/llvmlibc/resource
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT 

[PATCH] D76015: [clang-tidy] Mock system headers for portability-restrict-system-includes tests.

2020-03-11 Thread Paula Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf1736f7a2a66: [clang-tidy] Mock system headers for 
portability-restrict-system-includes tests. (authored by PaulkaToast).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76015

Files:
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/float.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stddef.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stdint.h
  
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/portability-restrict-system-includes-glob.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test glob functionality: disallow all headers except those that match
 // pattern "std*.h".
Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,stddef.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,stddef.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test allow-list functionality: disallow all but stddef.h.
 
Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.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-allow.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test block-list functionality: allow all but stddef.h.
 


Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test glob functionality: disallow all headers except those that match
 // pattern "std*.h".
Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
===
--- 

[PATCH] D76015: [clang-tidy] Mock system headers for portability-restrict-system-includes tests.

2020-03-11 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added reviewers: RKSimon, aaron.ballman.
PaulkaToast added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Didn't realize that headers such as stddef.h may not exist on all systems. This 
patch mocks the headers so that the check's tests work on all systems.  (:


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76015

Files:
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/float.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stddef.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stdint.h
  
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/portability-restrict-system-includes-glob.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test glob functionality: disallow all headers except those that match
 // pattern "std*.h".
Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,stddef.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '-*,stddef.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test allow-list functionality: disallow all but stddef.h.
 
Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.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-allow.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: 
portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test block-list functionality: allow all but stddef.h.
 


Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
@@ -1,5 +1,6 @@
 // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
-// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}"
+// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}" \
+// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system
 
 // Test glob functionality: disallow all headers except those that match
 // pattern "std*.h".
Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp

[PATCH] D75786: [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.

2020-03-11 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

In D75786#1916714 , @aaron.ballman 
wrote:

> In D75786#1916637 , @RKSimon wrote:
>
> > @PaulkaToast This patch appears to have caused a buildbot issue, please can 
> > you investigate/revert: 
> > http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/63869
>
>
> I believe the issue is that we're looking for system headers that are not 
> mocked as part of the test. Sorry about not catching that earlier in the 
> review! @PaulkaToast, you should create an empty `stdio.h` (and others used 
> by your test) in Inputs/fucscia-restrict-system-includes/system so that we're 
> not finding the actual system includes.


Working on that now, I'll send out a review shortly. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75786



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-10 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 249544.
PaulkaToast added a comment.

Addressed @Eugene.Zelenko comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,14 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+// We dont know which headers are provided on each system.
+// Therefore, we only test on linux.
+// UNSUPPORTED: !linux
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+// We dont know which headers are provided on each system.
+// Therefore, we only test on linux.
+// UNSUPPORTED: !linux
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
+
+
+This check is necessary because accidentally including system libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose ``dirent`` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-10 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp:66-67
+const SourceManager , Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  SmallString<128> CompilerIncudeDir =
+  StringRef(PP->getHeaderSearchInfo().getHeaderSearchOpts().ResourceDir);
+  llvm::sys::path::append(CompilerIncudeDir, "include");

aaron.ballman wrote:
> The user can control this path -- is that an issue? You're using it to 
> determine what a compiler-provided header file is, and this seems like an 
> escape hatch for users to get around that. If that's reasonable to you, then 
> I'm okay with it, but you had mentioned you want to remove human error as a 
> factor and this seems like it could be a subtle human error situation.
Ah, thanks for pointing this out! I didn't consider this. I feel like scenario 
is a more unlikely then situations I mentioned. Probably not something to be 
too concerned about unless you know of a way to get the default resource path?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-10 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 249530.
PaulkaToast marked 4 inline comments as done.
PaulkaToast added a comment.

Addressed @aaron.ballman comments (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
+
+
+This check is necessary because accidentally including system libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose ``dirent`` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"

[PATCH] D75786: [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.

2020-03-10 Thread Paula Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
PaulkaToast marked an inline comment as done.
Closed by commit rGebdb98f254f6: [clang-tidy] Move 
fuchsia-restrict-system-includes to portability module for… (authored by 
PaulkaToast).

Changed prior to commit:
  https://reviews.llvm.org/D75786?vs=248900=249492#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75786

Files:
  clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/portability/CMakeLists.txt
  clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/s.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/t.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/r.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/s.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/t.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/transitive2.h
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-headers.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.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/portability-restrict-system-includes-glob.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
@@ -1,11 +1,11 @@
 // RUN: rm -rf %T/Headers
 // RUN: mkdir %T/Headers
-// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Headers/fuchsia-restrict-system-includes
-// RUN: %check_clang_tidy -std=c++11 %s fuchsia-restrict-system-includes %t \
-// RUN:   -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
+// RUN: cp -r %S/Inputs/portability-restrict-system-includes %T/Headers/portability-restrict-system-includes
+// RUN: %check_clang_tidy -std=c++11 %s portability-restrict-system-includes %t \
+// RUN:   -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
 // RUN:   -system-headers -header-filter=.* \
-// RUN:   -- -I %T/Headers/fuchsia-restrict-system-includes -isystem 

[PATCH] D75786: [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.

2020-03-10 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast marked 2 inline comments as done.
PaulkaToast added a comment.






Comment at: 
clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst:48
+
+   A string containing a comma separated glob list of allowed include
+   filenames. Similar to the -checks glob list for running clang-tidy itself,

aaron.ballman wrote:
> This is not something you have to fix (and certainly not as part of this 
> patch), but is a note of a bug... we typically use semicolon-delimited lists, 
> and I think that may be especially important here as comma can be a valid 
> character in a file name on many file systems. I notice that we're using 
> `GlobList` which still seems to use comma-separated values. We may want to 
> consider allowing both semi-colon and commas in `GlobList` and then updating 
> the docs to suggest semicolons instead of commas.
thanks, I'll send a patch out for this as its own change. (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75786



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


[PATCH] D75786: [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.

2020-03-06 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 248900.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75786

Files:
  clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/portability/CMakeLists.txt
  clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/s.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/t.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/r.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/s.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/t.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/transitive2.h
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-headers.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.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/portability-restrict-system-includes-glob.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
@@ -1,11 +1,11 @@
 // RUN: rm -rf %T/Headers
 // RUN: mkdir %T/Headers
-// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Headers/fuchsia-restrict-system-includes
-// RUN: %check_clang_tidy -std=c++11 %s fuchsia-restrict-system-includes %t \
-// RUN:   -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
+// RUN: cp -r %S/Inputs/portability-restrict-system-includes %T/Headers/portability-restrict-system-includes
+// RUN: %check_clang_tidy -std=c++11 %s portability-restrict-system-includes %t \
+// RUN:   -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
 // RUN:   -system-headers -header-filter=.* \
-// RUN:   -- -I %T/Headers/fuchsia-restrict-system-includes -isystem %T/Headers/fuchsia-restrict-system-includes/system
-// RUN: FileCheck -input-file=%T/Headers/fuchsia-restrict-system-includes/transitive2.h %s -check-prefix=CHECK-FIXES
+// RUN:   -- -I %T/Headers/portability-restrict-system-includes -isystem 

[PATCH] D75786: [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.

2020-03-06 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 248882.
PaulkaToast marked 5 inline comments as done.
PaulkaToast added a comment.

Thanks for the heads up phosek, I removed the check from fuchsia's directory. 
Also addressed Eurgene.Zelenko's comments. (:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75786

Files:
  clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/portability/CMakeLists.txt
  clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/s.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/t.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/r.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/s.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/t.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/transitive2.h
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-headers.cpp
  
clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.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/portability-restrict-system-includes-glob.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
@@ -1,11 +1,11 @@
 // RUN: rm -rf %T/Headers
 // RUN: mkdir %T/Headers
-// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Headers/fuchsia-restrict-system-includes
-// RUN: %check_clang_tidy -std=c++11 %s fuchsia-restrict-system-includes %t \
-// RUN:   -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
+// RUN: cp -r %S/Inputs/portability-restrict-system-includes %T/Headers/portability-restrict-system-includes
+// RUN: %check_clang_tidy -std=c++11 %s portability-restrict-system-includes %t \
+// RUN:   -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
 // RUN:   -system-headers -header-filter=.* \
-// RUN:   -- -I %T/Headers/fuchsia-restrict-system-includes -isystem %T/Headers/fuchsia-restrict-system-includes/system
-// RUN: FileCheck 

[PATCH] D75786: [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.

2020-03-06 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added a reviewer: aaron.ballman.
PaulkaToast added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, phosek, xazax.hun, mgorny.
Herald added a project: clang.

Created a general check for restrict-system-includes under portability as 
recommend in the comments under D75332 . I 
also fleshed out the user facing documentation to show examples for common 
use-cases such as allow-list, block-list, and wild carding.

In the documentation I noted that this new check was moved out from fuchsia and 
an alias was created from the old name to the new name to keep everything 
working. I'm wondering if this is correctly formatted in the release notes.

Nothing should change on fuchsia's end, although feel free to add them if a 
check off is required. (:


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75786

Files:
  clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/portability/CMakeLists.txt
  clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst
  
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/portability-restrict-system-includes-glob.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
+// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}"
+
+// Test glob functionality: disallow all headers except those that match
+// pattern "std*.h".
+
+#include 
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed
Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
+// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,stdio.h'}]}"
+
+// Test allow-list functionality: disallow all but stdio.h.
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed
Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \
+// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stdio.h'}]}"
+
+// Test block-list functionality: allow all but stdio.h.
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed
+#include 
+#include 
Index: clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst
@@ -0,0 +1,51 @@
+.. title:: clang-tidy - portability-restrict-system-includes
+
+portability-restrict-system-includes
+
+
+Checks to selectively allow or disallow a configurable list of system headers.
+
+For example:
+
+In order to **only** allow zlib.h from the system you would set the options to
+`-*,zlib.h`.
+
+.. code-block:: c++
+
+  #include// Bad: disallowed system header.
+  #include   // Bad: disallowed system header.
+  #include  // Good: allowed system header.
+  #include "src/myfile.h"   // Good: non-system header always allowed.
+
+In order to allow everything **except** zlib.h from the system you would set
+the options to `*,-zlib.h`.
+
+.. 

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-06 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 248851.
PaulkaToast added a comment.

Thanks for the suggestions, the general check sounds like a great idea. I can 
see the use case for this as it can be used by anyone. I took the time to port 
out fuchsia's check and flesh out the user facing documentation. Here is the 
patch for that D75786 .

Keeping that in mind, I believe using the general check with a list of headers 
in llvm-libc's case is a bad idea due the following edge cases:

1. The compiler stops providing an include
--

If we had a list that specifically allowed stdbool.h and imagine the compiler 
used stopped providing this header, then we may accidentally pick up the system 
stdbool.h. Having to change the `.clang-tidy` file in llvm-libc's tree when the 
compiler provided includes changes is a maintenance burden and can quickly 
become stale.

2. Platform differences
---

The compiler provided headers may not be the same from operating system to 
operating system. This introduces the need for multiple lists for each system 
supported, where each list suffers from the above problem.

3. Accidental changes to the include order
--

In situations where a mistake is made in the build system and higher priority 
is given to the system includes over the compiler includes. A hand maintained 
list would not be able to catch this.

---

Above all else this test needs to be as strict as possible since many of these 
situations would allow libc to continue to compile, maybe even pass the tests 
but at run-time it could introduce bad behavior due to possible differences in 
implementation details. It is important to us to not have a human-point of 
failure on this check in my opinion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't 

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 248059.
PaulkaToast marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
+
+
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose ``dirent`` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-restrict-system-libc-headers `_,

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

In D75332#1903570 , @MaskRay wrote:

> > `RestrictSystemLibcHeadersCheck`
>
> As I commented previously, I think the checker name should be generalized, as 
> it does not need to be coupled with llvm-libc. Other projects may have 
> similar needs. For example, they don't want to accidentally include a system 
> zlib.h -> they may ship a bundled zlib (say, in third_party/zlib/).
>
> Maybe `misc/` (or `portability/`) is more suitable?


This is a simple check made precisely for llvm libc's use-case and doesn't 
require a human maintained list. As I mentioned, if a more general/configurable 
check is desired then porting out the fuchsia-restrict-system-includes would 
make more sense as it already implements white-lists and would handle the 
situation you described.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 248044.
PaulkaToast marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
+
+
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `dirent` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-restrict-system-libc-headers `_,

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 247960.
PaulkaToast marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
+
+
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `dirent` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-restrict-system-libc-headers `_,

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-02 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 247794.
PaulkaToast marked 11 inline comments as done.
Herald added subscribers: jfb, arphaman.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc
+   #include// Allowed because it is provided by the compiler
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc
+
+
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `FILE *` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-02 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

In D75332#1897487 , @njames93 wrote:

> The test cases need fixing as they are causing the build to fail.


Done.

> Also would it be wise to add a .clang-tidy file to libc/ to enable this 
> module for that subdirectory?

Yes, this will be done in a separate patch. Thanks for pointing it out!

In D75332#1897868 , @Eugene.Zelenko 
wrote:

> Please mention new module in docs/clang-tidy/index.rst and Release Notes (new 
> modules section is above new checks one and please add subsubsection).


Done.

In D75332#1899201 , @MaskRay wrote:

> I am of the feeling that this check should not be llvm-libc specific. It is a 
> general need that certain system headers are not desired. This patch can 
> provide a general mechanism (some whitelists and blacklists).


Please see my reply to aaron.




Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp:40
+SrcMgr::CharacteristicKind FileType) {
+  if (SrcMgr::isSystem(FileType)) {
+if (!SM.isInMainFile(HashLoc)) {

aaron.ballman wrote:
> njames93 wrote:
> > abrachet wrote:
> > > Could you whitelist the freestanding/compiler provided headers like 
> > > stddef, stdatomic...
> > Or have a user configurable whitelist 
> It should be configurable and named something other than whitelist. I'd 
> recommend `AllowedHeaders` or something along those lines.
Maintaining a list of acceptable and blacklisted headers would produce a fair 
bit of maintenance burden. We have a specific use-case in mind here for 
llvm-libc which is to avoid use of system libc headers that aren't provided by 
the compiler. I've added a check to allow for compiler provided headers without 
necessitating a black/white list. 

If a general check is desirable then my suggestion is to pull out [[ 
https://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
 | fuchsia-restrict-system-includes ]] which already implements the features 
mentioned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-02-28 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast created this revision.
PaulkaToast added a reviewer: sivachandra.
PaulkaToast added projects: clang-tools-extra, libc-project.
Herald added subscribers: cfe-commits, MaskRay, xazax.hun, mgorny.
Herald added a project: clang.

This adds a new module to enforce standards specific to the llvm-libc project. 
This change also adds the first check which restricts user from including 
system libc headers accidentally which can lead to subtle bugs that would be a 
challenge to detect.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,12 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,11 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers within llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // illegal include of system libc header
+   #include "internal/stdio.h"
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-restrict-system-libc-headers `_,
`misc-definitions-in-headers `_, "Yes"
`misc-misplaced-const `_,
`misc-new-delete-overloads `_,
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -88,6 +88,11 @@
   Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
   ``memcmp`` and similar derivatives on non-trivial types.
 
+- New :doc:`llvmlibc-restrict-system-libc-headers
+  ` check.
+
+  Finds includes of sytem libc headers in llvm-libc implementation.
+
 - New :doc:`objc-dealloc-in-category
   ` check.
 
Index: clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
@@ -0,0 +1,34 @@
+//===--- RestrictSystemLibcHeadersCheck.h - clang-tidy --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_RESTRICTSYSTEMLIBCHEADERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_RESTRICTSYSTEMLIBCHEADERSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {