This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add more test cases to the argument list tests
ClosedPublic

Authored by jhuber6 on Aug 25 2023, 10:53 AM.

Details

Summary

This patch adds some extra cases to the existing argument list test in
libc, mainly dealing with arguments of varying sizes and primitive
types.

The purpose of this patch is to provide a wider test area when we begin
to provide varargs support on the GPU as there is no other runtime code
that really tests it. So, running these tests more exhaustively in the
GPU libc project will serve as the runtime tests for GPU vararg support in
D158246.

Diff Detail

Event Timeline

jhuber6 created this revision.Aug 25 2023, 10:53 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 25 2023, 10:53 AM
jhuber6 requested review of this revision.Aug 25 2023, 10:53 AM
jhuber6 updated this revision to Diff 553548.Aug 25 2023, 11:00 AM

Adjust test

arsenm added inline comments.Aug 25 2023, 11:17 AM
libc/test/src/__support/arg_list_test.cpp
67

no char either?

77

Also should test short, half, pointers, ext_vector_type, bool

jhuber6 added inline comments.Aug 25 2023, 11:20 AM
libc/test/src/__support/arg_list_test.cpp
67

It's passed in as a char, but all varargs get promoted to an integer as far as I'm aware, https://godbolt.org/z/Wssrrz3M1.

77

Would ext_vector_type compile on the GPU?

arsenm added inline comments.Aug 25 2023, 11:23 AM
libc/test/src/__support/arg_list_test.cpp
77

well it's all the vector types. that's what opencl vectors are and work

jhuber6 added inline comments.Aug 25 2023, 11:27 AM
libc/test/src/__support/arg_list_test.cpp
77

Can you provide an example of that? I assume ext_vector_specific is an OpenCL term that might has some other way to use externally like a lot of other things. This test should primarily work on X64 but we can use macros to only enable a test for the GPU if needed (though it won't do anything right now).

arsenm added inline comments.Aug 25 2023, 11:32 AM
libc/test/src/__support/arg_list_test.cpp
77

No, it's the clang extension used to implement opencl, just through typedefs. e.g.

typedef int int4 __attribute__((ext_vector_type(4)));
jhuber6 added inline comments.Aug 25 2023, 11:58 AM
libc/test/src/__support/arg_list_test.cpp
77

Seems that's a clang extension, so we'll probably need to guard it somehow.

jhuber6 updated this revision to Diff 553570.Aug 25 2023, 12:16 PM

Fix test and add a vector type test if using clang.

Thank you for adding this! There's much reassurance to be had from knowing the variadic lowering produces code that executes as expected.

Does anything here check that the values have made it through unchanged? I see counting how often next_var was called, but not checking that values aren't mangled in transit

libc/test/src/__support/arg_list_test.cpp
77

There are a few vector types, different variations on syntax over the IR representation. Any one should do here - has_attribute or similar will suffice as a guard I think

134

Does this call va_copy on the argument? I.e. is va_end immediately after making one the safe thing to do, even if va_end is not a no-op?

jhuber6 updated this revision to Diff 553613.Aug 25 2023, 2:00 PM

Change to add LIBC_HAS_ATTRIBUTE and use separate values.

jhuber6 added inline comments.Aug 25 2023, 2:10 PM
libc/test/src/__support/arg_list_test.cpp
134

Yes, it va_copy's it for the constructor. I think there's an explicit test for that in this file.

sivachandra accepted this revision.Aug 25 2023, 5:00 PM

OK with some minor comments inline.

libc/src/__support/macros/config.h
44

s/__has_feature/__has_attribute

libc/test/src/__support/arg_list_test.cpp
90

Can we avoid non-primitives and just stick to primitives here? For example, instead of intmax_t, size_t and ptrdiff_t, add unsigned short etc? Then, we don't have to worry about platforms where size_t is not long long etc.

This revision is now accepted and ready to land.Aug 25 2023, 5:00 PM
jhuber6 added inline comments.Aug 25 2023, 5:01 PM
libc/src/__support/macros/config.h
44

Whoops, thanks for catching that.

libc/test/src/__support/arg_list_test.cpp
90

Will do.

This revision was automatically updated to reflect the committed changes.