Skip to content

[libc] Improve the state of the lint rules #135278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michaelrj-google
Copy link
Contributor

The goal of this change is to update the rules such that we can run the
linter and get a clean result. For testing purposes set
-DLLVM_LIBC_ENABLE_LINTING=ON and run ninja -j 1 -k 0 libc-lint, or
pick a single __lint__ target, such as ninja libc.src.stdio.sprintf.__lint__.

BEFORE MERGING:
remove --fix from the lint target

The goal of this change is to update the rules such that we can run the
linter and get a clean result. For testing purposes set
`-DLLVM_LIBC_ENABLE_LINTING=ON` and run `ninja -j 1 -k 0 libc-lint`, or
pick a single `__lint__` target, such as `ninja
libc.src.stdio.sprintf.__lint__`.

BEFORE MERGING:
remove --fix from the lint target
@llvmbot llvmbot added the libc label Apr 10, 2025
@michaelrj-google michaelrj-google marked this pull request as draft April 10, 2025 23:15
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

The goal of this change is to update the rules such that we can run the
linter and get a clean result. For testing purposes set
-DLLVM_LIBC_ENABLE_LINTING=ON and run ninja -j 1 -k 0 libc-lint, or
pick a single __lint__ target, such as ninja libc.src.stdio.sprintf.__lint__.

BEFORE MERGING:
remove --fix from the lint target


Full diff: https://github.com/llvm/llvm-project/pull/135278.diff

4 Files Affected:

  • (modified) libc/.clang-tidy (+8)
  • (modified) libc/cmake/modules/LLVMLibCObjectRules.cmake (+1-1)
  • (added) libc/include/.clang-tidy (+3)
  • (modified) libc/src/.clang-tidy (+1-1)
diff --git a/libc/.clang-tidy b/libc/.clang-tidy
index dbde88928ee63..bd09aae981ba9 100644
--- a/libc/.clang-tidy
+++ b/libc/.clang-tidy
@@ -6,6 +6,8 @@ CheckOptions:
     value:           CamelCase
   - key:             readability-identifier-naming.StructCase
     value:           aNy_CasE
+  - key:             readability-identifier-naming.StructIgnoredRegexp
+    value:           "_?(_[A-Za-z0-9]+)*"
   - key:             readability-identifier-naming.MemberCase
     value:           lower_case
   - key:             readability-identifier-naming.MemberIgnoredRegexp
@@ -14,6 +16,10 @@ CheckOptions:
     value:           lower_case
   - key:             readability-identifier-naming.VariableIgnoredRegexp
     value:           "_?(_[A-Za-z0-9]+)*"
+  - key:             readability-identifier-naming.ParameterCase
+    value:           lower_case
+  - key:             readability-identifier-naming.ParameterIgnoredRegexp
+    value:           "_?(_[A-Za-z0-9]+)*"
   - key:             readability-identifier-naming.FunctionCase
     value:           lower_case
   - key:             readability-identifier-naming.FunctionIgnoredRegexp
@@ -26,6 +32,8 @@ CheckOptions:
     value:           UPPER_CASE
   - key:             readability-identifier-naming.ConstexprVariableCase
     value:           UPPER_CASE
+  - key:             readability-identifier-naming.ConstexprVariableIgnoredRegexp
+    value:           "is(_[A-Za-z0-9]+)*_v"
   - key:             readability-identifier-naming.ConstexprFunctionCase
     value:           lower_case
   - key:             readability-identifier-naming.GetConfigPerFile
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 142778d9ea1cc..c8a20341ff74f 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -355,7 +355,7 @@ function(create_entrypoint_object fq_target_name)
       # Until this is fixed upstream, we use -fno-caret-diagnostics to surpress
       # these.
       COMMAND ${LLVM_LIBC_CLANG_TIDY}
-              "--extra-arg=-fno-caret-diagnostics" --quiet
+              "--extra-arg=-fno-caret-diagnostics" --quiet --fix
               # Path to directory containing compile_commands.json
               -p ${PROJECT_BINARY_DIR}
               ${ADD_ENTRYPOINT_OBJ_SRCS}
diff --git a/libc/include/.clang-tidy b/libc/include/.clang-tidy
new file mode 100644
index 0000000000000..a6c02dd90e4d2
--- /dev/null
+++ b/libc/include/.clang-tidy
@@ -0,0 +1,3 @@
+InheritParentConfig: false
+Checks: ''
+HeaderFilterRegex: '.*'
diff --git a/libc/src/.clang-tidy b/libc/src/.clang-tidy
index 1c79b1cf6aae6..7e97dac43d38a 100644
--- a/libc/src/.clang-tidy
+++ b/libc/src/.clang-tidy
@@ -4,4 +4,4 @@ HeaderFilterRegex: '.*'
 WarningsAsErrors: 'llvmlibc-*'
 CheckOptions:
   - key:             llvmlibc-restrict-system-libc-headers.Includes
-    value:           '-*, linux/*, asm/*.h, asm-generic/*.h'
+    value:           '-*, linux/*, asm/*.h, asm-generic/*.h. sys/syscall.h'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants