@@ -1252,10 +1252,17 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
1252
1252
}
1253
1253
1254
1254
// Lifted from the clang driver.
1255
- static void PrintArg (raw_ostream &OS, const char *Arg, bool Quote ) {
1255
+ static void PrintArg (raw_ostream &OS, const char *Arg, StringRef TempDir ) {
1256
1256
const bool Escape = std::strpbrk (Arg, " \"\\ $ " );
1257
1257
1258
- if (!Quote && !Escape) {
1258
+ if (StringRef (Arg).startswith (TempDir)) {
1259
+ // Don't write temporary file names in the debug info. This would prevent
1260
+ // incremental llvm compilation because we would generate different IR on
1261
+ // every compiler invocation.
1262
+ Arg = " <temporary-file>" ;
1263
+ }
1264
+
1265
+ if (!Escape) {
1259
1266
OS << Arg;
1260
1267
return ;
1261
1268
}
@@ -1479,9 +1486,14 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
1479
1486
const ArrayRef<const char *> &Args,
1480
1487
StringRef SDKPath,
1481
1488
StringRef ResourceDir) {
1489
+ // This isn't guaranteed to be the same temp directory as what the driver
1490
+ // uses, but it's highly likely.
1491
+ llvm::SmallString<128 > TDir;
1492
+ llvm::sys::path::system_temp_directory (true , TDir);
1493
+
1482
1494
llvm::raw_string_ostream OS (Output);
1483
1495
interleave (Args,
1484
- [&](const char *Argument) { PrintArg (OS, Argument, false ); },
1496
+ [&](const char *Argument) { PrintArg (OS, Argument, TDir. str () ); },
1485
1497
[&] { OS << " " ; });
1486
1498
1487
1499
// Inject the SDK path and resource dir if they are nonempty and missing.
@@ -1497,11 +1509,11 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
1497
1509
}
1498
1510
if (!haveSDKPath) {
1499
1511
OS << " -sdk " ;
1500
- PrintArg (OS, SDKPath.data (), false );
1512
+ PrintArg (OS, SDKPath.data (), TDir. str () );
1501
1513
}
1502
1514
if (!haveResourceDir) {
1503
1515
OS << " -resource-dir " ;
1504
- PrintArg (OS, ResourceDir.data (), false );
1516
+ PrintArg (OS, ResourceDir.data (), TDir. str () );
1505
1517
}
1506
1518
}
1507
1519
0 commit comments