aspect-build / aspect-build/rules_lint

[Bug]: clang-tidy includes violations in llvm_toolchain_llvm

Open
#566 1 comment 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Starlark
Stars
154
Forks
125
Avg merge
3d 21h
Merged PRs (30d)
20

Description

### What happened?

When linting with clang-tidy, it seems to find violations in `toolchains_llvm++llvm+llvm_toolchain_llvm`. The tidy error:

```
INFO: Analyzed 7 targets (0 packages loaded, 0 targets configured).
ERROR: /Users/jathu/Documents/color.cpp/src/BUILD:1:11: Linting //src:src with clang-tidy failed: (Exit 1): bash failed: error executing AspectRulesLintClangTidy command (from target //src:src) /bin/bash -c 'bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/aspect_rules_lint+/lint/clang_tidy_wrapper $@' '' ... (remaining 5 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
33649 warnings and 20 errors generated.
Error while processing /private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/sandbox/darwin-sandbox/40/execroot/_main/src/clr.cpp.
error: too many errors emitted, stopping now [clang-diagnostic-error]
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/__functional/hash.h:36:8: error: reference to unresolved using declaration [clang-diagnostic-error]
36 | std::memcpy(&__r, __p, sizeof(__r));
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/cstring:82:1: note: using declaration annotated with 'using_if_exists' here
82 | using ::memcpy _LIBCPP_USING_IF_EXISTS;
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/__mbstate_t.h:51:4: error: "We don't know how to get the definition of mbstate_t without on your platform." [clang-diagnostic-error]
51 | # error "We don't know how to get the definition of mbstate_t without on your platform."
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/math.h:395:31: error: use of undeclared identifier 'FP_NAN' [clang-diagnostic-error]
395 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/math.h:395:39: error: use of undeclared identifier 'FP_INFINITE' [clang-diagnostic-error]
395 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/math.h:395:52: error: use of undeclared identifier 'FP_NORMAL' [clang-diagnostic-error]
395 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/math.h:395:63: error: use of undeclared identifier 'FP_SUBNORMAL' [clang-diagnostic-error]
395 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/math.h:395:77: error: use of undeclared identifier 'FP_ZERO' [clang-diagnostic-error]
395 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/math.h:400:31: error: use of undeclared identifier 'FP_NAN' [clang-diagnostic-error]
400 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/stdlib.h:141:30: error: unknown type name 'ldiv_t' [clang-diagnostic-error]
141 | inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); }
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/stdlib.h:141:82: error: no member named 'ldiv' in the global namespace [clang-diagnostic-error]
141 | inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); }
| ~~^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/stdlib.h:143:30: error: unknown type name 'lldiv_t' [clang-diagnostic-error]
143 | inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); }
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/stdlib.h:143:93: error: no member named 'lldiv' in the global namespace [clang-diagnostic-error]
143 | inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); }
| ~~^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:142:20: error: use of undeclared identifier 'wcschr' [clang-diagnostic-error]
142 | return (wchar_t*)wcschr(__s, __c);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:152:20: error: use of undeclared identifier 'wcspbrk' [clang-diagnostic-error]
152 | return (wchar_t*)wcspbrk(__s1, __s2);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:163:20: error: use of undeclared identifier 'wcsrchr'; did you mean 'wcschr'? [clang-diagnostic-error]
163 | return (wchar_t*)wcsrchr(__s, __c);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:144:72: note: 'wcschr' declared here
144 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:173:20: error: no matching function for call to 'wcschr' [clang-diagnostic-error]
147 | return (wchar_t*)wcsstr(__s1, __s2);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:147:66: note: candidate disabled:
147 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcschr(wchar_t* __s, wchar_t __c) {
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:173:20: error: use of undeclared identifier 'wcsstr'; did you mean 'wcschr'? [clang-diagnostic-error]
173 | return (wchar_t*)wcsstr(__s1, __s2);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:147:66: note: 'wcschr' declared here
147 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcschr(wchar_t* __s, wchar_t __c) {
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:173:27: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'const wchar_t *' [clang-diagnostic-error]
173 | return (wchar_t*)wcsstr(__s1, __s2);
| ^~~~
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:147:82: note: passing argument to parameter '__s' here
147 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcschr(wchar_t* __s, wchar_t __c) {
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/../include/c++/v1/wchar.h:184:20: error: use of undeclared identifier 'wmemchr' [clang-diagnostic-error]
184 | return (wchar_t*)wmemchr(__s, __c, __n);
| ^
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/sandbox/darwin-sandbox/40/execroot/_main/src/clr.cpp:5:13: error: function 'HelloWorld' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage,-warnings-as-errors]
5 | std::string HelloWorld() {
| ^
| static
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/sandbox/darwin-sandbox/40/execroot/_main/src/clr.cpp:5:13: error: use a trailing return type for this function [modernize-use-trailing-return-type,-warnings-as-errors]
5 | std::string HelloWorld() {
| ~~~~~~~~~~~ ^
| auto -> std::string
/private/var/tmp/_bazel_jathu/ab620c5a9d348eb9b5840b21cd8ab57e/sandbox/darwin-sandbox/40/execroot/_main/src/clr.cpp:5:13: error: invalid case style for function 'HelloWorld' [readability-identifier-naming,-warnings-as-errors]
5 | std::string HelloWorld() {
| ^~~~~~~~~~
| hello_world
Suppressed 33654 warnings (33643 in non-user code, 8 NOLINT, 3 with check filters).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
3 warnings treated as errors
INFO: Elapsed time: 2.084s, Critical Path: 1.91s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully
```

### Version

Development (host) and target OS/architectures:

```
macOS Sequoia on M2 Pro
```

Output of `bazel --version`:

```
bazel 8.2.1
```

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:

```starlark
bazel_dep(name = "toolchains_llvm", version = "1.4.0")
bazel_dep(name = "aspect_rules_lint", version = "1.4.4")
bazel_dep(name = "buildifier_prebuilt", version = "8.0.3")

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(llvm_version = "20.1.0")
use_repo(llvm, "llvm_toolchain")
```

Language(s) and/or frameworks involved:

```
C++
```

### How to reproduce

```shell
bazel build --aspects //tools:linters.bzl%clang_tidy //...
```

### Any other information?

clang version:

```
$ clang++ --version

Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: arm64-apple-darwin24.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```

.bazelrc

```starlark

build --repo_env=CC=clang++

build --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
build --cxxopt=-stdlib=libc++ --host_cxxopt=-stdlib=libc++
build --cxxopt=-fno-rtti --host_cxxopt=-fno-rtti

build --copt=-Wall
build --copt=-Werror
build --copt=-Wextra
build --copt=-Wshadow
build --copt=-Wconversion
build --copt=-Wpedantic

build --macos_minimum_os=13
```

clang-tidy:

```
UseColor: true
WarningsAsErrors: "*"
SystemHeaders: false
Checks: >
-*,
bugprone-*,
google-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-branch-clone,
-google-build-namespaces,
-google-readability-todo,
-misc-no-recursion,
-modernize-raw-string-literal,
-modernize-use-nodiscard,
-misc-non-private-member-variables-in-classes,
-readability-identifier-length,
-readability-magic-numbers,
-readability-function-cognitive-complexity,
-readability-else-after-return
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
- { key: readability-identifier-naming.StaticVariableCase, value: lower_case }
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
- { key: readability-identifier-naming.MemberCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
- { key: readability-identifier-naming.PublicMemberSuffix, value: '' }
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.TypeAliasCase, value: CamelCase }
- { key: readability-identifier-naming.TypedefCase, value: CamelCase }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
```

tools/linters.bzl

```starlark
load("@aspect_rules_lint//lint:clang_tidy.bzl", "lint_clang_tidy_aspect")

# Example: https://github.com/aspect-build/rules_lint/blob/main/example/tools/lint/linters.bzl

clang_tidy = lint_clang_tidy_aspect(
binary = Label("@llvm_toolchain//:clang-tidy"),
global_config = [Label("//:.clang-tidy")],
)
```

I just have a single C++ file for testing, I think the violation is coming from the string import:

```cpp
#include

namespace clr {

std::string HelloWorld() {
return "hello";
}

} // namespace clr
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with `bazel build --aspects //tools:linters.bzl%clang_tidy //...` on the reported macOS and toolchain versions. Start with `tools:linters.bzl` and inspect how clang-tidy is applied to `//src:src`; done means the lint no longer reports external `toolchains_llvm` headers while the intended source diagnostics remain handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.