Skip to content

Commit 3e8dc4d

Browse files
authored
[clang][deps] NFC: Use qualified names for function definitions (#168586)
The compiler doesn't emit a diagnostics when the signature of a function defined in a namespace gets out-of-sync with its declaration. Let's use qualified names for function definitions instead of nesting them in a namespace so that mismatches are diagnosed by the compiler rather than by the (less understandable) linker.
1 parent 1157a22 commit 3e8dc4d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ void sanitizeDiagOpts(DiagnosticOptions &DiagOpts) {
358358
}
359359
} // namespace
360360

361-
namespace clang::tooling::dependencies {
362361
std::unique_ptr<DiagnosticOptions>
363-
createDiagOptions(ArrayRef<std::string> CommandLine) {
362+
dependencies::createDiagOptions(ArrayRef<std::string> CommandLine) {
364363
std::vector<const char *> CLI;
365364
for (const std::string &Arg : CommandLine)
366365
CLI.push_back(Arg.c_str());
@@ -382,9 +381,10 @@ DignosticsEngineWithDiagOpts::DignosticsEngineWithDiagOpts(
382381
}
383382

384383
std::pair<std::unique_ptr<driver::Driver>, std::unique_ptr<driver::Compilation>>
385-
buildCompilation(ArrayRef<std::string> ArgStrs, DiagnosticsEngine &Diags,
386-
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
387-
llvm::BumpPtrAllocator &Alloc) {
384+
dependencies::buildCompilation(ArrayRef<std::string> ArgStrs,
385+
DiagnosticsEngine &Diags,
386+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
387+
llvm::BumpPtrAllocator &Alloc) {
388388
SmallVector<const char *, 256> Argv;
389389
Argv.reserve(ArgStrs.size());
390390
for (const std::string &Arg : ArgStrs)
@@ -417,8 +417,8 @@ buildCompilation(ArrayRef<std::string> ArgStrs, DiagnosticsEngine &Diags,
417417
}
418418

419419
std::unique_ptr<CompilerInvocation>
420-
createCompilerInvocation(ArrayRef<std::string> CommandLine,
421-
DiagnosticsEngine &Diags) {
420+
dependencies::createCompilerInvocation(ArrayRef<std::string> CommandLine,
421+
DiagnosticsEngine &Diags) {
422422
llvm::opt::ArgStringList Argv;
423423
for (const std::string &Str : ArrayRef(CommandLine).drop_front())
424424
Argv.push_back(Str.c_str());
@@ -432,10 +432,10 @@ createCompilerInvocation(ArrayRef<std::string> CommandLine,
432432
}
433433

434434
std::pair<IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::vector<std::string>>
435-
initVFSForTUBuferScanning(IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
436-
ArrayRef<std::string> CommandLine,
437-
StringRef WorkingDirectory,
438-
llvm::MemoryBufferRef TUBuffer) {
435+
dependencies::initVFSForTUBuferScanning(
436+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
437+
ArrayRef<std::string> CommandLine, StringRef WorkingDirectory,
438+
llvm::MemoryBufferRef TUBuffer) {
439439
// Reset what might have been modified in the previous worker invocation.
440440
BaseFS->setCurrentWorkingDirectory(WorkingDirectory);
441441

@@ -459,9 +459,10 @@ initVFSForTUBuferScanning(IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
459459

460460
std::pair<IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>,
461461
std::vector<std::string>>
462-
initVFSForByNameScanning(IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
463-
ArrayRef<std::string> CommandLine,
464-
StringRef WorkingDirectory, StringRef ModuleName) {
462+
dependencies::initVFSForByNameScanning(
463+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
464+
ArrayRef<std::string> CommandLine, StringRef WorkingDirectory,
465+
StringRef ModuleName) {
465466
// Reset what might have been modified in the previous worker invocation.
466467
BaseFS->setCurrentWorkingDirectory(WorkingDirectory);
467468

@@ -486,7 +487,7 @@ initVFSForByNameScanning(IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
486487
return std::make_pair(OverlayFS, ModifiedCommandLine);
487488
}
488489

489-
bool initializeScanCompilerInstance(
490+
bool dependencies::initializeScanCompilerInstance(
490491
CompilerInstance &ScanInstance,
491492
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
492493
DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service,
@@ -559,7 +560,7 @@ bool initializeScanCompilerInstance(
559560
}
560561

561562
llvm::SmallVector<StringRef>
562-
getInitialStableDirs(const CompilerInstance &ScanInstance) {
563+
dependencies::getInitialStableDirs(const CompilerInstance &ScanInstance) {
563564
// Create a collection of stable directories derived from the ScanInstance
564565
// for determining whether module dependencies would fully resolve from
565566
// those directories.
@@ -571,8 +572,8 @@ getInitialStableDirs(const CompilerInstance &ScanInstance) {
571572
}
572573

573574
std::optional<PrebuiltModulesAttrsMap>
574-
computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
575-
llvm::SmallVector<StringRef> &StableDirs) {
575+
dependencies::computePrebuiltModulesASTMap(
576+
CompilerInstance &ScanInstance, llvm::SmallVector<StringRef> &StableDirs) {
576577
// Store a mapping of prebuilt module files and their properties like header
577578
// search options. This will prevent the implicit build to create duplicate
578579
// modules and will force reuse of the existing prebuilt module files
@@ -590,7 +591,8 @@ computePrebuiltModulesASTMap(CompilerInstance &ScanInstance,
590591
}
591592

592593
std::unique_ptr<DependencyOutputOptions>
593-
takeAndUpdateDependencyOutputOptionsFrom(CompilerInstance &ScanInstance) {
594+
dependencies::takeAndUpdateDependencyOutputOptionsFrom(
595+
CompilerInstance &ScanInstance) {
594596
// This function moves the existing dependency output options from the
595597
// invocation to the collector. The options in the invocation are reset,
596598
// which ensures that the compiler won't create new dependency collectors,
@@ -607,7 +609,8 @@ takeAndUpdateDependencyOutputOptionsFrom(CompilerInstance &ScanInstance) {
607609
return Opts;
608610
}
609611

610-
std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
612+
std::shared_ptr<ModuleDepCollector>
613+
dependencies::initializeScanInstanceDependencyCollector(
611614
CompilerInstance &ScanInstance,
612615
std::unique_ptr<DependencyOutputOptions> DepOutputOpts,
613616
StringRef WorkingDirectory, DependencyConsumer &Consumer,
@@ -633,7 +636,6 @@ std::shared_ptr<ModuleDepCollector> initializeScanInstanceDependencyCollector(
633636

634637
return MDC;
635638
}
636-
} // namespace clang::tooling::dependencies
637639

638640
bool DependencyScanningAction::runInvocation(
639641
std::unique_ptr<CompilerInvocation> Invocation,

0 commit comments

Comments
 (0)