This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] Relax restrictions on GPU-side variadic functions
ClosedPublic

Authored by tra on May 16 2023, 1:40 PM.

Details

Summary

Allow parsing GPU-side variadic functions when we're compiling with CUDA-9 or
newer. We still do not allow accessing variadic arguments.

CUDA-9 was the version which introduced PTX-6.0 which allows implementing
variadic functions, so older versions can't have variadics in principle.

This is required for dealing with headers in recent CUDA versions that rely on
variadic function declarations in some of the templated code in libcu++.
E.g. https://github.com/llvm/llvm-project/issues/58410

Diff Detail

Event Timeline

tra created this revision.May 16 2023, 1:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 1:40 PM
tra published this revision for review.May 16 2023, 1:42 PM
tra added reviewers: jlebar, yaxunl.
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 1:42 PM

This seems a little dangerous -- we're saying the frontend will accept this but we can't generate code for it? What happens if we try to generate code? Do we get some sort of error, or do we silently fail?

could make the diagnostic about variadic functions a deferred diagnostic, then the diag will only be emitted if the function is really emitted.

tra added a comment.May 17 2023, 10:33 AM

This seems a little dangerous -- we're saying the frontend will accept this but we can't generate code for it? What happens if we try to generate code? Do we get some sort of error, or do we silently fail?

This will allow generation of variadic functions, as long as they do not use va_arg (in other words, as long as they do not access the variadic arguments).
It's safe to do now, because NVPTX backend already has variadics support

In case va_arg is encountered, clang will produce correct diagnostics and it is already covered by test/SemaCUDA/vararg.cu

could make the diagnostic about variadic functions a deferred diagnostic, then the diag will only be emitted if the function is really emitted.

The short-term need is only for being able to parse variadic function declarations. Being able to emit some of them is nice, but not useful in practice. No point blocking the ones we can emit, but there's not much benefit in extending that set with deferred diags either.

I do plan to enable full support for variadics soon, anyways.

jlebar accepted this revision.May 17 2023, 12:13 PM

OK, sgtm.

This revision is now accepted and ready to land.May 17 2023, 12:13 PM
This revision was landed with ongoing or failed builds.May 17 2023, 12:51 PM
This revision was automatically updated to reflect the committed changes.