-
-
Notifications
You must be signed in to change notification settings - Fork 283
druntime: Implement va_arg for WebAssembly #5111
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,24 @@ else version (DigitalMars) | |
| */ | ||
| version (GNU) | ||
| T va_arg(T)(ref va_list ap); // intrinsic | ||
| else version (WebAssembly){ | ||
| pragma(LDC_va_arg) | ||
| T ldc_va_arg(T)(ref va_list ap); | ||
| T va_arg(T)(ref va_list ap) | ||
| { | ||
| static if (__traits(isScalar, T) || is(T == U*, U)) | ||
| { | ||
| return ldc_va_arg!T(ap); | ||
| } | ||
| else | ||
| { | ||
| ap = ap.alignUp!(T.alignof); | ||
| auto p = cast(T*) ap; | ||
| ap += T.sizeof.alignUp; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
| return *p; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| T va_arg(T)(ref va_list ap) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
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
elsebranch 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
elsebranch might really suffice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if the
elsebranch suffices, I'd say incorporate it in the genericva_argtemplate below, as for the other archs.