diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index 12f13736f55fb..67ce1590cbc82 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -560,13 +560,19 @@ class IRGenOptions { return OptMode == OptimizationMode::ForSize; } - std::string getDebugFlags(StringRef PrivateDiscriminator) const { + std::string getDebugFlags(StringRef PrivateDiscriminator, + bool EnableCXXInterop) const { std::string Flags = DebugFlags; if (!PrivateDiscriminator.empty()) { if (!Flags.empty()) Flags += " "; Flags += ("-private-discriminator " + PrivateDiscriminator).str(); } + if (EnableCXXInterop) { + if (!Flags.empty()) + Flags += " "; + Flags += "-enable-experimental-cxx-interop"; + } return Flags; } diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 72449da880708..83d23f6c2d082 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -2001,9 +2001,11 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts, SDK = *It; } + bool EnableCXXInterop = + IGM.getSILModule().getASTContext().LangOpts.EnableCXXInterop; TheCU = DBuilder.createCompileUnit( - Lang, MainFile, Producer, Opts.shouldOptimize(), Opts.getDebugFlags(PD), - MajorRuntimeVersion, SplitName, + Lang, MainFile, Producer, Opts.shouldOptimize(), + Opts.getDebugFlags(PD, EnableCXXInterop), MajorRuntimeVersion, SplitName, Opts.DebugInfoLevel > IRGenDebugInfoLevel::LineTables ? llvm::DICompileUnit::FullDebug : llvm::DICompileUnit::LineTablesOnly, diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 75ee76b427684..355f8912b80b5 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -124,13 +124,15 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context, case IRGenDebugInfoFormat::DWARF: CGO.DebugCompilationDir = Opts.DebugCompilationDir; CGO.DwarfVersion = Opts.DWARFVersion; - CGO.DwarfDebugFlags = Opts.getDebugFlags(PD); + CGO.DwarfDebugFlags = + Opts.getDebugFlags(PD, Context.LangOpts.EnableCXXInterop); break; case IRGenDebugInfoFormat::CodeView: CGO.EmitCodeView = true; CGO.DebugCompilationDir = Opts.DebugCompilationDir; // This actually contains the debug flags for codeview. - CGO.DwarfDebugFlags = Opts.getDebugFlags(PD); + CGO.DwarfDebugFlags = + Opts.getDebugFlags(PD, Context.LangOpts.EnableCXXInterop); break; } if (!Opts.TrapFuncName.empty()) { diff --git a/test/DebugInfo/cxx_interop.swift b/test/DebugInfo/cxx_interop.swift new file mode 100644 index 0000000000000..8b3bd5372653d --- /dev/null +++ b/test/DebugInfo/cxx_interop.swift @@ -0,0 +1,5 @@ +// Check that the "-enable-experimental-cxx-interop" is stored as a flag in the +// Compile Unit. + +// RUN: %target-swift-frontend -emit-ir -enable-experimental-cxx-interop -g %s -o - | %FileCheck %s +// CHECK: !DICompileUnit({{.*}}flags: "-enable-experimental-cxx-interop"