Skip to content

Commit 706f065

Browse files
Merge pull request #72649 from kateinoigakukun/pr-4bfcd7ce97f156f7d629719f05149ee051ecf670
Add "_multithreaded" as valid `_runtime` argument
2 parents be7b5b6 + 7441e03 commit 706f065

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

lib/Basic/LangOptions.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationPointerBit
111111
static const SupportedConditionalValue SupportedConditionalCompilationRuntimes[] = {
112112
"_ObjC",
113113
"_Native",
114+
"_multithreaded",
114115
};
115116

116117
static const SupportedConditionalValue SupportedConditionalCompilationTargetEnvironments[] = {
@@ -400,6 +401,16 @@ void LangOptions::setHasAtomicBitWidth(llvm::Triple triple) {
400401
}
401402
}
402403

404+
static bool isMultiThreadedRuntime(llvm::Triple triple) {
405+
if (triple.getOS() == llvm::Triple::WASI) {
406+
return triple.getEnvironmentName() == "threads";
407+
}
408+
if (triple.getOSName() == "none") {
409+
return false;
410+
}
411+
return true;
412+
}
413+
403414
std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
404415
clearAllPlatformConditionValues();
405416
clearAtomicBitWidths();
@@ -572,6 +583,11 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
572583
addPlatformConditionValue(PlatformConditionKind::TargetEnvironment,
573584
"macabi");
574585

586+
if (isMultiThreadedRuntime(Target)) {
587+
addPlatformConditionValue(PlatformConditionKind::Runtime,
588+
"_multithreaded");
589+
}
590+
575591
// Set the "_hasHasAtomicBitWidth" platform condition.
576592
setHasAtomicBitWidth(triple);
577593

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %swift -typecheck %s -verify -target arm64-apple-none-macho -parse-stdlib
2+
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target arm64-apple-none-macho
3+
4+
#if !_runtime(_multithreaded)
5+
func underNoThreads() {
6+
foo() // expected-error {{cannot find 'foo' in scope}}
7+
}
8+
#endif

test/Parse/ConditionalCompilation/wasm32Target.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ var x = C()
88
#endif
99
#endif
1010
var y = x
11+
12+
#if !_runtime(_multithreaded)
13+
let z = xx // expected-error {{cannot find 'xx' in scope}}
14+
#endif
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %swift -typecheck %s -verify -target wasm32-unknown-wasip1-threads -parse-stdlib
2+
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target wasm32-unknown-wasip1-threads
3+
4+
#if _runtime(_multithreaded)
5+
func underThreads() {
6+
foo() // expected-error {{cannot find 'foo' in scope}}
7+
}
8+
#endif

0 commit comments

Comments
 (0)