-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning by-ref values from overridden methods and not capturing them at call site #6542
Comments
P.S this was also something discovered by @LouisJenkinsCS |
6 tasks
3 tasks
mppf
added a commit
to mppf/chapel
that referenced
this issue
Sep 15, 2017
mppf
added a commit
that referenced
this issue
Sep 18, 2017
Add resolvedOrVirtualFunction, fix issue #6542 This PR takes two steps to fix issue #6542: 1. It introduces a function, `CallExpr::resolvedOrVirtualFunction`, factoring out a code pattern used already in callDestructors and errorHandling. The pattern is to find the resolved function, or, for a PRIM_VIRTUAL_METHOD_CALL, find one of the possible virtual methods that could be called at runtime. This function is appropriate to call for code that identifies calls to transform based upon the signature of the called function. 2. It calls this function in two places in order to resolve issue #6542. What was going wrong with issue #6542? The compiler includes a transformation that happens during resolution, `insertReturnTemps`, which finds all calls to functions that return a value that don't use the result of that return. In that case it adds a temporary variable to capture the returned value. Code in callDestructors / ReturnByRef relied on calls to transformable functions having a variable to capture the returned value. In the case of virtual method calls, `insertReturnTemps` was not transforming the call, and so the code pattern in issue #6542 led to failed assertions in callDestructors. The important part of this fix is to adjust `insertReturnTemps` to handle virtual calls (PRIM_VIRTUAL_METHOD_CALL). Passed full local testing. Reviewed by @noakesmichael - thanks!
@e-kayrakli , @LouisJenkinsCS - this bug should be fixed in master now. Could you check over the Collections modules & update any documentation / fix any workarounds? Once you do that we should close this issue. Thanks. |
I'll have it done soon. |
You can close the issue now. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary of Problem
Returning some values from overridden methods seems to cause compiler crashes, if the value returned is not captured at the call site.
(I am not entirely sure if the title of the issue captures the problem in a good way)
A little bit of GDB'ing shows that
calledFn
in https://github.com/chapel-lang/chapel/blob/master/compiler/resolution/callDestructors.cpp#L515 seems to be null if thecall
is aPRIM_VIRTUAL_METHOD_CALL
causing a null dereference in the next line.Steps to Reproduce
Source Code:
I have tried and confirmed that this crashes if
foo
returns: homogeneous/heterogeneous tuples and strings. Returning a class instance field of A seems to compile fine, any primitives are also fine. Moreover returning a primitive class field as such also seems fine:Compile command:
chpl foo.chpl
Execution command:
Doesn't compile.
Associated Future Test(s):
test/classes/elliot/non-captured-virtual-return.chpl
#7318Configuration Information
chpl --version
:$CHPL_HOME/util/printchplenv --anonymize
:The text was updated successfully, but these errors were encountered: