llvm-project/libcxx/test/support
JF Bastien 2df59c5068 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
2019-02-04 20:31:13 +00:00
..
test.support Support tests in freestanding 2019-02-04 20:31:13 +00:00
test.workarounds Support tests in freestanding 2019-02-04 20:31:13 +00:00
Counter.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
DefaultOnly.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
MoveOnly.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
allocators.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
any_helpers.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
archetypes.hpp [pair] Mark constructors as conditionally noexcept 2018-12-11 14:22:28 +00:00
archetypes.ipp [pair] Mark constructors as conditionally noexcept 2018-12-11 14:22:28 +00:00
asan_testing.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
assert_checkpoint.h Add checkpoint diagnostics to help diagnose buildbot failures. 2016-07-18 03:00:09 +00:00
charconv_test_helpers.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
cmpxchg_loop.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
constexpr_char_traits.hpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
container_test_types.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
controlled_allocators.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
coroutine_types.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
count_new.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
counting_predicates.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
debug_mode_helper.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
deleter_types.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
demangle.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
disable_missing_braces_warning.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
emplace_constructible.h fix shadowing warnings in new tests, try 2 2017-10-17 16:06:42 +00:00
experimental_any_helpers.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
external_threads.cpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
filesystem_dynamic_test_helper.py [test] [support] Use socket()+bind() to create unix sockets portably 2018-12-16 15:12:06 +00:00
filesystem_include.hpp Implement <filesystem> 2018-07-27 03:07:09 +00:00
filesystem_test_helper.hpp Add large file support to create_file for 32-bit. 2019-01-15 19:14:15 +00:00
format_string.hpp Fix missing includes in format_string.hpp helper 2018-07-25 04:21:59 +00:00
hexfloat.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
is_transparent.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
min_allocator.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
msvc_stdlib_force_include.hpp [test] Define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST in msvc_stdlib_force_include.hpp 2019-01-23 22:49:44 +00:00
nasty_containers.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
nasty_macros.hpp [libc++] Fix Windows build error in <functional> 2019-01-29 23:19:45 +00:00
nothing_to_do.pass.cpp Support tests in freestanding 2019-02-04 20:31:13 +00:00
platform_support.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
poisoned_hash_helper.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
private_constructor.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
propagate_const_helpers.h Implement std::experimental::propagate_const from LFTS v2 2016-06-19 19:34:13 +00:00
rapid-cxx-test.hpp Implement a better copy_file. 2018-07-22 02:00:53 +00:00
set_windows_crt_report_mode.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
test_allocator.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
test_comparisons.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
test_convertible.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
test_iterators.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
test_macros.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
test_memory_resource.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
test_workarounds.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
tracked_value.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
truncate_fp.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
type_id.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
unique_ptr_test_helper.h Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
user_defined_integral.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
uses_alloc_types.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
variant_test_helpers.hpp Update more file headers across all of the LLVM projects in the monorepo 2019-01-19 10:56:40 +00:00
verbose_assert.h Implement filesystem NB comments, relative paths, and related issues. 2018-04-02 23:03:41 +00:00