diff options
author | JF Bastien <jfbastien@apple.com> | 2019-02-04 20:31:13 +0000 |
---|---|---|
committer | JF Bastien <jfbastien@apple.com> | 2019-02-04 20:31:13 +0000 |
commit | 2df59c50688c122bbcae7467d3eaf862c3ea3088 (patch) | |
tree | 29c9a3e1c54fe76a506ffecc0cc4d8fbaba5cb04 /libcxx/test/std/utilities/any | |
parent | 6fd4e7fe0258ff71fe759535236883ea9060587c (diff) | |
download | bcm5719-llvm-2df59c50688c122bbcae7467d3eaf862c3ea3088.tar.gz bcm5719-llvm-2df59c50688c122bbcae7467d3eaf862c3ea3088.zip |
Support tests in freestanding
Summary:
Freestanding is *weird*. The standard allows it to differ in a bunch of odd
manners from regular C++, and the committee would like to improve that
situation. I'd like to make libc++ behave better with what freestanding should
be, so that it can be a tool we use in improving the standard. To do that we
need to try stuff out, both with "freestanding the language mode" and
"freestanding the library subset".
Let's start with the super basic: run the libc++ tests in freestanding, using
clang as the compiler, and see what works. The easiest hack to do this:
In utils/libcxx/test/config.py add:
self.cxx.compile_flags += ['-ffreestanding']
Run the tests and they all fail.
Why? Because in freestanding `main` isn't special. This "not special" property
has two effects: main doesn't get mangled, and main isn't allowed to omit its
`return` statement. The first means main gets mangled and the linker can't
create a valid executable for us to test. The second means we spew out warnings
(ew) and the compiler doesn't insert the `return` we omitted, and main just
falls of the end and does whatever undefined behavior (if you're luck, ud2
leading to non-zero return code).
Let's start my work with the basics. This patch changes all libc++ tests to
declare `main` as `int main(int, char**` so it mangles consistently (enabling us
to declare another `extern "C"` main for freestanding which calls the mangled
one), and adds `return 0;` to all places where it was missing. This touches 6124
files, and I apologize.
The former was done with The Magic Of Sed.
The later was done with a (not quite correct but decent) clang tool:
https://gist.github.com/jfbastien/793819ff360baa845483dde81170feed
This works for most tests, though I did have to adjust a few places when e.g.
the test runs with `-x c`, macros are used for main (such as for the filesystem
tests), etc.
Once this is in we can create a freestanding bot which will prevent further
regressions. After that, we can start the real work of supporting C++
freestanding fairly well in libc++.
<rdar://problem/47754795>
Reviewers: ldionne, mclow.lists, EricWF
Subscribers: christof, jkorous, dexonsmith, arphaman, miyuki, libcxx-commits
Differential Revision: https://reviews.llvm.org/D57624
llvm-svn: 353086
Diffstat (limited to 'libcxx/test/std/utilities/any')
22 files changed, 66 insertions, 22 deletions
diff --git a/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp index 0a8c3f7814b..6cf1efb86b3 100644 --- a/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.assign/copy.pass.cpp @@ -191,7 +191,7 @@ void test_copy_assign_throws() #endif } -int main() { +int main(int, char**) { test_copy_assign<small1, small2>(); test_copy_assign<large1, large2>(); test_copy_assign<small, large>(); @@ -201,4 +201,6 @@ int main() { test_copy_assign_self(); test_copy_assign_throws<small_throws_on_copy>(); test_copy_assign_throws<large_throws_on_copy>(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp index 4baadb2bbad..6e1b6d6a6f4 100644 --- a/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.assign/move.pass.cpp @@ -104,7 +104,7 @@ void test_move_assign_noexcept() { ); } -int main() { +int main(int, char**) { test_move_assign_noexcept(); test_move_assign<small1, small2>(); test_move_assign<large1, large2>(); @@ -112,4 +112,6 @@ int main() { test_move_assign<large, small>(); test_move_assign_empty<small>(); test_move_assign_empty<large>(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp index 7ccec4b3f88..888a6a654b3 100644 --- a/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.assign/value.pass.cpp @@ -202,7 +202,7 @@ void test_sfinae_constraints() { } } -int main() { +int main(int, char**) { test_assign_value<small1, small2>(); test_assign_value<large1, large2>(); test_assign_value<small, large>(); @@ -213,4 +213,6 @@ int main() { test_assign_throws<large_throws_on_copy>(); test_assign_throws<throws_on_move, /* Move = */ true>(); test_sfinae_constraints(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp index 6c4e9576d44..318d9ecabba 100644 --- a/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.cons/copy.pass.cpp @@ -98,10 +98,12 @@ void test_copy() assert(Type::count == 0); } -int main() { +int main(int, char**) { test_copy<small>(); test_copy<large>(); test_copy_empty(); test_copy_throws<small_throws_on_copy>(); test_copy_throws<large_throws_on_copy>(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp index 12692a17113..6cd7b8937d2 100644 --- a/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.cons/default.pass.cpp @@ -20,7 +20,7 @@ #include "any_helpers.h" #include "count_new.hpp" -int main() +int main(int, char**) { using std::any; { @@ -43,4 +43,6 @@ int main() any const a; assertEmpty(a); } + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp index f696ac5a206..9684fcac7e2 100644 --- a/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.cons/in_place_type.pass.cpp @@ -187,7 +187,7 @@ void test_constructor_explicit() { static_assert(std::is_constructible<std::any, IT, std::initializer_list<int>&, int>::value, ""); } -int main() { +int main(int, char**) { test_in_place_type<small>(); test_in_place_type<large>(); test_in_place_type<small_throws_on_copy>(); @@ -198,4 +198,6 @@ int main() { test_in_place_type_decayed(); test_ctor_sfinae(); test_constructor_explicit(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp index 265972a01e9..e75d56ef290 100644 --- a/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.cons/move.pass.cpp @@ -95,7 +95,7 @@ void test_move() { assert(Type::count == 0); } -int main() +int main(int, char**) { // noexcept test { @@ -108,4 +108,6 @@ int main() test_move<large>(); test_move_empty(); test_move_does_not_throw(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp index c80a407ff06..ed588497514 100644 --- a/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.cons/value.pass.cpp @@ -151,11 +151,13 @@ void test_sfinae_constraints() { } } -int main() { +int main(int, char**) { test_copy_move_value<small>(); test_copy_move_value<large>(); test_copy_value_throws<small_throws_on_copy>(); test_copy_value_throws<large_throws_on_copy>(); test_move_value_throws(); test_sfinae_constraints(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp index 3ac003dd086..7cb5d491328 100644 --- a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp @@ -275,7 +275,7 @@ void test_emplace_sfinae_constraints() { } } -int main() { +int main(int, char**) { test_emplace_type<small>(); test_emplace_type<large>(); test_emplace_type<small_throws_on_copy>(); @@ -288,4 +288,6 @@ int main() { test_emplace_throws<SmallThrows>(); test_emplace_throws<LargeThrows>(); #endif + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp index 352b25b8010..0a01e86252c 100644 --- a/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/reset.pass.cpp @@ -25,7 +25,7 @@ #include "any_helpers.h" -int main() +int main(int, char**) { using std::any; using std::any_cast; @@ -67,4 +67,6 @@ int main() assertEmpty<large>(a); assert(large::count == 0); } + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp index f1ff60d478b..f4f5ee4969c 100644 --- a/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp @@ -127,7 +127,7 @@ void test_self_swap() { assert(large::count == 0); } -int main() +int main(int, char**) { test_noexcept(); test_swap_empty<small>(); @@ -137,4 +137,6 @@ int main() test_swap<small, large>(); test_swap<large, small>(); test_self_swap(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp index 9b747dca610..54b4153c974 100644 --- a/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp @@ -17,7 +17,7 @@ #include "any_helpers.h" -int main() +int main(int, char**) { using std::any; // noexcept test @@ -60,4 +60,6 @@ int main() a = l; assert(a.has_value()); } + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp index 8d3b4081405..bb9089cd83e 100644 --- a/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp @@ -18,7 +18,7 @@ #include <cassert> #include "any_helpers.h" -int main() +int main(int, char**) { using std::any; { @@ -37,4 +37,6 @@ int main() any const a(l); assert(a.type() == typeid(large)); } + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp b/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp index b757f7b0bbe..3a275d51e4a 100644 --- a/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/not_literal_type.pass.cpp @@ -15,6 +15,8 @@ #include <any> #include <type_traits> -int main () { +int main(int, char**) { static_assert(!std::is_literal_type<std::any>::value, ""); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp index 8de9164c31f..9b9ec410958 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp @@ -166,7 +166,7 @@ void test_cast_function_pointer() { assert(fn_ptr == test_fn); } -int main() { +int main(int, char**) { test_cast_is_noexcept(); test_cast_return_type(); test_cast_nullptr(); @@ -175,4 +175,6 @@ int main() { test_cast<large>(); test_cast_non_copyable_type(); test_cast_function_pointer(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp index 810c482df78..fb69f0d39fb 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_reference.pass.cpp @@ -309,7 +309,7 @@ void test_cast_to_value() { assert(Type::count == 0); } -int main() { +int main(int, char**) { test_cast_is_not_noexcept(); test_cast_return_type(); test_cast_empty(); @@ -317,4 +317,6 @@ int main() { test_cast_to_reference<large>(); test_cast_to_value<small>(); test_cast_to_value<large>(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp index cd69a3d8508..396d994d22d 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp @@ -61,9 +61,11 @@ void test_rvalue_any_cast_request_lvalue() any_cast<int&>(42); } -int main() +int main(int, char**) { test_const_lvalue_cast_request_non_const_lvalue(); test_lvalue_any_cast_request_rvalue(); test_rvalue_any_cast_request_lvalue(); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.fail.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.fail.cpp index c0c6e03fdcf..8669de4fddb 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.fail.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.fail.cpp @@ -24,7 +24,7 @@ struct TestType2 {}; // is triggered by these tests. // expected-error@const_correctness.fail.cpp:* 0+ {{call to unavailable function 'any_cast': introduced in macOS 10.14}} -int main() +int main(int, char**) { using std::any; using std::any_cast; @@ -46,4 +46,6 @@ int main() // expected-error@any:* {{cannot cast from lvalue of type 'const TestType2' to rvalue reference type 'TestType2 &&'; types are not compatible}} // expected-error-re@any:* {{static_assert failed{{.*}} "ValueType is required to be a const lvalue reference or a CopyConstructible type"}} any_cast<TestType2 &&>(static_cast<any const&&>(a)); // expected-note {{requested here}} + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.fail.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.fail.cpp index c90df2ebd37..97f1d9795bc 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.fail.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.fail.cpp @@ -43,7 +43,7 @@ struct no_move { // is triggered by these tests. // expected-error@not_copy_constructible.fail.cpp:* 0+ {{call to unavailable function 'any_cast': introduced in macOS 10.14}} -int main() { +int main(int, char**) { any a; // expected-error-re@any:* {{static_assert failed{{.*}} "ValueType is required to be an lvalue reference or a CopyConstructible type"}} // expected-error@any:* {{static_cast from 'no_copy' to 'no_copy' uses deleted function}} @@ -58,4 +58,6 @@ int main() { // expected-error-re@any:* {{static_assert failed{{.*}} "ValueType is required to be an rvalue reference or a CopyConstructible type"}} // expected-error@any:* {{static_cast from 'typename remove_reference<no_move &>::type' (aka 'no_move') to 'no_move' uses deleted function}} any_cast<no_move>(static_cast<any &&>(a)); + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp index 19453582479..1ce06e289a9 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp @@ -21,7 +21,7 @@ using std::any; using std::any_cast; -int main() +int main(int, char**) { any a(1); @@ -50,4 +50,6 @@ int main() // expected-error-re@any:* 1 {{static_assert failed{{.*}} "_ValueType may not be a reference."}} any_cast<int const &&>(&a2); // expected-note {{requested here}} + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp index e185f239f69..1e9708545ff 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/make_any.pass.cpp @@ -131,7 +131,7 @@ void test_make_any_throws() #endif -int main() { +int main(int, char**) { test_make_any_type<small>(); test_make_any_type<large>(); test_make_any_type<small_throws_on_copy>(); @@ -144,4 +144,6 @@ int main() { test_make_any_throws<LargeThrows>(); #endif + + return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp index 3e5a91d0d23..cff34964a84 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp @@ -28,7 +28,7 @@ using std::any; using std::any_cast; -int main() +int main(int, char**) { { // test noexcept @@ -44,4 +44,6 @@ int main() assert(any_cast<int>(a1) == 2); assert(any_cast<int>(a2) == 1); } + + return 0; } |