@@ -430,7 +430,8 @@ static void
430430getNormalInvocationArguments (std::vector<std::string> &invocationArgStrs,
431431 ASTContext &ctx,
432432 const ClangImporterOptions &importerOpts) {
433- const llvm::Triple &triple = ctx.LangOpts .Target ;
433+ const auto &LangOpts = ctx.LangOpts ;
434+ const llvm::Triple &triple = LangOpts.Target ;
434435 SearchPathOptions &searchPathOpts = ctx.SearchPathOpts ;
435436
436437 auto languageVersion = ctx.LangOpts .EffectiveLanguageVersion ;
@@ -463,12 +464,15 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
463464 SHIMS_INCLUDE_FLAG, searchPathOpts.RuntimeResourcePath ,
464465 });
465466
467+ if (LangOpts.EnableObjCInterop )
468+ invocationArgStrs.insert (invocationArgStrs.end (),
469+ {" -x" , " objective-c" , " -std=gnu11" , " -fobjc-arc" });
470+ else
471+ invocationArgStrs.insert (invocationArgStrs.end (), {" -x" , " c" , " -std=gnu11" });
472+
466473 // Set C language options.
467474 if (triple.isOSDarwin ()) {
468475 invocationArgStrs.insert (invocationArgStrs.end (), {
469- // Darwin uses Objective-C ARC.
470- " -x" , " objective-c" , " -std=gnu11" , " -fobjc-arc" ,
471-
472476 // Define macros that Swift bridging headers use.
473477 " -DSWIFT_CLASS_EXTRA=__attribute__((annotate(\" "
474478 SWIFT_NATIVE_ANNOTATION_STRING " \" )))" ,
@@ -514,24 +518,16 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
514518 " -DSWIFT_SDK_OVERLAY_UIKIT_EPOCH=2" ,
515519 });
516520
517- // Get the version of this compiler and pass it to
518- // C/Objective-C declarations.
521+ // Get the version of this compiler and pass it to C/Objective-C
522+ // declarations.
519523 auto V = version::Version::getCurrentCompilerVersion ();
520524 if (!V.empty ()) {
521525 invocationArgStrs.insert (invocationArgStrs.end (), {
522526 V.preprocessorDefinition (" __SWIFT_COMPILER_VERSION" ,
523- {1000000000 , /* ignored*/ 0 , 1000000 , 1000 , 1 }),
527+ {1000000000 , /* ignored*/ 0 , 1000000 , 1000 , 1 }),
524528 });
525529 }
526530 } else {
527- invocationArgStrs.insert (invocationArgStrs.end (), {
528- // Non-Darwin platforms don't use the Objective-C runtime, so they can
529- // not import Objective-C modules.
530- //
531- // Just use the most feature-rich C language mode.
532- " -x" , " c" , " -std=gnu11" ,
533- });
534-
535531 // The module map used for Glibc depends on the target we're compiling for,
536532 // and is not included in the resource directory with the other implicit
537533 // module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
0 commit comments