Skip to content
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

Clang tidy not picking up all diagnostics in some code #148524

Closed
matanlurey opened this issue May 17, 2024 · 3 comments
Closed

Clang tidy not picking up all diagnostics in some code #148524

matanlurey opened this issue May 17, 2024 · 3 comments
Labels
c: tech-debt Technical debt, code quality, testing, etc. engine flutter/engine repository. See also e: labels. team-engine Owned by Engine team

Comments

@matanlurey
Copy link
Contributor

I see a warning in my IDE (via clangd) in shell/platform/android/android_display.cc:

The parameter 'jni_facade' is copied for each invocation but only used as a const reference; consider making it a const referenceclang-tidy[performance-unnecessary-value-param](https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-value-param.html)
param jni_facade
Type: std::shared_ptr<PlatformViewAndroidJNI>

// In AndroidDisplay::AndroidDisplay
std::shared_ptr<PlatformViewAndroidJNI> jni_facade

However, it isn't linted (either on CI or locally, i.e. with ./ci/clang_tidy.sh --variant android_debug_unopt_arm64.

@christopherfujino and I suspected maybe my configuration locally is different, there are different binaries, a bug in the rule, etc, but interestingly enough in another file (impeller/renderer/shader_library.cc) if I remove the opt-out (// NOLINT(performance-unnecessary-value-param)) it does trigger:

./ci/clang_tidy.sh --variant android_debug_unopt_arm64

🔶 linting flutter/impeller/renderer/shader_library.cc
🔶 linting flutter/shell/platform/android/android_display.cc
[0:04] Jobs:  50% done,   0/2   completed,  1 in progress,   0 pending,   1 failed.    
[0:04] Still running: [clang-tidy on /Users/matanl/Developer/engine/src/flutter/shell/platform/android/android_display.cc]
❌ Failures for clang-tidy on /Users/matanl/Developer/engine/src/flutter/impeller/renderer/shader_library.cc:
/Users/matanl/Developer/engine/src/flutter/impeller/renderer/shader_library.cc:18:26: error: the parameter 'callback' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param,-warnings-as-errors]
   18 |     RegistrationCallback callback) {
      |                          ^
Suppressed 1920 warnings (1894 in non-user code, 26 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error
[0:13] Jobs: 100% done,   1/2   completed,  0 in progress,   0 pending,   1 failed.    

Lint problems found

Even more interesting, the same lint will get flagged if I add another case of it in the same file:

// An example of a method that violates performance-unnecessary-value-param
void example(std::shared_ptr<int> a) {}
🔶 linting flutter/shell/platform/android/android_display.cc
[0:12] Jobs: 100% done,   0/1   completed,  0 in progress,   0 pending,   1 failed.    
❌ Failures for clang-tidy on /Users/matanl/Developer/engine/src/flutter/shell/platform/android/android_display.cc:
/Users/matanl/Developer/engine/src/flutter/shell/platform/android/android_display.cc:10:35: error: the parameter 'a' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param,-warnings-as-errors]
   10 | void example(std::shared_ptr<int> a) {}
      |                                   ^
      |              const               &
Suppressed 2717 warnings (2687 in non-user code, 30 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error

Lint problems found.

This is also linted in the same file:

// An example of a method that violates performance-unnecessary-value-param
class Foo {
 public:
  explicit Foo(std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
};

Foo::Foo(std::shared_ptr<PlatformViewAndroidJNI> jni_facade) {}

So either there is something specific about why AndroidDisplay::AndroidDisplay isn't linted, or its a clang-tidy bug.

@matanlurey matanlurey added engine flutter/engine repository. See also e: labels. c: tech-debt Technical debt, code quality, testing, etc. team-engine Owned by Engine team labels May 17, 2024
@bc-lee
Copy link

bc-lee commented May 17, 2024

clang-tidy won't generate a warning for performance-unnecessary-value-param if std::move is used.

The constructor in flutter/shell/platform/android/android_display.cc moves the parameter jni_facade into the member variable jni_facade_, so the warning probably won't be generated in this case.

To confirm if you're using the project's embedded clang-tidy binary (flutter/buildtools/{os}-{arch}/clang/bin/clang-tidy) , you can specify the Clang-Tidy binary using the C_Cpp.codeAnalysis.clangTidy.path setting in VSCode or Settings | Languages & Frameworks | C/C++ in CLion.

@matanlurey
Copy link
Contributor Author

Huh, that sort of begs that my VSCode configuration is borked some how (it's using ${workspaceFolder}/buildtools/mac-arm64/clang/bin/clangd, which I assume is synced with clang-tidy)?

Makes sense, thanks for flagging.

@matanlurey matanlurey closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: tech-debt Technical debt, code quality, testing, etc. engine flutter/engine repository. See also e: labels. team-engine Owned by Engine team
Projects
None yet
Development

No branches or pull requests

2 participants