[libcxx-commits] [PATCH] D57624: Support tests in freestanding

JF Bastien via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 1 15:01:47 PST 2019


jfb created this revision.
jfb added reviewers: ldionne, mclow.lists, EricWF.
Herald added subscribers: libcxx-commits, miyuki, arphaman, dexonsmith, jkorous, christof.

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 mark
main as `extern "C"` so it mangles properly, and adds `return 0;` to all places
where it was missing. This touches 6118 files, and I apologize.

The former was done with The Magic Of Sed:

  git grep "\bmain\b" ./test/ | grep -v 'extern "C"' | grep "\.cpp:" | cut -d: -f1 | xargs -n1 -I{} -P20 gsed -i 's/int main *(/extern "C" int main(/g' {}

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++.


Repository:
  rCXX libc++

https://reviews.llvm.org/D57624

Files:
  test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.cxx1z.pass.cpp
  test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.depr_in_cxx14.fail.cpp
  test/libcxx/algorithms/debug_less.pass.cpp
  test/libcxx/algorithms/half_positive.pass.cpp
  test/libcxx/algorithms/version.pass.cpp
  test/libcxx/atomics/atomics.align/align.pass.sh.cpp
  test/libcxx/atomics/atomics.flag/init_bool.pass.cpp
  test/libcxx/atomics/diagnose_invalid_memory_order.fail.cpp
  test/libcxx/atomics/libcpp-has-no-threads.fail.cpp
  test/libcxx/atomics/libcpp-has-no-threads.pass.cpp
  test/libcxx/atomics/version.pass.cpp
  test/libcxx/containers/associative/map/version.pass.cpp
  test/libcxx/containers/associative/non_const_comparator.fail.cpp
  test/libcxx/containers/associative/set/version.pass.cpp
  test/libcxx/containers/associative/tree_balance_after_insert.pass.cpp
  test/libcxx/containers/associative/tree_key_value_traits.pass.cpp
  test/libcxx/containers/associative/tree_left_rotate.pass.cpp
  test/libcxx/containers/associative/tree_remove.pass.cpp
  test/libcxx/containers/associative/tree_right_rotate.pass.cpp
  test/libcxx/containers/associative/undef_min_max.pass.cpp
  test/libcxx/containers/container.adaptors/queue/version.pass.cpp
  test/libcxx/containers/container.adaptors/stack/version.pass.cpp
  test/libcxx/containers/gnu_cxx/hash_map.pass.cpp
  test/libcxx/containers/gnu_cxx/hash_set.pass.cpp
  test/libcxx/containers/sequences/array/array.zero/db_back.pass.cpp
  test/libcxx/containers/sequences/array/array.zero/db_front.pass.cpp
  test/libcxx/containers/sequences/array/array.zero/db_indexing.pass.cpp
  test/libcxx/containers/sequences/array/version.pass.cpp
  test/libcxx/containers/sequences/deque/incomplete.pass.cpp
  test/libcxx/containers/sequences/deque/pop_back_empty.pass.cpp
  test/libcxx/containers/sequences/deque/version.pass.cpp
  test/libcxx/containers/sequences/forwardlist/version.pass.cpp
  test/libcxx/containers/sequences/list/list.cons/db_copy.pass.cpp
  test/libcxx/containers/sequences/list/list.cons/db_move.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/emplace_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/insert_iter_iter_iter_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/insert_iter_rvalue_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/insert_iter_size_value_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/insert_iter_value_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.modifiers/pop_back_db1.pass.cpp
  test/libcxx/containers/sequences/list/list.ops/db_splice_pos_list.pass.cpp
  test/libcxx/containers/sequences/list/list.ops/db_splice_pos_list_iter.pass.cpp
  test/libcxx/containers/sequences/list/list.ops/db_splice_pos_list_iter_iter.pass.cpp
  test/libcxx/containers/sequences/list/version.pass.cpp
  test/libcxx/containers/sequences/vector/asan.pass.cpp
  test/libcxx/containers/sequences/vector/asan_throw.pass.cpp
  test/libcxx/containers/sequences/vector/const_value_type.pass.cpp
  test/libcxx/containers/sequences/vector/db_back.pass.cpp
  test/libcxx/containers/sequences/vector/db_cback.pass.cpp
  test/libcxx/containers/sequences/vector/db_cfront.pass.cpp
  test/libcxx/containers/sequences/vector/db_cindex.pass.cpp
  test/libcxx/containers/sequences/vector/db_front.pass.cpp
  test/libcxx/containers/sequences/vector/db_index.pass.cpp
  test/libcxx/containers/sequences/vector/db_iterators_2.pass.cpp
  test/libcxx/containers/sequences/vector/db_iterators_3.pass.cpp
  test/libcxx/containers/sequences/vector/db_iterators_4.pass.cpp
  test/libcxx/containers/sequences/vector/db_iterators_5.pass.cpp
  test/libcxx/containers/sequences/vector/db_iterators_6.pass.cpp
  test/libcxx/containers/sequences/vector/db_iterators_7.pass.cpp
  test/libcxx/containers/sequences/vector/db_iterators_8.pass.cpp
  test/libcxx/containers/sequences/vector/pop_back_empty.pass.cpp
  test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
  test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
  test/libcxx/containers/sequences/vector/version.pass.cpp
  test/libcxx/containers/unord/key_value_traits.pass.cpp
  test/libcxx/containers/unord/next_pow2.pass.cpp
  test/libcxx/containers/unord/next_prime.pass.cpp
  test/libcxx/containers/unord/non_const_comparator.fail.cpp
  test/libcxx/containers/unord/unord.map/db_iterators_7.pass.cpp
  test/libcxx/containers/unord/unord.map/db_iterators_8.pass.cpp
  test/libcxx/containers/unord/unord.map/db_local_iterators_7.pass.cpp
  test/libcxx/containers/unord/unord.map/db_local_iterators_8.pass.cpp
  test/libcxx/containers/unord/unord.map/version.pass.cpp
  test/libcxx/containers/unord/unord.set/missing_hash_specialization.fail.cpp
  test/libcxx/containers/unord/unord.set/version.pass.cpp
  test/libcxx/debug/containers/db_associative_container_tests.pass.cpp
  test/libcxx/debug/containers/db_sequence_container_iterators.pass.cpp
  test/libcxx/debug/containers/db_string.pass.cpp
  test/libcxx/debug/containers/db_unord_container_tests.pass.cpp
  test/libcxx/debug/debug_abort.pass.cpp
  test/libcxx/debug/debug_throw.pass.cpp
  test/libcxx/debug/debug_throw_register.pass.cpp
  test/libcxx/depr/depr.auto.ptr/auto.ptr/auto_ptr.cxx1z.pass.cpp
  test/libcxx/depr/depr.auto.ptr/auto.ptr/auto_ptr.depr_in_cxx11.fail.cpp
  test/libcxx/depr/depr.c.headers/ciso646.pass.cpp
  test/libcxx/depr/depr.c.headers/complex.h.pass.cpp
  test/libcxx/depr/depr.c.headers/extern_c.pass.cpp
  test/libcxx/depr/depr.c.headers/locale_h.pass.cpp
  test/libcxx/depr/depr.c.headers/tgmath_h.pass.cpp
  test/libcxx/depr/depr.function.objects/adaptors.depr_in_cxx11.fail.cpp
  test/libcxx/depr/depr.function.objects/depr.adaptors.cxx1z.pass.cpp
  test/libcxx/depr/depr.str.strstreams/version.pass.cpp
  test/libcxx/depr/enable_removed_cpp17_features.pass.cpp
  test/libcxx/depr/exception.unexpected/get_unexpected.pass.cpp
  test/libcxx/depr/exception.unexpected/set_unexpected.pass.cpp
  test/libcxx/depr/exception.unexpected/unexpected.pass.cpp
  test/libcxx/depr/exception.unexpected/unexpected_disabled_cpp17.fail.cpp
  test/libcxx/diagnostics/assertions/version_cassert.pass.cpp
  test/libcxx/diagnostics/enable_nodiscard.fail.cpp
  test/libcxx/diagnostics/enable_nodiscard_disable_after_cxx17.fail.cpp
  test/libcxx/diagnostics/enable_nodiscard_disable_nodiscard_ext.fail.cpp
  test/libcxx/diagnostics/errno/version_cerrno.pass.cpp
  test/libcxx/diagnostics/nodiscard.pass.cpp
  test/libcxx/diagnostics/nodiscard_aftercxx17.fail.cpp
  test/libcxx/diagnostics/nodiscard_aftercxx17.pass.cpp
  test/libcxx/diagnostics/nodiscard_extensions.fail.cpp
  test/libcxx/diagnostics/nodiscard_extensions.pass.cpp
  test/libcxx/diagnostics/std.exceptions/version.pass.cpp
  test/libcxx/diagnostics/syserr/version.pass.cpp
  test/libcxx/double_include.sh.cpp
  test/libcxx/experimental/algorithms/header.algorithm.synop/includes.pass.cpp
  test/libcxx/experimental/algorithms/version.pass.cpp
  test/libcxx/experimental/diagnostics/syserr/use_header_warning.fail.cpp
  test/libcxx/experimental/diagnostics/syserr/version.pass.cpp
  test/libcxx/experimental/filesystem/version.pass.cpp
  test/libcxx/experimental/language.support/support.coroutines/dialect_support.sh.cpp
  test/libcxx/experimental/language.support/support.coroutines/version.sh.cpp
  test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/construct_piecewise_pair.pass.cpp
  test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/db_deallocate.pass.cpp
  test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/db_deallocate.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_deque_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_forward_list_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_list_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_map_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_regex_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_set_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_string_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_unordered_map_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_unordered_set_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.aliases/header_vector_libcpp_version.pass.cpp
  test/libcxx/experimental/memory/memory.resource.global/global_memory_resource_lifetime.pass.cpp
  test/libcxx/experimental/memory/memory.resource.global/new_delete_resource_lifetime.pass.cpp
  test/libcxx/experimental/memory/memory.resource.synop/version.pass.cpp
  test/libcxx/experimental/numerics/numeric.ops/use_header_warning.fail.cpp
  test/libcxx/experimental/numerics/numeric.ops/version.pass.cpp
  test/libcxx/experimental/strings/string.view/use_header_warning.fail.cpp
  test/libcxx/experimental/strings/string.view/version.pass.cpp
  test/libcxx/experimental/utilities/any/use_header_warning.fail.cpp
  test/libcxx/experimental/utilities/any/version.pass.cpp
  test/libcxx/experimental/utilities/meta/version.pass.cpp
  test/libcxx/experimental/utilities/optional/use_header_warning.fail.cpp
  test/libcxx/experimental/utilities/optional/version.pass.cpp
  test/libcxx/experimental/utilities/ratio/use_header_warning.fail.cpp
  test/libcxx/experimental/utilities/ratio/version.pass.cpp
  test/libcxx/experimental/utilities/time/use_header_warning.fail.cpp
  test/libcxx/experimental/utilities/time/version.pass.cpp
  test/libcxx/experimental/utilities/tuple/use_header_warning.fail.cpp
  test/libcxx/experimental/utilities/tuple/version.pass.cpp
  test/libcxx/experimental/utilities/utility/version.pass.cpp
  test/libcxx/extensions/hash/specializations.fail.cpp
  test/libcxx/extensions/hash/specializations.pass.cpp
  test/libcxx/extensions/hash_map/const_iterator.fail.cpp
  test/libcxx/extensions/nothing_to_do.pass.cpp
  test/libcxx/fuzzing/nth_element.cpp
  test/libcxx/fuzzing/partial_sort.cpp
  test/libcxx/fuzzing/partial_sort_copy.cpp
  test/libcxx/fuzzing/partition.cpp
  test/libcxx/fuzzing/partition_copy.cpp
  test/libcxx/fuzzing/regex_ECMAScript.cpp
  test/libcxx/fuzzing/regex_POSIX.cpp
  test/libcxx/fuzzing/regex_awk.cpp
  test/libcxx/fuzzing/regex_egrep.cpp
  test/libcxx/fuzzing/regex_extended.cpp
  test/libcxx/fuzzing/regex_grep.cpp
  test/libcxx/fuzzing/sort.cpp
  test/libcxx/fuzzing/stable_partition.cpp
  test/libcxx/fuzzing/stable_sort.cpp
  test/libcxx/fuzzing/unique.cpp
  test/libcxx/fuzzing/unique_copy.cpp
  test/libcxx/include_as_c.sh.cpp
  test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/fopen.fail.cpp
  test/libcxx/input.output/file.streams/c.files/no.global.filesystem.namespace/rename.fail.cpp
  test/libcxx/input.output/file.streams/c.files/version_ccstdio.pass.cpp
  test/libcxx/input.output/file.streams/c.files/version_cinttypes.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/filebuf/traits_mismatch.fail.cpp
  test/libcxx/input.output/file.streams/fstreams/fstream.close.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/fstream.cons/wchar_pointer.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/fstream.members/open_wchar_pointer.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/ifstream.cons/wchar_pointer.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/ifstream.members/open_wchar_pointer.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/ofstream.cons/wchar_pointer.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/ofstream.members/open_wchar_pointer.pass.cpp
  test/libcxx/input.output/file.streams/fstreams/traits_mismatch.fail.cpp
  test/libcxx/input.output/file.streams/fstreams/version.pass.cpp
  test/libcxx/input.output/filesystems/class.path/path.itr/iterator_db.pass.cpp
  test/libcxx/input.output/filesystems/class.path/path.itr/reverse_iterator_produces_diagnostic.fail.cpp
  test/libcxx/input.output/filesystems/class.path/path.req/is_pathable.pass.cpp
  test/libcxx/input.output/filesystems/convert_file_time.sh.cpp
  test/libcxx/input.output/filesystems/version.pass.cpp
  test/libcxx/input.output/iostream.format/input.streams/traits_mismatch.fail.cpp
  test/libcxx/input.output/iostream.format/input.streams/version.pass.cpp
  test/libcxx/input.output/iostream.format/output.streams/traits_mismatch.fail.cpp
  test/libcxx/input.output/iostream.format/output.streams/version.pass.cpp
  test/libcxx/input.output/iostream.format/std.manip/version.pass.cpp
  test/libcxx/input.output/iostream.forward/version.pass.cpp
  test/libcxx/input.output/iostream.objects/version.pass.cpp
  test/libcxx/input.output/iostreams.base/version.pass.cpp
  test/libcxx/input.output/stream.buffers/version.pass.cpp
  test/libcxx/input.output/string.streams/traits_mismatch.fail.cpp
  test/libcxx/input.output/string.streams/version.pass.cpp
  test/libcxx/iterators/failed.pass.cpp
  test/libcxx/iterators/trivial_iterators.pass.cpp
  test/libcxx/iterators/version.pass.cpp
  test/libcxx/language.support/cmp/version.pass.cpp
  test/libcxx/language.support/cstdint/version.pass.cpp
  test/libcxx/language.support/cxa_deleted_virtual.pass.cpp
  test/libcxx/language.support/has_c11_features.pass.cpp
  test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
  test/libcxx/language.support/support.dynamic/new_faligned_allocation.sh.cpp
  test/libcxx/language.support/support.dynamic/version.pass.cpp
  test/libcxx/language.support/support.exception/version.pass.cpp
  test/libcxx/language.support/support.initlist/version.pass.cpp
  test/libcxx/language.support/support.limits/c.limits/version_cfloat.pass.cpp
  test/libcxx/language.support/support.limits/c.limits/version_climits.pass.cpp
  test/libcxx/language.support/support.limits/limits/version.pass.cpp
  test/libcxx/language.support/support.limits/version.pass.cpp
  test/libcxx/language.support/support.rtti/version.pass.cpp
  test/libcxx/language.support/support.runtime/version_csetjmp.pass.cpp
  test/libcxx/language.support/support.runtime/version_csignal.pass.cpp
  test/libcxx/language.support/support.runtime/version_cstdarg.pass.cpp
  test/libcxx/language.support/support.runtime/version_cstdbool.pass.cpp
  test/libcxx/language.support/support.runtime/version_cstdlib.pass.cpp
  test/libcxx/language.support/support.runtime/version_ctime.pass.cpp
  test/libcxx/language.support/support.types/version.pass.cpp
  test/libcxx/libcpp_alignof.pass.cpp
  test/libcxx/libcpp_version.pass.cpp
  test/libcxx/localization/c.locales/version.pass.cpp
  test/libcxx/localization/locale.categories/__scan_keyword.pass.cpp
  test/libcxx/localization/locale.stdcvt/version.pass.cpp
  test/libcxx/localization/locales/locale.convenience/conversions/conversions.string/ctor_move.pass.cpp
  test/libcxx/localization/locales/locale/locale.types/locale.facet/facet.pass.cpp
  test/libcxx/localization/locales/locale/locale.types/locale.id/id.pass.cpp
  test/libcxx/localization/version.pass.cpp
  test/libcxx/memory/aligned_allocation_macro.pass.cpp
  test/libcxx/memory/is_allocator.pass.cpp
  test/libcxx/modules/cinttypes_exports.sh.cpp
  test/libcxx/modules/clocale_exports.sh.cpp
  test/libcxx/modules/cstdint_exports.sh.cpp
  test/libcxx/modules/inttypes_h_exports.sh.cpp
  test/libcxx/modules/stdint_h_exports.sh.cpp
  test/libcxx/numerics/c.math/constexpr-fns.pass.cpp
  test/libcxx/numerics/c.math/ctgmath.pass.cpp
  test/libcxx/numerics/c.math/fdelayed-template-parsing.sh.cpp
  test/libcxx/numerics/c.math/tgmath_h.pass.cpp
  (5868 more files...)





More information about the libcxx-commits mailing list