[llvm] [Inliner] Fix bug where attributes are propagated incorrectly (PR #109347)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 16:19:36 PDT 2024
================
@@ -1477,6 +1483,12 @@ static void AddReturnAttributes(CallBase &CB, ValueToValueMapTy &VMap) {
auto *NewRetVal = dyn_cast_or_null<CallBase>(VMap.lookup(RetVal));
if (!NewRetVal)
continue;
+
+ // The RetVal might have be simplified during the inlining
+ // process. Only propagate return attributes if we are in fact calling the
+ // same function.
+ if (RetVal->getCalledFunction() != NewRetVal->getCalledFunction())
----------------
efriedma-quic wrote:
This doesn't seem like it will reliably detect the issue.
First off, if both calls are indirect, both calls to getCalledFunction() would return nullptr, in which case you aren't getting any useful information at all.
Second, even if both calls are calling the "same" function, it might not have the same behavior if the arguments are different. Or global state is different. Not sure how likely this is given the limited simplifications the inline performs, but it's hard to rule out.
So I think we need to avoid using VMap, and pass down the equivalence information some other way.
https://github.com/llvm/llvm-project/pull/109347
More information about the llvm-commits
mailing list