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
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 9f09dea..02187c5 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 @@
     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 @@
     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 4f75e01..914842b 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 @@
     assert(s.size() == 0);
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -53,4 +53,6 @@
     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 2359dea..1bfa388 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 56d925d..47827db 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 @@
     assert(s.empty() == (s.size() == 0));
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -40,4 +40,6 @@
     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 617d81a..b61ec48 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 @@
     assert(s.length() == s.size());
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -38,4 +38,6 @@
     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 68017f4..8f8c9a3 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 @@
     test2(s);
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -70,4 +70,6 @@
     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 414b674..9832df5 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 @@
     assert ( false );
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -51,4 +51,6 @@
     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 33699a7..f49125c 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 @@
 #endif
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -131,4 +131,6 @@
     }
     }
 #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 ad37dc3..8b54593 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 @@
 #endif
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -85,4 +85,6 @@
     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 b900534..b5e5aff 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 @@
 #endif
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -85,4 +85,6 @@
     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 ee91ac1..2c6ce0d 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 @@
     assert(s.capacity() >= s.size());
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -59,4 +59,6 @@
     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 16b236e..f3f89a5 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 @@
     assert(s.size() == c);
 }
 
-int main()
+int main(int, char**)
 {
     {
     typedef std::string S;
@@ -38,4 +38,6 @@
     test(S("12345678901234567890123456789012345678901234567890"), 50);
     }
 #endif
+
+  return 0;
 }