Did you mean llvm/unittests? I believe llvm/test only contains the regression tests.
No, I meant llvm/test.
Apologies for the late return to the discussion, I started reviewing the Langref again and saw that fixes for attributes like align, nonnull, dereferenceable that trigger UB on conditions are simple to fix. Though I am confused about how to handle usage of stores, loads with ptr argument as undef or poison, considering the usage of freeze instruction results in non dereferenceable pointer. Can you suggest a solution in regards to that?
for loads and stores, just add a new ptr argument to the function. It’s the same strategy as for branches.
Unfortunately this project was not selected for GSoC.
If anyone wants to work on this, feel free to open PRs and CC me for review. Feel free to ask questions as well.
Thanks,
Nuno
Hi @nlopes,
I’m interested in this project and I have a few questions:
-
Can you elaborate on this step “Use Alive2 to detect further patterns (by searching for tests that are always UB)”? Does it mean that if I run
./bin/llvm-lit -s -Dopt=$ALIVE2_HOME/build/opt-alive.sh ../llvm/test/Transforms/InstCombine/
locally for against InstCombine, tests with UB would fail? -
You said that we can replace
br i1 undef
withbr i1 %new_fn_arg
. Does this apply to all of the cases for branching under? Here’s one example I found in llvm/test, is this the desired change we want? I’m not quite sure how it works by replacing a new function argument with undef. -
For more advanced cases, such as
store ..., ptr undef
, what’s your suggested approach? Probably use Python’s structural matching?
I’ll try to come up with a small patch or verify with you with Alive2 and godbolt before sending a PR to LLVM.
Thanks,
Lee
you can run llvm-lit like that and then grep the logs directory for “Source function is always UB”.
You also want to change the opt-alive.sh script to pass the flag -tv-fail-src-ub
to opt.
That looks good.
That’s the same thing as branches. A regex should catch all those cases and create new function arguments.
Thanks! I’ll try to craft a small fix PR first and we’ll work on top of that.