Skip to content

Commit 69bdaad

Browse files
tools: disable ObjC for wasm in SILFunctionExtractor (#31920)
Currently, `clang` doesn't support Objective-C with the WebAssembly object format. Because of this, `sil-function-extractor` tool crashes in [Clang's `CGObjCCommonMac::GetSectionName` function](https://github.com/apple/llvm-project/blob/c3e5ae3fdebb67d936aeec2b04b7d2b6a784f69e/clang/lib/CodeGen/CGObjCMac.cpp#L5065-L5084). Since Swift doesn't provide Objective-C interop for WebAssembly, it would make sense to disable it explicitly. `sil-function-extractor` is used in the test suite, so this PR is required for those tests to proceed when testing the WebAssembly toolchain and SDK. Related to SR-9307. Co-authored-by: Saleem Abdulrasool <[email protected]>
1 parent d40e4f3 commit 69bdaad

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/sil-func-extractor/SILFunctionExtractor.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ static llvm::cl::opt<bool> EnableOSSAModules(
116116
"this is disabled we do not serialize in OSSA "
117117
"form when optimizing."));
118118

119+
static llvm::cl::opt<llvm::cl::boolOrDefault> EnableObjCInterop(
120+
"enable-objc-interop",
121+
llvm::cl::desc("Whether the Objective-C interop should be enabled. "
122+
"The value is `true` by default on Darwin platforms."));
123+
119124
// This function isn't referenced outside its translation unit, but it
120125
// can't use the "static" keyword because its address is used for
121126
// getMainExecutable (since some platforms don't support taking the
@@ -250,6 +255,14 @@ int main(int argc, char **argv) {
250255
Invocation.getLangOptions().EnableAccessControl = false;
251256
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
252257

258+
if (EnableObjCInterop == llvm::cl::BOU_UNSET) {
259+
Invocation.getLangOptions().EnableObjCInterop =
260+
Invocation.getLangOptions().Target.isOSDarwin();
261+
} else {
262+
Invocation.getLangOptions().EnableObjCInterop =
263+
EnableObjCInterop == llvm::cl::BOU_TRUE;
264+
}
265+
253266
SILOptions &Opts = Invocation.getSILOptions();
254267
Opts.EmitVerboseSIL = EmitVerboseSIL;
255268
Opts.EmitSortedSIL = EmitSortedSIL;

0 commit comments

Comments
 (0)