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 possible to disable specific clang-analyzer checks #59588

Open
carlosgalvezp opened this issue Dec 19, 2022 · 9 comments
Open
Labels
bug Indicates an unexpected problem or unintended behavior clang-tidy

Comments

@carlosgalvezp
Copy link
Contributor

carlosgalvezp commented Dec 19, 2022

Running clang-tidy as:

clang-tidy main.cpp -checks=-*,clang-analyzer-core*,-clang-analyzer-core.uninitialized.Assign --list-checks

Displays:

    clang-analyzer-core.CallAndMessage
    clang-analyzer-core.CallAndMessageModeling
    clang-analyzer-core.DivideZero
    clang-analyzer-core.DynamicTypePropagation
    clang-analyzer-core.NonNullParamChecker
    clang-analyzer-core.NonnilStringConstants
    clang-analyzer-core.NullDereference
    clang-analyzer-core.StackAddrEscapeBase
    clang-analyzer-core.StackAddressEscape
    clang-analyzer-core.UndefinedBinaryOperatorResult
    clang-analyzer-core.VLASize
    clang-analyzer-core.builtin.BuiltinFunctions
    clang-analyzer-core.builtin.NoReturnFunctions
    clang-analyzer-core.uninitialized.ArraySubscript
    clang-analyzer-core.uninitialized.Assign                                   <<<<<<<<<< Should be removed
    clang-analyzer-core.uninitialized.Branch
    clang-analyzer-core.uninitialized.CapturedBlockVariable
    clang-analyzer-core.uninitialized.NewArraySize
    clang-analyzer-core.uninitialized.UndefReturn

This behavior does not happen on other checks.

@carlosgalvezp carlosgalvezp added bug Indicates an unexpected problem or unintended behavior clang-tidy new issue labels Dec 19, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 19, 2022

@llvm/issue-subscribers-bug

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 19, 2022

@llvm/issue-subscribers-clang-tidy

@firewave
Copy link

They can be disabled as a whole via -checks=-clang-analyzer-* though.

@carlosgalvezp
Copy link
Contributor Author

Yep. I do want to disable only specific checks that are problematic/have false positives, not all of them...

Could it be the dots in the name of the check which is the problem? The other checks don't have dots in the name.

@carlosgalvezp
Copy link
Contributor Author

If I add --explain-config, I see something interesting:

'clang-analyzer-core.uninitialized.ArraySubscript' is enabled in the command-line option '-checks'.
'clang-analyzer-core.uninitialized.Assign' is enabled in the clang-tidy binary.

So the check is enabled in the binary, not via -checks, and can't be overriden.

@carlosgalvezp
Copy link
Contributor Author

Digging deep into the code, I find:

  // Always add all core checkers if any other static analyzer check is enabled.
  // This is currently necessary, as other path sensitive checks rely on the
  // core checkers.

I don't quite understand the comment. What are path sensitive checks?

@firewave
Copy link

That appears to be a certain type of static analyzer check - hence https://github.com/llvm/llvm-project/tree/main/clang/include/clang/StaticAnalyzer/Core/PathSensitive.

@carlosgalvezp
Copy link
Contributor Author

@haoNoQ Do you have any insight as to why core CSA checks must be enabled for all other checks to work? Is the comment still valid nowadays?

  // List all static analyzer checkers that our filter enables.
  //
  // Always add all core checkers if any other static analyzer check is enabled.
  // This is currently necessary, as other path sensitive checks rely on the
  // core checkers.
  for (StringRef CheckName : RegisteredCheckers) {
    std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());

    if (CheckName.startswith("core") ||
        Context.isCheckEnabled(ClangTidyCheckName)) {
      List.emplace_back(std::string(CheckName), true);
    }
  }

@carlosgalvezp
Copy link
Contributor Author

carlosgalvezp commented Jan 28, 2023

This was first introduced around 10 years ago here. I don't see many details in the commit message to tell what exactly is it that was failing in the past that needed this to be added. @r4nt do you recall? Is this comment valid today? If I were to remove it, how can I test that things still work as expected? ninja check-clang-tools works just fine without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior clang-tidy
Projects
None yet
Development

No branches or pull requests

4 participants