Skip to content

Commit 005c2e5

Browse files
committed
[vfs] Don't bail out after a missing -ivfsoverlay file
This make -ivfsoverlay behave more like other fatal errors (e.g. missing -include file) by skipping the missing file instead of bailing out of the whole compilation. This makes it possible for libclang to still provide some functionallity as well as to correctly produce the fatal error diagnostic (previously we lost the diagnostic in libclang since there was no TU to tie it to). rdar://33385423 llvm-svn: 328337
1 parent a237866 commit 005c2e5

File tree

10 files changed

+48
-22
lines changed

10 files changed

+48
-22
lines changed

clang/include/clang/Frontend/PrecompiledPreamble.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ enum class BuildPreambleError {
289289
PreambleIsEmpty = 1,
290290
CouldntCreateTempFile,
291291
CouldntCreateTargetInfo,
292-
CouldntCreateVFSOverlay,
293292
BeginSourceFileFailed,
294293
CouldntEmitPCH
295294
};

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,6 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
13541354
case BuildPreambleError::CouldntCreateTargetInfo:
13551355
case BuildPreambleError::BeginSourceFileFailed:
13561356
case BuildPreambleError::CouldntEmitPCH:
1357-
case BuildPreambleError::CouldntCreateVFSOverlay:
13581357
// These erros are more likely to repeat, retry after some period.
13591358
PreambleRebuildCounter = DefaultPreambleRebuildInterval;
13601359
return nullptr;
@@ -1456,8 +1455,6 @@ ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
14561455
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
14571456
IntrusiveRefCntPtr<vfs::FileSystem> VFS =
14581457
createVFSFromCompilerInvocation(*CI, *Diags);
1459-
if (!VFS)
1460-
return nullptr;
14611458
AST->Diagnostics = Diags;
14621459
AST->FileSystemOpts = CI->getFileSystemOpts();
14631460
AST->Invocation = std::move(CI);
@@ -1735,14 +1732,14 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
17351732
// Create the AST unit.
17361733
std::unique_ptr<ASTUnit> AST;
17371734
AST.reset(new ASTUnit(false));
1735+
AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
1736+
AST->StoredDiagnostics.swap(StoredDiagnostics);
17381737
ConfigureDiags(Diags, *AST, CaptureDiagnostics);
17391738
AST->Diagnostics = Diags;
17401739
AST->FileSystemOpts = CI->getFileSystemOpts();
17411740
if (!VFS)
17421741
VFS = vfs::getRealFileSystem();
17431742
VFS = createVFSFromCompilerInvocation(*CI, *Diags, VFS);
1744-
if (!VFS)
1745-
return nullptr;
17461743
AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
17471744
AST->PCMCache = new MemoryBufferCache;
17481745
AST->OnlyLocalDecls = OnlyLocalDecls;
@@ -1752,8 +1749,6 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
17521749
AST->IncludeBriefCommentsInCodeCompletion
17531750
= IncludeBriefCommentsInCodeCompletion;
17541751
AST->UserFilesAreVolatile = UserFilesAreVolatile;
1755-
AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
1756-
AST->StoredDiagnostics.swap(StoredDiagnostics);
17571752
AST->Invocation = CI;
17581753
if (ForSerialization)
17591754
AST->WriterData.reset(new ASTWriterData(*AST->PCMCache));

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,9 @@ CompilerInstance::createDiagnostics(DiagnosticOptions *Opts,
302302

303303
FileManager *CompilerInstance::createFileManager() {
304304
if (!hasVirtualFileSystem()) {
305-
if (IntrusiveRefCntPtr<vfs::FileSystem> VFS =
306-
createVFSFromCompilerInvocation(getInvocation(), getDiagnostics()))
307-
setVirtualFileSystem(VFS);
308-
else
309-
return nullptr;
305+
IntrusiveRefCntPtr<vfs::FileSystem> VFS =
306+
createVFSFromCompilerInvocation(getInvocation(), getDiagnostics());
307+
setVirtualFileSystem(VFS);
310308
}
311309
FileMgr = new FileManager(getFileSystemOpts(), VirtualFileSystem);
312310
return FileMgr.get();

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,16 +3073,15 @@ createVFSFromCompilerInvocation(const CompilerInvocation &CI,
30733073
BaseFS->getBufferForFile(File);
30743074
if (!Buffer) {
30753075
Diags.Report(diag::err_missing_vfs_overlay_file) << File;
3076-
return IntrusiveRefCntPtr<vfs::FileSystem>();
3076+
continue;
30773077
}
30783078

30793079
IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getVFSFromYAML(
30803080
std::move(Buffer.get()), /*DiagHandler*/ nullptr, File);
3081-
if (!FS.get()) {
3081+
if (FS)
3082+
Overlay->pushOverlay(FS);
3083+
else
30823084
Diags.Report(diag::err_invalid_vfs_overlay) << File;
3083-
return IntrusiveRefCntPtr<vfs::FileSystem>();
3084-
}
3085-
Overlay->pushOverlay(FS);
30863085
}
30873086
return Overlay;
30883087
}

clang/lib/Frontend/PrecompiledPreamble.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
303303

304304
VFS =
305305
createVFSFromCompilerInvocation(Clang->getInvocation(), Diagnostics, VFS);
306-
if (!VFS)
307-
return BuildPreambleError::CouldntCreateVFSOverlay;
308306

309307
// Create a file manager object to provide access to and cache the filesystem.
310308
Clang->setFileManager(new FileManager(Clang->getFileSystemOpts(), VFS));
@@ -756,8 +754,6 @@ std::string BuildPreambleErrorCategory::message(int condition) const {
756754
return "Could not create temporary file for PCH";
757755
case BuildPreambleError::CouldntCreateTargetInfo:
758756
return "CreateTargetInfo() return null";
759-
case BuildPreambleError::CouldntCreateVFSOverlay:
760-
return "Could not create VFS Overlay";
761757
case BuildPreambleError::BeginSourceFileFailed:
762758
return "BeginSourceFile() return an error";
763759
case BuildPreambleError::CouldntEmitPCH:

clang/test/Index/missing_vfs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: c-index-test -test-load-source local %s -ivfsoverlay %t/does-not-exist.yaml &> %t.out
2+
// RUN: FileCheck -check-prefix=STDERR %s < %t.out
3+
// STDERR: fatal error: virtual filesystem overlay file '{{.*}}' not found
4+
// RUN: FileCheck %s < %t.out
5+
// CHECK: missing_vfs.c:[[@LINE+1]]:6: FunctionDecl=foo:[[@LINE+1]]:6
6+
void foo(void);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// void funcA(void);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module A {
2+
header "a.h"
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
'version': 0,
3+
'ignore-non-existent-contents': false,
4+
'roots': [
5+
{ 'name': 'INPUT_DIR', 'type': 'directory',
6+
'contents': [
7+
{ 'name': 'a.h', 'type': 'file',
8+
'external-contents': 'OUT_DIR/a.h'
9+
}
10+
]
11+
}
12+
]
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: shell
2+
// RUN: rm -rf %t && mkdir -p %t
3+
// RUN: echo "void funcA(void);" >> %t/a.h
4+
5+
// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml 2>&1 | FileCheck %s -check-prefix=ERROR
6+
// ERROR: virtual filesystem overlay file '{{.*}}' not found
7+
// RUN: find %t/mcp -name "A-*.pcm" | count 1
8+
9+
// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/MissingVFS/vfsoverlay.yaml > %t/vfs.yaml
10+
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml
11+
// RUN: find %t/mcp -name "A-*.pcm" | count 1
12+
13+
@import A;
14+
void test(void) {
15+
funcA();
16+
}

0 commit comments

Comments
 (0)