Skip to content

Fix generator output for functions with a parameter named ret - #184

Draft
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-generator-ret-param
Draft

Fix generator output for functions with a parameter named ret#184
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-generator-ret-param

Conversation

@rootkiller6788

Copy link
Copy Markdown

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 as v_ret_ and the local copy of each parameter as v_<name>_. For a parameter named ret, both variables end up named v_ret_ in the same scope, so the generated header does not compile ("redeclaration of 'v_ret_'"). This breaks headers like libxslt's that use ret as a parameter name.

This change renames the return-value slot to v_ret. Parameter-derived variables always carry a trailing underscore, so v_ret can never collide with them.

Verified by compiling the generated wrapper for int FunctionWithRet(int ret) with g++: before the fix it fails with error: 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 to sandbox_->Call() as two distinct variables.

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
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.

Generator cannot handle arguments named ret

1 participant