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/function.objects/bind/func.bind | |
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/function.objects/bind/func.bind')
14 files changed, 42 insertions, 14 deletions
diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp index 4c025d1415a..931778f54d9 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp @@ -28,7 +28,9 @@ struct Fun } }; -int main() +int main(int, char**) { std::bind(Fun{}, std::placeholders::_1, 42)("hello"); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp index fc089e16528..7010b33f331 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp @@ -115,7 +115,7 @@ void do_test_r(Fn* func) { } } -int main() +int main(int, char**) { do_test<int>(return_value); do_test<int&>(return_lvalue); @@ -129,4 +129,6 @@ int main() do_test_r<long>(return_rvalue); do_test_r<long>(return_const_rvalue); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp index ccc6c27e716..8beeb3321d5 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp @@ -26,11 +26,13 @@ float _pow(float a, float b) return std::pow(a, b); } -int main() +int main(int, char**) { std::function<float(float, float)> fnc = _pow; auto task = std::bind(fnc, 2.f, 4.f); auto task2(task); assert(task() == 16); assert(task2() == 16); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp index b386b99a90f..b87918da110 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp @@ -38,7 +38,7 @@ struct BadUnaryFunction } }; -int main() +int main(int, char**) { // Check that BadUnaryFunction::operator()(S const &) is not // instantiated when checking if BadUnaryFunction is a nested bind @@ -47,4 +47,6 @@ int main() b(0); auto b2 = std::bind<long>(DummyUnaryFunction(), BadUnaryFunction()); b2(0); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp index 8d6bc70e79a..a77e1895d6f 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp @@ -40,7 +40,7 @@ struct A_int_0 int operator()() const {return 5;} }; -int main() +int main(int, char**) { test(std::bind(f), 1); test(std::bind(&f), 1); @@ -51,4 +51,6 @@ int main() test(std::bind<int>(&f), 1); test(std::bind<int>(A_int_0()), 4); test_const(std::bind<int>(A_int_0()), 5); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp index 92f65af2c91..9b81d330132 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp @@ -280,10 +280,12 @@ test3() assert(b); } -int main() +int main(int, char**) { test_void_1(); test_int_1(); test_void_2(); test3(); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp index b7facb38ac6..10d2ce017f8 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp @@ -258,10 +258,12 @@ void test_nested() assert(std::bind(f_nested, std::bind(g_nested, _1))(3) == 31); } -int main() +int main(int, char**) { test_void_1(); test_int_1(); test_void_2(); test_nested(); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp index cc982d1b80f..2c8e56f034e 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp @@ -54,7 +54,7 @@ struct A_int_0 int operator()() const {count += 2; return 5;} }; -int main() +int main(int, char**) { test(std::bind(f)); test(std::bind(&f)); @@ -70,4 +70,6 @@ int main() test(std::bind<void>(&g)); test(std::bind<void>(A_int_0())); test_const(std::bind<void>(A_int_0())); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp index c4d82948e37..0d5be341353 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp @@ -41,11 +41,13 @@ struct plus_one } }; -int main() +int main(int, char**) { using std::placeholders::_1; auto g = std::bind(power(), 2, _1); assert(g(5) == 32); assert(std::bind(plus_one(), g)(5) == 33); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp index cf065e4e382..8314dbe1e8e 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp @@ -27,11 +27,13 @@ test(const T&) struct C {}; -int main() +int main(int, char**) { test<true>(std::bind(C())); test<true>(std::bind(C(), std::placeholders::_2)); test<true>(std::bind<int>(C())); test<false>(1); test<false>(std::placeholders::_2); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp index da7880fb25f..c1af159b293 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp @@ -24,7 +24,7 @@ void test() { struct C {}; -int main() { +int main(int, char**) { test<int>(); test<void>(); test<C>(); @@ -35,4 +35,6 @@ int main() { test<int(*)()>(); test<int (C::*)()>(); test<decltype(std::placeholders::_2)>(); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp index ecaa45bba28..d2ccf1fafdc 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_placeholder.pass.cpp @@ -25,7 +25,7 @@ test(const T&) struct C {}; -int main() +int main(int, char**) { test<1>(std::placeholders::_1); test<2>(std::placeholders::_2); @@ -41,4 +41,6 @@ int main() test<0>(5.5); test<0>('a'); test<0>(C()); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp index 8e4ec60ef13..b71aae818a0 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.place/placeholders.pass.cpp @@ -80,7 +80,7 @@ void use_placeholders_to_prevent_unused_warning() { #endif } -int main() +int main(int, char**) { use_placeholders_to_prevent_unused_warning(); test(std::placeholders::_1); @@ -93,4 +93,6 @@ int main() test(std::placeholders::_8); test(std::placeholders::_9); test(std::placeholders::_10); + + return 0; } diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp index f77636c8475..1f764da05d6 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/nothing_to_do.pass.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// -int main() +int main(int, char**) { + + return 0; } |