@@ -430,49 +430,54 @@ 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 ;
437438
438- if (llvm::sys::path::extension (importerOpts.BridgingHeader ).endswith (
439- PCH_EXTENSION)) {
440- invocationArgStrs.insert (
441- invocationArgStrs.end (),
442- { " -include-pch" , importerOpts.BridgingHeader }
443- );
439+ if (llvm::sys::path::extension (importerOpts.BridgingHeader )
440+ .endswith (PCH_EXTENSION)) {
441+ invocationArgStrs.insert (invocationArgStrs.end (), {
442+ " -include-pch" , importerOpts.BridgingHeader
443+ });
444444 }
445445
446446 // Construct the invocation arguments for the current target.
447447 // Add target-independent options first.
448- invocationArgStrs.insert (
449- invocationArgStrs.end (),
450- {
448+ invocationArgStrs.insert (invocationArgStrs.end (), {
449+ // Enable modules
450+ " -fmodules" ,
451+ " -Werror=non-modular-include-in-framework-module" ,
452+ " -Xclang" , " -fmodule-feature" , " -Xclang" , " swift" ,
451453
452- // Enable modules
453- " -fmodules" ,
454- " -Werror=non-modular-include-in-framework-module" ,
455- " -Xclang" , " -fmodule-feature" , " -Xclang" , " swift" ,
454+ // Don't emit LLVM IR.
455+ " -fsyntax-only" ,
456456
457- // Don't emit LLVM IR .
458- " -fsyntax-only " ,
457+ // Enable block support .
458+ " -fblocks " ,
459459
460- // Enable block support.
461- " -fblocks" ,
460+ languageVersion.preprocessorDefinition (" __swift__" , {10000 , 100 , 1 }),
462461
463- languageVersion. preprocessorDefinition ( " __swift__ " , { 10000 , 100 , 1 }) ,
462+ " -fretain-comments-from-system-headers " ,
464463
465- " -fretain-comments-from-system-headers" ,
464+ SHIMS_INCLUDE_FLAG, searchPathOpts.RuntimeResourcePath ,
465+ });
466466
467- SHIMS_INCLUDE_FLAG, searchPathOpts.RuntimeResourcePath ,
468- });
467+ if (LangOpts.EnableObjCInterop ) {
468+ invocationArgStrs.insert (invocationArgStrs.end (),
469+ {" -x" , " objective-c" , " -std=gnu11" , " -fobjc-arc" });
470+ // TODO: Investigate whether 7.0 is a suitable default version.
471+ if (!triple.isOSDarwin ())
472+ invocationArgStrs.insert (invocationArgStrs.end (),
473+ {" -fobjc-runtime=ios-7.0" });
474+ } else {
475+ invocationArgStrs.insert (invocationArgStrs.end (), {" -x" , " c" , " -std=gnu11" });
476+ }
469477
470478 // Set C language options.
471479 if (triple.isOSDarwin ()) {
472480 invocationArgStrs.insert (invocationArgStrs.end (), {
473- // Darwin uses Objective-C ARC.
474- " -x" , " objective-c" , " -std=gnu11" , " -fobjc-arc" ,
475-
476481 // Define macros that Swift bridging headers use.
477482 " -DSWIFT_CLASS_EXTRA=__attribute__((annotate(\" "
478483 SWIFT_NATIVE_ANNOTATION_STRING " \" )))" ,
@@ -518,24 +523,16 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
518523 " -DSWIFT_SDK_OVERLAY_UIKIT_EPOCH=2" ,
519524 });
520525
521- // Get the version of this compiler and pass it to
522- // C/Objective-C declarations.
526+ // Get the version of this compiler and pass it to C/Objective-C
527+ // declarations.
523528 auto V = version::Version::getCurrentCompilerVersion ();
524529 if (!V.empty ()) {
525530 invocationArgStrs.insert (invocationArgStrs.end (), {
526531 V.preprocessorDefinition (" __SWIFT_COMPILER_VERSION" ,
527- {1000000000 , /* ignored*/ 0 , 1000000 , 1000 , 1 }),
532+ {1000000000 , /* ignored*/ 0 , 1000000 , 1000 , 1 }),
528533 });
529534 }
530535 } else {
531- invocationArgStrs.insert (invocationArgStrs.end (), {
532- // Non-Darwin platforms don't use the Objective-C runtime, so they can
533- // not import Objective-C modules.
534- //
535- // Just use the most feature-rich C language mode.
536- " -x" , " c" , " -std=gnu11" ,
537- });
538-
539536 // The module map used for Glibc depends on the target we're compiling for,
540537 // and is not included in the resource directory with the other implicit
541538 // module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
0 commit comments