CallSiteValue::get_called_fn_value: return None on indirect calls #572
+119
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #571.
CallSiteValue::get_called_fn_value
now matches the behavior ofCallBase::getCalledFunction
and returnsNone
when the underlying instruction is an indirect call or a type inconsistency is detected (the latter only for LLVM >= 8).CallSiteValue::get_called_fn_type
corresponds toCallBase::getFunctionType
and returns the type of the function called by the underlying call/invoke instruction. This is always well defined, whether the call is indirect or not. This new function only exists for LLVM >=8 because it depends onLLVMGetCalledFunctionType
.Related Issue
#571
How This Has Been Tested
Non-regression on #571 is tested by a dedicated test which uses a simplified version of the issue's reproduction code. For simplicity, this test is restricted to LLVM >= 15 (the test's IR snippet uses opaque pointers).
Doctests of
CallSiteValue::get_called_fn_value
and the newCallSiteValue::get_called_fn_type
cover the usual-case, happy paths.Breaking Changes
CallSiteValue::get_called_fn_value
now returns anOption<FunctionValue>
instead of aFunctionValue
to model the fact that it may not be possible to retrieve the underlying function value (when the call is indirect).Discussion
FunctionValue::new
differs from most other type constructors (e.g.FunctionType::new
) since it checks for the safety requirements and returnsNone
if they are not met:unsafe
?unsafe
?Checklist