Skip to content

Commit b4fdd3c

Browse files
committed
[libcxx] Define _LIBCPP_HAS_C8RTOMB_MBRTOC8 to true if compiling with clang
Define `_LIBCPP_HAS_C8RTOMB_MBRTOC8` to `1` if compiling with clang. Some tests involving functionality from `uchar.h`/`cuchar` fail when the platform or the supporting C library does not provide support for the corresponding features. These have been xfailed. This patch will enable the adoption of newer picolibc versions.
1 parent 22f860a commit b4fdd3c

File tree

7 files changed

+74
-41
lines changed

7 files changed

+74
-41
lines changed

libcxx/include/__config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,9 @@ typedef __char32_t char32_t;
10211021
// the latter depends on internal GNU libc details that are not appropriate
10221022
// to depend on here, so any declarations present when __cpp_char8_t is not
10231023
// defined are ignored.
1024-
# if defined(_LIBCPP_GLIBC_PREREQ)
1024+
# if defined(__clang__)
1025+
# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
1026+
# elif defined(_LIBCPP_GLIBC_PREREQ)
10251027
# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
10261028
# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
10271029
# else

libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
// __STDC_UTF_16__ may or may not be defined by the C standard library
2424
// __STDC_UTF_32__ may or may not be defined by the C standard library
2525

26-
#if !defined(TEST_HAS_NO_C8RTOMB_MBRTOC8)
27-
ASSERT_SAME_TYPE(size_t, decltype(mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
28-
ASSERT_SAME_TYPE(size_t, decltype(c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
29-
#endif
30-
3126
ASSERT_SAME_TYPE(size_t, decltype(mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
3227
ASSERT_SAME_TYPE(size_t, decltype(c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
3328

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// The following platforms do not provide mbrtoc8 and c8rtomb so the tests fail
12+
// XFAIL: target={{.+}}-aix{{.*}}
13+
// XFAIL: android
14+
// XFAIL: darwin
15+
// XFAIL: freebsd
16+
// XFAIL: windows
17+
// XFAIL: glibc-no-char8_t-support
18+
// XFAIL: LIBCXX-PICOLIBC-FIXME
19+
20+
// <uchar.h>
21+
22+
#include <uchar.h>
23+
24+
#include "test_macros.h"
25+
26+
ASSERT_SAME_TYPE(size_t, decltype(mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
27+
ASSERT_SAME_TYPE(size_t, decltype(c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));

libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
// __STDC_UTF_16__ may or may not be defined by the C standard library
2424
// __STDC_UTF_32__ may or may not be defined by the C standard library
2525

26-
#if !defined(TEST_HAS_NO_C8RTOMB_MBRTOC8)
27-
ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
28-
ASSERT_SAME_TYPE(std::size_t, decltype(std::c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));
29-
#endif
30-
3126
ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc16((char16_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
3227
ASSERT_SAME_TYPE(std::size_t, decltype(std::c16rtomb((char*)0, (char16_t)0, (mbstate_t*)0)));
3328

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
// The following platforms do not provide mbrtoc8 and c8rtomb so the tests fail
12+
// XFAIL: target={{.+}}-aix{{.*}}
13+
// XFAIL: android
14+
// XFAIL: darwin
15+
// XFAIL: freebsd
16+
// XFAIL: windows
17+
// XFAIL: glibc-no-char8_t-support
18+
// XFAIL: LIBCXX-PICOLIBC-FIXME
19+
20+
// <cuchar>
21+
22+
#include <cuchar>
23+
24+
#include "test_macros.h"
25+
26+
ASSERT_SAME_TYPE(std::size_t, decltype(std::mbrtoc8((char8_t*)0, (const char*)0, (size_t)0, (mbstate_t*)0)));
27+
ASSERT_SAME_TYPE(std::size_t, decltype(std::c8rtomb((char*)0, (char8_t)0, (mbstate_t*)0)));

libcxx/test/std/strings/c.strings/no_c8rtomb_mbrtoc8.verify.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

libcxx/utils/libcxx/test/features.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,23 @@ def _mingwSupportsModules(cfg):
293293
""",
294294
),
295295
),
296+
# Check for Glibc < 2.36, where there was no support for char8_t functions
297+
Feature(
298+
name="glibc-no-char8_t-support",
299+
when=lambda cfg: "__GLIBC__" in compilerMacros(cfg)
300+
and not sourceBuilds(
301+
cfg,
302+
"""
303+
#include <uchar.h>
304+
#include <wchar.h>
305+
mbstate_t s;
306+
int main(void) {
307+
char8_t c;
308+
return mbrtoc8(&c, "", 0, &s);
309+
}
310+
""",
311+
),
312+
),
296313
Feature(
297314
name="has-unix-headers",
298315
when=lambda cfg: sourceBuilds(

0 commit comments

Comments
 (0)