Skip to content

[WIP] stdlib: add support for AAPCS64 variadics #12623

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 1 commit into from

Conversation

compnerd
Copy link
Member

The AAPCS64 ABI requires that va_list be defined as:

typedef struct __va_list {
  void *__stack;  /* next stack param */
  void *__gr_top; /* end of GP reg save area */
  void *__vr_top; /* end of FP/SIMD reg save area */
  int __gr_offs;  /* offset from __gr_top to next GP register arg */
  int __vr_offs;  /* offset from __vr_top to next FP register arg */
} va_list;

This type does not decay and does not match pointer size.

__stack points to the register save area. __gr_top points to the
byte immediately following the GPR save area, which is rounded to a
16-byte boundary. __vr_top points to the byte immediately following
the FPR save area, which is rounded to a 16-byte boundary. __gr_offs
contains the ((8 - GRCount) * 8), __vr_offs contains
((8 - FPCount) * 16).

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@@ -220,6 +241,7 @@ extension CVaListPointer : CustomDebugStringConvertible {
return value.debugDescription
}
}
#endif
Copy link
Contributor

@gparker42 gparker42 Oct 26, 2017

Choose a reason for hiding this comment

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

This #endif should be up a few lines. The CustomDebugStringConvertible extension should be valid for all definitions.

…and if it isn't valid, you should add a valid one for the AAPCS version.

Copy link
Member Author

@compnerd compnerd Oct 26, 2017

Choose a reason for hiding this comment

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

The value type is different in all cases. In fact, for the AAPCS64 case, its a tuple, rather than an UnsafeMutablePointer. So this doesn't apply in all cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Saleem and I briefly talked about this at the LLVM dev meeting, and I told him to go ahead without it. I'm not sure we have a good debug description for a struct-based va_list that's any better than just showing the children (the default behavior of String(reflecting:)).

@@ -201,6 +201,27 @@ extension OpaquePointer : Equatable {
}

/// The corresponding Swift type to `va_list` in imported C APIs.
#if arch(arm64) && !(os(macOS) || os(iOS) || os(tvOS) || os(watchOS))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment here describing this as the AAPCS64 case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@compnerd compnerd changed the title stdlib: add support for AAPCS64 variadics [WIP] stdlib: add support for AAPCS64 variadics Oct 26, 2017
The AAPCS64 ABI requires that `va_list` be defined as:

    typedef struct __va_list {
      void *__stack;  /* next stack param */
      void *__gr_top; /* end of GP reg save area */
      void *__vr_top; /* end of FP/SIMD reg save area */
      int __gr_offs;  /* offset from __gr_top to next GP register arg */
      int __vr_offs;  /* offset from __vr_top to next FP register arg */
    } va_list;

This type does not decay and does not match pointer size.

`__stack` points to the register save area.  `__gr_top` points to the
byte immediately following the GPR save area, which is rounded to a
16-byte boundary.  `__vr_top` points to the byte immediately following
the FPR save area, which is rounded to a 16-byte boundary.  `__gr_offs`
contains the `((8 - GRCount) * 8)`, `__vr_offs` contains
`((8 - FPCount) * 16)`.
// TODO compare this against the size of the SwiftType rather than the
// void * type.
if (!IsAAPCS64 &&
(ClangTypeSize != ClangCtx.getTypeSize(ClangCtx.VoidPtrTy)))
Copy link
Member Author

Choose a reason for hiding this comment

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

@jrose-apple I couldn't see the equivalent of getTypeSize in the swift ASTContext, perhaps I missed something? Is there an easy way to address that TODO?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really. Swift doesn't bother measuring sizes until IR generation time, and even then you won't be able to do it under certain conditions. I think it's okay to just explicitly leave AAPCS64 out of the impedance check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, Ill probably move this back into the switch then

@compnerd
Copy link
Member Author

compnerd commented May 4, 2018

#15174 is more complete and supersedes this

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.

3 participants