Skip to content

druntime: Implement va_arg for WebAssembly#5111

Open
IDONTUSEGH wants to merge 1 commit intoldc-developers:masterfrom
IDONTUSEGH:wasm-vararg
Open

druntime: Implement va_arg for WebAssembly#5111
IDONTUSEGH wants to merge 1 commit intoldc-developers:masterfrom
IDONTUSEGH:wasm-vararg

Conversation

@IDONTUSEGH
Copy link
Copy Markdown
Contributor

It uses 'pragma(LDC_va_arg)' to emit the LLVM instruction for scalars and pointers (matches how it's implemented in tocall.cpp), else it falls back to manual pointer arithmetic.

I'm not 100% sure if that's correct.

{
static if (__traits(isScalar, T) || is(T == U*, U))
{
return ldc_va_arg!T(ap);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't use this LLVM intrinsic anywhere else, it's basically useless and only works for trivial types (if at all), where the implementation is trivial anyway (your else branch most likely).

After glancing at https://github.com/ldc-developers/ldc/blob/master/gen/abi/wasm.cpp and the last paragraph in https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md#function-arguments-and-return-values, I think the else branch might really suffice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So if the else branch suffices, I'd say incorporate it in the generic va_arg template below, as for the other archs.

{
ap = ap.alignUp!(T.alignof);
auto p = cast(T*) ap;
ap += T.sizeof.alignUp;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think the size needs to be aligned up here; this will be taken care of by the alignUp!(T.alignof) for the next argument. If I understand the spec paragraph correctly:

Arguments are arranged in order in the buffer, with each argument placed at the lowest appropriately aligned address after the previous argument.

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