Skip to content

Add "_multithreaded" as valid _runtime argument #72649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationPointerBit
static const SupportedConditionalValue SupportedConditionalCompilationRuntimes[] = {
"_ObjC",
"_Native",
"_multithreaded",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the spelling we want, it should probably match the casing of the other valid values.

};

static const SupportedConditionalValue SupportedConditionalCompilationTargetEnvironments[] = {
Expand Down Expand Up @@ -400,6 +401,16 @@ void LangOptions::setHasAtomicBitWidth(llvm::Triple triple) {
}
}

static bool isMultiThreadedRuntime(llvm::Triple triple) {
if (triple.getOS() == llvm::Triple::WASI) {
return triple.getEnvironmentName() == "threads";
}
if (triple.getOSName() == "none") {
return false;
}
return true;
}

std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
clearAllPlatformConditionValues();
clearAtomicBitWidths();
Expand Down Expand Up @@ -572,6 +583,11 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
addPlatformConditionValue(PlatformConditionKind::TargetEnvironment,
"macabi");

if (isMultiThreadedRuntime(Target)) {
addPlatformConditionValue(PlatformConditionKind::Runtime,
"_multithreaded");
}

// Set the "_hasHasAtomicBitWidth" platform condition.
setHasAtomicBitWidth(triple);

Expand Down
8 changes: 8 additions & 0 deletions test/Parse/ConditionalCompilation/noneOSTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %swift -typecheck %s -verify -target arm64-apple-none-macho -parse-stdlib
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target arm64-apple-none-macho

#if !_runtime(_multithreaded)
func underNoThreads() {
foo() // expected-error {{cannot find 'foo' in scope}}
}
#endif
4 changes: 4 additions & 0 deletions test/Parse/ConditionalCompilation/wasm32Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ var x = C()
#endif
#endif
var y = x

#if !_runtime(_multithreaded)
let z = xx // expected-error {{cannot find 'xx' in scope}}
#endif
8 changes: 8 additions & 0 deletions test/Parse/ConditionalCompilation/wasm32ThreadsTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %swift -typecheck %s -verify -target wasm32-unknown-wasip1-threads -parse-stdlib
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target wasm32-unknown-wasip1-threads

#if _runtime(_multithreaded)
func underThreads() {
foo() // expected-error {{cannot find 'foo' in scope}}
}
#endif