Skip to content

Commit a2d2fd8

Browse files
committed
diagnosticMain: Rebuild preamble for bounds change
1 parent 4ff22e6 commit a2d2fd8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/sema_manager.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ void *diagnosticMain(void *manager_) {
556556
std::shared_ptr<PreambleData> preamble = session->getPreamble();
557557
IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs =
558558
preamble ? preamble->stat_cache->consumer(session->fs) : session->fs;
559+
std::unique_ptr<CompilerInvocation> ci =
560+
buildCompilerInvocation(task.path, session->file.args, fs);
561+
if (!ci)
562+
continue;
559563
if (preamble) {
560564
bool rebuild = false;
561565
{
@@ -567,16 +571,25 @@ void *diagnosticMain(void *manager_) {
567571
rebuild = true;
568572
}
569573
}
574+
if (!rebuild) {
575+
std::string content = manager->wfiles->getContent(task.path);
576+
auto buf = llvm::MemoryBuffer::getMemBuffer(content);
577+
#if LLVM_VERSION_MAJOR >= 12 // llvmorg-12-init-11522-g4c55c3b66de
578+
PreambleBounds bounds =
579+
ComputePreambleBounds(*ci->getLangOpts(), *buf, 0);
580+
#else
581+
PreambleBounds bounds =
582+
ComputePreambleBounds(*ci->getLangOpts(), buf.get(), 0);
583+
#endif
584+
if (bounds.Size != preamble->preamble.getBounds().Size)
585+
rebuild = true;
586+
}
570587
if (rebuild) {
571588
manager->preamble_tasks.pushBack({task.path, nullptr, true}, true);
572589
continue;
573590
}
574591
}
575592

576-
std::unique_ptr<CompilerInvocation> ci =
577-
buildCompilerInvocation(task.path, session->file.args, fs);
578-
if (!ci)
579-
continue;
580593
// If main file is a header, add -Wno-unused-function
581594
if (lookupExtension(session->file.filename).second)
582595
ci->getDiagnosticOpts().Warnings.push_back("no-unused-function");

0 commit comments

Comments
 (0)