Skip to content

Commit abb876a

Browse files
committed
[cxx-interop][linux] modularize the bits part of libstdc++
Fixes swiftlang#64457 (cherry picked from commit c215abd)
1 parent 549ad3f commit abb876a

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,47 @@ static void getLibStdCxxFileMapping(
344344
"codecvt",
345345
// C++17 and newer:
346346
"any", "charconv", "filesystem", "memory_resource", "optional",
347-
"string_view", "variant"};
347+
"string_view", "variant", "bits/algorithmfwd.h", "bits/align.h",
348+
"bits/alloc_traits.h", "bits/allocated_ptr.h", "bits/allocator.h",
349+
"bits/atomic_base.h", "bits/atomic_futex.h",
350+
"bits/atomic_lockfree_defines.h", "bits/basic_ios.h",
351+
"bits/basic_string.h", "bits/c++0x_warning.h", "bits/char_traits.h",
352+
"bits/charconv.h", "bits/codecvt.h", "bits/concept_check.h",
353+
"bits/cpp_type_traits.h", "bits/cxxabi_forced.h",
354+
"bits/cxxabi_init_exception.h", "bits/enable_special_members.h",
355+
"bits/erase_if.h", "bits/exception.h", "bits/exception_defines.h",
356+
"bits/exception_ptr.h", "bits/forward_list.h", "bits/fs_dir.h",
357+
"bits/fs_fwd.h", "bits/fs_ops.h", "bits/fs_path.h", "bits/functexcept.h",
358+
"bits/functional_hash.h", "bits/gslice.h", "bits/gslice_array.h",
359+
"bits/hash_bytes.h", "bits/hashtable.h", "bits/hashtable_policy.h",
360+
"bits/indirect_array.h", "bits/invoke.h", "bits/ios_base.h",
361+
"bits/iterator_concepts.h", "bits/locale_classes.h", "bits/locale_conv.h",
362+
"bits/locale_facets.h", "bits/locale_facets_nonio.h", "bits/localefwd.h",
363+
"bits/mask_array.h", "bits/max_size_type.h", "bits/memoryfwd.h",
364+
"bits/move.h", "bits/nested_exception.h", "bits/node_handle.h",
365+
"bits/ostream_insert.h", "bits/parse_numbers.h", "bits/postypes.h",
366+
"bits/predefined_ops.h", "bits/ptr_traits.h", "bits/quoted_string.h",
367+
"bits/random.h", "bits/range_access.h", "bits/ranges_algo.h",
368+
"bits/ranges_algobase.h", "bits/ranges_base.h", "bits/ranges_cmp.h",
369+
"bits/ranges_uninitialized.h", "bits/ranges_util.h", "bits/refwrap.h",
370+
"bits/shared_ptr.h", "bits/shared_ptr_atomic.h", "bits/shared_ptr_base.h",
371+
"bits/slice_array.h", "bits/std_abs.h", "bits/std_function.h",
372+
"bits/std_mutex.h", "bits/std_thread.h", "bits/stl_algo.h",
373+
"bits/stl_algobase.h", "bits/stl_bvector.h", "bits/stl_construct.h",
374+
"bits/stl_deque.h", "bits/stl_function.h", "bits/stl_heap.h",
375+
"bits/stl_iterator.h", "bits/stl_iterator_base_funcs.h",
376+
"bits/stl_iterator_base_types.h", "bits/stl_list.h", "bits/stl_map.h",
377+
"bits/stl_multimap.h", "bits/stl_multiset.h", "bits/stl_numeric.h",
378+
"bits/stl_pair.h", "bits/stl_queue.h", "bits/stl_raw_storage_iter.h",
379+
"bits/stl_relops.h", "bits/stl_set.h", "bits/stl_stack.h",
380+
"bits/stl_tempbuf.h", "bits/stl_tree.h", "bits/stl_uninitialized.h",
381+
"bits/stl_vector.h", "bits/stream_iterator.h",
382+
"bits/streambuf_iterator.h", "bits/stringfwd.h",
383+
"bits/this_thread_sleep.h", "bits/uniform_int_dist.h",
384+
"bits/unique_lock.h", "bits/unique_ptr.h", "bits/unordered_map.h",
385+
"bits/unordered_set.h", "bits/uses_allocator.h",
386+
"bits/uses_allocator_args.h", "bits/valarray_after.h",
387+
"bits/valarray_array.h", "bits/valarray_before.h"};
348388
std::string additionalHeaderDirectives;
349389
llvm::raw_string_ostream os(additionalHeaderDirectives);
350390
os << contents.substr(0, headerInjectionPoint);

stdlib/public/Cxx/libstdcxx/libstdcxx.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,11 @@ module std {
8282
requires cplusplus
8383
export *
8484
}
85+
86+
module cstdlib {
87+
header "cstdlib"
88+
requires cplusplus
89+
export *
90+
}
8591
}
8692
}

test/Interop/Cxx/foreign-reference/Inputs/reference-counted.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#define TEST_INTEROP_CXX_FOREIGN_REFERENCE_INPUTS_REFERENCE_COUNTED_H
33

44
#include <stdlib.h>
5+
#include <new>
56

67
#include "visibility.h"
78

8-
inline void *operator new(size_t, void *p) { return p; }
9-
109
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
1110

1211
static int finalLocalRefCount = 100;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++14 -Xcc -fmodules-cache-path=%t
3+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t
4+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -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 -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB
11+
// RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB
12+
13+
// REQUIRES: OS=macosx || OS=linux-gnu
14+
15+
#if canImport(Foundation)
16+
import Foundation
17+
#endif
18+
19+
#if ADD_CXXSTDLIB
20+
import CxxStdlib
21+
#endif
22+
23+
func test() {
24+
#if ADD_CXXSTDLIB
25+
let _ = std.string()
26+
#endif
27+
}
28+
29+
// CHECK: std-{{.*}}.pcm

0 commit comments

Comments
 (0)