@@ -1752,24 +1752,32 @@ static void applyOverrideOptions(std::vector<std::string> &args,
1752
1752
1753
1753
void SwiftASTContext::AddExtraClangArgs (
1754
1754
const std::vector<std::string> &ExtraArgs, StringRef overrideOpts) {
1755
+ if (ExtraArgs.empty ())
1756
+ return ;
1757
+
1755
1758
swift::ClangImporterOptions &importer_options = GetClangImporterOptions ();
1756
1759
1757
1760
// Detect cc1 flags. When DirectClangCC1ModuleBuild is on then the
1758
1761
// clang arguments in the serialized invocation are clang cc1 flags,
1759
1762
// which are very specific to one compiler version and cannot
1760
1763
// be merged with driver options.
1761
1764
bool fresh_invocation = importer_options.ExtraArgs .empty ();
1762
- if (fresh_invocation && !ExtraArgs.empty () && ExtraArgs.front () == " -cc1" )
1763
- importer_options.DirectClangCC1ModuleBuild = true ;
1764
- if (!importer_options.DirectClangCC1ModuleBuild && !ExtraArgs.empty () &&
1765
- ExtraArgs.front () == " -cc1" )
1765
+ bool invocation_direct_cc1 = ExtraArgs.front () == " -cc1" ;
1766
+
1767
+ // If it is not a fresh invocation, make sure the cc1 option matches.
1768
+ if (!fresh_invocation &&
1769
+ (importer_options.DirectClangCC1ModuleBuild != invocation_direct_cc1))
1766
1770
AddDiagnostic (
1767
1771
eSeverityWarning,
1768
1772
" Mixing and matching of driver and cc1 Clang options detected" );
1769
1773
1774
+ importer_options.DirectClangCC1ModuleBuild = invocation_direct_cc1;
1775
+
1770
1776
// If using direct cc1 flags, compute the arguments and return.
1771
- // Since this is cc1 flags, no driver overwrite can be applied .
1777
+ // Since this is cc1 flags, override options are driver flags and don't apply .
1772
1778
if (importer_options.DirectClangCC1ModuleBuild ) {
1779
+ if (!fresh_invocation)
1780
+ importer_options.ExtraArgs .clear ();
1773
1781
AddExtraClangCC1Args (ExtraArgs, importer_options.ExtraArgs );
1774
1782
return ;
1775
1783
}
@@ -1821,12 +1829,17 @@ void SwiftASTContext::AddExtraClangCC1Args(
1821
1829
invocation.getFrontendOpts ().ModuleCacheKeys .clear ();
1822
1830
invocation.getCASOpts () = clang::CASOptions ();
1823
1831
1832
+ // Ignore CAS info inside modules when loading.
1833
+ invocation.getFrontendOpts ().ModuleLoadIgnoreCAS = true ;
1834
+
1824
1835
// Remove non-existing modules in a systematic way.
1825
1836
bool module_missing = false ;
1826
1837
auto CheckFileExists = [&](const char *file) {
1827
1838
if (!llvm::sys::fs::exists (file)) {
1828
- std::string m_description;
1829
- HEALTH_LOG_PRINTF (" Nonexistent explicit module file %s" , file);
1839
+ std::string warn;
1840
+ llvm::raw_string_ostream (warn)
1841
+ << " Nonexistent explicit module file " << file;
1842
+ AddDiagnostic (eSeverityWarning, warn);
1830
1843
module_missing = true ;
1831
1844
}
1832
1845
};
@@ -1835,8 +1848,8 @@ void SwiftASTContext::AddExtraClangCC1Args(
1835
1848
llvm::for_each (invocation.getFrontendOpts ().ModuleFiles ,
1836
1849
[&](const auto &mod) { CheckFileExists (mod.c_str ()); });
1837
1850
1838
- // If missing, clear all the prebuilt module options and use implicit module
1839
- // build.
1851
+ // If missing, clear all the prebuilt module options and switch to implicit
1852
+ // modules build.
1840
1853
if (module_missing) {
1841
1854
invocation.getHeaderSearchOpts ().PrebuiltModuleFiles .clear ();
1842
1855
invocation.getFrontendOpts ().ModuleFiles .clear ();
@@ -1944,6 +1957,10 @@ void SwiftASTContext::RemapClangImporterOptions(
1944
1957
1945
1958
void SwiftASTContext::FilterClangImporterOptions (
1946
1959
std::vector<std::string> &extra_args, SwiftASTContext *ctx) {
1960
+ // The direct cc1 mode do not need any extra audit.
1961
+ if (ctx && ctx->GetClangImporterOptions ().DirectClangCC1ModuleBuild )
1962
+ return ;
1963
+
1947
1964
std::string ivfs_arg;
1948
1965
// Copy back a filtered version of ExtraArgs.
1949
1966
std::vector<std::string> orig_args (std::move (extra_args));
@@ -1954,11 +1971,6 @@ void SwiftASTContext::FilterClangImporterOptions(
1954
1971
arg_sr == " -fno-implicit-module-maps" )
1955
1972
continue ;
1956
1973
1957
- // This is not a cc1 option.
1958
- if (arg_sr.starts_with (" --target=" ) && ctx &&
1959
- ctx->GetClangImporterOptions ().DirectClangCC1ModuleBuild )
1960
- continue ;
1961
-
1962
1974
// The VFS options turn into fatal errors when the referenced file
1963
1975
// is not found. Since the Xcode build system tends to create a
1964
1976
// lot of VFS overlays by default, stat them and emit a warning if
@@ -2245,6 +2257,11 @@ ProcessModule(Module &module, std::string m_description,
2245
2257
for (auto path : opts.getFrameworkSearchPaths ())
2246
2258
framework_search_paths.push_back ({path.Path , path.IsSystem });
2247
2259
auto &clang_opts = invocation.getClangImporterOptions ().ExtraArgs ;
2260
+ // If the args embedded are cc1 args, they are not compatible with existing
2261
+ // setting. Clear the previous args.
2262
+ if (!clang_opts.empty () && clang_opts.front () == " -cc1" )
2263
+ extra_clang_args.clear ();
2264
+
2248
2265
for (const std::string &arg : clang_opts) {
2249
2266
extra_clang_args.push_back (arg);
2250
2267
LOG_VERBOSE_PRINTF (GetLog (LLDBLog::Types), " adding Clang argument \" %s\" ." ,
0 commit comments