-
Notifications
You must be signed in to change notification settings - Fork 333
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
Add lint for nondeterministic pointer comparison #1054
Conversation
Thanks, I'll have a look. |
@nuchi I rebased with master-dev and tried to build but could not for now. Could you simply paste somewhere the entire log you get with the lint plugin ? Then I could try to fix the code starting from that. |
4fd3f8c
to
87c523c
Compare
Hi @sletz , thanks for letting me know the build failed for you, I rebased on latest and also fixed the issues with git submodule permissions by replacing git@-style submodule with https-style submodule. I also addressed an issue that would have prevented building on linux. If you don't mind would you be willing to try |
Thanks. Trying to build on macOS Monterey 12.7.6 with LLCM/Clang 19 installed with macports, I has to do:
but then make debug gives:
Which LLvm/Clang version are you using ? |
OK, compiling with LLVM 18. |
@nuchi I was able to fix all sources of non-determinism, using a somewhat "brute-force" approach on all use of Tree pointer comparisons, either directly, or when used on STL containers. Thanks again for the PR that makes this fix possible ! |
great to hear it! I'm happy to leave this branch up to make it easier to periodically rebase and check for accidental relapses if you don't want to merge. sounds like it might introduce maintenance burdens re: updating LLVM. |
Finally merged, version 2.77.1. I guess it will be doable this way. |
@sletz I figured out a CMake integration for the pointer nondeterminism lint I mentioned to you. I did it by wrapping clang-query into a clang plugin, so that a query can be automatically converted into a compiler warning. The plugin is at https://github.com/nuchi/node-matcher-plugin
(Context for others: code generation is nondeterministic because sometimes the compiler will compare pointers in situations where it needs to arbitrarily choose one. But pointers are generated by malloc/new and therefore change from run to run. One way to eliminate this non-determinism is to not compare pointers. But that can be hard to detect. Hence this new lint step.)
Adds a compiler warning for doing a pointer comparison between
CTreeBase*
orSymbol*
, in order to better find where nondeterminism is happening.It's enabled automatically for
make debug
, and can be enabled for other targets by doingmake compiler NONDETERMINISM_LINT=yes
Needs
llvm-config
to be in one's PATH; it'll set the C++ compiler to be the version of clang that's shipped with LLVM. (It builds a clang plugin against the installed LLVM, so it needs to use the same C++ compiler.)Sample cmake output:
Note that it'll be very noisy, because it'll give the same warning for e.g.
tree.hh
in every translation unit that includes it.