[Attributor][FIX] Do not use assumed information for UB detection
authorJohannes Doerfert <johannes@jdoerfert.de>
Tue, 8 Feb 2022 01:39:19 +0000 (19:39 -0600)
committerJohannes Doerfert <johannes@jdoerfert.de>
Tue, 8 Feb 2022 02:19:19 +0000 (20:19 -0600)
commitdd101c808b85aad8edb48ab6d5f754cc6527fcff
treec8076afc66fd27de10da2752a6e5cfb215772771
parent29c8ebad10b4c349a185438fed52e08426d603e1
[Attributor][FIX] Do not use assumed information for UB detection

The helper `Attributor::checkForAllReturnedValuesAndReturnInsts`
simplifies the returned value optimistically. In `AAUndefinedBehavior`
we cannot use such optimistic values when deducing UB. As a result, we
assumed UB for the return value of a function because we initially
(=optimistically) thought the function return is `undef`. While we later
adjusted this properly, the `AAUndefinedBehavior` was under the
impression the return value is "known" (=fix) and could never change.

To correct this we use `Attributor::checkForAllInstructions` and then
manually to perform simplification of the return value, only allowing
known values to be used. This actually matches the other UB deductions.

Fixes #53647
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/Attributor/undefined_behavior.ll