Fix generator output for functions with a parameter named ret - #184
Draft
rootkiller6788 wants to merge 1 commit into
Draft
Fix generator output for functions with a parameter named ret#184rootkiller6788 wants to merge 1 commit into
ret#184rootkiller6788 wants to merge 1 commit into
Conversation
The return value slot of a generated wrapper function was named `v_ret_`, which collides with the local copy of a parameter named `ret` (parameter locals are built as `v_<name>_`, so `ret` becomes `v_ret_`). The generated code then declared `v_ret_` twice in the same scope, e.g. for libxslt functions that use `ret` as a parameter name. Rename the return value variable to `v_ret`, which cannot collide with any parameter-derived variable since those always carry a trailing underscore. Fixes google#142
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #142: the clang generator emits syntactically invalid wrapper code when a sandboxed function has a parameter named
ret.The client-side wrapper generated by
Emitter::DoEmitFunction()declares the return-value slot asv_ret_and the local copy of each parameter asv_<name>_. For a parameter namedret, both variables end up namedv_ret_in the same scope, so the generated header does not compile ("redeclaration of 'v_ret_'"). This breaks headers like libxslt's that useretas a parameter name.This change renames the return-value slot to
v_ret. Parameter-derived variables always carry a trailing underscore, sov_retcan never collide with them.Verified by compiling the generated wrapper for
int FunctionWithRet(int ret)with g++: before the fix it fails witherror: redeclaration of 'sapi::v::Int v_ret_'; after the fix it compiles cleanly. A regression test (EmitterTest.ParameterNamedRet) checks that the return slot and the parameter copy are passed tosandbox_->Call()as two distinct variables.