[clang] [Inliner] Improve attribute propagation to callsites when inlining. (PR #66036)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 18 03:00:08 PDT 2023


nikic wrote:

> > It occurs to me that the current return attribute propagation is currently buggy for poison-generating attributes: https://llvm.godbolt.org/z/x8n18q9Mj
> > In this case the argument to use() will now be poison as well, while before inlining only the return value was poison.
> > This code needs to distinguish poison and UB generating attributes.
> 
> Good catch. I think this means basically `nonnull`, `noundef`, and `align` can only be propagated if there are no other uses in to-be-inlined function. That sound right or do you see any more robust way forward?

Limiting poison-generating attributes to one-use while keeping the rest of the logic (with guarantee-to-transfer) would be the simplest way to make the existing code correct. There are two additional ways to generalize:

 * If the return is also noundef, we don't need one-use.
 * Just one-use is enough for poison-generating, we don't need guaranteed-to-transfer, BUT: we need to be careful about an implicit "use" in the call itself. That is, if the call we're transfering to is noundef and we only check one-use but not guaranteed-to-transfer, we would convert poison into UB at that point.

https://github.com/llvm/llvm-project/pull/66036


More information about the cfe-commits mailing list