Mehdi Amini f8764e30d5 Add deployment knobs to tests (for Apple platforms)
The tests for libc++ specify -target on the command-line to the
compiler, but this is problematic for a few reasons.

Firstly, the -target option isn't supported on Apple platforms. Parts
of the triple get dropped and ignored. Instead, software should be
compiled with a combination of the -arch and -m<name>-version-min
options.

Secondly, the generic "darwin" target references a kernel version
instead of a platform version. Each platform has its own independent
versions (with different versions of libc++.1.dylib), independent of the
version of the Darwin kernel.

This commit adds support to the LIT infrastructure for testing against
Apple platforms using -arch and -platform options.

If the host is not on OS X, or the compiler type is not clang or apple-clang, then this commit has NFC.
If the host is on OS X and --param=target_triple=... is specified, then a warning is emitted to use arch and platform instead. Besides the warning, there's NFC.
If the host is on OS X and *no* target-triple is specified, then use the new deployment target logic. This uses two new lit parameters, --param=arch=<arch> and --param=platform=<platform>. <platform> has the form <name>[<version>].
By default, arch is auto-detected from clang -dumpmachine, and platform is "macosx".
If the platform doesn't have a version:
For "macosx", the version is auto-detected from the host system using sw_vers. This may give a different version than the SDK, since new SDKs can be installed on older hosts.
Otherwise, the version is auto-detected from the SDK version using xcrun --show-sdk-path.
-arch <arch> -m<name>-version-min=<version> is added to the compiler flags.
The target triple is computed as <arch>-apple-<platform>. It is *not* passed to clang, but it is available for XFAIL and UNSUPPORTED (as is with_system_cxx_lib=<target>).
For convenience, apple-darwin and <arch>-apple-darwin are added to the set of available features.
There were a number of tests marked to XFAIL on x86_64-apple-darwin11
and x86_64-apple-darwin12. I updated these to
x86_64-apple-macosx10.7 and x86_64-apple-macosx10.8.

llvm-svn: 297798
2017-03-15 00:59:54 +00:00

189 lines
3.7 KiB
C++

//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7
// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8
// <string>
// float stof(const string& str, size_t *idx = 0);
// float stof(const wstring& str, size_t *idx = 0);
#include <string>
#include <cmath>
#include <cassert>
#include "test_macros.h"
int main()
{
assert(std::stof("0") == 0);
assert(std::stof(L"0") == 0);
assert(std::stof("-0") == 0);
assert(std::stof(L"-0") == 0);
assert(std::stof("-10") == -10);
assert(std::stof(L"-10.5") == -10.5);
assert(std::stof(" 10") == 10);
assert(std::stof(L" 10") == 10);
size_t idx = 0;
assert(std::stof("10g", &idx) == 10);
assert(idx == 2);
idx = 0;
assert(std::stof(L"10g", &idx) == 10);
assert(idx == 2);
#ifndef TEST_HAS_NO_EXCEPTIONS
idx = 0;
try
{
assert(std::stof("1.e60", &idx) == INFINITY);
assert(false);
}
catch (const std::out_of_range&)
{
assert(idx == 0);
}
try
{
assert(std::stof(L"1.e60", &idx) == INFINITY);
assert(false);
}
catch (const std::out_of_range&)
{
assert(idx == 0);
}
idx = 0;
try
{
assert(std::stof("1.e360", &idx) == INFINITY);
assert(false);
}
catch (const std::out_of_range&)
{
assert(idx == 0);
}
try
{
assert(std::stof(L"1.e360", &idx) == INFINITY);
assert(false);
}
catch (const std::out_of_range&)
{
assert(idx == 0);
}
try
#endif
{
assert(std::stof("INF", &idx) == INFINITY);
assert(idx == 3);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
catch (const std::out_of_range&)
{
assert(false);
}
#endif
idx = 0;
#ifndef TEST_HAS_NO_EXCEPTIONS
try
#endif
{
assert(std::stof(L"INF", &idx) == INFINITY);
assert(idx == 3);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
catch (const std::out_of_range&)
{
assert(false);
}
#endif
idx = 0;
#ifndef TEST_HAS_NO_EXCEPTIONS
try
#endif
{
assert(std::isnan(std::stof("NAN", &idx)));
assert(idx == 3);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
catch (const std::out_of_range&)
{
assert(false);
}
#endif
idx = 0;
#ifndef TEST_HAS_NO_EXCEPTIONS
try
#endif
{
assert(std::isnan(std::stof(L"NAN", &idx)));
assert(idx == 3);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
catch (const std::out_of_range&)
{
assert(false);
}
idx = 0;
try
{
std::stof("", &idx);
assert(false);
}
catch (const std::invalid_argument&)
{
assert(idx == 0);
}
try
{
std::stof(L"", &idx);
assert(false);
}
catch (const std::invalid_argument&)
{
assert(idx == 0);
}
try
{
std::stof(" - 8", &idx);
assert(false);
}
catch (const std::invalid_argument&)
{
assert(idx == 0);
}
try
{
std::stof(L" - 8", &idx);
assert(false);
}
catch (const std::invalid_argument&)
{
assert(idx == 0);
}
try
{
std::stof("a1", &idx);
assert(false);
}
catch (const std::invalid_argument&)
{
assert(idx == 0);
}
try
{
std::stof(L"a1", &idx);
assert(false);
}
catch (const std::invalid_argument&)
{
assert(idx == 0);
}
#endif
}