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/strings/basic.string/string.capacity | |
| 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/strings/basic.string/string.capacity')
12 files changed, 36 insertions, 12 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp index 9f09dea1d3e..02187c5193a 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/capacity.pass.cpp @@ -40,7 +40,7 @@ test(S s) S::allocator_type::throw_after = INT_MAX; } -int main() +int main(int, char**) { { typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S; @@ -60,4 +60,6 @@ int main() assert(s.capacity() > 0); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp index 4f75e013401..914842bb7a6 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp @@ -23,7 +23,7 @@ test(S s) assert(s.size() == 0); } -int main() +int main(int, char**) { { typedef std::string S; @@ -53,4 +53,6 @@ int main() test(s); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/empty.fail.cpp b/libcxx/test/std/strings/basic.string/string.capacity/empty.fail.cpp index 2359dea942d..1bfa388b7b9 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/empty.fail.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/empty.fail.cpp @@ -20,8 +20,10 @@ #include "test_macros.h" -int main () +int main(int, char**) { std::string c; c.empty(); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp index 56d925d571c..47827db7f75 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/empty.pass.cpp @@ -24,7 +24,7 @@ test(const S& s) assert(s.empty() == (s.size() == 0)); } -int main() +int main(int, char**) { { typedef std::string S; @@ -40,4 +40,6 @@ int main() test(S("12345678901234567890123456789012345678901234567890")); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp index 617d81a9205..b61ec488e27 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/length.pass.cpp @@ -22,7 +22,7 @@ test(const S& s) assert(s.length() == s.size()); } -int main() +int main(int, char**) { { typedef std::string S; @@ -38,4 +38,6 @@ int main() test(S("12345678901234567890123456789012345678901234567890")); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp index 68017f45349..8f8c9a3fb42 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/max_size.pass.cpp @@ -54,7 +54,7 @@ test(const S& s) test2(s); } -int main() +int main(int, char**) { { typedef std::string S; @@ -70,4 +70,6 @@ int main() test(S("12345678901234567890123456789012345678901234567890")); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp index 414b6742495..9832df536c9 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/over_max_size.pass.cpp @@ -35,7 +35,7 @@ test(const S& s) assert ( false ); } -int main() +int main(int, char**) { { typedef std::string S; @@ -51,4 +51,6 @@ int main() test(S("12345678901234567890123456789012345678901234567890")); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp index 33699a79932..f49125cec98 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/reserve.pass.cpp @@ -65,7 +65,7 @@ test(S s, typename S::size_type res_arg) #endif } -int main() +int main(int, char**) { { typedef std::string S; @@ -131,4 +131,6 @@ int main() } } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp index ad37dc30a1e..8b545939e3d 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size.pass.cpp @@ -43,7 +43,7 @@ test(S s, typename S::size_type n, S expected) #endif } -int main() +int main(int, char**) { { typedef std::string S; @@ -85,4 +85,6 @@ int main() test(S(), S::npos, S("not going to happen")); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp index b9005341456..b5e5aff8424 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/resize_size_char.pass.cpp @@ -43,7 +43,7 @@ test(S s, typename S::size_type n, typename S::value_type c, S expected) #endif } -int main() +int main(int, char**) { { typedef std::string S; @@ -85,4 +85,6 @@ int main() test(S(), S::npos, 'a', S("not going to happen")); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp index ee91ac1676b..2c6ce0df6f9 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp @@ -29,7 +29,7 @@ test(S s) assert(s.capacity() >= s.size()); } -int main() +int main(int, char**) { { typedef std::string S; @@ -59,4 +59,6 @@ int main() test(s); } #endif + + return 0; } diff --git a/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp index 16b236eebb8..f3f89a5a6d8 100644 --- a/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.capacity/size.pass.cpp @@ -22,7 +22,7 @@ test(const S& s, typename S::size_type c) assert(s.size() == c); } -int main() +int main(int, char**) { { typedef std::string S; @@ -38,4 +38,6 @@ int main() test(S("12345678901234567890123456789012345678901234567890"), 50); } #endif + + return 0; } |

