mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-04 14:17:07 +00:00 
			
		
		
		
	Construct SourceManager with UserFilesAreVolatile
Prettify pipeline
This commit is contained in:
		
							parent
							
								
									a127ca9b02
								
							
						
					
					
						commit
						d4871207ed
					
				@ -202,6 +202,12 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance(
 | 
				
			|||||||
      Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
 | 
					      Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
 | 
				
			||||||
  if (!Clang->hasTarget())
 | 
					  if (!Clang->hasTarget())
 | 
				
			||||||
    return nullptr;
 | 
					    return nullptr;
 | 
				
			||||||
 | 
					  // Construct SourceManager with UserFilesAreVolatile: true because otherwise
 | 
				
			||||||
 | 
					  // RequiresNullTerminator: true may cause out-of-bounds read when a file is
 | 
				
			||||||
 | 
					  // mmap'ed but is saved concurrently.
 | 
				
			||||||
 | 
					  Clang->createFileManager();
 | 
				
			||||||
 | 
					  Clang->setSourceManager(new SourceManager(Clang->getDiagnostics(),
 | 
				
			||||||
 | 
					                                            Clang->getFileManager(), true));
 | 
				
			||||||
  return Clang;
 | 
					  return Clang;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -162,10 +162,14 @@ std::unique_ptr<IndexFile> RawCacheLoad(const std::string &path) {
 | 
				
			|||||||
                           IndexFile::kMajorVersion);
 | 
					                           IndexFile::kMajorVersion);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
					std::mutex &GetFileMutex(const std::string &path) {
 | 
				
			||||||
                   Project *project, VFS *vfs, const GroupMatch &matcher) {
 | 
					 | 
				
			||||||
  const int N_MUTEXES = 256;
 | 
					  const int N_MUTEXES = 256;
 | 
				
			||||||
  static std::mutex mutexes[N_MUTEXES];
 | 
					  static std::mutex mutexes[N_MUTEXES];
 | 
				
			||||||
 | 
					  return mutexes[std::hash<std::string>()(path) % N_MUTEXES];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
				
			||||||
 | 
					                   Project *project, VFS *vfs, const GroupMatch &matcher) {
 | 
				
			||||||
  std::optional<Index_Request> opt_request = index_request->TryPopFront();
 | 
					  std::optional<Index_Request> opt_request = index_request->TryPopFront();
 | 
				
			||||||
  if (!opt_request)
 | 
					  if (!opt_request)
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
@ -216,8 +220,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  if (reparse < 2)
 | 
					  if (reparse < 2)
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
      std::unique_lock lock(
 | 
					      std::unique_lock lock(GetFileMutex(path_to_index));
 | 
				
			||||||
        mutexes[std::hash<std::string>()(path_to_index) % N_MUTEXES]);
 | 
					 | 
				
			||||||
      prev = RawCacheLoad(path_to_index);
 | 
					      prev = RawCacheLoad(path_to_index);
 | 
				
			||||||
      if (!prev || CacheInvalid(vfs, prev.get(), path_to_index, entry.args,
 | 
					      if (!prev || CacheInvalid(vfs, prev.get(), path_to_index, entry.args,
 | 
				
			||||||
          std::nullopt))
 | 
					          std::nullopt))
 | 
				
			||||||
@ -256,8 +259,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
				
			|||||||
        std::string path = dep.first.val().str();
 | 
					        std::string path = dep.first.val().str();
 | 
				
			||||||
        if (!vfs->Stamp(path, dep.second, 1))
 | 
					        if (!vfs->Stamp(path, dep.second, 1))
 | 
				
			||||||
          continue;
 | 
					          continue;
 | 
				
			||||||
        std::lock_guard lock1(
 | 
					        std::lock_guard lock1(GetFileMutex(path));
 | 
				
			||||||
          mutexes[std::hash<std::string>()(path) % N_MUTEXES]);
 | 
					 | 
				
			||||||
        prev = RawCacheLoad(path);
 | 
					        prev = RawCacheLoad(path);
 | 
				
			||||||
        if (!prev)
 | 
					        if (!prev)
 | 
				
			||||||
          continue;
 | 
					          continue;
 | 
				
			||||||
@ -313,7 +315,7 @@ bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles,
 | 
				
			|||||||
    LOG_IF_S(INFO, loud) << "store index for " << path << " (delta: " << !!prev
 | 
					    LOG_IF_S(INFO, loud) << "store index for " << path << " (delta: " << !!prev
 | 
				
			||||||
                         << ")";
 | 
					                         << ")";
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      std::lock_guard lock(mutexes[std::hash<std::string>()(path) % N_MUTEXES]);
 | 
					      std::lock_guard lock(GetFileMutex(path));
 | 
				
			||||||
      if (vfs->Loaded(path))
 | 
					      if (vfs->Loaded(path))
 | 
				
			||||||
        prev = RawCacheLoad(path);
 | 
					        prev = RawCacheLoad(path);
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user