llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

using negative regular expressions with {run-}clang-tidy #85905

Open firewave opened 8 months ago

firewave commented 8 months ago

https://github.com/llvm/llvm-project/pull/82416#issuecomment-1955055082 mentioned that filter options with regular expression support can use negative expressions as exclude patterns.

I thought one of the limitations of llvm::RegEx is that it doesn't support negative expressions so I wonder how that should work.

I want to use this with -source-filter for run-clang-tidy as well as bugprone-unused-return-value.CheckFunctions.

CC @carlosgalvezp @HerrCai0907

firewave commented 8 months ago

Use cases:

1) With run-clang-tidy I want to scan a compilation database from a CMake project but exclude all moc_*.cpp (generated by moc from Qt) files. 2) With bugprone-unused-return-value.CheckFunctions I want to check all functions (via ::.*) but need to exclude functions like std::map::insert() and std::map::emplace() where the return code is rarely checked.

firewave commented 8 months ago

@EugeneZelenko This is actually a question. The feature is supposedly already there.

EugeneZelenko commented 8 months ago

@firewave: Do you have triage role? If not, please request it, since you file issues often, it'll be definitely helpful to have possibility to adjust labels.

firewave commented 8 months ago

@firewave: Do you have triage role? If not, please request it, since you file issues often, it'll be definitely helpful to have possibility to adjust labels.

No, I don't. How do I request that? The contribution guides do not seem to mention that.

"often" seems a bit like a stretch though. 😀 I am happy to help out though.

EugeneZelenko commented 8 months ago

@firewave: I asked for commit access (roles were split only recently) as described on https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access. My guess that procedure for triage access is same.

carlosgalvezp commented 8 months ago

Hi!

Sorry for the delay in answering. I have looked a bit deeper into this. It seems llvm::Regex implements POSIX Extended Regular Expression (ERE), which does not support negative lookahead patterns (which would be required for this use case). Thus my original comment was wrong, it's not possible to get this behavior out of the box. Apologies for introducing confusion!

Thus we probably need to make do with two filters, one for filtering in, and one for filtering out.

EugeneZelenko commented 8 months ago

@tstellar: I think will be good idea to extend https://llvm.org/docs/DeveloperPolicy.html or https://llvm.org/docs/BugLifeCycle.html with details about getting triage access.

tstellar commented 8 months ago

@EugeneZelenko We don't currently have a process to apply for triage access. Users should follow the process for requesting commit access.

nicovank commented 7 months ago

I want to use this with -source-filter for run-clang-tidy.

This will work for run-clang-tidy.py, because the source-filter there uses Python regular expressions, it's not passed to the underlying Clang-Tidy.

Just a silly example to demonstrate: all files in a clang-query directory not in tool subdirectory. clang-tools-extra/clang-query/tool/ClangQuery.cpp is not matched anymore.

python3~/llvm-project/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py \
    -source-filter='.*/clang-query/(?!tool).*'