Skip to content

Fix zend_separate_if_call_and_write for FUNC_ARGs #12140

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

Closed
wants to merge 3 commits into from

Conversation

iluuu1994
Copy link
Member

@iluuu1994 iluuu1994 commented Sep 6, 2023

Fixes GH-12102

Note on the optimizer changes: Zend/tests/gh12102_3.phpt demonstrates an existing issue in the optimizer. Namely, we're always converting FETCH_DIM_FUNC_ARG/FETCH_OBJ_FUNC_ARG into FETCH_DIM_W/FETCH_OBJ_W if the parameter is known to be by-ref. However, this is incorrect for containers that are TMP, as there's no such specialization.

If we don't convert these fetches, we also need to keep the CHECK_FUNC_ARG opcode, so that we're actually aware of the fetch-mode in the FUNC_ARG opcodes.

@iluuu1994 iluuu1994 changed the title Fix zend_compile_simple_var for FUNC_ARGs Fix zend_separate_if_call_and_write for FUNC_ARGs Sep 6, 2023
@iluuu1994 iluuu1994 force-pushed the gh-12102 branch 6 times, most recently from e184f86 to 3361eb3 Compare September 6, 2023 20:05
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look good. Please check the comments. (May be I didn't understand all the details).

@@ -272,6 +281,7 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
opline->opcode = ZEND_FETCH_STATIC_PROP_R;
}
}
MAKE_NOP(call_stack[call - 1].last_check_func_arg_opline);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the right place for MAKE_NOP.
I would move it into ZEND_SEND_FUNC_ARG.

		case ZEND_SEND_FUNC_ARG:
				/* Don't transform SEND_FUNC_ARG if any FETCH opcodes weren't transformed. */
				if (call_stack[call - 1].last_check_func_arg_opline == NULL) {
					if (opline->op2_type == IS_CONST) {
						call_stack[call - 1].try_inline = 0;
					}
					break;
+				} else {
+                  MAKE_NOP(call_stack[call - 1].last_check_func_arg_opline);
				}
				call_stack[call - 1].last_check_func_arg_opline = NULL;
				ZEND_FALLTHROUGH;
			case ZEND_SEND_VAR_EX:

@iluuu1994
Copy link
Member Author

Thanks for the reviews @dstogov!

iluuu1994 added a commit that referenced this pull request Sep 7, 2023
@iluuu1994
Copy link
Member Author

Merged as 748adf1 (misspelled "closes")

@iluuu1994 iluuu1994 closed this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants