Skip to content

Commit a49eb8e

Browse files
authored
Merge pull request #74348 from hyp/eng/android-stdatomiccxx23
[android] do not import stdatomic from android's libc++
2 parents 4517333 + 98b74d8 commit a49eb8e

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

stdlib/public/Platform/SwiftAndroidNDK.h

+7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@
2424
#include <math.h>
2525
#include <setjmp.h>
2626
#include <signal.h>
27+
#ifdef __cplusplus
28+
// The Android r26 NDK contains an old libc++ modulemap that requires C++23
29+
// for 'stdatomic', which can't be imported unless we're using C++23. Thus,
30+
// import stdatomic from the NDK directly, bypassing the stdatomic from the libc++.
31+
#pragma clang module import _stdatomic
32+
#else
2733
#include <stdatomic.h>
34+
#endif
2835
#include <stdint.h>
2936
#include <stdio.h>
3037
#include <stdio_ext.h>

stdlib/public/Platform/SwiftBionic.h

+7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@
2424
#include <math.h>
2525
#include <setjmp.h>
2626
#include <signal.h>
27+
#ifdef __cplusplus
28+
// The Android r26 NDK contains an old libc++ modulemap that requires C++23
29+
// for 'stdatomic', which can't be imported unless we're using C++23. Thus,
30+
// import stdatomic from the NDK directly, bypassing the stdatomic from the libc++.
31+
#pragma clang module import _stdatomic
32+
#else
2733
#include <stdatomic.h>
34+
#endif
2835
#include <stdint.h>
2936
#include <stdio.h>
3037
#include <stdio_ext.h>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++14 -Xcc -fmodules-cache-path=%t
3+
// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t
4+
// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t
5+
6+
// RUN: find %t | %FileCheck %s
7+
8+
// RUN: %empty-directory(%t)
9+
10+
// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB
11+
// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB
12+
13+
// REQUIRES: OS=linux-android
14+
15+
import Android
16+
import Bionic
17+
18+
#if ADD_CXXSTDLIB
19+
import CxxStdlib
20+
#endif
21+
22+
func test() {
23+
#if ADD_CXXSTDLIB
24+
let _ = std.string()
25+
#endif
26+
}
27+
28+
// CHECK-DAG: Android{{.*}}.pcm
29+
// CHECK-DAG: std{{.*}}.pcm

0 commit comments

Comments
 (0)