[PATCH] D132405: [clang][deps] Split translation units into individual -cc1 or other commands

2022-08-30 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM. Up to you if you act on the last comment. Thanks for seeing this through!




Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp:295
+if (MDC)
+  MDC->applyDiscoveredDependencies(CI);
+LastCC1Arguments = CI.getCC1CommandLine();

I'm not a fan of storing `MDC` as a member, but I don't see any clearly better 
alternatives. One option would be to pass `CompilerInvocation` out-parameter to 
`ModuleDepCollector`'s constructor and relying on the collector to apply 
discovered dependencies, but that's not super obvious.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132405/new/

https://reviews.llvm.org/D132405

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133209: [clang] Document environment variables used by the driver

2022-09-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:2-5
   ---
   NOTE: This file is automatically generated by running clang-tblgen
   -gen-opt-docs. Do not edit this file by hand!!
   ---

aaron.ballman wrote:
> mizvekov wrote:
> > aaron.ballman wrote:
> > > I think you might have missed this bit. ;-)
> > > 
> > > @jansvoboda11 -- do you know of an ergonomic way for people to associate 
> > > extra documentation along with the command line reference to support 
> > > adding documentation like this? This is the second time in the past hour 
> > > I've seen people adding documentation directly to this file and the docs 
> > > would be kind of onerous to put in `HelpText<>` directly. I'm wondering 
> > > if the FE options can support something along the lines of AttrDocs.td 
> > > where we can specify some out-of-line documentation in another .td for 
> > > things that are nontrivial to document?
> > Ooops!
> > 
> > Why do we even commit this file then? :-)
> +1 -- we automatically generate the document from the cmake sphinx target, so 
> I think it's reasonable to remove this file from version control (same as we 
> did for AttributeReference.rst and DiagnosticReference.rst).
We don't have good place for extra documentation. Doing something similar to 
`AttrDocs.td` for command-line options is a good direction IMO.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133209/new/

https://reviews.llvm.org/D133209

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127647: [clang][lex] NFCI: Use FileEntryRef in ModuleMap::{load,lookup}ModuleMap()

2022-09-07 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 458555.
jansvoboda11 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127647/new/

https://reviews.llvm.org/D127647

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp

Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -987,9 +987,9 @@
   // We haven't looked here before. Load a module map, if there is
   // one.
   bool IsFrameworkDir = Parent.endswith(".framework");
-  if (const FileEntry *ModMapFile =
-HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
-parseModuleMapFile(ModMapFile, Attrs.IsSystem, *ParentDir);
+  if (Optional ModMapFile =
+  HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
+parseModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
 inferred = InferredDirectories.find(*ParentDir);
   }
 
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1615,10 +1615,10 @@
   return true;
 }
 
-static const FileEntry *getPrivateModuleMap(const FileEntry *File,
+static const FileEntry *getPrivateModuleMap(FileEntryRef File,
 FileManager &FileMgr) {
-  StringRef Filename = llvm::sys::path::filename(File->getName());
-  SmallString<128>  PrivateFilename(File->getDir()->getName());
+  StringRef Filename = llvm::sys::path::filename(File.getName());
+  SmallString<128>  PrivateFilename(File.getDir().getName());
   if (Filename == "module.map")
 llvm::sys::path::append(PrivateFilename, "module_private.map");
   else if (Filename == "module.modulemap")
@@ -1630,7 +1630,7 @@
   return nullptr;
 }
 
-bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
+bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem,
  FileID ID, unsigned *Offset,
  StringRef OriginalModuleMapFile) {
   // Find the directory for the module. For frameworks, that may require going
@@ -1649,9 +1649,7 @@
 Dir = FakeFile.getDir();
   }
 } else {
-  // TODO: Replace with `Dir = File.getDir()` when `File` is switched to
-  // `FileEntryRef`.
-  Dir = FileMgr.getOptionalDirectoryRef(File->getDir()->getName());
+  Dir = File.getDir();
 }
 
 assert(Dir && "parent must exist");
@@ -1680,11 +1678,9 @@
 }
 
 HeaderSearch::LoadModuleMapResult
-HeaderSearch::loadModuleMapFileImpl(const FileEntry *File, bool IsSystem,
+HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
 DirectoryEntryRef Dir, FileID ID,
 unsigned *Offset) {
-  assert(File && "expected FileEntry");
-
   // Check whether we've already loaded this module map, and mark it as being
   // loaded in case we recursively try to load it from itself.
   auto AddResult = LoadedModuleMaps.insert(std::make_pair(File, true));
@@ -1708,23 +1704,23 @@
   return LMM_NewlyLoaded;
 }
 
-const FileEntry *
+Optional
 HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
   if (!HSOpts->ImplicitModuleMaps)
-return nullptr;
+return None;
   // For frameworks, the preferred spelling is Modules/module.modulemap, but
   // module.map at the framework root is also accepted.
   SmallString<128> ModuleMapFileName(Dir->getName());
   if (IsFramework)
 llvm::sys::path::append(ModuleMapFileName, "Modules");
   llvm::sys::path::append(ModuleMapFileName, "module.modulemap");
-  if (auto F = FileMgr.getFile(ModuleMapFileName))
+  if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
 return *F;
 
   // Continue to allow module.map
   ModuleMapFileName = Dir->getName();
   llvm::sys::path::append(ModuleMapFileName, "module.map");
-  if (auto F = FileMgr.getFile(ModuleMapFileName))
+  if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
 return *F;
 
   // For frameworks, allow to have a private module map with a preferred
@@ -1733,10 +1729,10 @@
 ModuleMapFileName = Dir->getName();
 llvm::sys::path::append(ModuleMapFileName, "Modules",
 "module.private.modulemap");
-if (auto F = FileMgr.getFile(ModuleMapFileName))
+if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
   return *F;
   }
-  return nullptr;
+  return None;
 }
 
 Module *HeaderSearch::loadFrameworkModule(StringRef Name, DirectoryEntryRef Dir,
@@ -1779,9 +1775,10 @@
   if (KnownDir != DirectoryHasModuleMap.end())
 return KnownDir->second ? LMM_AlreadyLoaded : LMM_Inv

[PATCH] D133617: [Clang][ScanDeps] Change multiple-commands.c test to use -fmodules-cache-path on implicit builds

2022-09-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.

LGTM, thanks! Though we usually put the cache directory into `%t/cache` (aka 
`DIR/cache` in the JSON file) in other scanner tests, which would allow you to 
drop the second `sed` expression. (And you'd want to `rm -rf %t` instead.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133617/new/

https://reviews.llvm.org/D133617

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133674: [Lex/DependencyDirectivesScanner] Handle the case where the source line starts with a `tok::hashhash`

2022-09-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Could you explain why this is necessary and even correct? I'd expect Clang to 
give an error when seeing `##` in this position, and I'd expect the scanner to 
do the same.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133674/new/

https://reviews.llvm.org/D133674

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133674: [Lex/DependencyDirectivesScanner] Handle the case where the source line starts with a `tok::hashhash`

2022-09-13 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

Thank you! LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133674/new/

https://reviews.llvm.org/D133674

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129030: [Driver] Ignore the clang modules validation-related flags if clang modules are not enabled

2022-07-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129030/new/

https://reviews.llvm.org/D129030

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122385: [clang][deps] Fix clang-cl output argument parsing

2022-03-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, saudi.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

One goal of the ad-hoc command line argument parsing in `clang-scan-deps` is to 
get the last output path value.

Currently, the algorithm walks the arguments in reverse and identifies 
potention output path arguments.

Interestingly, in `clang-cl` mode, the output path can be specified in multiple 
ways. For example `/o /opt/build` and `/o/opt/build` are equivalent. The parser 
currently fails to correctly parse the former. It considers the value 
(`/opt/build/`) to be a shorthand for `/o pt/build`. It doesn't look at the 
preceding `/o`.

This patch simplifies the algorithm by doing forward iteration and fixes the 
bug by correctly handling separate `/o` argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122385

Files:
  clang/test/ClangScanDeps/cl-output.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -470,27 +470,29 @@
   llvm::sys::path::stem(Args[0]).contains_insensitive("clang-cl") 
||
   llvm::is_contained(Args, "--driver-mode=cl");
 
-  // Reverse scan, starting at the end or at the element before "--".
-  auto R = std::make_reverse_iterator(FlagsEnd);
-  for (auto I = R, E = Args.rend(); I != E; ++I) {
+  for (auto I = Args.begin(); I != FlagsEnd; ++I) {
 StringRef Arg = *I;
 if (ClangCLMode) {
   // Ignore arguments that are preceded by "-Xclang".
-  if ((I + 1) != E && I[1] == "-Xclang")
-continue;
-  if (LastO.empty()) {
-// With clang-cl, the output obj file can be specified with
-// "/opath", "/o path", "/Fopath", and the dash counterparts.
-// Also, clang-cl adds ".obj" extension if none is found.
-if ((Arg == "-o" || Arg == "/o") && I != R)
-  LastO = I[-1]; // Next argument (reverse iterator)
-else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
-  LastO = Arg.drop_front(3).str();
-else if (Arg.startswith("/o") || Arg.startswith("-o"))
-  LastO = Arg.drop_front(2).str();
-
-if (!LastO.empty() && !llvm::sys::path::has_extension(LastO))
-  LastO.append(".obj");
+  if (Arg == "-Xclang")
+++I;
+
+  // With clang-cl, the output obj file can be specified with
+  // "/opath", "/o path", "/Fopath", and the dash counterparts.
+  // Also, clang-cl adds ".obj" extension if none is found.
+  llvm::StringRef CurrentO;
+  if ((Arg == "/o" || Arg == "-o") && I != FlagsEnd)
+CurrentO = *++I;
+  else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
+CurrentO = Arg.drop_front(3);
+  else if (Arg.startswith("/o") || Arg.startswith("-o"))
+CurrentO = Arg.drop_front(2);
+
+  if (!CurrentO.empty()) {
+if (!llvm::sys::path::has_extension(CurrentO))
+  LastO = (CurrentO + ".obj").str();
+else
+  LastO = CurrentO.str();
   }
 }
 if (Arg == "-resource-dir")
Index: clang/test/ClangScanDeps/cl-output.c
===
--- clang/test/ClangScanDeps/cl-output.c
+++ clang/test/ClangScanDeps/cl-output.c
@@ -46,6 +46,10 @@
   "file": "DIR/test.c",
   "directory": "DIR",
   "command": "clang-cl /c -o DIR/test.o -o DIR/last.o -- DIR/test.c"
+},{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang-cl /c /o /opt/test.o -- DIR/test.c"
 }]
 
 //--- test.c
@@ -81,7 +85,9 @@
 // Check that the last argument specifying the output path wins.
 //
 // RUN: sed -e "s|DIR|%/t|g" %t/last-arg-cdb.json.template > 
%t/last-arg-cdb.json
-// RUN: clang-scan-deps -compilation-database %t/last-arg-cdb.json > 
%t/last-arg-result.d
+// RUN: clang-scan-deps -compilation-database %t/last-arg-cdb.json -j 1 > 
%t/last-arg-result.d
 // RUN: cat %t/last-arg-result.d | sed 's:\?:/:g' | FileCheck %s 
-DPREFIX=%/t --check-prefix=CHECK-LAST
 // CHECK-LAST:  [[PREFIX]]/last.o:
 // CHECK-LAST-NEXT:   [[PREFIX]]/test.c
+// CHECK-LAST-NEXT: /opt/test.o:
+// CHECK-LAST-NEXT:   [[PREFIX]]/test.c


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -47

[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Sorry for the breakage and thanks for reporting this! This is a real bug 
uncovered by your build using `/opt`. I have a fix here: D122385 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-28 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Thanks for the revert @gulfem. I was hoping I'll be able to quickly forward-fix 
the issue, but turns out there's more to investigate.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123070: [Driver][NFC] Simplify handling of flags in Options.td

2022-04-05 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.

Thank you for working on this!

I you haven't already, I suggest you test this change by dumping all TableGen 
records in the backend and comparing the before and after. When working on 
`Options.td`, I found it quite easy to introduce small differences that don't 
cause test failures on my machine, but may become observable on other 
configurations.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123070/new/

https://reviews.llvm.org/D123070

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123229: [clang][deps] Ensure deterministic file names on case-insensitive filesystems

2022-04-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman, akyrtzi.
Herald added a subscriber: mgrang.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The dependency scanner can reuse single FileManager instance across multiple 
translation units. This may lead to non-deterministic output depending on which 
TU gets processed first.

The root cause is the fact that Clang is using DirectoryEntry::getName in the 
header search algorithm. This function returns the path that was first used to 
construct the (shared) entry in FileManager. Using DirectoryEntryRef::getName 
instead preserves the case as it was spelled out for the current "get directory 
entry" request.

rdar://90647508


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123229

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/ClangScanDeps/header-search-case-sensitivity.c


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 
1 | FileCheck %s
+
+// In the reversed case, Clang starts by scanning "t2.c". When looking up the 
"arm/lower.h" header,
+// the string is appended to "DIR/dir2". That file ("DIR/dir2/arm/lower.h") 
doesn't exist, but when
+// learning so, the FileManager stats and caches the parent directory 
("DIR/dir2/arm"), using the
+// UID as the key.
+// When scanning "t1.c" later on, the "DIR/dir2/ARM" search directory is 
assigned the **same**
+// directory entry (with lowercase "arm"), since they share the UID on 
case-insensitive filesystems.
+// To preserve the correct case throughout the compiler for any file within 
that directory, it's
+// important to use the spelling actually used, not just the cached one.
+// RUN: clang-scan-deps -compilation-database=%t/cdb-rev.json -format make -j 
1 | FileCheck %s
+
+// CHECK: ARM/upper.h
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -436,10 +436,10 @@
   SmallString<1024> TmpDir;
   if (isNormalDir()) {
 // Concatenate the requested file onto the directory.
-TmpDir = getDir()->getName();
+TmpDir = getDirRef()->getName();
 llvm::sys::path::append(TmpDir, Filename);
 if (SearchPath) {
-  StringRef SearchPathRef(getDir()->getName());
+  StringRef SearchPathRef(getDirRef()->getName());
   SearchPath->clear();
   SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
 }
Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -91,6 +91,10 @@
 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
   }
 
+  Optional getDirRef() const {
+return isNormalDir() ? Optional(u.Dir) : None;
+  }
+
   /// getFrameworkDir - Return the directory that this framework refers to.
   ///
   const DirectoryEntry *getFrameworkDir() const {


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json

[PATCH] D123229: [clang][deps] Ensure deterministic file names on case-insensitive filesystems

2022-04-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 420905.
jansvoboda11 added a comment.

Finish test description.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123229/new/

https://reviews.llvm.org/D123229

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/ClangScanDeps/header-search-case-sensitivity.c


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on 
case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 
1 | FileCheck %s
+
+// In the reversed case, Clang starts by scanning "t2.c". When looking up the 
"arm/lower.h" header,
+// the string is appended to "DIR/dir2". That file ("DIR/dir2/arm/lower.h") 
doesn't exist, but when
+// learning so, the FileManager stats and caches the parent directory 
("DIR/dir2/arm"), using the
+// UID as the key.
+// When scanning "t1.c" later on, the "DIR/dir2/ARM" search directory is 
assigned the **same**
+// directory entry (with lowercase "arm"), since they share the UID on 
case-insensitive filesystems.
+// To preserve the correct case throughout the compiler for any file within 
that directory, it's
+// important to use the spelling actually used, not just the cached one.
+// RUN: clang-scan-deps -compilation-database=%t/cdb-rev.json -format make -j 
1 | FileCheck %s
+
+// CHECK: ARM/upper.h
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -436,10 +436,10 @@
   SmallString<1024> TmpDir;
   if (isNormalDir()) {
 // Concatenate the requested file onto the directory.
-TmpDir = getDir()->getName();
+TmpDir = getDirRef()->getName();
 llvm::sys::path::append(TmpDir, Filename);
 if (SearchPath) {
-  StringRef SearchPathRef(getDir()->getName());
+  StringRef SearchPathRef(getDirRef()->getName());
   SearchPath->clear();
   SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
 }
Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -91,6 +91,10 @@
 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
   }
 
+  Optional getDirRef() const {
+return isNormalDir() ? Optional(u.Dir) : None;
+  }
+
   /// getFrameworkDir - Return the directory that this framework refers to.
   ///
   const DirectoryEntry *getFrameworkDir() const {


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 

[PATCH] D121997: [clang][driver] Fix compilation database dump with multiple architectures

2022-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D121997#3676972 , @alanphipps 
wrote:

> Should there be an aarch64 guard on the test? There exist downstream Arm 
> compilers that don't support Arm64 and fail.  I know other tests explicitly 
> state "REQUIRES: aarch64-registered-target"

Could you describe your build config? I don't need to enable the Aarch64 or X86 
target for this test to pass on macOS.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121997/new/

https://reviews.llvm.org/D121997

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129884: [clang][deps] Include canonical invocation in ContextHash

2022-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Makes sense, thanks. LGTM provided you add brief explanation to each of the new 
tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129884/new/

https://reviews.llvm.org/D129884

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130620: Fix lack of cc1 flag in llvmcmd sections when assertions are enabled

2022-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Thanks for the fix! Left one suggestion.




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4549
+Invocation.generateCC1CommandLine(Args, SA);
+Args.insert(Args.begin(), "-cc1");
+  },

This will shift all generated arguments in the vector. Could you do something 
like this instead?

```
Args.push_back("-cc1");
Invocation.generateCC1CommandLine(Args, SA);
```

I think `generateCC1CommandLine()` //appends// to `Args`, so this should be 
safe to do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130620/new/

https://reviews.llvm.org/D130620

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130620: Fix lack of cc1 flag in llvmcmd sections when assertions are enabled

2022-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

The code change looks good to me, could you also include a test case for this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130620/new/

https://reviews.llvm.org/D130620

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130620: Fix lack of cc1 flag in llvmcmd sections when assertions are enabled

2022-07-28 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Thanks for adding the tests. They are failing in CI though, and I don't think 
they're entirely correct.

My understanding is that the goal is to make sure Clang doesn't drop the `-cc1` 
flag when embedding command-lines into object files.

During normal compilation, the arguments given by the driver to 
`CompilerInvocation::CreateFromArgs()` already begin with `-cc1`, so I suggest 
setting up the tests to do so as well. We could use `{"-cc1", 
"-round-trip-args"}` in the first test case and `{"-cc1", 
"-no-round-trip-args"}` in the second.

We probably want to verify that the `CompilerInvocation` member used to store 
the command-line looks correctly. My guess is that the bitcode is using 
`CodeGenOptions::CommandLineArgs`, so I suggest checking that instead of 
`GeneratedArgs` in the final assertion.

(I feel like `GeneratedArgs` are an implementation detail in this particular 
test case. Moreover, the vector will be empty in the current revision, since 
you don't call `Invocation.generateCC1CommandLine(GeneratedArgs, *this)` like 
the surrounding test cases do.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130620/new/

https://reviews.llvm.org/D130620

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130620: Fix lack of cc1 flag in llvmcmd sections when assertions are enabled

2022-07-28 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the patch!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130620/new/

https://reviews.llvm.org/D130620

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131124: [Serialization] Remove `ORIGINAL_PCH_DIR` record

2022-08-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131124/new/

https://reviews.llvm.org/D131124

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131241: [Clang][Lex] Extend HeaderSearch::LookupFile to control OpenFile behavior.

2022-08-05 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM. It'd be nice to have some tests for this, but since it's just forwarding 
arguments to `FileManager` I'm also fine with this as is.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131241/new/

https://reviews.llvm.org/D131241

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126676: [clang] Disallow differences in defines used for creating and using PCH

2022-08-05 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Do you think it would make sense to introduce a command-line flag that would 
control this behavior?

Also, I'd like to test this patch internally to see if it affects anything on 
our end. I should be able to do so next week.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126676/new/

https://reviews.llvm.org/D126676

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131412: [clang][deps] Stop sharing FileManager across module builds in scanner

2022-08-08 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks. (For context, this patch build on top of D131076 
).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131412/new/

https://reviews.llvm.org/D131412

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131420: [clang][deps] Always generate module paths

2022-08-08 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, Bigcheese.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since D129389  (and downstream PR 
https://github.com/apple/llvm-project/pull/4965), the dependency scanner is 
responsible for generating full command-lines, including the modules paths. 
This patch removes the flag that was making this an opt-in behavior in 
clang-scan-deps.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131420

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/generate-modules-path-args.c
  clang/test/ClangScanDeps/modulemap-via-vfs.m
  clang/test/ClangScanDeps/modules-context-hash-module-map-path.c
  clang/test/ClangScanDeps/modules-context-hash-outputs.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-disable-free.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch-dangling.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/modules-symlink.c
  clang/test/ClangScanDeps/removed-args.c
  clang/test/ClangScanDeps/submodule-order.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -138,36 +138,11 @@
 llvm::cl::init(ScanningOutputFormat::Make),
 llvm::cl::cat(DependencyScannerCategory));
 
-// This mode is mostly useful for development of explicitly built modules.
-// Command lines will contain arguments specifying modulemap file paths and
-// absolute paths to PCM files in the module cache directory.
-//
-// Build tools that want to put the PCM files in a different location should use
-// the C++ APIs instead, of which there are two flavors:
-//
-// 1. APIs that generate arguments with paths PCM files via a callback provided
-//by the client:
-// * ModuleDeps::getCanonicalCommandLine(LookupPCMPath)
-// * FullDependencies::getCommandLine(LookupPCMPath)
-//
-// 2. APIs that don't generate arguments with paths PCM files and instead expect
-// the client to append them manually after the fact:
-// * ModuleDeps::getCanonicalCommandLineWithoutModulePaths()
-// * FullDependencies::getCommandLineWithoutModulePaths()
-//
-static llvm::cl::opt GenerateModulesPathArgs(
-"generate-modules-path-args",
-llvm::cl::desc(
-"With '-format experimental-full', include arguments specifying "
-"modules-related paths in the generated command lines: "
-"'-fmodule-file=', '-o', '-fmodule-map-file='."),
-llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
-
 static llvm::cl::opt ModuleFilesDir(
 "module-files-dir",
-llvm::cl::desc("With '-generate-modules-path-args', paths to module files "
-   "in the generated command lines will begin with the "
-   "specified directory instead the module cache directory."),
+llvm::cl::desc(
+"The build directory for modules. Defaults to the value of "
+"'-fmodules-cache-path=' from command lines for implicit modules."),
 llvm::cl::cat(DependencyScannerCategory));
 
 static llvm::cl::opt OptimizeArgs(
@@ -198,8 +173,7 @@
 
 llvm::cl::list ModuleDepTargets(
 "dependency-target",
-llvm::cl::desc("With '-generate-modules-path-args', the names of "
-   "dependency targets for the dependency file"),
+llvm::cl::desc("The names of dependency targets for the dependency file"),
 llvm::cl::cat(DependencyScannerCategory));
 
 enum ResourceDirRecipeKind {
@@ -295,11 +269,9 @@
 }
 
 ID.CommandLine =
-GenerateModulesPathArgs
-? FD.getCommandLine([&](const ModuleID &MID, ModuleOutputKind MOK) {
-return lookupModuleOutput(MID, MOK);
-  })
-: FD.getCommandLineWithoutModulePaths();
+FD.getCommandLine([&](const ModuleID &MID, ModuleOutputKind MOK) {
+  return lookupModuleOutput(MID, MOK);
+});
 Inputs.push_back(std::move(ID));
   }
 
@@ -329,13 +301,10 @@
   {"file-deps", toJSONSorted(MD.Fil

[PATCH] D126676: [clang] Disallow differences in defines used for creating and using PCH

2022-08-10 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.

LGTM, no issues on our side.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126676/new/

https://reviews.llvm.org/D126676

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131420: [clang][deps] Always generate module paths

2022-08-10 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71e32d5cf005: [clang][deps] Always generate module paths 
(authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D131420?vs=450887&id=451593#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131420/new/

https://reviews.llvm.org/D131420

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/generate-modules-path-args.c
  clang/test/ClangScanDeps/modulemap-via-vfs.m
  clang/test/ClangScanDeps/modules-context-hash-module-map-path.c
  clang/test/ClangScanDeps/modules-context-hash-outputs.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-disable-free.c
  clang/test/ClangScanDeps/modules-file-path-isolation.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch-dangling.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/modules-symlink.c
  clang/test/ClangScanDeps/removed-args.c
  clang/test/ClangScanDeps/submodule-order.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -138,36 +138,11 @@
 llvm::cl::init(ScanningOutputFormat::Make),
 llvm::cl::cat(DependencyScannerCategory));
 
-// This mode is mostly useful for development of explicitly built modules.
-// Command lines will contain arguments specifying modulemap file paths and
-// absolute paths to PCM files in the module cache directory.
-//
-// Build tools that want to put the PCM files in a different location should use
-// the C++ APIs instead, of which there are two flavors:
-//
-// 1. APIs that generate arguments with paths PCM files via a callback provided
-//by the client:
-// * ModuleDeps::getCanonicalCommandLine(LookupPCMPath)
-// * FullDependencies::getCommandLine(LookupPCMPath)
-//
-// 2. APIs that don't generate arguments with paths PCM files and instead expect
-// the client to append them manually after the fact:
-// * ModuleDeps::getCanonicalCommandLineWithoutModulePaths()
-// * FullDependencies::getCommandLineWithoutModulePaths()
-//
-static llvm::cl::opt GenerateModulesPathArgs(
-"generate-modules-path-args",
-llvm::cl::desc(
-"With '-format experimental-full', include arguments specifying "
-"modules-related paths in the generated command lines: "
-"'-fmodule-file=', '-o', '-fmodule-map-file='."),
-llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
-
 static llvm::cl::opt ModuleFilesDir(
 "module-files-dir",
-llvm::cl::desc("With '-generate-modules-path-args', paths to module files "
-   "in the generated command lines will begin with the "
-   "specified directory instead the module cache directory."),
+llvm::cl::desc(
+"The build directory for modules. Defaults to the value of "
+"'-fmodules-cache-path=' from command lines for implicit modules."),
 llvm::cl::cat(DependencyScannerCategory));
 
 static llvm::cl::opt OptimizeArgs(
@@ -198,8 +173,7 @@
 
 llvm::cl::list ModuleDepTargets(
 "dependency-target",
-llvm::cl::desc("With '-generate-modules-path-args', the names of "
-   "dependency targets for the dependency file"),
+llvm::cl::desc("The names of dependency targets for the dependency file"),
 llvm::cl::cat(DependencyScannerCategory));
 
 enum ResourceDirRecipeKind {
@@ -295,11 +269,9 @@
 }
 
 ID.CommandLine =
-GenerateModulesPathArgs
-? FD.getCommandLine([&](const ModuleID &MID, ModuleOutputKind MOK) {
-return lookupModuleOutput(MID, MOK);
-  })
-: FD.getCommandLineWithoutModulePaths();
+FD.getCommandLine([&](const ModuleID &MID, ModuleOutputKind MOK) {
+  return lookupModuleOutput(MID, MOK);
+});
 Inputs.push_back(std::move(ID));
   }
 
@@ -329,13 +301,10 @@
   {"file-deps", toJSONSorted(MD.FileDeps)},
   {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
   {"clang-modulemap-file", MD.ClangModuleMapFile},
-  {"command-line",

[PATCH] D106064: [clang][deps] Normalize paths in minimizing file system

2021-07-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 added a project: clang.
jansvoboda11 requested review of this revision.

This patch normalizes paths in `DependencyScanningWorkerFilesystem` so that 
lookup of ignored files and cached file entries works correctly on Windows 
(where `/` and `\` are equivalent).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106064

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -128,11 +128,11 @@
   // Add any filenames that were explicity passed in the build settings and
   // that might be opened, as we want to ensure we don't run source
   // minimization on them.
-  DepFS->IgnoredFiles.clear();
+  DepFS->clearIgnoredFiles();
   for (const auto &Entry : CI.getHeaderSearchOpts().UserEntries)
-DepFS->IgnoredFiles.insert(Entry.Path);
+DepFS->ignoreFile(Entry.Path);
   for (const auto &Entry : CI.getHeaderSearchOpts().VFSOverlayFiles)
-DepFS->IgnoredFiles.insert(Entry);
+DepFS->ignoreFile(Entry);
 
   // Support for virtual file system overlays on top of the caching
   // filesystem.
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -149,9 +149,18 @@
   return shouldMinimize(Filename); // Only cache stat failures on source files.
 }
 
+void DependencyScanningWorkerFilesystem::ignoreFile(StringRef RawFilename) {
+  llvm::SmallString<256> Filename;
+  llvm::sys::path::native(RawFilename, Filename);
+  IgnoredFiles.insert(Filename);
+}
+
 llvm::ErrorOr
 DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
-const StringRef Filename) {
+const StringRef RawFilename) {
+  llvm::SmallString<256> Filename;
+  llvm::sys::path::native(RawFilename, Filename);
+
   if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename)) {
 return Entry;
   }
Index: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
===
--- 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -153,8 +153,8 @@
   llvm::ErrorOr>
   openFileForRead(const Twine &Path) override;
 
-  /// The set of files that should not be minimized.
-  llvm::StringSet<> IgnoredFiles;
+  void clearIgnoredFiles() { IgnoredFiles.clear(); }
+  void ignoreFile(StringRef Filename);
 
 private:
   void setCachedEntry(StringRef Filename, const CachedFileSystemEntry *Entry) {
@@ -179,6 +179,8 @@
   /// excluded conditional directive skip mappings that are used by the
   /// currently active preprocessor.
   ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
+  /// The set of files that should not be minimized.
+  llvm::StringSet<> IgnoredFiles;
 };
 
 } // end namespace dependencies


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -128,11 +128,11 @@
   // Add any filenames that were explicity passed in the build settings and
   // that might be opened, as we want to ensure we don't run source
   // minimization on them.
-  DepFS->IgnoredFiles.clear();
+  DepFS->clearIgnoredFiles();
   for (const auto &Entry : CI.getHeaderSearchOpts().UserEntries)
-DepFS->IgnoredFiles.insert(Entry.Path);
+DepFS->ignoreFile(Entry.Path);
   for (const auto &Entry : CI.getHeaderSearchOpts().VFSOverlayFiles)
-DepFS->IgnoredFiles.insert(Entry);
+DepFS->ignoreFile(Entry);
 
   // Support for virtual file system overlays on top of the caching
   // filesystem.
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -149,9 +149,18 @@
   return shouldMinimize(Filename); // Only cache stat failures on source files.
 }
 
+void DependencyScanningWorkerFilesyste

[PATCH] D104536: WIP: [clang][deps] Avoid minimizing PCH input files

2021-07-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 358951.
jansvoboda11 edited the summary of this revision.
jansvoboda11 set the repository for this revision to rG LLVM Github Monorepo.
jansvoboda11 added a comment.

Rebase on top of D106064 , solving Windows CI 
failure.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104536/new/

https://reviews.llvm.org/D104536

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -6,7 +6,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
 // RUN: echo -%t > %t/result_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_pch.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
 // RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
 //
 // Check we didn't build the PCH during dependency scanning.
@@ -127,9 +127,8 @@
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu.json
-// FIXME: Make this work with '-mode preprocess-minimized-sources'.
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu.json
 // RUN: cat %t/result_tu.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU
 //
 // CHECK-TU:  -[[PREFIX:.*]]
@@ -193,7 +192,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu_with_common.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu_with_common.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu_with_common.json
 // RUN: cat %t/result_tu_with_common.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU-WITH-COMMON
 //
 // CHECK-TU-WITH-COMMON:  -[[PREFIX:.*]]
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -46,25 +46,73 @@
   DependencyConsumer &C;
 };
 
-/// A listener that collects the names and paths to imported modules.
-class ImportCollectingListener : public ASTReaderListener {
-  using PrebuiltModuleFilesT =
-  decltype(HeaderSearchOptions::PrebuiltModuleFiles);
-
+/// A listener that collects the imported modules and optionally the input
+/// files.
+class PrebuiltModuleListener : public ASTReaderListener {
 public:
-  ImportCollectingListener(PrebuiltModuleFilesT &PrebuiltModuleFiles)
-  : PrebuiltModuleFiles(PrebuiltModuleFiles) {}
+  PrebuiltModuleListener(llvm::StringMap &PrebuiltModuleFiles,
+ llvm::StringSet<> &InputFiles, bool VisitInputFiles)
+  : PrebuiltModuleFiles(PrebuiltModuleFiles), InputFiles(InputFiles),
+VisitInputFiles(VisitInputFiles) {}
 
   bool needsImportVisitation() const override { return true; }
+  bool needsInputFileVisitation() override { return VisitInputFiles; }
+  bool needsSystemInputFileVisitation() override { return VisitInputFiles; }
 
   void visitImport(StringRef ModuleName, StringRef Filename) override {
-PrebuiltModuleFiles[std::string(ModuleName)] = std::string(Filename);
+PrebuiltModuleFiles.insert({ModuleName, Filename.str()});
+  }
+
+  bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden,
+  bool isExplicitModule) override {
+InputFiles.insert(Filename);
+return true;
   }
 
 private:
-  PrebuiltModuleFilesT &PrebuiltModuleFiles;
+  llvm::StringMap &PrebuiltModuleFiles;
+  llvm::StringSet<> &InputFiles;
+  bool VisitInputFiles;
 };
 
+using PrebuiltModuleFilesT = decltype(HeaderSearchOptions::PrebuiltModuleFiles);
+
+/// Visit the given prebuilt module and collect all of the modules it
+/// transitively imports and contributing input files.
+static void visitPrebuiltModule(StringRef PrebuiltModuleFilename,
+CompilerInstance &CI,
+PrebuiltModuleFilesT &ModuleFiles,
+llvm::StringSet<> &InputFiles,
+bool VisitInputFiles) {
+  // Maps the names o

[PATCH] D106146: [clang][deps] Separate filesystem caches for minimized and original files

2021-07-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 added a project: clang.
Herald added a subscriber: mgorny.
jansvoboda11 requested review of this revision.

This patch separates the local and global caches of 
`DependencyScanningFilesystem` into two buckets: minimized files and original 
files. This is necessary to deal with precompiled modules/headers.

Consider a single worker with its instance of filesystem:

1. Build system uses the worker to scan dependencies of module A => filesystem 
cache gets populated with minimized input files.
2. Build system uses the results to explicitly build module A => explicitly 
built module captures the state of the real filesystem (containing 
non-minimized input files).
3. Build system uses the prebuilt module A as an explicit precompiled 
dependency for another compile job B.
4. Build system uses the same worker to scan dependencies for job B => worker 
uses implicit modular build to discover dependencies, which validates the 
filesystem state embedded in the prebuilt module (non-minimized files) to the 
current view of the filesystem (minimized files), resulting in validation 
failures.

This problem can be avoided in step 4 by collecting input files from the 
precompiled module and marking them as "ignored" in the minimizing filesystem. 
This way, the validation should succeed, since we should be always dealing with 
the original (non-minized) input files. However, the filesystem already 
minimized the input files in step 1 and put it in the cache, which gets used in 
step 4 as well even though it's marked ignored (do not minimize). This patch 
essentially fixes this oversight by making the `"file is minimized"` part of 
the cache key (from high level).

Depends on D106064 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106146

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/DependencyScannerTest.cpp

Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
@@ -203,5 +204,35 @@
   EXPECT_EQ(convert_to_slash(Deps[5]), "/root/symlink.h");
 }
 
+namespace dependencies {
+TEST(DependencyScanningFilesystem, IgnoredFilesHaveSeparateCache) {
+  auto VFS = llvm::makeIntrusiveRefCnt();
+  VFS->addFile("/mod.h", 0, llvm::MemoryBuffer::getMemBuffer("// hi there!\n"));
+
+  DependencyScanningFilesystemSharedCache SharedCache;
+  auto Mappings = std::make_unique();
+  DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
+
+  auto StatusMinimized0 = DepFS.status("/mod.h");
+  DepFS.ignoreFile("/mod.h");
+  auto StatusFull1 = DepFS.status("/mod.h");
+  DepFS.clearIgnoredFiles();
+
+  auto StatusMinimized2 = DepFS.status("/mod.h");
+  DepFS.ignoreFile("/mod.h");
+  auto StatusFull3 = DepFS.status("/mod.h");
+
+  EXPECT_TRUE(StatusMinimized0);
+  EXPECT_EQ(StatusMinimized0->getSize(), 0u);
+  EXPECT_TRUE(StatusFull1);
+  EXPECT_EQ(StatusFull1->getSize(), 13u);
+
+  EXPECT_TRUE(StatusMinimized2);
+  EXPECT_EQ(StatusMinimized2->getSize(), 0u);
+  EXPECT_TRUE(StatusFull3);
+  EXPECT_EQ(StatusFull3->getSize(), 13u);
+}
+
+} // end namespace dependencies
 } // end namespace tooling
 } // end namespace clang
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -68,6 +68,7 @@
   clangAST
   clangASTMatchers
   clangBasic
+  clangDependencyScanning
   clangFormat
   clangFrontend
   clangLex
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -99,8 +99,7 @@
   return Result;
 }
 
-DependencyScanningFilesystemSharedCache::
-DependencyScanningFilesystemSharedCache() {
+DependencyScanningFilesystemSharedCache::SingleCache::SingleCache() {
   // This heuristic was chosen using a empirical testing on a
   // reasonably high core machine (iMacPro 18 cores / 36 threads). The cache
   // sharding gives a performance edge by reducing the lock contention.
@@ -111,18 +110,20 @@
   CacheShards = std::m

[PATCH] D104536: [clang][deps] Avoid minimizing PCH input files

2021-07-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 359299.
jansvoboda11 added a comment.

Rebase on top of D106146 .


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104536/new/

https://reviews.llvm.org/D104536

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -6,7 +6,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
 // RUN: echo -%t > %t/result_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_pch.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
 // RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
 //
 // Check we didn't build the PCH during dependency scanning.
@@ -127,9 +127,8 @@
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu.json
-// FIXME: Make this work with '-mode preprocess-minimized-sources'.
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu.json
 // RUN: cat %t/result_tu.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU
 //
 // CHECK-TU:  -[[PREFIX:.*]]
@@ -193,7 +192,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu_with_common.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu_with_common.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu_with_common.json
 // RUN: cat %t/result_tu_with_common.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU-WITH-COMMON
 //
 // CHECK-TU-WITH-COMMON:  -[[PREFIX:.*]]
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -46,25 +46,73 @@
   DependencyConsumer &C;
 };
 
-/// A listener that collects the names and paths to imported modules.
-class ImportCollectingListener : public ASTReaderListener {
-  using PrebuiltModuleFilesT =
-  decltype(HeaderSearchOptions::PrebuiltModuleFiles);
-
+/// A listener that collects the imported modules and optionally the input
+/// files.
+class PrebuiltModuleListener : public ASTReaderListener {
 public:
-  ImportCollectingListener(PrebuiltModuleFilesT &PrebuiltModuleFiles)
-  : PrebuiltModuleFiles(PrebuiltModuleFiles) {}
+  PrebuiltModuleListener(llvm::StringMap &PrebuiltModuleFiles,
+ llvm::StringSet<> &InputFiles, bool VisitInputFiles)
+  : PrebuiltModuleFiles(PrebuiltModuleFiles), InputFiles(InputFiles),
+VisitInputFiles(VisitInputFiles) {}
 
   bool needsImportVisitation() const override { return true; }
+  bool needsInputFileVisitation() override { return VisitInputFiles; }
+  bool needsSystemInputFileVisitation() override { return VisitInputFiles; }
 
   void visitImport(StringRef ModuleName, StringRef Filename) override {
-PrebuiltModuleFiles[std::string(ModuleName)] = std::string(Filename);
+PrebuiltModuleFiles.insert({ModuleName, Filename.str()});
+  }
+
+  bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden,
+  bool isExplicitModule) override {
+InputFiles.insert(Filename);
+return true;
   }
 
 private:
-  PrebuiltModuleFilesT &PrebuiltModuleFiles;
+  llvm::StringMap &PrebuiltModuleFiles;
+  llvm::StringSet<> &InputFiles;
+  bool VisitInputFiles;
 };
 
+using PrebuiltModuleFilesT = decltype(HeaderSearchOptions::PrebuiltModuleFiles);
+
+/// Visit the given prebuilt module and collect all of the modules it
+/// transitively imports and contributing input files.
+static void visitPrebuiltModule(StringRef PrebuiltModuleFilename,
+CompilerInstance &CI,
+PrebuiltModuleFilesT &ModuleFiles,
+llvm::StringSet<> &InputFiles,
+bool VisitInputFiles) {
+  // Maps the names of modules that weren't yet visited to their PCM path.
+  llvm::StringMap ModuleFilesWorklist;
+  // Contains PCM paths of all visited modules.
+  llvm::StringSet<> VisitedModuleFiles;
+
+  Prebuil

[PATCH] D106064: [clang][deps] Normalize paths in minimizing file system

2021-07-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp:161-162
+const StringRef RawFilename) {
+  llvm::SmallString<256> Filename;
+  llvm::sys::path::native(RawFilename, Filename);
+

dexonsmith wrote:
> I'm a bit nervous about the impact of modifying the input filename on Windows 
> before passing it into other APIs. This could change behaviour of lower 
> layers of the VFS (since they'll see a different filename than when 
> DependencyScanningWOrkerFileSystem is NOT on top of them).
> 
> Can we restrict this just to what's passed to IgnoredFiles? (Maybe add 
> `shouldIgnore()` API, which returns `false` if the set is empty, and then 
> locally converts to native and checks for membership...)
> 
> It also seems wasteful to be calling `sys::path::native` and the memcpy all 
> the time, when usually it has no effect. Have you checked whether this 
> affects performance of scanning something big?
Yeah, I can see that path changing between VFS layers can be problematic. I'm 
pretty sure we can get away with only converting `Filename` to its native form 
when interacting with `IgnoredFiles`.

I haven't checked the performance impact. If it ends up being measurable, I 
could implement something like `sys::path::is_native` and avoid the copy most 
of the time on unix-like OSes. WDYT?



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp:171-172
 
   bool KeepOriginalSource = IgnoredFiles.count(Filename) ||
 !shouldMinimize(Filename);
   DependencyScanningFilesystemSharedCache::SharedFileSystemEntry

dexonsmith wrote:
> Looking at this, makes me wonder if this is just fixing a specific instance 
> of a more general problem.
> 
> Maybe `IgnoredFiles` should be a set of `FileEntry`s instead of 
> `StringRef`s... but that'd create a different performance bottleneck when the 
> set is big, since creating the FileEntrys would be expensive. We'd want the 
> FileEntry lookup to be globally cached / etc. -- and FileManager isn't quite 
> safe to use globally.
> 
> Do you think IgnoredFiles as-is will work well enough for where it'll be used 
> for PCH? Or do we need to catch headers referenced in two different ways 
> somehow?
I think we could use `llvm::sys::fs::UniqueID` instead of the filename to refer 
to files. Since the VFS layer resolves symlinks when stat-ing a file, that 
should be a canonical file identifier. I can tackle that in a follow up patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106064/new/

https://reviews.llvm.org/D106064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106064: [clang][deps] Normalize paths in minimizing file system

2021-07-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

With the call to `llvm::sys::path::native` scoped only to `IgnoredFiles`, would 
this patch LGTY?




Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp:161-162
+const StringRef RawFilename) {
+  llvm::SmallString<256> Filename;
+  llvm::sys::path::native(RawFilename, Filename);
+

dexonsmith wrote:
> jansvoboda11 wrote:
> > dexonsmith wrote:
> > > I'm a bit nervous about the impact of modifying the input filename on 
> > > Windows before passing it into other APIs. This could change behaviour of 
> > > lower layers of the VFS (since they'll see a different filename than when 
> > > DependencyScanningWOrkerFileSystem is NOT on top of them).
> > > 
> > > Can we restrict this just to what's passed to IgnoredFiles? (Maybe add 
> > > `shouldIgnore()` API, which returns `false` if the set is empty, and then 
> > > locally converts to native and checks for membership...)
> > > 
> > > It also seems wasteful to be calling `sys::path::native` and the memcpy 
> > > all the time, when usually it has no effect. Have you checked whether 
> > > this affects performance of scanning something big?
> > Yeah, I can see that path changing between VFS layers can be problematic. 
> > I'm pretty sure we can get away with only converting `Filename` to its 
> > native form when interacting with `IgnoredFiles`.
> > 
> > I haven't checked the performance impact. If it ends up being measurable, I 
> > could implement something like `sys::path::is_native` and avoid the copy 
> > most of the time on unix-like OSes. WDYT?
> Probably it'll end up not being measurable, but if it is, something like 
> `is_native` might help... that said, if this will eventually be replaced with 
> logic relyin on fs::UniqueID it might not be worth optimizing.
Agreed.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp:171-172
 
   bool KeepOriginalSource = IgnoredFiles.count(Filename) ||
 !shouldMinimize(Filename);
   DependencyScanningFilesystemSharedCache::SharedFileSystemEntry

dexonsmith wrote:
> jansvoboda11 wrote:
> > dexonsmith wrote:
> > > Looking at this, makes me wonder if this is just fixing a specific 
> > > instance of a more general problem.
> > > 
> > > Maybe `IgnoredFiles` should be a set of `FileEntry`s instead of 
> > > `StringRef`s... but that'd create a different performance bottleneck when 
> > > the set is big, since creating the FileEntrys would be expensive. We'd 
> > > want the FileEntry lookup to be globally cached / etc. -- and FileManager 
> > > isn't quite safe to use globally.
> > > 
> > > Do you think IgnoredFiles as-is will work well enough for where it'll be 
> > > used for PCH? Or do we need to catch headers referenced in two different 
> > > ways somehow?
> > I think we could use `llvm::sys::fs::UniqueID` instead of the filename to 
> > refer to files. Since the VFS layer resolves symlinks when stat-ing a file, 
> > that should be a canonical file identifier. I can tackle that in a follow 
> > up patch.
> Yup, a unique ID should work for a file identifier.
> 
> I'm concerned about the cost of looking up the unique ID — avoiding stat 
> traffic was measured to be an important performance benefit in the dependency 
> scanner model.
> 
> To avoid a perf regression, I think you could use caches like:
> - ids: filename -> unique-id
> - originals: unique-id -> original file content
> - minimized: unique-id -> minimized file content
> 
> Where "ids" and "originals" are read/cached in lock-step when accessing a 
> filename, additionally computing "minimized" if not in the ignore-list. 
> (Adding a file to the ignore-list would put content in "ids" and "originals".)
> 
> The goal is to amortize the `stat` cost across the lifetime of the service 
> while ensuring a consistent view of the file content.
> 
> WDYT?
> 
> ... regardless I think all of this is out of scope for the current patch, 
> which is still useful for unblocking adding tests to the subsequent patches 
> in the stack.
Yes, this is the cache structure I had in mind.

I agree that this should be tackled in a follow-up patch. I'm going to create a 
patch with xfailing test case that demonstrates how one file with two different 
names (e.g. symlink) can cause issues with the current approach.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106064/new/

https://reviews.llvm.org/D106064

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106100: [clang-scan-deps] ignore top-level module dependencies that aren't actually imported

2021-07-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106100/new/

https://reviews.llvm.org/D106100

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106064: [clang][deps] Normalize ignored filenames in minimizing file system

2021-07-20 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG63fd109d3aa6: [clang][deps] Normalize ignored filenames in 
minimizing file system (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D106064?vs=358947&id=360060#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106064/new/

https://reviews.llvm.org/D106064

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -128,11 +128,11 @@
   // Add any filenames that were explicity passed in the build settings and
   // that might be opened, as we want to ensure we don't run source
   // minimization on them.
-  DepFS->IgnoredFiles.clear();
+  DepFS->clearIgnoredFiles();
   for (const auto &Entry : CI.getHeaderSearchOpts().UserEntries)
-DepFS->IgnoredFiles.insert(Entry.Path);
+DepFS->ignoreFile(Entry.Path);
   for (const auto &Entry : CI.getHeaderSearchOpts().VFSOverlayFiles)
-DepFS->IgnoredFiles.insert(Entry);
+DepFS->ignoreFile(Entry);
 
   // Support for virtual file system overlays on top of the caching
   // filesystem.
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -149,6 +149,19 @@
   return shouldMinimize(Filename); // Only cache stat failures on source files.
 }
 
+void DependencyScanningWorkerFilesystem::ignoreFile(StringRef RawFilename) {
+  llvm::SmallString<256> Filename;
+  llvm::sys::path::native(RawFilename, Filename);
+  IgnoredFiles.insert(Filename);
+}
+
+bool DependencyScanningWorkerFilesystem::shouldIgnoreFile(
+StringRef RawFilename) {
+  llvm::SmallString<256> Filename;
+  llvm::sys::path::native(RawFilename, Filename);
+  return IgnoredFiles.contains(Filename);
+}
+
 llvm::ErrorOr
 DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
 const StringRef Filename) {
@@ -159,7 +172,7 @@
   // FIXME: Handle PCM/PCH files.
   // FIXME: Handle module map files.
 
-  bool KeepOriginalSource = IgnoredFiles.count(Filename) ||
+  bool KeepOriginalSource = shouldIgnoreFile(Filename) ||
 !shouldMinimize(Filename);
   DependencyScanningFilesystemSharedCache::SharedFileSystemEntry
   &SharedCacheEntry = SharedCache.get(Filename);
Index: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
===
--- 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -153,10 +153,12 @@
   llvm::ErrorOr>
   openFileForRead(const Twine &Path) override;
 
-  /// The set of files that should not be minimized.
-  llvm::StringSet<> IgnoredFiles;
+  void clearIgnoredFiles() { IgnoredFiles.clear(); }
+  void ignoreFile(StringRef Filename);
 
 private:
+  bool shouldIgnoreFile(StringRef Filename);
+
   void setCachedEntry(StringRef Filename, const CachedFileSystemEntry *Entry) {
 bool IsInserted = Cache.try_emplace(Filename, Entry).second;
 (void)IsInserted;
@@ -179,6 +181,8 @@
   /// excluded conditional directive skip mappings that are used by the
   /// currently active preprocessor.
   ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings;
+  /// The set of files that should not be minimized.
+  llvm::StringSet<> IgnoredFiles;
 };
 
 } // end namespace dependencies


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -128,11 +128,11 @@
   // Add any filenames that were explicity passed in the build settings and
   // that might be opened, as we want to ensure we don't run source
   // minimization on them.
-  DepFS->IgnoredFiles.clear();
+  DepFS->clearIgnoredFiles();
   for (const auto &Entry : CI.getHeaderSearchOpts().UserEntries)
-DepFS->IgnoredFiles.insert(Entry.Path);
+DepFS->ignoreFile(Entry.Path);
   for (const auto &Entry : CI.getHeaderSearchOpts().VFSOverlayFiles)
-DepFS->IgnoredFiles.insert(Entry);

[PATCH] D106146: [clang][deps] Separate filesystem caches for minimized and original files

2021-07-20 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbc1a2979fc70: [clang][deps] Separate filesystem caches for 
minimized and original files (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D106146?vs=359294&id=360065#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106146/new/

https://reviews.llvm.org/D106146

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/DependencyScannerTest.cpp

Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
@@ -203,5 +204,35 @@
   EXPECT_EQ(convert_to_slash(Deps[5]), "/root/symlink.h");
 }
 
+namespace dependencies {
+TEST(DependencyScanningFilesystem, IgnoredFilesHaveSeparateCache) {
+  auto VFS = llvm::makeIntrusiveRefCnt();
+  VFS->addFile("/mod.h", 0, llvm::MemoryBuffer::getMemBuffer("// hi there!\n"));
+
+  DependencyScanningFilesystemSharedCache SharedCache;
+  auto Mappings = std::make_unique();
+  DependencyScanningWorkerFilesystem DepFS(SharedCache, VFS, Mappings.get());
+
+  auto StatusMinimized0 = DepFS.status("/mod.h");
+  DepFS.ignoreFile("/mod.h");
+  auto StatusFull1 = DepFS.status("/mod.h");
+  DepFS.clearIgnoredFiles();
+
+  auto StatusMinimized2 = DepFS.status("/mod.h");
+  DepFS.ignoreFile("/mod.h");
+  auto StatusFull3 = DepFS.status("/mod.h");
+
+  EXPECT_TRUE(StatusMinimized0);
+  EXPECT_EQ(StatusMinimized0->getSize(), 0u);
+  EXPECT_TRUE(StatusFull1);
+  EXPECT_EQ(StatusFull1->getSize(), 13u);
+
+  EXPECT_TRUE(StatusMinimized2);
+  EXPECT_EQ(StatusMinimized2->getSize(), 0u);
+  EXPECT_TRUE(StatusFull3);
+  EXPECT_EQ(StatusFull3->getSize(), 13u);
+}
+
+} // end namespace dependencies
 } // end namespace tooling
 } // end namespace clang
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -68,6 +68,7 @@
   clangAST
   clangASTMatchers
   clangBasic
+  clangDependencyScanning
   clangFormat
   clangFrontend
   clangLex
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -99,8 +99,7 @@
   return Result;
 }
 
-DependencyScanningFilesystemSharedCache::
-DependencyScanningFilesystemSharedCache() {
+DependencyScanningFilesystemSharedCache::SingleCache::SingleCache() {
   // This heuristic was chosen using a empirical testing on a
   // reasonably high core machine (iMacPro 18 cores / 36 threads). The cache
   // sharding gives a performance edge by reducing the lock contention.
@@ -111,18 +110,20 @@
   CacheShards = std::make_unique(NumShards);
 }
 
-/// Returns a cache entry for the corresponding key.
-///
-/// A new cache entry is created if the key is not in the cache. This is a
-/// thread safe call.
 DependencyScanningFilesystemSharedCache::SharedFileSystemEntry &
-DependencyScanningFilesystemSharedCache::get(StringRef Key) {
+DependencyScanningFilesystemSharedCache::SingleCache::get(StringRef Key) {
   CacheShard &Shard = CacheShards[llvm::hash_value(Key) % NumShards];
   std::unique_lock LockGuard(Shard.CacheLock);
   auto It = Shard.Cache.try_emplace(Key);
   return It.first->getValue();
 }
 
+DependencyScanningFilesystemSharedCache::SharedFileSystemEntry &
+DependencyScanningFilesystemSharedCache::get(StringRef Key, bool Minimized) {
+  SingleCache &Cache = Minimized ? CacheMinimized : CacheOriginal;
+  return Cache.get(Key);
+}
+
 /// Whitelist file extensions that should be minimized, treating no extension as
 /// a source file that should be minimized.
 ///
@@ -165,17 +166,17 @@
 llvm::ErrorOr
 DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
 const StringRef Filename) {
-  if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename)) {
+  bool ShouldMinimize =
+  !IgnoredFiles.count(Filename) && shouldMinimize(Filename);
+
+  if (const auto *Entry = Cache.getCachedEntry(Filename, ShouldMinimize))
 return Entry;
-  }
 
   // FIXME: Handle PCM/PCH files.
   // FIXME: Handle modu

[PATCH] D104536: [clang][deps] Avoid minimizing PCH input files

2021-07-20 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe564fd93ab85: [clang][deps] Avoid minimizing PCH input files 
(authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104536/new/

https://reviews.llvm.org/D104536

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -6,7 +6,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
 // RUN: echo -%t > %t/result_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_pch.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
 // RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
 //
 // Check we didn't build the PCH during dependency scanning.
@@ -127,9 +127,8 @@
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu.json
-// FIXME: Make this work with '-mode preprocess-minimized-sources'.
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu.json
 // RUN: cat %t/result_tu.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU
 //
 // CHECK-TU:  -[[PREFIX:.*]]
@@ -193,7 +192,7 @@
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_tu_with_common.json > %t/cdb.json
 // RUN: echo -%t > %t/result_tu_with_common.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build -mode preprocess >> %t/result_tu_with_common.json
+// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_tu_with_common.json
 // RUN: cat %t/result_tu_with_common.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-TU-WITH-COMMON
 //
 // CHECK-TU-WITH-COMMON:  -[[PREFIX:.*]]
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -46,25 +46,73 @@
   DependencyConsumer &C;
 };
 
-/// A listener that collects the names and paths to imported modules.
-class ImportCollectingListener : public ASTReaderListener {
-  using PrebuiltModuleFilesT =
-  decltype(HeaderSearchOptions::PrebuiltModuleFiles);
-
+/// A listener that collects the imported modules and optionally the input
+/// files.
+class PrebuiltModuleListener : public ASTReaderListener {
 public:
-  ImportCollectingListener(PrebuiltModuleFilesT &PrebuiltModuleFiles)
-  : PrebuiltModuleFiles(PrebuiltModuleFiles) {}
+  PrebuiltModuleListener(llvm::StringMap &PrebuiltModuleFiles,
+ llvm::StringSet<> &InputFiles, bool VisitInputFiles)
+  : PrebuiltModuleFiles(PrebuiltModuleFiles), InputFiles(InputFiles),
+VisitInputFiles(VisitInputFiles) {}
 
   bool needsImportVisitation() const override { return true; }
+  bool needsInputFileVisitation() override { return VisitInputFiles; }
+  bool needsSystemInputFileVisitation() override { return VisitInputFiles; }
 
   void visitImport(StringRef ModuleName, StringRef Filename) override {
-PrebuiltModuleFiles[std::string(ModuleName)] = std::string(Filename);
+PrebuiltModuleFiles.insert({ModuleName, Filename.str()});
+  }
+
+  bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden,
+  bool isExplicitModule) override {
+InputFiles.insert(Filename);
+return true;
   }
 
 private:
-  PrebuiltModuleFilesT &PrebuiltModuleFiles;
+  llvm::StringMap &PrebuiltModuleFiles;
+  llvm::StringSet<> &InputFiles;
+  bool VisitInputFiles;
 };
 
+using PrebuiltModuleFilesT = decltype(HeaderSearchOptions::PrebuiltModuleFiles);
+
+/// Visit the given prebuilt module and collect all of the modules it
+/// transitively imports and contributing input files.
+static void visitPrebuiltModule(StringRef PrebuiltModuleFilename,
+CompilerInstance &CI,
+PrebuiltModuleFilesT &ModuleFiles,
+llvm::StringSet<> &InputFiles,
+bool VisitInputFiles) {
+  // Maps the names of modules that weren't yet visited to their PCM path.
+  llvm:

[PATCH] D104536: [clang][deps] Avoid minimizing PCH input files

2021-07-20 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D104536#288 , @thakis wrote:

> Looks like this breaks tests on Windows: 
> http://45.33.8.238/win/42264/step_7.txt
>
> Please take a look, and revert for now if it takes a while to fix.

Thanks, that was a bad rebase. Should be fixed in 
c94a345a5c693b6c12a41e8f50e3fe96d1311991 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104536/new/

https://reviews.llvm.org/D104536

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106787: [clang][driver] NFC: Move InputInfo.h from lib to include

2021-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added subscribers: frasercrmck, kerbowa, luismarques, apazos, 
sameer.abuasal, usaxena95, s.egerton, Jim, kadircet, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, nhaehnle, jvesely, dylanmckay.
jansvoboda11 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Moving `InputInfo.h` from `lib/Driver/` into `include/Driver` to be able to 
expose it in an API consumed from outside of `clangDriver`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106787

Files:
  clang/include/clang/Driver/InputInfo.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/InputInfo.h
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/Tool.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  clang/lib/Driver/ToolChains/Ananas.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CloudABI.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/lib/Driver/ToolChains/MSP430.h
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/Minix.cpp
  clang/lib/Driver/ToolChains/NaCl.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp

Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -8,8 +8,8 @@
 
 #include "RISCVToolchain.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
Index: clang/lib/Driver/ToolChains/NaCl.cpp
===
--- clang/lib/Driver/ToolChains/NaCl.cpp
+++ clang/lib/Driver/ToolChains/NaCl.cpp
@@ -7,11 +7,11 @@
 //===--===//
 
 #include "NaCl.h"
-#include "InputInfo.h"
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -8,9 +8,9 @@
 
 #include "Minix.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/VirtualFileSystem.h"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -7,12 +7,12 @@
 //===--===//
 
 #include "MinGW.h"
-#include "InputInfo.h"
 #include "CommonArgs.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
Index: clang/lib/Driver/ToolChains/MSP430.h
===
--- clang/lib/Driver/ToolChains/MSP430.h
+++ clang/lib/Driver/ToolChains/MSP430.h
@@ -10,9 +10,9 @@
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSP430_H
 
 #include "Gnu.h"
-#include "InputInfo.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/StringRef.h"
Index: clang/lib/Driver/ToolChains/MSP430.cpp
===
--- clang/lib/Driver/ToolChains/MSP430.cpp
+++ clang/lib/Driver/ToolChains/MSP430.cpp
@@ -9,8 +9,8 @@
 #include "MSP430.h"
 #include "CommonArgs.h"
 #include "Gnu.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Multilib.h"
 #include "clang/Driver/Options.h"
 #inc

[PATCH] D102488: [clang][deps] Prune unused header search paths

2021-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 planned changes to this revision.
jansvoboda11 added a comment.

After speaking with @dexonsmith, the laziness is probably not necessary when 
dealing with a short bit vector. I'll also explore using `llvm::BitVector` 
instead of `std::vector`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102488/new/

https://reviews.llvm.org/D102488

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106788: [clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

2021-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch exposes `InputInfo` in `Job` instead of plain filenames. This is 
useful in a follow-up patch that uses this to recognize `-cc1` commands 
interesting for Clang tooling.

Depends on D106787 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106788

Files:
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Job.cpp
  clang/unittests/Driver/ToolChainTest.cpp


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a.out", ExeFile);
Index: clang/lib/Driver/Job.cpp
===
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -43,7 +43,7 @@
   Executable(Executable), Arguments(Arguments) {
   for (const auto &II : Inputs)
 if (II.isFilename())
-  InputFilenames.push_back(II.getFilename());
+  InputInfoList.push_back(II);
   for (const auto &II : Outputs)
 if (II.isFilename())
   OutputFilenames.push_back(II.getFilename());
@@ -237,9 +237,10 @@
 }
   }
 
-  auto Found = llvm::find_if(InputFilenames,
- [&Arg](StringRef IF) { return IF == Arg; });
-  if (Found != InputFilenames.end() &&
+  auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
+return II.getFilename() == Arg;
+  });
+  if (Found != InputInfoList.end() &&
   (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
 // Replace the input file name with the crashinfo's file name.
 OS << ' ';
@@ -302,8 +303,8 @@
 
 void Command::PrintFileNames() const {
   if (PrintInputFilenames) {
-for (const char *Arg : InputFilenames)
-  llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
+for (const auto &Arg : InputInfoList)
+  llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
 llvm::outs().flush();
   }
 }
Index: clang/include/clang/Driver/Job.h
===
--- clang/include/clang/Driver/Job.h
+++ clang/include/clang/Driver/Job.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_DRIVER_JOB_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Driver/InputInfo.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
@@ -119,8 +120,8 @@
   /// argument, which will be the executable).
   llvm::opt::ArgStringList Arguments;
 
-  /// The list of program arguments which are inputs.
-  llvm::opt::ArgStringList InputFilenames;
+  /// The list of program inputs.
+  std::vector InputInfoList;
 
   /// The list of program arguments which are outputs. May be empty.
   std::vector OutputFilenames;
@@ -207,9 +208,7 @@
 
   const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
 
-  const llvm::opt::ArgStringList &getInputFilenames() const {
-return InputFilenames;
-  }
+  const std::vector &getInputInfos() const { return InputInfoList; }
 
   const std::vector &getOutputFilenames() const {
 return OutputFilenames;


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a

[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 361626.
jansvoboda11 added a comment.

Also ignore cc1 jobs that have inputs that are not source files.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105695/new/

https://reviews.llvm.org/D105695

Files:
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/Tooling.cpp
  clang/test/Tooling/clang-check-offload.cpp
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -18,6 +20,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
@@ -258,6 +261,98 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+namespace {
+/// Overlays the real filesystem with the given VFS and returns the result.
+llvm::IntrusiveRefCntPtr
+overlayRealFS(llvm::IntrusiveRefCntPtr VFS) {
+  auto RFS = llvm::vfs::getRealFileSystem();
+  auto OverlayFS = llvm::makeIntrusiveRefCnt(RFS);
+  OverlayFS->pushOverlay(VFS);
+  return OverlayFS;
+}
+
+struct CommandLineExtractorTest : public ::testing::Test {
+  llvm::IntrusiveRefCntPtr InMemoryFS;
+  llvm::IntrusiveRefCntPtr Diags;
+  driver::Driver Driver;
+
+public:
+  CommandLineExtractorTest()
+  : InMemoryFS(new llvm::vfs::InMemoryFileSystem),
+Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)),
+Driver("clang", llvm::sys::getDefaultTargetTriple(), *Diags,
+   "clang LLVM compiler", overlayRealFS(InMemoryFS)) {}
+
+  void addFile(StringRef Name, StringRef Content) {
+InMemoryFS->addFile(Name, 0, llvm::MemoryBuffer::getMemBuffer(Content));
+  }
+
+  const llvm::opt::ArgStringList *
+  extractCC1Arguments(llvm::ArrayRef Argv) {
+const std::unique_ptr Compilation(
+Driver.BuildCompilation(llvm::makeArrayRef(Argv)));
+
+return getCC1Arguments(Diags.get(), Compilation.get());
+  }
+};
+} // namespace
+
+TEST_F(CommandLineExtractorTest, AcceptOffloading) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target",  "arm64-apple-macosx11.0.0",
+"-x","hip",  "test.c",
+"-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingCompile) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang",  "-target",   "arm64-apple-macosx11.0.0",
+"-c", "-x","hip",
+"test.c", "-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingSyntaxOnly) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target",   "arm64-apple-macosx11.0.0",
+  "-fsyntax-only", "-x","hip",
+  "test.c","-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptExternalAssembler) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target", "arm64-apple-macosx11.0.0", "-fno-integrated-as",
+  "-c","test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptEmbedBitcode) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","-fembed-bitcode", "test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-arch", "x86_64",  "-arch",
+"arm64", "-c",  "test.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleInputFiles) {
+  addFile("one.c", "void one() {}\n");
+  addFile("two.c", "void two() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","one.c",   "two.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
 struct VerifyEndCallback : public SourceFileCallbacks {
   VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {}
   bool handleBeginSource(CompilerInstance &CI) override {
Inde

[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 requested review of this revision.
jansvoboda11 added a comment.

Requesting re-review, since there are two changes:

- `-cc1` commands that don't read a source file are ignored (e.g. jobs 
generated by `-fembed-bitcode`),
- test now have `-target arm64-apple-macosx11.0.0` to ensure things work 
platforms that don't have external assembler.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105695/new/

https://reviews.llvm.org/D105695

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 361630.
jansvoboda11 added a comment.

Formatting


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105695/new/

https://reviews.llvm.org/D105695

Files:
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/Tooling.cpp
  clang/test/Tooling/clang-check-offload.cpp
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -18,6 +20,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
@@ -258,6 +261,98 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+namespace {
+/// Overlays the real filesystem with the given VFS and returns the result.
+llvm::IntrusiveRefCntPtr
+overlayRealFS(llvm::IntrusiveRefCntPtr VFS) {
+  auto RFS = llvm::vfs::getRealFileSystem();
+  auto OverlayFS = llvm::makeIntrusiveRefCnt(RFS);
+  OverlayFS->pushOverlay(VFS);
+  return OverlayFS;
+}
+
+struct CommandLineExtractorTest : public ::testing::Test {
+  llvm::IntrusiveRefCntPtr InMemoryFS;
+  llvm::IntrusiveRefCntPtr Diags;
+  driver::Driver Driver;
+
+public:
+  CommandLineExtractorTest()
+  : InMemoryFS(new llvm::vfs::InMemoryFileSystem),
+Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)),
+Driver("clang", llvm::sys::getDefaultTargetTriple(), *Diags,
+   "clang LLVM compiler", overlayRealFS(InMemoryFS)) {}
+
+  void addFile(StringRef Name, StringRef Content) {
+InMemoryFS->addFile(Name, 0, llvm::MemoryBuffer::getMemBuffer(Content));
+  }
+
+  const llvm::opt::ArgStringList *
+  extractCC1Arguments(llvm::ArrayRef Argv) {
+const std::unique_ptr Compilation(
+Driver.BuildCompilation(llvm::makeArrayRef(Argv)));
+
+return getCC1Arguments(Diags.get(), Compilation.get());
+  }
+};
+} // namespace
+
+TEST_F(CommandLineExtractorTest, AcceptOffloading) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target",  "arm64-apple-macosx11.0.0",
+"-x","hip",  "test.c",
+"-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingCompile) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang",  "-target",   "arm64-apple-macosx11.0.0",
+"-c", "-x","hip",
+"test.c", "-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingSyntaxOnly) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target",   "arm64-apple-macosx11.0.0",
+  "-fsyntax-only", "-x","hip",
+  "test.c","-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptExternalAssembler) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target", "arm64-apple-macosx11.0.0", "-fno-integrated-as",
+  "-c","test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptEmbedBitcode) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","-fembed-bitcode", "test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-arch", "x86_64",  "-arch",
+"arm64", "-c",  "test.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleInputFiles) {
+  addFile("one.c", "void one() {}\n");
+  addFile("two.c", "void two() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","one.c",   "two.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
 struct VerifyEndCallback : public SourceFileCallbacks {
   VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {}
   bool handleBeginSource(CompilerInstance &CI) override {
Index: clang/test/Tooling/clang-check-offload.cpp

[PATCH] D105881: [flang][driver] Switch to `BoolFOption` for boolean options

2021-07-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Sorry, I'm not sure I follow.

In D105881#2890134 , @awarzynski 
wrote:

> Apologies, it has taken me a bit longer to get back to this. @jansvoboda11 , 
> now I'm realising the key disadvantage of using `OptInFFlag/OptOutFFlag` - 
> it's impossible to express the `opt-in`/`opt-out` semantics in TableGen.

What do you mean exactly? I think the semantics are expressed pretty well from 
Clang's point of view:

- `OptInFFlag` -> users can opt-in into the behavior by specifying the positive 
flag in `clang -cc1` (e.g. `-fmodules`),
- `OptOutFFlag` -> users can opt-out of the behavior by specifying the negative 
flag in `clang -cc1` (e.g. `-fno-rtti`).

> In fact, only the contents of `clang -cc1 --help` are being tweaked by using 
> `OptInFFlag/OptOutFFlag`.

That's incorrect, `OptInFFlag` and `OptOutFFlag` both set `HelpText` for the 
positive and negative driver flags.

> Basically:
>
> - for `OptInFFlang`, only `-ffoo` is printed with `-clang -cc1 --help` (the 
> help text for `-ffno-foo` becomes irrelevant)
> - for `OptOutFFlang`, only `-fno-foo` is printed with `-clang -cc1 --help` 
> (the help text for `-ffoo` is irrelevant)
>
> IIUC, this is achieved through `flags` (`CC1Option` vs `[]`).

Correct.

> In Flang, we rely on the fact that "no help text? don't include it in 
> `flang-new -fc1 --help`" instead. This behavior is implemented in 
> `clangDriver` and applies to all drivers that use it (so this is nothing 
> specific to Flang).

I see. Is this intentional?

> This way, we can always mark Flang options with the relevant flags (e.g. 
> `FC1Option`). In other words, we can claim them and make it clear that other 
> drivers can ignore them.

I don't understand this. Can you elaborate? Are you relying on the 
absence/presence of a help text to mark flags with `FC1Option`? When does this 
happen? (In `Options.td`? The TableGen backend? The consumer of `Options.inc`?)

> In general, I think that Options.td would become a bit cleaner and easier to 
> reason about if all options specified all their flags. That wouldn't be easy 
> to achieve though!

I think that the way we define flags for the Clang driver and `-cc1` in one go 
is already bit confusing. But it's convenient, so we roll with it. On top of 
that, we have the marshalling infrastructure, that explicitly only applies to 
the `-cc1` side of things. If we introduce `EmptyKPM` to the mix and say 
"Marshalling only applies to `-cc1`, but sometimes not at all", things stop 
making sense in my opinion. People will copy-paste it and be confused things 
don't work.

> I'm just about send an updated patch. It takes into account the points that I 
> raised above ^^^. It also fixes the failing tests reported by @PeteSteinfeld. 
> Does this new approach work for Clang (I quickly tested `clang -cc1 --help` 
> and see no difference)?

I'd need to double-check if we particularly care about showing/hiding flags 
without help text.

> It would be nicer to have the `opt-in`/`opt-out` semantics for Flang in 
> TableGen through something similar to `BoolFOption`. No need for this just 
> now - one step at a time :)

I suggest to find another means of achieving the semantics you want. You always 
just copy the `BoolFOption` implementation and remove the marshalling stuff, if 
that's really the semantics you want.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105881/new/

https://reviews.llvm.org/D105881

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D105695#2905028 , @dexonsmith 
wrote:

> Seeing the `-fembed-bitcode` case made me think of `-save-temps`. I think 
> this will work since `-x cpp-output` should return false for `isSrcFile()`... 
> but probably worth adding a test. LGTM assuming the test passes.

Thanks for pointing that out. Things work as expected, committing with the 
added test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105695/new/

https://reviews.llvm.org/D105695

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106787: [clang][driver] NFC: Move InputInfo.h from lib to include

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG60426f33b1d4: [clang][driver] NFC: Move InputInfo.h from lib 
to include (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106787/new/

https://reviews.llvm.org/D106787

Files:
  clang/include/clang/Driver/InputInfo.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/InputInfo.h
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/Tool.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  clang/lib/Driver/ToolChains/Ananas.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CloudABI.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/MSP430.cpp
  clang/lib/Driver/ToolChains/MSP430.h
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/Minix.cpp
  clang/lib/Driver/ToolChains/NaCl.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp

Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -8,8 +8,8 @@
 
 #include "RISCVToolchain.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
Index: clang/lib/Driver/ToolChains/NaCl.cpp
===
--- clang/lib/Driver/ToolChains/NaCl.cpp
+++ clang/lib/Driver/ToolChains/NaCl.cpp
@@ -7,11 +7,11 @@
 //===--===//
 
 #include "NaCl.h"
-#include "InputInfo.h"
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -8,9 +8,9 @@
 
 #include "Minix.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/VirtualFileSystem.h"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -7,12 +7,12 @@
 //===--===//
 
 #include "MinGW.h"
-#include "InputInfo.h"
 #include "CommonArgs.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
Index: clang/lib/Driver/ToolChains/MSP430.h
===
--- clang/lib/Driver/ToolChains/MSP430.h
+++ clang/lib/Driver/ToolChains/MSP430.h
@@ -10,9 +10,9 @@
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSP430_H
 
 #include "Gnu.h"
-#include "InputInfo.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/StringRef.h"
Index: clang/lib/Driver/ToolChains/MSP430.cpp
===
--- clang/lib/Driver/ToolChains/MSP430.cpp
+++ clang/lib/Driver/ToolChains/MSP430.cpp
@@ -9,8 +9,8 @@
 #include "MSP430.h"
 #include "CommonArgs.h"
 #include "Gnu.h"
-#include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Multilib.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -8,10 +8,10 @@
 
 #include "Hexagon.h"
 #include "CommonArgs.h"
-#include "InputInfo.h"
 #include "clang/Driver/Co

[PATCH] D106788: [clang][driver] NFC: Expose InputInfo in Job instead of plain filenames

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb76c7c6faf06: [clang][driver] NFC: Expose InputInfo in Job 
instead of plain filenames (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106788/new/

https://reviews.llvm.org/D106788

Files:
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Job.cpp
  clang/unittests/Driver/ToolChainTest.cpp


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a.out", ExeFile);
Index: clang/lib/Driver/Job.cpp
===
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -43,7 +43,7 @@
   Executable(Executable), Arguments(Arguments) {
   for (const auto &II : Inputs)
 if (II.isFilename())
-  InputFilenames.push_back(II.getFilename());
+  InputInfoList.push_back(II);
   for (const auto &II : Outputs)
 if (II.isFilename())
   OutputFilenames.push_back(II.getFilename());
@@ -237,9 +237,10 @@
 }
   }
 
-  auto Found = llvm::find_if(InputFilenames,
- [&Arg](StringRef IF) { return IF == Arg; });
-  if (Found != InputFilenames.end() &&
+  auto Found = llvm::find_if(InputInfoList, [&Arg](const InputInfo &II) {
+return II.getFilename() == Arg;
+  });
+  if (Found != InputInfoList.end() &&
   (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
 // Replace the input file name with the crashinfo's file name.
 OS << ' ';
@@ -302,8 +303,8 @@
 
 void Command::PrintFileNames() const {
   if (PrintInputFilenames) {
-for (const char *Arg : InputFilenames)
-  llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
+for (const auto &Arg : InputInfoList)
+  llvm::outs() << llvm::sys::path::filename(Arg.getFilename()) << "\n";
 llvm::outs().flush();
   }
 }
Index: clang/include/clang/Driver/Job.h
===
--- clang/include/clang/Driver/Job.h
+++ clang/include/clang/Driver/Job.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_DRIVER_JOB_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/Driver/InputInfo.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
@@ -119,8 +120,8 @@
   /// argument, which will be the executable).
   llvm::opt::ArgStringList Arguments;
 
-  /// The list of program arguments which are inputs.
-  llvm::opt::ArgStringList InputFilenames;
+  /// The list of program inputs.
+  std::vector InputInfoList;
 
   /// The list of program arguments which are outputs. May be empty.
   std::vector OutputFilenames;
@@ -207,9 +208,7 @@
 
   const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
 
-  const llvm::opt::ArgStringList &getInputFilenames() const {
-return InputFilenames;
-  }
+  const std::vector &getInputInfos() const { return InputInfoList; }
 
   const std::vector &getOutputFilenames() const {
 return OutputFilenames;


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -321,13 +321,13 @@
   const JobList &Jobs = CC->getJobs();
 
   const auto &CmdCompile = Jobs.getJobs().front();
-  const auto &InFile = CmdCompile->getInputFilenames().front();
+  const auto &InFile = CmdCompile->getInputInfos().front().getFilename();
   EXPECT_STREQ(InFile, "foo.cpp");
   auto ObjFile = CmdCompile->getOutputFilenames().front();
   EXPECT_TRUE(StringRef(ObjFile).endswith(".o"));
 
   const auto &CmdLink = Jobs.getJobs().back();
-  const auto LinkInFile = CmdLink->getInputFilenames().front();
+  const auto LinkInFile = CmdLink->getInputInfos().front().getFilename();
   EXPECT_EQ(ObjFile, LinkInFile);
   auto ExeFile = CmdLink->getOutputFilenames().front();
   EXPECT_EQ("a.out", ExeFile);
Index: clang/lib/Driver/Job.cpp
===
--- clang

[PATCH] D105695: [clang][tooling] Accept Clang invocations with multiple jobs

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG11ee699b3c81: [clang][tooling] Accept Clang invocations with 
multiple jobs (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D105695?vs=361630&id=361942#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105695/new/

https://reviews.llvm.org/D105695

Files:
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/Tooling.cpp
  clang/test/Tooling/clang-check-offload.cpp
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -9,6 +9,8 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
@@ -18,6 +20,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
@@ -258,6 +261,105 @@
   EXPECT_TRUE(Consumer.SawSourceManager);
 }
 
+namespace {
+/// Overlays the real filesystem with the given VFS and returns the result.
+llvm::IntrusiveRefCntPtr
+overlayRealFS(llvm::IntrusiveRefCntPtr VFS) {
+  auto RFS = llvm::vfs::getRealFileSystem();
+  auto OverlayFS = llvm::makeIntrusiveRefCnt(RFS);
+  OverlayFS->pushOverlay(VFS);
+  return OverlayFS;
+}
+
+struct CommandLineExtractorTest : public ::testing::Test {
+  llvm::IntrusiveRefCntPtr InMemoryFS;
+  llvm::IntrusiveRefCntPtr Diags;
+  driver::Driver Driver;
+
+public:
+  CommandLineExtractorTest()
+  : InMemoryFS(new llvm::vfs::InMemoryFileSystem),
+Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)),
+Driver("clang", llvm::sys::getDefaultTargetTriple(), *Diags,
+   "clang LLVM compiler", overlayRealFS(InMemoryFS)) {}
+
+  void addFile(StringRef Name, StringRef Content) {
+InMemoryFS->addFile(Name, 0, llvm::MemoryBuffer::getMemBuffer(Content));
+  }
+
+  const llvm::opt::ArgStringList *
+  extractCC1Arguments(llvm::ArrayRef Argv) {
+const std::unique_ptr Compilation(
+Driver.BuildCompilation(llvm::makeArrayRef(Argv)));
+
+return getCC1Arguments(Diags.get(), Compilation.get());
+  }
+};
+} // namespace
+
+TEST_F(CommandLineExtractorTest, AcceptOffloading) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target",  "arm64-apple-macosx11.0.0",
+"-x","hip",  "test.c",
+"-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingCompile) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang",  "-target",   "arm64-apple-macosx11.0.0",
+"-c", "-x","hip",
+"test.c", "-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptOffloadingSyntaxOnly) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target",   "arm64-apple-macosx11.0.0",
+  "-fsyntax-only", "-x","hip",
+  "test.c","-nogpulib", "-nogpuinc"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptExternalAssembler) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {
+  "clang", "-target", "arm64-apple-macosx11.0.0", "-fno-integrated-as",
+  "-c","test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptEmbedBitcode) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","-fembed-bitcode", "test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, AcceptSaveTemps) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-c","-save-temps", "test.c"};
+  EXPECT_NE(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectMultipleArchitectures) {
+  addFile("test.c", "int main() {}\n");
+  const char *Args[] = {"clang", "-target", "arm64-apple-macosx11.0.0",
+"-arch", "x86_64",  "-arch",
+"arm64", "-c",  "test.c"};
+  EXPECT_EQ(extractCC1Arguments(Args), nullptr);
+}
+
+TEST_F(CommandLineExtractorTest, RejectM

[PATCH] D106862: [clang][modules] Avoid creating partial FullSourceLoc for explicit modules imports

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman, christof.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Some parts of the codebase use `FullSourceLoc` -- a wrapper around regular 
`SourceLocation` and `SourceManager`.

>From the existing code, it looks like the wrapper can be in two states:

- valid `SourceLocation`, present `SourceManager`,
- invalid `SourceLocation`, missing `SourceManager`.

When importing an explicitly-built module, the `SourceLocation` of the `import` 
directive is invalid, since the module is "imported" by the command-line 
argument. This causes an assertion failure in `hasManager` when serializing 
diagnostics containing this `SourceLocation` to file.

This patch makes sure the `FullSourceLoc` for invalid import `SourceLocations` 
omits the `SourceManager`, upholding the class invariant.

I also tried more defensive approach: making sure the wrapped `SourceLocation` 
is always valid in the `FullSourceLoc` constructor. However, some clients 
apparently rely on the fact they can construct invalid source locations and 
later modify their `ID` to make them valid.

Another approach (that works) is checking `Loc.isValid() && Loc.hasManager()` 
in `SDiagsRenderer::emitNote` before working with the `FullSourceLoc`. I think 
this is what all users of the wrapper should do, but I think that's something 
people more closely familiar with this code to consider. (@christof)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106862

Files:
  clang/lib/Basic/SourceLocation.cpp
  clang/test/Modules/Inputs/explicit-build-diags/a.h
  clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
  clang/test/Modules/explicit-build-diags.cpp


Index: clang/test/Modules/explicit-build-diags.cpp
===
--- /dev/null
+++ clang/test/Modules/explicit-build-diags.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -fmodules -x c++ 
%S/Inputs/explicit-build-diags/module.modulemap -fmodule-name=a -emit-module -o 
%t/a.pcm
+// RUN: %clang_cc1 -fmodules -Wdeprecated-declarations 
-fdiagnostics-show-note-include-stack -serialize-diagnostic-file %t/tu.dia \
+// RUN:   -I %S/Inputs/explicit-build-diags -fmodule-file=%t/a.pcm 
-fsyntax-only %s
+
+#include "a.h"
+
+void foo() { a(); }
Index: clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
@@ -0,0 +1 @@
+module a { header "a.h" }
Index: clang/test/Modules/Inputs/explicit-build-diags/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/a.h
@@ -0,0 +1 @@
+void a() __attribute__((deprecated));
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -199,6 +199,10 @@
 
   std::pair ImportLoc =
   SrcMgr->getModuleImportLoc(*this);
+
+  if (!ImportLoc.first.isValid())
+return std::make_pair(FullSourceLoc(), ImportLoc.second);
+
   return std::make_pair(FullSourceLoc(ImportLoc.first, *SrcMgr),
 ImportLoc.second);
 }


Index: clang/test/Modules/explicit-build-diags.cpp
===
--- /dev/null
+++ clang/test/Modules/explicit-build-diags.cpp
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %clang_cc1 -fmodules -x c++ %S/Inputs/explicit-build-diags/module.modulemap -fmodule-name=a -emit-module -o %t/a.pcm
+// RUN: %clang_cc1 -fmodules -Wdeprecated-declarations -fdiagnostics-show-note-include-stack -serialize-diagnostic-file %t/tu.dia \
+// RUN:   -I %S/Inputs/explicit-build-diags -fmodule-file=%t/a.pcm -fsyntax-only %s
+
+#include "a.h"
+
+void foo() { a(); }
Index: clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/module.modulemap
@@ -0,0 +1 @@
+module a { header "a.h" }
Index: clang/test/Modules/Inputs/explicit-build-diags/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/explicit-build-diags/a.h
@@ -0,0 +1 @@
+void a() __attribute__((deprecated));
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -199,6 +199,10 @@
 
   std::pair ImportLoc =
   SrcMgr->getModuleImportLoc(*this);
+
+  if (!ImportLoc.first.isValid())
+return std::make_pair(FullSourceLoc(), ImportLoc.second);
+
   return std::make_pair(FullSourceLoc(ImportLoc.first,

[PATCH] D106864: [clang][cli] Expose -fno-cxx-modules in cc1

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
Herald added a subscriber: dang.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For some use-cases, it might be useful to be able to turn off modules for C++ 
in `-cc1`. (The feature is implied by `-std=C++20`.)

This patch exposes the `-fno-cxx-modules` option in `-cc1`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106864

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/cxx20-disable.cpp


Index: clang/test/Modules/cxx20-disable.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-disable.cpp
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s
+
+export module Foo;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3150,8 +3150,6 @@
   Opts.HexFloats = Std.hasHexFloats();
   Opts.ImplicitInt = Std.hasImplicitInt();
 
-  Opts.CPlusPlusModules = Opts.CPlusPlus20;
-
   // Set OpenCL Version.
   Opts.OpenCL = Std.isOpenCL();
   if (LangStd == LangStandard::lang_opencl10)
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -467,7 +467,6 @@
 defvar hip = LangOpts<"HIP">;
 defvar gnu_mode = LangOpts<"GNUMode">;
 defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
-defvar cpp_modules = LangOpts<"CPlusPlusModules">;
 
 defvar std = !strconcat("LangStandard::getLangStandardForKind(", 
lang_std.KeyPath, ")");
 
@@ -1329,8 +1328,11 @@
 defm async_exceptions: BoolFOption<"async-exceptions",
   LangOpts<"EHAsynch">, DefaultFalse,
   PosFlag, 
NegFlag>;
-def fcxx_modules : Flag <["-"], "fcxx-modules">, Group,
-  Flags<[NoXarchOption]>;
+defm cxx_modules : BoolFOption<"cxx-modules",
+  LangOpts<"CPlusPlusModules">, Default,
+  NegFlag, PosFlag,
+  BothFlags<[NoXarchOption], " modules for C++">>,
+  ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;
 def fdebug_pass_structure : Flag<["-"], "fdebug-pass-structure">, 
Group;
 def fdepfile_entry : Joined<["-"], "fdepfile-entry=">,
@@ -2146,7 +2148,7 @@
   Flags<[CC1Option]>, HelpText<"Enable support for the C++ Modules TS">,
   MarshallingInfoFlag>;
 defm modules : BoolFOption<"modules",
-  LangOpts<"Modules">, Default,
+  LangOpts<"Modules">, Default,
   PosFlag,
   NegFlag, BothFlags<[NoXarchOption, CoreOption]>>;
 def fmodule_maps : Flag <["-"], "fmodule-maps">, Flags<[CoreOption]>, 
Alias;
@@ -2205,8 +2207,6 @@
   Flags<[CoreOption, NoXarchOption]>;
 def fno_common : Flag<["-"], "fno-common">, Group, Flags<[CC1Option]>,
 HelpText<"Compile common globals like normal definitions">;
-def fno_cxx_modules : Flag <["-"], "fno-cxx-modules">, Group,
-  Flags<[NoXarchOption]>;
 defm digraphs : BoolFOption<"digraphs",
   LangOpts<"Digraphs">, Default,
   PosFlag', 
'<%', '%>', '%:', '%:%:' (default)">,
@@ -5283,7 +5283,7 @@
   HelpText<"Enforce name visibility rules across submodules of the same "
"top-level module.">,
   MarshallingInfoFlag>,
-  ImpliedByAnyOf<[fmodules_ts.KeyPath, cpp_modules.KeyPath]>;
+  ImpliedByAnyOf<[fmodules_ts.KeyPath, fcxx_modules.KeyPath]>;
 def fmodules_codegen :
   Flag<["-"], "fmodules-codegen">,
   HelpText<"Generate code for uses of this module that assumes an explicit "


Index: clang/test/Modules/cxx20-disable.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-disable.cpp
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s
+
+export module Foo;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3150,8 +3150,6 @@
   Opts.HexFloats = Std.hasHexFloats();
   Opts.ImplicitInt = Std.hasImplicitInt();
 
-  Opts.CPlusPlusModules = Opts.CPlusPlus20;
-
   // Set OpenCL Version.
   Opts.OpenCL = Std.isOpenCL();
   if (LangStd == LangStandard::lang_opencl10)
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -467,7 +467,6 @@
 defvar hip = LangOpts<"HIP">;
 defvar gnu_mode = LangOpts<"GNUMode">;
 defvar asm_preprocessor = LangOpts<"AsmPreprocessor">;
-defvar cpp_modules = LangOpts<"CPlusPlusModules">;
 
 defvar std = !strconcat("LangStandard::getLangStandardForKind(", lang_

[PATCH] D106864: [clang][cli] Expose -fno-cxx-modules in cc1

2021-07-27 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/Modules/cxx20-disable.cpp:2
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -x objective-c++ -std=c++20 -fno-cxx-modules -I %t %s
+

I'm not sure how to best test this. Checking the error messages is not that 
useful, since they don't make the intent here any clearer:

```
/llvm-project/clang/test/Modules/cxx20-disable.cpp:4:8: error: expected 
template
export module Foo;
   ^
/llvm-project/clang/test/Modules/cxx20-disable.cpp:4:8: error: unknown 
type name 'module'
2 errors generated.
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106864/new/

https://reviews.llvm.org/D106864

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121295: [clang][deps] Modules don't contribute to search path usage

2022-03-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

To reduce the number of modules we build in explicit builds (which use strict 
context hash), we prune unused header search paths. This essentially merges 
parts of the dependency graph.

Determining whether a search path was used to discover a module (through 
implicit module maps) proved to be somewhat complicated. Initial support landed 
in D102923 , while D113676 
 attempts to fix some bugs.

However, now that we don't use implicit module maps in explicit builds (since 
D120465 ), we don't need to consider such 
search paths as used anymore. Modules are no longer discovered through the 
header search mechanism, so we can drop such search paths (provided they are 
not needed for other reasons).

This patch removes whatever support for detecting such usage we had, since it's 
buggy and not required anymore.

Depends on D120465 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121295

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Preprocessor/search-path-usage.m


Index: clang/test/Preprocessor/search-path-usage.m
===
--- clang/test/Preprocessor/search-path-usage.m
+++ clang/test/Preprocessor/search-path-usage.m
@@ -129,7 +129,7 @@
 #endif
 #endif
 
-// Check that search paths with module maps are reported.
+// Check that search paths with module maps are NOT reported.
 //
 // RUN: mkdir %t/modulemap_abs
 // RUN: sed "s|DIR|%/S/Inputs/search-path-usage|g"\
@@ -142,5 +142,5 @@
 // RUN:   -DMODMAP_ABS -verify
 #ifdef MODMAP_ABS
 @import b; // \
-// expected-remark-re {{search path used: '{{.*}}/modulemap_abs'}}
+// expected-no-diagnostics
 #endif
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -299,20 +299,19 @@
SourceLocation ImportLoc,
bool AllowExtraModuleMapSearch) {
   Module *Module = nullptr;
-  SearchDirIterator It = nullptr;
 
   // Look through the various header search paths to load any available module
   // maps, searching for a module map that describes this module.
-  for (It = search_dir_begin(); It != search_dir_end(); ++It) {
-if (It->isFramework()) {
+  for (DirectoryLookup Dir : search_dir_range()) {
+if (Dir.isFramework()) {
   // Search for or infer a module map for a framework. Here we use
   // SearchName rather than ModuleName, to permit finding private modules
   // named FooPrivate in buggy frameworks named Foo.
   SmallString<128> FrameworkDirName;
-  FrameworkDirName += It->getFrameworkDir()->getName();
+  FrameworkDirName += Dir.getFrameworkDir()->getName();
   llvm::sys::path::append(FrameworkDirName, SearchName + ".framework");
   if (auto FrameworkDir = FileMgr.getDirectory(FrameworkDirName)) {
-bool IsSystem = It->getDirCharacteristic() != SrcMgr::C_User;
+bool IsSystem = Dir.getDirCharacteristic() != SrcMgr::C_User;
 Module = loadFrameworkModule(ModuleName, *FrameworkDir, IsSystem);
 if (Module)
   break;
@@ -322,12 +321,12 @@
 // FIXME: Figure out how header maps and module maps will work together.
 
 // Only deal with normal search directories.
-if (!It->isNormalDir())
+if (!Dir.isNormalDir())
   continue;
 
-bool IsSystem = It->isSystemHeaderDirectory();
+bool IsSystem = Dir.isSystemHeaderDirectory();
 // Search for a module map file in this directory.
-if (loadModuleMapFile(It->getDir(), IsSystem,
+if (loadModuleMapFile(Dir.getDir(), IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded) {
   // We just loaded a module map file; check whether the module is
   // available now.
@@ -339,7 +338,7 @@
 // Search for a module map in a subdirectory with the same name as the
 // module.
 SmallString<128> NestedModuleMapDirName;
-NestedModuleMapDirName = It->getDir()->getName();
+NestedModuleMapDirName = Dir.getDir()->getName();
 llvm::sys::path::append(NestedModuleMapDirName, ModuleName);
 if (loadModuleMapFile(NestedModuleMapDirName, IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded){
@@ -351,13 +350,13 @@
 
 // If we've already performed the exhaustive search for module maps in this
 // search directory, don't do it again.
-if (It->haveSearchedAllModuleMaps())
+if (Dir.haveSearchedAllModuleMaps())
   continue;
 
 // Load all module maps in the immediate subdirectori

[PATCH] D121303: [clang][deps] Don't prune search paths used by dependencies

2022-03-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When pruning header search paths (to reduce the number of modules we need to 
build explicitly), we can't prune the search paths used in (transitive) 
dependencies of a module. Otherwise, we could end up with either of the 
following dependency graphs:

  X: -> Y:
  X: -> Y:

depending on the search paths of the translation unit we discovered `X` and `Y` 
from.

This patch fixes that.

Depends on D121295 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121303

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/header-search-pruning-transitive.c

Index: clang/test/ClangScanDeps/header-search-pruning-transitive.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-pruning-transitive.c
@@ -0,0 +1,169 @@
+// This test checks that pruning of header search paths produces consistent dependency graphs.
+//
+// When pruning header search paths for a module, we can't remove any paths its dependencies use.
+// Otherwise, we could get either of the following dependency graphs depending on the search path
+// configuration of the particular TU that first discovered the module:
+//   X: -> Y:
+//   X: -> Y:
+// We can't have the same version of module X depend on multiple different versions of Y based on
+// the TU configuration.
+//
+// Keeping all header search paths (transitive) dependencies use will ensure we get consistent
+// dependency graphs:
+//   X: -> Y:
+//   X: -> Y:
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- a/a.h
+//--- b/b.h
+//--- begin/begin.h
+//--- end/end.h
+//--- Y.h
+#include "begin.h"
+#if __has_include("a.h")
+#include "a.h"
+#endif
+#include "end.h"
+
+//--- X.h
+#include "Y.h"
+
+//--- module.modulemap
+module Y { header "Y.h" }
+module X { header "X.h" }
+
+//--- test.c
+#include "X.h"
+
+//--- cdb_with_a.json.template
+[{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang -c test.c -o DIR/test.o -fmodules -fimplicit-modules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -Ibegin -Ia -Ib -Iend"
+}]
+
+//--- cdb_without_a.json.template
+[{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang -c test.c -o DIR/test.o -fmodules -fimplicit-modules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -Ibegin -Ib -Iend"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb_with_a.json.template> %t/cdb_with_a.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb_without_a.json.template > %t/cdb_without_a.json
+
+// RUN: echo -%t > %t/results.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_with_a.json-format experimental-full -optimize-args >> %t/results.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_without_a.json -format experimental-full -optimize-args >> %t/results.json
+// RUN: cat %t/results.json | sed 's/\\/\//g' | FileCheck %s
+
+// CHECK:  -[[PREFIX:.*]]
+// CHECK-NEXT: {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "[[HASH_Y_WITH_A:.*]]",
+// CHECK-NEXT:   "module-name": "Y"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "[[HASH_X:.*]]",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/./X.h",
+// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "X"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "[[HASH_Y_WITH_A]]",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/./Y.h",
+// CHECK-NEXT: "[[PREFIX]]/./a/a.h",
+// CHECK-NEXT: "[[PREFIX]]/./begin/begin.h",
+// CHECK-NEXT: "[[PREFIX]]/./end/end.h",
+// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "Y"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "[[HASH_X]]",
+// CHECK-NEXT:   "module-name": "X"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "command-line": [
+// CHECK:   

[PATCH] D120465: [clang][deps] Disable implicit module maps

2022-03-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:269-273
+  // However, some module maps loaded implicitly during the dependency scan can
+  // describe anti-dependencies. That happens when the current module is marked
+  // as '[no_undeclared_includes]', doesn't 'use' module from such module map,
+  // but tries to import it anyway. We need to tell the explicit build about
+  // such module map for it to have the same semantics as the implicit build.

dexonsmith wrote:
> jansvoboda11 wrote:
> > dexonsmith wrote:
> > > Is there another long-term solution to this that could be pointed at with 
> > > a FIXME? E.g., could the module map be encoded redundantly here? If so, 
> > > what else would need to change to make that okay?
> > I'm not sure I understand why this would warrant "long-term solution" or a 
> > FIXME. This code handles an existing feature that just happens to be a 
> > corner case from the dependency scanning point of view. (You can read up on 
> > the feature [[ https://clang.llvm.org/docs/Modules.html | here ]].)
> > 
> > What do you mean by encoding the module map redundantly?
> Yes, I know the feature.
> 
> ... but I was probably wrong about how it affects the logic here.
> 
> I also now have two guesses at the scenario being handled here (previously I 
> assumed (1)):
> 
> 1. A textual include from a module that is not marked as used. I wasn't sure 
> what you meant by "tries to import", but I guess I thought it was just "loads 
> the module map and finds the textual header listed there". IIUC, there's no 
> actual attempt to import a module when the only thing referenced from it is a 
> textual header, but I could see how parsing the module map could affect the 
> state anyway.
> 
> 2. A modular include from a module that is not marked as used. Something like 
> a `__has_include`, or a `#include` that fails but there's another search path 
> with the same header. In this case, there'd be an actual import attempt, 
> which would fail. And that could also affect state.
> 
> Can you clarify which scenario you need to handle? Or is it a 3rd?
> 
> > I'm not sure I understand why this would warrant "long-term solution" or a 
> > FIXME.
> 
> This smells like a workaround to me. IIUC, sending in module maps that aren't 
> actually "needed" except to reproduce side effects of failed queries.
> 
> My intuition is that the right long-term fix would involve isolate the failed 
> queries from the compiler state in the scanning phase so that they don't have 
> side effects. Then there would be no side effects to reproduce in the 
> explicit build.
> 
> > What do you mean by encoding the module map redundantly?
> 
> I think I was confused about scanning vs building, thinking that a module 
> using a textual include (1) could be copied into each module PCM that 
> directly imports it. (I know that this wouldn't scale right now for various 
> reasons, but I wondered if there was some way to get there... but regardless, 
> seems like it's totally unrelated)
The scenario being handled is the following:

3. Modular `#include` of B from module A, where A is marked 
`[no_undeclared_includes]` and doesn't `use B`. Typically, that `#include` 
would be guarded by `__has_include`.

With implicit module maps disabled, the presence of module map B allows us to 
evaluate the `__has_include` the same way as with them enabled. This is the 
only reason we need module map B. There are no side effects from failed 
queries. The query failure itself is the behavior we need to reproduce.

I'm not even thinking about "another search path with the same header" in this 
patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120465/new/

https://reviews.llvm.org/D120465

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121465: WIP: [clang][modules] Do not report declarations without linkage as ambiguous

2022-03-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, vsapsai.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When finalizing the result of name lookup that encountered ambiguity, we check 
equivalence for declarations with internal linkage. If the declarations are 
equivalent, we just produce a warning instead of ambiguous result.

In `Sema::isEquivalentInternalLinkageDeclaration` that implements the check, we 
have a special case for constants of anonymous enums. However, it only kicks in 
for C++ anonymous enums (since they have `NoLinkage`, meaning they are not 
externally visible).

In (Objective)C, constants of anonymous enums are `VisibleNoLinkage`, meaning 
they _are_ externally visible, so the special case doesn't apply for them.

This patch renames the function to `isEquivalentNonExternalLinkageDeclaration` 
(its documentation already says it handles declarations with "internal/no 
linkage") and makes it so that even `VisibleNoLinkage` declarations are not 
marked as ambiguous. This is achieved by using `hasExternalFormalLinkage` 
instead of `isExternallyVisible` in one of the equivalence checks. Later on, we 
don't even emit the warning for such declarations, since they are considered 
the same entity.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121465

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/Modules/ambiguous-anonymous-enum-lookup.m.cpp

Index: clang/test/Modules/ambiguous-anonymous-enum-lookup.m.cpp
===
--- /dev/null
+++ clang/test/Modules/ambiguous-anonymous-enum-lookup.m.cpp
@@ -0,0 +1,40 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -I %t/include %t/test.cpp -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -I %t/include %t/test.m   -verify
+
+//--- include/textual.h
+#ifndef TEXTUAL_H
+#define TEXTUAL_H
+enum { kAnonymousEnumValue = 0 };
+#endif
+
+//--- include/empty.h
+//--- include/initially_hidden.h
+#include "textual.h"
+
+//--- include/module.modulemap
+module Piecewise {
+  module Empty   { header "empty.h"}
+  module InitiallyHidden { header "initially_hidden.h" }
+}
+
+//--- test.cpp
+#include "empty.h"
+#include "textual.h"
+#include "initially_hidden.h"
+
+int testReferencingAnonymousEnumConstant() {
+  return kAnonymousEnumValue; // expected-warning {{ambiguous use of internal linkage declaration 'kAnonymousEnumValue' defined in multiple modules}}
+  // expected-note@textual.h:3 {{declared here}}
+  // expected-note@textual.h:3 {{declared here in module 'Piecewise.InitiallyHidden'}}
+}
+
+//--- test.m
+#include "empty.h"
+#include "textual.h"
+#include "initially_hidden.h"
+
+int testReferencingAnonymousEnumConstant() {
+  return kAnonymousEnumValue; // expected-no-diagnostics
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9955,19 +9955,19 @@
 /// declare the same entity, but we also don't want lookups with both
 /// declarations visible to be ambiguous in some cases (this happens when using
 /// a modularized libstdc++).
-bool Sema::isEquivalentInternalLinkageDeclaration(const NamedDecl *A,
-  const NamedDecl *B) {
+bool Sema::isEquivalentNonExternalLinkageDeclaration(const NamedDecl *A,
+ const NamedDecl *B) {
   auto *VA = dyn_cast_or_null(A);
   auto *VB = dyn_cast_or_null(B);
   if (!VA || !VB)
 return false;
 
-  // The declarations must be declaring the same name as an internal linkage
+  // The declarations must be declaring the same name as an internal/no linkage
   // entity in different modules.
   if (!VA->getDeclContext()->getRedeclContext()->Equals(
   VB->getDeclContext()->getRedeclContext()) ||
   getOwningModule(VA) == getOwningModule(VB) ||
-  VA->isExternallyVisible() || VB->isExternallyVisible())
+  VA->hasExternalFormalLinkage() || VB->hasExternalFormalLinkage())
 return false;
 
   // Check that the declarations appear to be equivalent.
@@ -10093,8 +10093,8 @@
 PendingBest.push_back(Cand);
 Cand->Best = true;
 
-if (S.isEquivalentInternalLinkageDeclaration(Cand->Function,
- Curr->Function))
+if (S.isEquivalentNonExternalLinkageDeclaration(Cand->Function,
+Curr->Function))
   EquivalentCand

[PATCH] D120465: [clang][deps] Disable implicit module maps

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6ef3635461c: [clang][deps] Disable implicit module maps 
(authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D120465?vs=413384&id=414814#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120465/new/

https://reviews.llvm.org/D120465

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -26,6 +26,7 @@
 // CHECK-PCH-NEXT: "-cc1"
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModCommon1"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -43,6 +44,7 @@
 // CHECK-PCH-NEXT: "-cc1"
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModCommon2"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -66,6 +68,7 @@
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModPCH"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -139,6 +142,7 @@
 // CHECK-TU-NEXT:   "command-line": [
 // CHECK-TU-NEXT: "-cc1",
 // CHECK-TU:  "-emit-module",
+// CHECK-TU-NOT:  "-fimplicit-module-maps",
 // CHECK-TU:  "-fmodule-name=ModTU",
 // CHECK-TU:  "-fno-implicit-modules",
 // CHECK-TU:],
@@ -202,6 +206,7 @@
 // CHECK-TU-WITH-COMMON-NEXT: "-cc1",
 // CHECK-TU-WITH-COMMON:  "-emit-module",
 // CHECK-TU-WITH-COMMON:  "-fmodule-file=[[PREFIX]]/build/{{.*}}/ModCommon1-{{.*}}.pcm",
+// CHECK-TU-WITH-COMMON-NOT:  "-fimplicit-module-maps",
 // CHECK-TU-WITH-COMMON:  "-fmodule-name=ModTUWithCommon",
 // CHECK-TU-WITH-COMMON:  "-fno-implicit-modules",
 // CHECK-TU-WITH-COMMON:],
Index: clang/test/ClangScanDeps/modules-no-undeclared-includes.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-no-undeclared-includes.c
@@ -0,0 +1,72 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- undeclared/module.modulemap
+module Undeclared { header "undeclared.h" }
+
+//--- undeclared/undeclared.h
+
+//--- module.modulemap
+module User [no_undeclared_includes] { header "user.h" }
+
+//--- user.h
+#if __has_include("undeclared.h")
+#error Unreachable. Undeclared comes from a module that's not 'use'd, meaning the compiler should pretend it doesn't exist.
+#endif
+
+//--- test.c
+#include "user.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -IDIR/undeclared -c DIR/test.c -o DIR/test.o",
+  "file": "DIR/test.c"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
+// RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%t
+
+// CHECK:{
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/undeclared/module.modulemap"
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/undeclared/module.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/user.h"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "User"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}"
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEX

[PATCH] D118915: [clang][deps] Generate '-fmodule-file=' only for direct dependencies

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f6af607464e: [clang][deps] Generate 
'-fmodule-file=' only for direct dependencies (authored by 
jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118915/new/

https://reviews.llvm.org/D118915

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-pch.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -298,10 +298,7 @@
 
 ID.CommandLine = GenerateModulesPathArgs
  ? FD.getCommandLine(
-   [&](ModuleID MID) { return lookupPCMPath(MID); },
-   [&](ModuleID MID) -> const ModuleDeps & {
- return lookupModuleDeps(MID);
-   })
+   [&](ModuleID MID) { return lookupPCMPath(MID); })
  : FD.getCommandLineWithoutModulePaths();
 
 Inputs.push_back(std::move(ID));
@@ -336,10 +333,7 @@
   {"command-line",
GenerateModulesPathArgs
? MD.getCanonicalCommandLine(
- [&](ModuleID MID) { return lookupPCMPath(MID); },
- [&](ModuleID MID) -> const ModuleDeps & {
-   return lookupModuleDeps(MID);
- })
+ [&](ModuleID MID) { return lookupPCMPath(MID); })
: MD.getCanonicalCommandLineWithoutModulePaths()},
   };
   OutModules.push_back(std::move(O));
@@ -369,12 +363,16 @@
   StringRef lookupPCMPath(ModuleID MID) {
 auto PCMPath = PCMPaths.insert({MID, ""});
 if (PCMPath.second)
-  PCMPath.first->second = constructPCMPath(lookupModuleDeps(MID));
+  PCMPath.first->second = constructPCMPath(MID);
 return PCMPath.first->second;
   }
 
   /// Construct a path for the explicitly built PCM.
-  std::string constructPCMPath(const ModuleDeps &MD) const {
+  std::string constructPCMPath(ModuleID MID) const {
+auto MDIt = Modules.find(IndexedModuleID{MID, 0});
+assert(MDIt != Modules.end());
+const ModuleDeps &MD = MDIt->second;
+
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
 
 SmallString<256> ExplicitPCMPath(
@@ -385,12 +383,6 @@
 return std::string(ExplicitPCMPath);
   }
 
-  const ModuleDeps &lookupModuleDeps(ModuleID MID) {
-auto I = Modules.find(IndexedModuleID{MID, 0});
-assert(I != Modules.end());
-return I->second;
-  };
-
   struct IndexedModuleID {
 ModuleID ID;
 mutable size_t InputIndex;
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -97,7 +97,6 @@
 // CHECK-PCH:  "-fno-implicit-modules",
 // CHECK-PCH-NEXT: "-fno-implicit-module-maps",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_1]]/ModCommon1-{{.*}}.pcm",
-// CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_PCH]]/ModPCH-{{.*}}.pcm"
 // CHECK-PCH-NEXT:   ],
 // CHECK-PCH-NEXT:   "file-deps": [
Index: clang/test/ClangScanDeps/modules-full.cpp
===
--- clang/test/ClangScanDeps/modules-full.cpp
+++ clang/test/ClangScanDeps/modules-full.cpp
@@ -169,9 +169,7 @@
 // CHECK:  "-fno-implicit-modules"
 // CHECK-NEXT: "-fno-implicit-module-maps"
 // CHECK-NO-ABS-NOT:   "-fmodule-file={{.*}}"
-// CHECK-ABS-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[HASH_H2_DINCLUDE]]/header2-{{[A-Z0-9]+}}.pcm"
 // CHECK-ABS-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[HASH_H1_DINCLUDE]]/header1-{{[A-Z0-9]+}}.pcm"
-// CHECK-CUSTOM-NEXT:  "-fmodule-file=[[PREFIX]]/custom/[[HASH_H2_DINCLUDE]]/header2-{{[A-Z0-9]+}}.pcm"
 // CHECK-CUSTOM-NEXT:  "-fmodule-file=[[PREFIX]]/custom/[[HASH_H1_DINCLUDE]]/header1-{{[A-Z0-9]+}}.pcm"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "file-deps": [
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clan

[PATCH] D120474: [clang][deps] Remove '-fmodules-cache-path=' arguments

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcf4a31fc0f97: [clang][deps] Remove 
'-fmodules-cache-path=' arguments (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120474/new/

https://reviews.llvm.org/D120474

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/tools/clang-scan-deps/ClangScanDeps.cpp


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -374,11 +374,11 @@
 const ModuleDeps &MD = MDIt->second;
 
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
+StringRef ModuleCachePath = llvm::sys::path::parent_path(
+llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
 
-SmallString<256> ExplicitPCMPath(
-!ModuleFilesDir.empty()
-? ModuleFilesDir
-: MD.BuildInvocation.getHeaderSearchOpts().ModuleCachePath);
+SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
+ : 
ModuleCachePath);
 llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
 return std::string(ExplicitPCMPath);
   }
Index: clang/test/ClangScanDeps/modules-inferred-explicit-build.m
===
--- clang/test/ClangScanDeps/modules-inferred-explicit-build.m
+++ clang/test/ClangScanDeps/modules-inferred-explicit-build.m
@@ -12,7 +12,7 @@
 // RUN: %python %S/../../utils/module-deps-to-rsp.py %t.db --tu-index=0 > 
%t.tu.rsp
 // RUN: %clang @%t.inferred.cc1.rsp -pedantic -Werror
 // RUN: %clang @%t.system.cc1.rsp -pedantic -Werror
-// RUN: %clang @%t.tu.rsp -pedantic -Werror -Wno-unused-command-line-argument
+// RUN: %clang @%t.tu.rsp -pedantic -Werror
 
 #include 
 #include 
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -51,6 +51,7 @@
 
   CI.getLangOpts()->ImplicitModules = false;
   CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
+  CI.getHeaderSearchOpts().ModuleCachePath.clear();
 
   // Report the prebuilt modules this module uses.
   for (const auto &PrebuiltModule : Deps.PrebuiltModuleDeps)
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -31,7 +31,13 @@
   getAdditionalArgsWithoutModulePaths();
   Args.insert(Args.end(), AdditionalArgs.begin(), AdditionalArgs.end());
 
-  // TODO: Filter out implicit modules leftovers (e.g. 
"-fmodules-cache-path=").
+  // This argument is unused in explicit compiles.
+  llvm::erase_if(Args, [](const std::string &Arg) {
+return Arg.find("-fmodules-cache-path=") == 0;
+  });
+
+  // TODO: Filter out the remaining implicit modules leftovers
+  // (e.g. "-fmodules-prune-interval=" or "-fmodules-prune-after=").
 
   return Args;
 }


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -374,11 +374,11 @@
 const ModuleDeps &MD = MDIt->second;
 
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
+StringRef ModuleCachePath = llvm::sys::path::parent_path(
+llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
 
-SmallString<256> ExplicitPCMPath(
-!ModuleFilesDir.empty()
-? ModuleFilesDir
-: MD.BuildInvocation.getHeaderSearchOpts().ModuleCachePath);
+SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
+ : ModuleCachePath);
 llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
 return std::string(ExplicitPCMPath);
   }
Index: clang/test/ClangScanDeps/modules-inferred-explicit-build.m
===
--- clang/test/ClangScanDeps/modules-inferred-explicit-build.m
+++ clang/test/ClangScanDeps/modules-inferred-explicit-build.m
@@ -12,7 +12,7 @@
 // RUN: %python %S/../../utils/module-deps-to-rsp.py %t.db --tu-index=0 > %t.tu.rsp
 // RUN: %clang @%t.inferred.cc1.rsp -pedantic -Werror
 // RUN: %clang @%t.system.cc1.rsp -

[PATCH] D121516: [clang][deps] Simplify PREFIX definitions in tests

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Instead of outputting the test directory into the JSON result file, parsing it 
with `FileCheck` and then potentially stripping it, simply use `FileCheck`'s 
`-D` option.

Note that we use `%/t` instead of `%t` in order to normalize to forward slashes 
on Windows, which matches what we print in the scanner.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121516

Files:
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/preserved-args.c
  clang/test/ClangScanDeps/removed-args.c

Index: clang/test/ClangScanDeps/removed-args.c
===
--- clang/test/ClangScanDeps/removed-args.c
+++ clang/test/ClangScanDeps/removed-args.c
@@ -8,12 +8,10 @@
 // RUN: cp %S/Inputs/removed-args/* %t
 
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/removed-args/cdb.json.template > %t/cdb.json
-// RUN: echo -%t > %t/result.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full >> %t/result.json
-// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
 //
-// CHECK:  -[[PREFIX:.*]]
-// CHECK-NEXT: {
+// CHECK:  {
 // CHECK-NEXT:   "modules": [
 // CHECK-NEXT: {
 // CHECK-NEXT:   "clang-module-deps": [],
Index: clang/test/ClangScanDeps/preserved-args.c
===
--- clang/test/ClangScanDeps/preserved-args.c
+++ clang/test/ClangScanDeps/preserved-args.c
@@ -2,12 +2,10 @@
 // RUN: cp -r %S/Inputs/preserved-args/* %t
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
 
-// RUN: echo -%t > %t/result.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full >> %t/result.json
-// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
 
-// CHECK:  -[[PREFIX:.*]]
-// CHECK-NEXT: {
+// CHECK:  {
 // CHECK-NEXT:   "modules": [
 // CHECK-NEXT: {
 // CHECK:"command-line": [
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -8,16 +8,14 @@
 // Scan dependencies of the PCH:
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
-// RUN: echo -%t > %t/result_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
-// RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
+// RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result_pch.json
+// RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-PCH
 //
 // Check we didn't build the PCH during dependency scanning.
 // RUN: not cat %/t/pch.h.gch
 //
-// CHECK-PCH:  -[[PREFIX:.*]]
-// CHECK-PCH-NEXT: {
+// CHECK-PCH:  {
 // CHECK-PCH-NEXT:   "modules": [
 // CHECK-PCH-NEXT: {
 // CHECK-PCH-NEXT:   "clang-module-deps": [],
@@ -109,14 +107,13 @@
 
 // Explicitly build the PCH:
 //
-// RUN: tail -n +2 %t/result_pch.json > %t/result_pch_stripped.json
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --module-name=ModCommon1 > %t/mod_common_1.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --module-name=ModCommon2 > %t/mod_common_2.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --module-name=ModPCH > %t/mod_pch.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --tu-index=0 > %t/pc

[PATCH] D121516: [clang][deps] Simplify PREFIX definitions in tests

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4b13f7a2f7f: [clang][deps] Simplify PREFIX definitions in 
tests (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121516/new/

https://reviews.llvm.org/D121516

Files:
  clang/test/ClangScanDeps/diagnostics.c
  clang/test/ClangScanDeps/modules-context-hash.c
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/preserved-args.c
  clang/test/ClangScanDeps/removed-args.c

Index: clang/test/ClangScanDeps/removed-args.c
===
--- clang/test/ClangScanDeps/removed-args.c
+++ clang/test/ClangScanDeps/removed-args.c
@@ -8,12 +8,10 @@
 // RUN: cp %S/Inputs/removed-args/* %t
 
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/removed-args/cdb.json.template > %t/cdb.json
-// RUN: echo -%t > %t/result.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full >> %t/result.json
-// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
 //
-// CHECK:  -[[PREFIX:.*]]
-// CHECK-NEXT: {
+// CHECK:  {
 // CHECK-NEXT:   "modules": [
 // CHECK-NEXT: {
 // CHECK-NEXT:   "clang-module-deps": [],
Index: clang/test/ClangScanDeps/preserved-args.c
===
--- clang/test/ClangScanDeps/preserved-args.c
+++ clang/test/ClangScanDeps/preserved-args.c
@@ -2,12 +2,10 @@
 // RUN: cp -r %S/Inputs/preserved-args/* %t
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
 
-// RUN: echo -%t > %t/result.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full >> %t/result.json
-// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
 
-// CHECK:  -[[PREFIX:.*]]
-// CHECK-NEXT: {
+// CHECK:  {
 // CHECK-NEXT:   "modules": [
 // CHECK-NEXT: {
 // CHECK:"command-line": [
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -8,16 +8,14 @@
 // Scan dependencies of the PCH:
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch/cdb_pch.json > %t/cdb.json
-// RUN: echo -%t > %t/result_pch.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
-// RUN:   -generate-modules-path-args -module-files-dir %t/build >> %t/result_pch.json
-// RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -check-prefix=CHECK-PCH
+// RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result_pch.json
+// RUN: cat %t/result_pch.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-PCH
 //
 // Check we didn't build the PCH during dependency scanning.
 // RUN: not cat %/t/pch.h.gch
 //
-// CHECK-PCH:  -[[PREFIX:.*]]
-// CHECK-PCH-NEXT: {
+// CHECK-PCH:  {
 // CHECK-PCH-NEXT:   "modules": [
 // CHECK-PCH-NEXT: {
 // CHECK-PCH-NEXT:   "clang-module-deps": [],
@@ -109,14 +107,13 @@
 
 // Explicitly build the PCH:
 //
-// RUN: tail -n +2 %t/result_pch.json > %t/result_pch_stripped.json
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --module-name=ModCommon1 > %t/mod_common_1.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --module-name=ModCommon2 > %t/mod_common_2.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --module-name=ModPCH > %t/mod_pch.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch_stripped.json \
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
 // RUN:   --tu-index=0 > %t/pch.rsp
 //
 // RUN: %clang @%t/mod_common_1.cc1.rsp
@@ -127,13 +124,11 @@
 // Scan dependencies of the TU:
 //
 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch

[PATCH] D121516: [clang][deps] Simplify PREFIX definitions in tests

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a reviewer: Bigcheese.
jansvoboda11 added a comment.

In case you want to do a post-commit review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121516/new/

https://reviews.llvm.org/D121516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121525: [clang][deps] Create lit substitution for deps-to-rsp

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: Bigcheese.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch gets rid of the ridiculous relative path we use to invoke the 
`module-deps-to-rsp.py` script and creates proper lit substituion, cleaning up 
the tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121525

Files:
  clang/test/ClangScanDeps/modulemap-via-vfs.m
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/modules-symlink.c
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -115,6 +115,11 @@
 ('%hmaptool', "'%s' %s" % (config.python_executable,
  os.path.join(config.clang_tools_dir, 'hmaptool'
 
+config.substitutions.append(
+('%deps-to-rsp',
+ '"%s" %s' % (config.python_executable, os.path.join(config.clang_src_dir, 'utils',
+ 'module-deps-to-rsp.py'
+
 config.substitutions.append(('%host_cc', config.host_cc))
 config.substitutions.append(('%host_cxx', config.host_cxx))
 
Index: clang/test/ClangScanDeps/modules-symlink.c
===
--- clang/test/ClangScanDeps/modules-symlink.c
+++ clang/test/ClangScanDeps/modules-symlink.c
@@ -43,10 +43,8 @@
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
 // RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result_pch.json
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=mod > %t/mod.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --tu-index=0 > %t/pch.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=mod > %t/mod.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --tu-index=0 > %t/pch.rsp
 //
 // RUN: %clang @%t/mod.cc1.rsp
 // RUN: %clang @%t/pch.rsp
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -107,14 +107,10 @@
 
 // Explicitly build the PCH:
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=ModCommon1 > %t/mod_common_1.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=ModCommon2 > %t/mod_common_2.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=ModPCH > %t/mod_pch.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --tu-index=0 > %t/pch.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=ModCommon1 > %t/mod_common_1.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=ModCommon2 > %t/mod_common_2.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=ModPCH > %t/mod_pch.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --tu-index=0 > %t/pch.rsp
 //
 // RUN: %clang @%t/mod_common_1.cc1.rsp
 // RUN: %clang @%t/mod_common_2.cc1.rsp
@@ -173,10 +169,8 @@
 
 // Explicitly build the TU:
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu.json \
-// RUN:   --module-name=ModTU > %t/mod_tu.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu.json \
-// RUN:   --tu-index=0 > %t/tu.rsp
+// RUN: %deps-to-rsp %t/result_tu.json --module-name=ModTU > %t/mod_tu.cc1.rsp
+// RUN: %deps-to-rsp %t/result_tu.json --tu-index=0 > %t/tu.rsp
 //
 // RUN: %clang @%t/mod_tu.cc1.rsp
 // RUN: %clang @%t/tu.rsp
@@ -235,10 +229,8 @@
 
 // Explicitly build the TU that has common modules with the PCH:
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu_with_common.json \
-// RUN:   --module-name=ModTUWithCommon > %t/mod_tu_with_common.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu_with_common.json \
-// RUN:   --tu-index=0 > %t/tu_with_common.rsp
+// RUN: %deps-to-rsp %t/result_tu_with_common.json --module-name=ModTUWithCommon > %t/mod_tu_with_common.cc1.rsp
+// RUN: %deps-to-rsp %t/result_tu_with_common.json --tu-index=0 > %t/tu_with_common.rsp
 //
 // RUN: %clang @%t/mod_tu_with_common.cc1.rsp
 // RUN: %clang @%t/tu_with_common.rsp
Index: clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
===
--- clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
+++ clang/test/ClangScanDeps/modules-pch-c

[PATCH] D121533: [clang][deps] Fix traversal of precompiled dependencies

2022-03-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The code for traversing precompiled dependencies is somewhat complicated and 
contains a dangling iterator bug.

This patch uses simpler, recursive implementation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121533

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -84,33 +84,18 @@
 PrebuiltModuleFilesT &ModuleFiles,
 llvm::StringSet<> &InputFiles,
 bool VisitInputFiles) {
-  // Maps the names of modules that weren't yet visited to their PCM path.
-  llvm::StringMap ModuleFilesWorklist;
-  // Contains PCM paths of all visited modules.
-  llvm::StringSet<> VisitedModuleFiles;
-
-  PrebuiltModuleListener Listener(ModuleFilesWorklist, InputFiles,
-  VisitInputFiles);
-
-  auto GatherModuleFileInfo = [&](StringRef ASTFile) {
-ASTReader::readASTFileControlBlock(
-ASTFile, CI.getFileManager(), CI.getPCHContainerReader(),
-/*FindModuleFileExtensions=*/false, Listener,
-/*ValidateDiagnosticOptions=*/false);
-  };
-
-  GatherModuleFileInfo(PrebuiltModuleFilename);
-  while (!ModuleFilesWorklist.empty()) {
-auto WorklistItemIt = ModuleFilesWorklist.begin();
-
-if (!VisitedModuleFiles.contains(WorklistItemIt->getValue())) {
-  VisitedModuleFiles.insert(WorklistItemIt->getValue());
-  GatherModuleFileInfo(WorklistItemIt->getValue());
-  ModuleFiles[WorklistItemIt->getKey().str()] = WorklistItemIt->getValue();
-}
-
-ModuleFilesWorklist.erase(WorklistItemIt);
-  }
+  // Maps the names of imported modules to their PCM paths.
+  llvm::StringMap Imports;
+  PrebuiltModuleListener Listener(Imports, InputFiles, VisitInputFiles);
+  ASTReader::readASTFileControlBlock(
+  PrebuiltModuleFilename, CI.getFileManager(), CI.getPCHContainerReader(),
+  /*FindModuleFileExtensions=*/false, Listener,
+  /*ValidateDiagnosticOptions=*/false);
+
+  for (const auto &Import : Imports)
+if (ModuleFiles.insert({Import.getKey().str(), Import.getValue()}).second)
+  visitPrebuiltModule(Import.getValue(), CI, ModuleFiles, InputFiles,
+  VisitInputFiles);
 }
 
 /// Transform arbitrary file name into an object-like file name.


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -84,33 +84,18 @@
 PrebuiltModuleFilesT &ModuleFiles,
 llvm::StringSet<> &InputFiles,
 bool VisitInputFiles) {
-  // Maps the names of modules that weren't yet visited to their PCM path.
-  llvm::StringMap ModuleFilesWorklist;
-  // Contains PCM paths of all visited modules.
-  llvm::StringSet<> VisitedModuleFiles;
-
-  PrebuiltModuleListener Listener(ModuleFilesWorklist, InputFiles,
-  VisitInputFiles);
-
-  auto GatherModuleFileInfo = [&](StringRef ASTFile) {
-ASTReader::readASTFileControlBlock(
-ASTFile, CI.getFileManager(), CI.getPCHContainerReader(),
-/*FindModuleFileExtensions=*/false, Listener,
-/*ValidateDiagnosticOptions=*/false);
-  };
-
-  GatherModuleFileInfo(PrebuiltModuleFilename);
-  while (!ModuleFilesWorklist.empty()) {
-auto WorklistItemIt = ModuleFilesWorklist.begin();
-
-if (!VisitedModuleFiles.contains(WorklistItemIt->getValue())) {
-  VisitedModuleFiles.insert(WorklistItemIt->getValue());
-  GatherModuleFileInfo(WorklistItemIt->getValue());
-  ModuleFiles[WorklistItemIt->getKey().str()] = WorklistItemIt->getValue();
-}
-
-ModuleFilesWorklist.erase(WorklistItemIt);
-  }
+  // Maps the names of imported modules to their PCM paths.
+  llvm::StringMap Imports;
+  PrebuiltModuleListener Listener(Imports, InputFiles, VisitInputFiles);
+  ASTReader::readASTFileControlBlock(
+  PrebuiltModuleFilename, CI.getFileManager(), CI.getPCHContainerReader(),
+  /*FindModuleFileExtensions=*/false, Listener,
+  /*ValidateDiagnosticOptions=*/false);
+
+  for (const auto &Import : Imports)
+if (ModuleFiles.insert({Import.getKey().str(), Import.getValue()}).second)
+  visitPrebuiltModule(Import.getValue(), CI, ModuleFiles, InputFiles,
+  

[PATCH] D120540: [Driver] Enable to use C++20 modules standalone by -fcxx-modules

2022-03-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

I agree. My understanding is that `-fcxx-modules` enables Clang modules that 
don't interact with C++20 modules. @Bigcheese, any thoughts?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120540/new/

https://reviews.llvm.org/D120540

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121533: [clang][deps] Fix traversal of precompiled dependencies

2022-03-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 415380.
jansvoboda11 added a comment.

Throw away recursive implementation, add reproducer


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121533/new/

https://reviews.llvm.org/D121533

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-pch-dangling.c

Index: clang/test/ClangScanDeps/modules-pch-dangling.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-pch-dangling.c
@@ -0,0 +1,139 @@
+// Unsupported on AIX because we don't support the requisite "__clangast"
+// section in XCOFF yet.
+// UNSUPPORTED: aix
+
+// This test checks that the dependency scanner can handle larger amount of
+// explicitly built modules retrieved from the PCH.
+// (Previously, there was a bug dangling iterator bug that manifested only with
+// 16 and more retrieved modules.)
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- mod_00.h
+//--- mod_01.h
+//--- mod_02.h
+//--- mod_03.h
+//--- mod_04.h
+//--- mod_05.h
+//--- mod_06.h
+//--- mod_07.h
+//--- mod_08.h
+//--- mod_09.h
+//--- mod_10.h
+//--- mod_11.h
+//--- mod_12.h
+//--- mod_13.h
+//--- mod_14.h
+//--- mod_15.h
+//--- mod_16.h
+//--- mod.h
+#include "mod_00.h"
+#include "mod_01.h"
+#include "mod_02.h"
+#include "mod_03.h"
+#include "mod_04.h"
+#include "mod_05.h"
+#include "mod_06.h"
+#include "mod_07.h"
+#include "mod_08.h"
+#include "mod_09.h"
+#include "mod_10.h"
+#include "mod_11.h"
+#include "mod_12.h"
+#include "mod_13.h"
+#include "mod_14.h"
+#include "mod_15.h"
+#include "mod_16.h"
+//--- module.modulemap
+module mod_00 { header "mod_00.h" }
+module mod_01 { header "mod_01.h" }
+module mod_02 { header "mod_02.h" }
+module mod_03 { header "mod_03.h" }
+module mod_04 { header "mod_04.h" }
+module mod_05 { header "mod_05.h" }
+module mod_06 { header "mod_06.h" }
+module mod_07 { header "mod_07.h" }
+module mod_08 { header "mod_08.h" }
+module mod_09 { header "mod_09.h" }
+module mod_10 { header "mod_10.h" }
+module mod_11 { header "mod_11.h" }
+module mod_12 { header "mod_12.h" }
+module mod_13 { header "mod_13.h" }
+module mod_14 { header "mod_14.h" }
+module mod_15 { header "mod_15.h" }
+module mod_16 { header "mod_16.h" }
+module mod{ header "mod.h"}
+
+//--- pch.h
+#include "mod.h"
+
+//--- tu.c
+
+//--- cdb_pch.json.template
+[{
+  "file": "DIR/pch.h",
+  "directory": "DIR",
+  "command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch"
+}]
+
+//--- cdb_tu.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/pch.h -o DIR/tu.o"
+}]
+
+// Scan dependencies of the PCH:
+//
+// RUN: sed "s|DIR|%/t|g" %t/cdb_pch.json.template > %t/cdb_pch.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_pch.json -format experimental-full \
+// RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result_pch.json
+
+// Explicitly build the PCH:
+//
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_00 > %t/mod_00.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_01 > %t/mod_01.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_02 > %t/mod_02.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_03 > %t/mod_03.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_04 > %t/mod_04.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_05 > %t/mod_05.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_06 > %t/mod_06.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_07 > %t/mod_07.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_08 > %t/mod_08.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_09 > %t/mod_09.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_10 > %t/mod_10.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_11 > %t/mod_11.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_12 > %t/mod_12.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_13 > %t/mod_13.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_14 > %t/mod_14.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_15 > %t/mod

[PATCH] D121533: [clang][deps] Fix traversal of precompiled dependencies

2022-03-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Fair enough, iterative implementation will be better.

I simplified it a bit by using the in-out parameter `ModuleFiles` to keep track 
of visited files. I also switched to using `SmallVector` for the newly 
discovered (not-yet-visited) imports, which allows using the suggested 
`pop_back_val` and avoids using (potentially dangling) iterator.

The test case is a bit unwieldy, since the old implementation only failed when 
the `StringMap` got rehashed (with 16 entries).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121533/new/

https://reviews.llvm.org/D121533

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121295: [clang][deps] Modules don't contribute to search path usage

2022-03-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 415381.
jansvoboda11 added a comment.

Undo unrelated changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121295/new/

https://reviews.llvm.org/D121295

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Preprocessor/search-path-usage.m


Index: clang/test/Preprocessor/search-path-usage.m
===
--- clang/test/Preprocessor/search-path-usage.m
+++ clang/test/Preprocessor/search-path-usage.m
@@ -129,7 +129,7 @@
 #endif
 #endif
 
-// Check that search paths with module maps are reported.
+// Check that search paths with module maps are NOT reported.
 //
 // RUN: mkdir %t/modulemap_abs
 // RUN: sed "s|DIR|%/S/Inputs/search-path-usage|g"\
@@ -142,5 +142,5 @@
 // RUN:   -DMODMAP_ABS -verify
 #ifdef MODMAP_ABS
 @import b; // \
-// expected-remark-re {{search path used: '{{.*}}/modulemap_abs'}}
+// expected-no-diagnostics
 #endif
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -365,9 +365,6 @@
   break;
   }
 
-  if (Module)
-noteLookupUsage(It.Idx, ImportLoc);
-
   return Module;
 }
 


Index: clang/test/Preprocessor/search-path-usage.m
===
--- clang/test/Preprocessor/search-path-usage.m
+++ clang/test/Preprocessor/search-path-usage.m
@@ -129,7 +129,7 @@
 #endif
 #endif
 
-// Check that search paths with module maps are reported.
+// Check that search paths with module maps are NOT reported.
 //
 // RUN: mkdir %t/modulemap_abs
 // RUN: sed "s|DIR|%/S/Inputs/search-path-usage|g"\
@@ -142,5 +142,5 @@
 // RUN:   -DMODMAP_ABS -verify
 #ifdef MODMAP_ABS
 @import b; // \
-// expected-remark-re {{search path used: '{{.*}}/modulemap_abs'}}
+// expected-no-diagnostics
 #endif
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -365,9 +365,6 @@
   break;
   }
 
-  if (Module)
-noteLookupUsage(It.Idx, ImportLoc);
-
   return Module;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121685: [clang][deps] NFC: Use range-based for loop instead of iterators

2022-03-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The iterator is needed after the loop body, meaning we can use more terse 
range-based for loop.

Depends on D121295 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121685

Files:
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -299,20 +299,19 @@
SourceLocation ImportLoc,
bool AllowExtraModuleMapSearch) {
   Module *Module = nullptr;
-  SearchDirIterator It = nullptr;
 
   // Look through the various header search paths to load any available module
   // maps, searching for a module map that describes this module.
-  for (It = search_dir_begin(); It != search_dir_end(); ++It) {
-if (It->isFramework()) {
+  for (DirectoryLookup Dir : search_dir_range()) {
+if (Dir.isFramework()) {
   // Search for or infer a module map for a framework. Here we use
   // SearchName rather than ModuleName, to permit finding private modules
   // named FooPrivate in buggy frameworks named Foo.
   SmallString<128> FrameworkDirName;
-  FrameworkDirName += It->getFrameworkDir()->getName();
+  FrameworkDirName += Dir.getFrameworkDir()->getName();
   llvm::sys::path::append(FrameworkDirName, SearchName + ".framework");
   if (auto FrameworkDir = FileMgr.getDirectory(FrameworkDirName)) {
-bool IsSystem = It->getDirCharacteristic() != SrcMgr::C_User;
+bool IsSystem = Dir.getDirCharacteristic() != SrcMgr::C_User;
 Module = loadFrameworkModule(ModuleName, *FrameworkDir, IsSystem);
 if (Module)
   break;
@@ -322,12 +321,12 @@
 // FIXME: Figure out how header maps and module maps will work together.
 
 // Only deal with normal search directories.
-if (!It->isNormalDir())
+if (!Dir.isNormalDir())
   continue;
 
-bool IsSystem = It->isSystemHeaderDirectory();
+bool IsSystem = Dir.isSystemHeaderDirectory();
 // Search for a module map file in this directory.
-if (loadModuleMapFile(It->getDir(), IsSystem,
+if (loadModuleMapFile(Dir.getDir(), IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded) {
   // We just loaded a module map file; check whether the module is
   // available now.
@@ -339,7 +338,7 @@
 // Search for a module map in a subdirectory with the same name as the
 // module.
 SmallString<128> NestedModuleMapDirName;
-NestedModuleMapDirName = It->getDir()->getName();
+NestedModuleMapDirName = Dir.getDir()->getName();
 llvm::sys::path::append(NestedModuleMapDirName, ModuleName);
 if (loadModuleMapFile(NestedModuleMapDirName, IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded){
@@ -351,13 +350,13 @@
 
 // If we've already performed the exhaustive search for module maps in this
 // search directory, don't do it again.
-if (It->haveSearchedAllModuleMaps())
+if (Dir.haveSearchedAllModuleMaps())
   continue;
 
 // Load all module maps in the immediate subdirectories of this search
 // directory if ModuleName was from @import.
 if (AllowExtraModuleMapSearch)
-  loadSubdirectoryModuleMaps(*It);
+  loadSubdirectoryModuleMaps(Dir);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -299,20 +299,19 @@
SourceLocation ImportLoc,
bool AllowExtraModuleMapSearch) {
   Module *Module = nullptr;
-  SearchDirIterator It = nullptr;
 
   // Look through the various header search paths to load any available module
   // maps, searching for a module map that describes this module.
-  for (It = search_dir_begin(); It != search_dir_end(); ++It) {
-if (It->isFramework()) {
+  for (DirectoryLookup Dir : search_dir_range()) {
+if (Dir.isFramework()) {
   // Search for or infer a module map for a framework. Here we use
   // SearchName rather than ModuleName, to permit finding private modules
   // named FooPrivate in buggy frameworks named Foo.
   SmallString<128> FrameworkDirName;
-  FrameworkDirName += It->getFrameworkDir()->getName();
+  FrameworkDirName += Dir.getFrameworkDir()->getName();
   llvm::sys::path::append(FrameworkDirName, SearchName + ".framework");
   if (auto FrameworkDir = FileMgr.getDirectory(FrameworkDirName)) {
-bool IsSystem = It->getDirCharacteri

[PATCH] D121295: [clang][deps] Modules don't contribute to search path usage

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG77924d60efa8: [clang][deps] Modules don't contribute to 
search path usage (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D121295?vs=415381&id=415776#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121295/new/

https://reviews.llvm.org/D121295

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Preprocessor/search-path-usage.m


Index: clang/test/Preprocessor/search-path-usage.m
===
--- clang/test/Preprocessor/search-path-usage.m
+++ clang/test/Preprocessor/search-path-usage.m
@@ -129,7 +129,7 @@
 #endif
 #endif
 
-// Check that search paths with module maps are reported.
+// Check that search paths with module maps are NOT reported.
 //
 // RUN: mkdir %t/modulemap_abs
 // RUN: sed "s|DIR|%/S/Inputs/search-path-usage|g"\
@@ -142,5 +142,5 @@
 // RUN:   -DMODMAP_ABS -verify
 #ifdef MODMAP_ABS
 @import b; // \
-// expected-remark-re {{search path used: '{{.*}}/modulemap_abs'}}
+// expected-no-diagnostics
 #endif
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -365,9 +365,6 @@
   break;
   }
 
-  if (Module)
-noteLookupUsage(It.Idx, ImportLoc);
-
   return Module;
 }
 
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -561,6 +561,7 @@
 
   /// Determine which HeaderSearchOptions::UserEntries have been successfully
   /// used so far and mark their index with 'true' in the resulting bit vector.
+  /// Note: implicit module maps don't contribute to entry usage.
   std::vector computeUserEntryUsage() const;
 
   /// This method returns a HeaderMap for the specified


Index: clang/test/Preprocessor/search-path-usage.m
===
--- clang/test/Preprocessor/search-path-usage.m
+++ clang/test/Preprocessor/search-path-usage.m
@@ -129,7 +129,7 @@
 #endif
 #endif
 
-// Check that search paths with module maps are reported.
+// Check that search paths with module maps are NOT reported.
 //
 // RUN: mkdir %t/modulemap_abs
 // RUN: sed "s|DIR|%/S/Inputs/search-path-usage|g"\
@@ -142,5 +142,5 @@
 // RUN:   -DMODMAP_ABS -verify
 #ifdef MODMAP_ABS
 @import b; // \
-// expected-remark-re {{search path used: '{{.*}}/modulemap_abs'}}
+// expected-no-diagnostics
 #endif
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -365,9 +365,6 @@
   break;
   }
 
-  if (Module)
-noteLookupUsage(It.Idx, ImportLoc);
-
   return Module;
 }
 
Index: clang/include/clang/Lex/HeaderSearch.h
===
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -561,6 +561,7 @@
 
   /// Determine which HeaderSearchOptions::UserEntries have been successfully
   /// used so far and mark their index with 'true' in the resulting bit vector.
+  /// Note: implicit module maps don't contribute to entry usage.
   std::vector computeUserEntryUsage() const;
 
   /// This method returns a HeaderMap for the specified
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121685: [clang][deps] NFC: Use range-based for loop instead of iterators

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6007b0b67bcb: [clang][deps] NFC: Use range-based for loop 
instead of iterators (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121685/new/

https://reviews.llvm.org/D121685

Files:
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -299,20 +299,19 @@
SourceLocation ImportLoc,
bool AllowExtraModuleMapSearch) {
   Module *Module = nullptr;
-  SearchDirIterator It = nullptr;
 
   // Look through the various header search paths to load any available module
   // maps, searching for a module map that describes this module.
-  for (It = search_dir_begin(); It != search_dir_end(); ++It) {
-if (It->isFramework()) {
+  for (DirectoryLookup Dir : search_dir_range()) {
+if (Dir.isFramework()) {
   // Search for or infer a module map for a framework. Here we use
   // SearchName rather than ModuleName, to permit finding private modules
   // named FooPrivate in buggy frameworks named Foo.
   SmallString<128> FrameworkDirName;
-  FrameworkDirName += It->getFrameworkDir()->getName();
+  FrameworkDirName += Dir.getFrameworkDir()->getName();
   llvm::sys::path::append(FrameworkDirName, SearchName + ".framework");
   if (auto FrameworkDir = FileMgr.getDirectory(FrameworkDirName)) {
-bool IsSystem = It->getDirCharacteristic() != SrcMgr::C_User;
+bool IsSystem = Dir.getDirCharacteristic() != SrcMgr::C_User;
 Module = loadFrameworkModule(ModuleName, *FrameworkDir, IsSystem);
 if (Module)
   break;
@@ -322,12 +321,12 @@
 // FIXME: Figure out how header maps and module maps will work together.
 
 // Only deal with normal search directories.
-if (!It->isNormalDir())
+if (!Dir.isNormalDir())
   continue;
 
-bool IsSystem = It->isSystemHeaderDirectory();
+bool IsSystem = Dir.isSystemHeaderDirectory();
 // Search for a module map file in this directory.
-if (loadModuleMapFile(It->getDir(), IsSystem,
+if (loadModuleMapFile(Dir.getDir(), IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded) {
   // We just loaded a module map file; check whether the module is
   // available now.
@@ -339,7 +338,7 @@
 // Search for a module map in a subdirectory with the same name as the
 // module.
 SmallString<128> NestedModuleMapDirName;
-NestedModuleMapDirName = It->getDir()->getName();
+NestedModuleMapDirName = Dir.getDir()->getName();
 llvm::sys::path::append(NestedModuleMapDirName, ModuleName);
 if (loadModuleMapFile(NestedModuleMapDirName, IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded){
@@ -351,13 +350,13 @@
 
 // If we've already performed the exhaustive search for module maps in this
 // search directory, don't do it again.
-if (It->haveSearchedAllModuleMaps())
+if (Dir.haveSearchedAllModuleMaps())
   continue;
 
 // Load all module maps in the immediate subdirectories of this search
 // directory if ModuleName was from @import.
 if (AllowExtraModuleMapSearch)
-  loadSubdirectoryModuleMaps(*It);
+  loadSubdirectoryModuleMaps(Dir);
 
 // Look again for the module.
 Module = ModMap.findModule(ModuleName);


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -299,20 +299,19 @@
SourceLocation ImportLoc,
bool AllowExtraModuleMapSearch) {
   Module *Module = nullptr;
-  SearchDirIterator It = nullptr;
 
   // Look through the various header search paths to load any available module
   // maps, searching for a module map that describes this module.
-  for (It = search_dir_begin(); It != search_dir_end(); ++It) {
-if (It->isFramework()) {
+  for (DirectoryLookup Dir : search_dir_range()) {
+if (Dir.isFramework()) {
   // Search for or infer a module map for a framework. Here we use
   // SearchName rather than ModuleName, to permit finding private modules
   // named FooPrivate in buggy frameworks named Foo.
   SmallString<128> FrameworkDirName;
-  FrameworkDirName += It->getFrameworkDir()->getName();
+  FrameworkDirName += Dir.getFrameworkDir()->getName();
   llvm::sys::path::append(FrameworkDirName, SearchName + ".framework");
   if (auto FrameworkDir = FileMgr.getDirectory(FrameworkDirName)) {
-bool IsSystem = It->getDirCharacteristic() != SrcMgr::C_User;
+bool IsSystem = Dir.getDirCharact

[PATCH] D121303: [clang][deps] Don't prune search paths used by dependencies

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd73daa913546: [clang][deps] Don't prune search paths 
used by dependencies (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D121303?vs=414119&id=415778#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121303/new/

https://reviews.llvm.org/D121303

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/header-search-pruning-transitive.c

Index: clang/test/ClangScanDeps/header-search-pruning-transitive.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-pruning-transitive.c
@@ -0,0 +1,169 @@
+// This test checks that pruning of header search paths produces consistent dependency graphs.
+//
+// When pruning header search paths for a module, we can't remove any paths its dependencies use.
+// Otherwise, we could get either of the following dependency graphs depending on the search path
+// configuration of the particular TU that first discovered the module:
+//   X: -> Y:
+//   X: -> Y:
+// We can't have the same version of module X depend on multiple different versions of Y based on
+// the TU configuration.
+//
+// Keeping all header search paths (transitive) dependencies use will ensure we get consistent
+// dependency graphs:
+//   X: -> Y:
+//   X: -> Y:
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- a/a.h
+//--- b/b.h
+//--- begin/begin.h
+//--- end/end.h
+//--- Y.h
+#include "begin.h"
+#if __has_include("a.h")
+#include "a.h"
+#endif
+#include "end.h"
+
+//--- X.h
+#include "Y.h"
+
+//--- module.modulemap
+module Y { header "Y.h" }
+module X { header "X.h" }
+
+//--- test.c
+#include "X.h"
+
+//--- cdb_with_a.json.template
+[{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang -c test.c -o DIR/test.o -fmodules -fimplicit-modules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -Ibegin -Ia -Ib -Iend"
+}]
+
+//--- cdb_without_a.json.template
+[{
+  "file": "DIR/test.c",
+  "directory": "DIR",
+  "command": "clang -c test.c -o DIR/test.o -fmodules -fimplicit-modules -fmodules-cache-path=DIR/module-cache -fimplicit-module-maps -Ibegin -Ib -Iend"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb_with_a.json.template> %t/cdb_with_a.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb_without_a.json.template > %t/cdb_without_a.json
+
+// RUN: echo -%t > %t/results.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_with_a.json-format experimental-full -optimize-args >> %t/results.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_without_a.json -format experimental-full -optimize-args >> %t/results.json
+// RUN: cat %t/results.json | sed 's/\\/\//g' | FileCheck %s
+
+// CHECK:  -[[PREFIX:.*]]
+// CHECK-NEXT: {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "[[HASH_Y_WITH_A:.*]]",
+// CHECK-NEXT:   "module-name": "Y"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "[[HASH_X:.*]]",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/./X.h",
+// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "X"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "[[HASH_Y_WITH_A]]",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/./Y.h",
+// CHECK-NEXT: "[[PREFIX]]/./a/a.h",
+// CHECK-NEXT: "[[PREFIX]]/./begin/begin.h",
+// CHECK-NEXT: "[[PREFIX]]/./end/end.h",
+// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "Y"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "[[HASH_X]]",
+// CHECK-NEXT:   "module-name": "X"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/test.c"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "input-file": "[[PREFIX]]/test.c"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+// CHECK-NEXT: {
+// CHECK-NEXT:   "modules": [

[PATCH] D121533: [clang][deps] Fix traversal of precompiled dependencies

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e25ff84d89e: [clang][deps] Fix traversal of precompiled 
dependencies (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D121533?vs=415380&id=415779#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121533/new/

https://reviews.llvm.org/D121533

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-pch-dangling.c

Index: clang/test/ClangScanDeps/modules-pch-dangling.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-pch-dangling.c
@@ -0,0 +1,139 @@
+// Unsupported on AIX because we don't support the requisite "__clangast"
+// section in XCOFF yet.
+// UNSUPPORTED: aix
+
+// This test checks that the dependency scanner can handle larger amount of
+// explicitly built modules retrieved from the PCH.
+// (Previously, there was a bug dangling iterator bug that manifested only with
+// 16 and more retrieved modules.)
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- mod_00.h
+//--- mod_01.h
+//--- mod_02.h
+//--- mod_03.h
+//--- mod_04.h
+//--- mod_05.h
+//--- mod_06.h
+//--- mod_07.h
+//--- mod_08.h
+//--- mod_09.h
+//--- mod_10.h
+//--- mod_11.h
+//--- mod_12.h
+//--- mod_13.h
+//--- mod_14.h
+//--- mod_15.h
+//--- mod_16.h
+//--- mod.h
+#include "mod_00.h"
+#include "mod_01.h"
+#include "mod_02.h"
+#include "mod_03.h"
+#include "mod_04.h"
+#include "mod_05.h"
+#include "mod_06.h"
+#include "mod_07.h"
+#include "mod_08.h"
+#include "mod_09.h"
+#include "mod_10.h"
+#include "mod_11.h"
+#include "mod_12.h"
+#include "mod_13.h"
+#include "mod_14.h"
+#include "mod_15.h"
+#include "mod_16.h"
+//--- module.modulemap
+module mod_00 { header "mod_00.h" }
+module mod_01 { header "mod_01.h" }
+module mod_02 { header "mod_02.h" }
+module mod_03 { header "mod_03.h" }
+module mod_04 { header "mod_04.h" }
+module mod_05 { header "mod_05.h" }
+module mod_06 { header "mod_06.h" }
+module mod_07 { header "mod_07.h" }
+module mod_08 { header "mod_08.h" }
+module mod_09 { header "mod_09.h" }
+module mod_10 { header "mod_10.h" }
+module mod_11 { header "mod_11.h" }
+module mod_12 { header "mod_12.h" }
+module mod_13 { header "mod_13.h" }
+module mod_14 { header "mod_14.h" }
+module mod_15 { header "mod_15.h" }
+module mod_16 { header "mod_16.h" }
+module mod{ header "mod.h"}
+
+//--- pch.h
+#include "mod.h"
+
+//--- tu.c
+
+//--- cdb_pch.json.template
+[{
+  "file": "DIR/pch.h",
+  "directory": "DIR",
+  "command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch"
+}]
+
+//--- cdb_tu.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/tu.c -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/pch.h -o DIR/tu.o"
+}]
+
+// Scan dependencies of the PCH:
+//
+// RUN: sed "s|DIR|%/t|g" %t/cdb_pch.json.template > %t/cdb_pch.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_pch.json -format experimental-full \
+// RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result_pch.json
+
+// Explicitly build the PCH:
+//
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_00 > %t/mod_00.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_01 > %t/mod_01.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_02 > %t/mod_02.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_03 > %t/mod_03.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_04 > %t/mod_04.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_05 > %t/mod_05.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_06 > %t/mod_06.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_07 > %t/mod_07.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_08 > %t/mod_08.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_09 > %t/mod_09.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_10 > %t/mod_10.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_11 > %t/mod_11.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_12 > %t/mod_12.cc1.rsp
+// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json --module-name=mod_13 > %t/mod_13.cc1.rsp
+// RUN: %python %

[PATCH] D113676: [clang][lex] Fix search path usage remark with modules

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 abandoned this revision.
jansvoboda11 added a comment.
Herald added a project: All.

Abandoning this. We don't need to collect usage info from 
`-fimplicit-module-maps` because we don't use that feature during explicit 
builds: D120465 . Support for usage 
collection for modules was removed entirely in D121295 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113676/new/

https://reviews.llvm.org/D113676

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, saudi.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In D92191 , a bunch of tests were introduced 
to ensure `clang-scan-deps` works in `clang-cl` mode as well.

This patch de-duplicates them. We don't need to duplicate all our tests; it 
should be enough to test the couple of special cases we have in 
`clang-scan-deps` for `clang-cl`:

1. Deducing output path (and therefore target name in our make output).
2. Ignoring `-Xclang` arguments in step 1.
3. Deducing resource directory by invoking the compiler executuable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121812

Files:
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl_by_mod_name.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/cl-output.c
  clang/test/ClangScanDeps/cl-resource-dir.c
  clang/test/ClangScanDeps/cl-xclang.c
  clang/test/ClangScanDeps/error.cpp
  clang/test/ClangScanDeps/has_include_if_elif.cpp
  clang/test/ClangScanDeps/header_stat_before_open.m
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules.cpp
  clang/test/ClangScanDeps/no-werror.cpp
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/test/ClangScanDeps/static-analyzer.c
  clang/test/ClangScanDeps/strip_diag_serialize.cpp
  clang/test/ClangScanDeps/target-filename.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp

Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/vfsoverlay_input.cpp
-// RUN: cp %s %t.dir/vfsoverlay_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay.yaml > %t.dir/vfsoverlay.yaml
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
@@ -16,7 +15,3 @@
 // CHECK: vfsoverlay_input.o
 // CHECK-NEXT: vfsoverlay_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}header.h
-
-// CHECK: vfsoverlay_input_clangcl.o
-// CHECK-NEXT: vfsoverlay_input_clangcl.cpp
-// CHECK-NEXT: Inputs{{/|\\}}header.h
Index: clang/test/ClangScanDeps/target-filename.cpp
===
--- clang/test/ClangScanDeps/target-filename.cpp
+++ clang/test/ClangScanDeps/target-filename.cpp
@@ -21,27 +21,3 @@
 
 // CHECK: target-filename_input.o:
 // CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-a.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-b.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-c.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-d.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-e.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastf.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastg.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lasth.o:
-// CHECK-NEXT: target-filename_input.cpp
Index: clang/test/ClangScanDeps/strip_diag_serialize.cpp
===
--- clang/test/ClangScanDeps/strip_diag_serialize.cpp
+++ clang/test/ClangScanDeps/strip_diag_serialize.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/strip_diag_serialize_input.cpp
-// RUN: cp %s %t.dir/strip_diag_serialize_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/strip_diag_serialize.json > %t.cdb
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 2>&1 | FileCheck %s
Index: clang/test/ClangScanDeps/static-analyzer.c
===
--- clang/test/ClangScanDeps/static-analyzer.c
+++ clang/test/ClangScanDeps/static-analyzer.c
@@ -3,7 +3,6 @@
 // RUN: mkdir -p %t.dir
 // Change file name to avoid false positives in CHECK, since "static-analyzer.c" is found in %S.
 // RUN: cp %s %t.dir/static-anal

[PATCH] D116751: [clang][lex] NFC: Extract module creation into function

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 abandoned this revision.
jansvoboda11 added a comment.
Herald added a project: All.

Abandoning this. We don't need to collect usage info from 
-fimplicit-module-maps because we don't use that feature during explicit 
builds: D120465 . Support for usage 
collection for modules was removed entirely in D121295 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116751/new/

https://reviews.llvm.org/D116751

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 415856.
jansvoboda11 added a comment.

Remove backslashes from make output checks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

Files:
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl_by_mod_name.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/cl-output.c
  clang/test/ClangScanDeps/cl-resource-dir.c
  clang/test/ClangScanDeps/cl-xclang.c
  clang/test/ClangScanDeps/error.cpp
  clang/test/ClangScanDeps/has_include_if_elif.cpp
  clang/test/ClangScanDeps/header_stat_before_open.m
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules.cpp
  clang/test/ClangScanDeps/no-werror.cpp
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/test/ClangScanDeps/static-analyzer.c
  clang/test/ClangScanDeps/strip_diag_serialize.cpp
  clang/test/ClangScanDeps/target-filename.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp

Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/vfsoverlay_input.cpp
-// RUN: cp %s %t.dir/vfsoverlay_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay.yaml > %t.dir/vfsoverlay.yaml
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
@@ -16,7 +15,3 @@
 // CHECK: vfsoverlay_input.o
 // CHECK-NEXT: vfsoverlay_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}header.h
-
-// CHECK: vfsoverlay_input_clangcl.o
-// CHECK-NEXT: vfsoverlay_input_clangcl.cpp
-// CHECK-NEXT: Inputs{{/|\\}}header.h
Index: clang/test/ClangScanDeps/target-filename.cpp
===
--- clang/test/ClangScanDeps/target-filename.cpp
+++ clang/test/ClangScanDeps/target-filename.cpp
@@ -21,27 +21,3 @@
 
 // CHECK: target-filename_input.o:
 // CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-a.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-b.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-c.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-d.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-e.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastf.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastg.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lasth.o:
-// CHECK-NEXT: target-filename_input.cpp
Index: clang/test/ClangScanDeps/strip_diag_serialize.cpp
===
--- clang/test/ClangScanDeps/strip_diag_serialize.cpp
+++ clang/test/ClangScanDeps/strip_diag_serialize.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/strip_diag_serialize_input.cpp
-// RUN: cp %s %t.dir/strip_diag_serialize_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/strip_diag_serialize.json > %t.cdb
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 2>&1 | FileCheck %s
Index: clang/test/ClangScanDeps/static-analyzer.c
===
--- clang/test/ClangScanDeps/static-analyzer.c
+++ clang/test/ClangScanDeps/static-analyzer.c
@@ -3,7 +3,6 @@
 // RUN: mkdir -p %t.dir
 // Change file name to avoid false positives in CHECK, since "static-analyzer.c" is found in %S.
 // RUN: cp %s %t.dir/static-analyzer_clang.c
-// RUN: cp %s %t.dir/static-analyzer_clangcl.c
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/analyze_header_input.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/static-analyzer-cdb.json > %t-cdb.json
@@ -16,6 +15,3 @@
 
 // CHECK: static-analyzer_clang.c
 // CHECK-NEXT: analyze_header_input.h
-
-// CHECK: static-analyzer_clangcl.c
-// CHECK-NEXT: analyze_header_input.h
Index: clang/test/ClangScanDeps/regular_cdb.cpp
===
--- clang/test/ClangScanDep

[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-16 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 415857.
jansvoboda11 added a comment.

Add `-NEXT` to a check


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

Files:
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl_by_mod_name.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/cl-output.c
  clang/test/ClangScanDeps/cl-resource-dir.c
  clang/test/ClangScanDeps/cl-xclang.c
  clang/test/ClangScanDeps/error.cpp
  clang/test/ClangScanDeps/has_include_if_elif.cpp
  clang/test/ClangScanDeps/header_stat_before_open.m
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules.cpp
  clang/test/ClangScanDeps/no-werror.cpp
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/test/ClangScanDeps/static-analyzer.c
  clang/test/ClangScanDeps/strip_diag_serialize.cpp
  clang/test/ClangScanDeps/target-filename.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp

Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/vfsoverlay_input.cpp
-// RUN: cp %s %t.dir/vfsoverlay_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay.yaml > %t.dir/vfsoverlay.yaml
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
@@ -16,7 +15,3 @@
 // CHECK: vfsoverlay_input.o
 // CHECK-NEXT: vfsoverlay_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}header.h
-
-// CHECK: vfsoverlay_input_clangcl.o
-// CHECK-NEXT: vfsoverlay_input_clangcl.cpp
-// CHECK-NEXT: Inputs{{/|\\}}header.h
Index: clang/test/ClangScanDeps/target-filename.cpp
===
--- clang/test/ClangScanDeps/target-filename.cpp
+++ clang/test/ClangScanDeps/target-filename.cpp
@@ -21,27 +21,3 @@
 
 // CHECK: target-filename_input.o:
 // CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-a.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-b.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-c.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-d.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-e.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastf.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastg.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lasth.o:
-// CHECK-NEXT: target-filename_input.cpp
Index: clang/test/ClangScanDeps/strip_diag_serialize.cpp
===
--- clang/test/ClangScanDeps/strip_diag_serialize.cpp
+++ clang/test/ClangScanDeps/strip_diag_serialize.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/strip_diag_serialize_input.cpp
-// RUN: cp %s %t.dir/strip_diag_serialize_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/strip_diag_serialize.json > %t.cdb
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 2>&1 | FileCheck %s
Index: clang/test/ClangScanDeps/static-analyzer.c
===
--- clang/test/ClangScanDeps/static-analyzer.c
+++ clang/test/ClangScanDeps/static-analyzer.c
@@ -3,7 +3,6 @@
 // RUN: mkdir -p %t.dir
 // Change file name to avoid false positives in CHECK, since "static-analyzer.c" is found in %S.
 // RUN: cp %s %t.dir/static-analyzer_clang.c
-// RUN: cp %s %t.dir/static-analyzer_clangcl.c
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/analyze_header_input.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/static-analyzer-cdb.json > %t-cdb.json
@@ -16,6 +15,3 @@
 
 // CHECK: static-analyzer_clang.c
 // CHECK-NEXT: analyze_header_input.h
-
-// CHECK: static-analyzer_clangcl.c
-// CHECK-NEXT: analyze_header_input.h
Index: clang/test/ClangScanDeps/regular_cdb.cpp
===
--- clang/test/ClangScanDeps/regular_cdb.cpp
++

[PATCH] D121997: [clang][driver] Fix compilation database dump with multiple architectures

2022-03-18 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman, jkorous.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Command lines with multiple `-arch` arguments expand into multiple entries in 
the compilation database. However, the file writes are not appending, meaning 
subsequent writes end up overwriting the previous ones, resulting in garbled 
output.

This patch fixes that by always appending to the file.

rdar://90165004


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121997

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/compilation_database_multiarch.c


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -c %s -o %t/out -arch x86_64 -arch arm64 -MJ 
%t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=arm64-apple-ios5.0.0"]},
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2382,7 +2382,8 @@
   if (!CompilationDatabase) {
 std::error_code EC;
 auto File = std::make_unique(
-Filename, EC, llvm::sys::fs::OF_TextWithCRLF);
+Filename, EC,
+llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
 if (EC) {
   D.Diag(clang::diag::err_drv_compilationdatabase) << Filename
<< EC.message();


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -c %s -o %t/out -arch x86_64 -arch arm64 -MJ %t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=arm64-apple-ios5.0.0"]},
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2382,7 +2382,8 @@
   if (!CompilationDatabase) {
 std::error_code EC;
 auto File = std::make_unique(
-Filename, EC, llvm::sys::fs::OF_TextWithCRLF);
+Filename, EC,
+llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
 if (EC) {
   D.Diag(clang::diag::err_drv_compilationdatabase) << Filename
<< EC.message();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121997: [clang][driver] Fix compilation database dump with multiple architectures

2022-03-18 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 416569.
jansvoboda11 added a comment.

Specify the `apple-darwin` target


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121997/new/

https://reviews.llvm.org/D121997

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/compilation_database_multiarch.c


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -c %s -o %t/out -target x86_64-apple-darwin -arch x86_64 -arch 
arm64 -MJ %t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=arm64-apple-ios5.0.0"]},
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2382,7 +2382,8 @@
   if (!CompilationDatabase) {
 std::error_code EC;
 auto File = std::make_unique(
-Filename, EC, llvm::sys::fs::OF_TextWithCRLF);
+Filename, EC,
+llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
 if (EC) {
   D.Diag(clang::diag::err_drv_compilationdatabase) << Filename
<< EC.message();


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -c %s -o %t/out -target x86_64-apple-darwin -arch x86_64 -arch arm64 -MJ %t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=arm64-apple-ios5.0.0"]},
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2382,7 +2382,8 @@
   if (!CompilationDatabase) {
 std::error_code EC;
 auto File = std::make_unique(
-Filename, EC, llvm::sys::fs::OF_TextWithCRLF);
+Filename, EC,
+llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
 if (EC) {
   D.Diag(clang::diag::err_drv_compilationdatabase) << Filename
<< EC.message();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121997: [clang][driver] Fix compilation database dump with multiple architectures

2022-03-18 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/Driver/compilation_database_multiarch.c:2
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -c %s -o %t/out -arch x86_64 -arch arm64 -MJ 
%t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s

dexonsmith wrote:
> Usually driver tests don't depend on the `-cc1` working. The `-cc1` depends 
> on the backends. You'd need to check that the relevant targets have been 
> built and linked in. It'd be better to keep this isolated to the driver?
> 
> Is there a way to get the driver to dump the compilation database only 
> (without actually running the actions)?
> 
> E.g., will `-###` still emit the compilation database? Looks like not:
> ```
>   // If this is a dry run, do not create the compilation database file.
>   if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
> return;
> ```
> But maybe there's some other way to avoid running the actions. Or, we can add 
> something like `-MJ-only `, which acts like `-MJ ` and then exits 
> before running the actions.
If we manage to only run the driver (without invoking the `-cc1`s), would the 
question of built targets go away?

Flang has a frontend option `-init-only`. Maybe we could add something similar 
to that to Clang's driver? (`-driver-only`) Creating a specialized `-MJ-only` 
seems too specific IMO.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121997/new/

https://reviews.llvm.org/D121997

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121997: [clang][driver] Fix compilation database dump with multiple architectures

2022-03-18 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 416576.
jansvoboda11 added a comment.

Avoid buggy driver behavior


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121997/new/

https://reviews.llvm.org/D121997

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/compilation_database_multiarch.c


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -c %s -o %t/out -target x86_64-apple-macos -arch arm64 -arch 
x86_64 -MJ %t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=arm64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2382,7 +2382,8 @@
   if (!CompilationDatabase) {
 std::error_code EC;
 auto File = std::make_unique(
-Filename, EC, llvm::sys::fs::OF_TextWithCRLF);
+Filename, EC,
+llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
 if (EC) {
   D.Diag(clang::diag::err_drv_compilationdatabase) << Filename
<< EC.message();


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -c %s -o %t/out -target x86_64-apple-macos -arch arm64 -arch x86_64 -MJ %t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=arm64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2382,7 +2382,8 @@
   if (!CompilationDatabase) {
 std::error_code EC;
 auto File = std::make_unique(
-Filename, EC, llvm::sys::fs::OF_TextWithCRLF);
+Filename, EC,
+llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
 if (EC) {
   D.Diag(clang::diag::err_drv_compilationdatabase) << Filename
<< EC.message();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121997: [clang][driver] Fix compilation database dump with multiple architectures

2022-03-21 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 416846.
jansvoboda11 added a comment.

Introduce `-driver-only` to avoid running `-cc1`s.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121997/new/

https://reviews.llvm.org/D121997

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
  clang/test/Driver/compilation_database_multiarch.c


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -driver-only -o %/out %s -mtargetos=macos12 -arch arm64 -arch 
x86_64 -MJ %t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", 
"arguments": [{{.*}} "--target=arm64-apple-macosx12.0.0"]},
Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -56,6 +56,9 @@
   if (!C)
 return nullptr;
 
+  if (C->getArgs().hasArg(driver::options::OPT_driver_only))
+return nullptr;
+
   // Just print the cc1 options if -### was present.
   if (C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) {
 C->getJobs().Print(llvm::errs(), "\n", true);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2382,7 +2382,8 @@
   if (!CompilationDatabase) {
 std::error_code EC;
 auto File = std::make_unique(
-Filename, EC, llvm::sys::fs::OF_TextWithCRLF);
+Filename, EC,
+llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
 if (EC) {
   D.Diag(clang::diag::err_drv_compilationdatabase) << Filename
<< EC.message();
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1597,6 +1597,9 @@
 int Driver::ExecuteCompilation(
 Compilation &C,
 SmallVectorImpl> &FailingCommands) {
+  if (C.getArgs().hasArg(options::OPT_driver_only))
+return 0;
+
   // Just print if -### was present.
   if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
 C.getJobs().Print(llvm::errs(), "\n", true);
@@ -1843,6 +1846,7 @@
   }
 
   if (C.getArgs().hasArg(options::OPT_v) ||
+  C.getArgs().hasArg(options::OPT_driver_only) ||
   C.getArgs().hasArg(options::OPT__HASH_HASH_HASH) ||
   C.getArgs().hasArg(options::OPT_print_supported_cpus)) {
 PrintVersion(C, llvm::errs());
@@ -4425,6 +4429,8 @@
   C.getArgs().hasArg(options::OPT_Qunused_arguments))
 return;
 
+  // Claim -driver-only here.
+  (void)C.getArgs().hasArg(options::OPT_driver_only);
   // Claim -### here.
   (void)C.getArgs().hasArg(options::OPT__HASH_HASH_HASH);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2688,6 +2688,7 @@
 " overwriting polymorphic C++ objects">,
   NegFlag>;
 def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group;
+def driver_only : Flag<["-"], "driver-only">, Flags<[NoXarchOption, 
CoreOption]>, HelpText<"Only run the driver.">;
 def fsyntax_only : Flag<["-"], "fsyntax-only">,
   Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group;
 def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group;


Index: clang/test/Driver/compilation_database_multiarch.c
===
--- /dev/null
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang -driver-only -o %/out %s -mtargetos=macos12 -arch arm64 -arch x86_64 -MJ %t/compilation_database.json
+// RUN: FileCheck --input-file=%t/compilation_database.json %s
+
+// CHECK:  { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]},
+// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=arm64-apple-macosx12.0.0"]},
Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Fronten

[PATCH] D122237: [clang][lex] Fix failures with Microsoft header search rules

2022-03-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`HeaderSearch` currently assumes `LookupFileCache` is eventually populated in 
`LookupFile`. However, that's not always the case with `-fms-compatibility` and 
its early returns.

This patch adds a defensive check that the iterator pulled out of the cache is 
actually valid before using it.

(This bug was introduced in D119721 . Before 
that, the cache was initialized to `0` - essentially the `search_dir_begin()` 
iterator.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122237

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Preprocessor/microsoft-header-search-fail.c


Index: clang/test/Preprocessor/microsoft-header-search-fail.c
===
--- /dev/null
+++ clang/test/Preprocessor/microsoft-header-search-fail.c
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -Eonly -fms-compatibility %t/test.c -I %t/include -verify
+
+//--- test.c
+#include "x/header.h"
+#include "z/header.h"
+
+// expected-warning-re@include/y/header.h:1 {{#include resolved using 
non-portable Microsoft search rules as: {{.*}}/x/culprit.h}}
+// expected-error@include/z/header.h:1 {{'culprit.h' file not found}}
+
+//--- include/x/header.h
+#include "y/header.h"
+
+//--- include/y/header.h
+#include "culprit.h"
+
+//--- include/x/culprit.h
+
+//--- include/z/header.h
+#include "culprit.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -976,7 +976,8 @@
   // this is a matching hit.
   if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-It = CacheLookup.HitIt;
+if (CacheLookup.HitIt)
+  It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)


Index: clang/test/Preprocessor/microsoft-header-search-fail.c
===
--- /dev/null
+++ clang/test/Preprocessor/microsoft-header-search-fail.c
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -Eonly -fms-compatibility %t/test.c -I %t/include -verify
+
+//--- test.c
+#include "x/header.h"
+#include "z/header.h"
+
+// expected-warning-re@include/y/header.h:1 {{#include resolved using non-portable Microsoft search rules as: {{.*}}/x/culprit.h}}
+// expected-error@include/z/header.h:1 {{'culprit.h' file not found}}
+
+//--- include/x/header.h
+#include "y/header.h"
+
+//--- include/y/header.h
+#include "culprit.h"
+
+//--- include/x/culprit.h
+
+//--- include/z/header.h
+#include "culprit.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -976,7 +976,8 @@
   // this is a matching hit.
   if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-It = CacheLookup.HitIt;
+if (CacheLookup.HitIt)
+  It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119721: [clang][lex] Use `ConstSearchDirIterator` in lookup cache

2022-03-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Thanks for reporting this (also reported here: 
https://github.com/llvm/llvm-project/issues/54426). I have a fix up for review 
here: D122237 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119721/new/

https://reviews.llvm.org/D119721

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121525: [clang][deps] Create lit substitution for deps-to-rsp

2022-03-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121525/new/

https://reviews.llvm.org/D121525

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122237: [clang][lex] Fix failures with Microsoft header search rules

2022-03-23 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 417527.
jansvoboda11 added a comment.

Remove slash from test to make it pass on Windows


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122237/new/

https://reviews.llvm.org/D122237

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Preprocessor/microsoft-header-search-fail.c


Index: clang/test/Preprocessor/microsoft-header-search-fail.c
===
--- /dev/null
+++ clang/test/Preprocessor/microsoft-header-search-fail.c
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -Eonly -fms-compatibility %t/test.c -I %t/include -verify
+
+//--- test.c
+#include "x/header.h"
+#include "z/header.h"
+
+// expected-warning-re@include/y/header.h:1 {{#include resolved using 
non-portable Microsoft search rules as: {{.*}}x/culprit.h}}
+// expected-error@include/z/header.h:1 {{'culprit.h' file not found}}
+
+//--- include/x/header.h
+#include "y/header.h"
+
+//--- include/y/header.h
+#include "culprit.h"
+
+//--- include/x/culprit.h
+
+//--- include/z/header.h
+#include "culprit.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -976,7 +976,8 @@
   // this is a matching hit.
   if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-It = CacheLookup.HitIt;
+if (CacheLookup.HitIt)
+  It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)


Index: clang/test/Preprocessor/microsoft-header-search-fail.c
===
--- /dev/null
+++ clang/test/Preprocessor/microsoft-header-search-fail.c
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -Eonly -fms-compatibility %t/test.c -I %t/include -verify
+
+//--- test.c
+#include "x/header.h"
+#include "z/header.h"
+
+// expected-warning-re@include/y/header.h:1 {{#include resolved using non-portable Microsoft search rules as: {{.*}}x/culprit.h}}
+// expected-error@include/z/header.h:1 {{'culprit.h' file not found}}
+
+//--- include/x/header.h
+#include "y/header.h"
+
+//--- include/y/header.h
+#include "culprit.h"
+
+//--- include/x/culprit.h
+
+//--- include/z/header.h
+#include "culprit.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -976,7 +976,8 @@
   // this is a matching hit.
   if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-It = CacheLookup.HitIt;
+if (CacheLookup.HitIt)
+  It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122237: [clang][lex] Fix failures with Microsoft header search rules

2022-03-23 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59dadd178b0b: [clang][lex] Fix failures with Microsoft 
header search rules (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122237/new/

https://reviews.llvm.org/D122237

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Preprocessor/microsoft-header-search-fail.c


Index: clang/test/Preprocessor/microsoft-header-search-fail.c
===
--- /dev/null
+++ clang/test/Preprocessor/microsoft-header-search-fail.c
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -Eonly -fms-compatibility %t/test.c -I %t/include -verify
+
+//--- test.c
+#include "x/header.h"
+#include "z/header.h"
+
+// expected-warning-re@include/y/header.h:1 {{#include resolved using 
non-portable Microsoft search rules as: {{.*}}x/culprit.h}}
+// expected-error@include/z/header.h:1 {{'culprit.h' file not found}}
+
+//--- include/x/header.h
+#include "y/header.h"
+
+//--- include/y/header.h
+#include "culprit.h"
+
+//--- include/x/culprit.h
+
+//--- include/z/header.h
+#include "culprit.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -976,7 +976,8 @@
   // this is a matching hit.
   if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-It = CacheLookup.HitIt;
+if (CacheLookup.HitIt)
+  It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)


Index: clang/test/Preprocessor/microsoft-header-search-fail.c
===
--- /dev/null
+++ clang/test/Preprocessor/microsoft-header-search-fail.c
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -Eonly -fms-compatibility %t/test.c -I %t/include -verify
+
+//--- test.c
+#include "x/header.h"
+#include "z/header.h"
+
+// expected-warning-re@include/y/header.h:1 {{#include resolved using non-portable Microsoft search rules as: {{.*}}x/culprit.h}}
+// expected-error@include/z/header.h:1 {{'culprit.h' file not found}}
+
+//--- include/x/header.h
+#include "y/header.h"
+
+//--- include/y/header.h
+#include "culprit.h"
+
+//--- include/x/culprit.h
+
+//--- include/z/header.h
+#include "culprit.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -976,7 +976,8 @@
   // this is a matching hit.
   if (!SkipCache && CacheLookup.StartIt == NextIt) {
 // Skip querying potentially lots of directories for this lookup.
-It = CacheLookup.HitIt;
+if (CacheLookup.HitIt)
+  It = CacheLookup.HitIt;
 if (CacheLookup.MappedName) {
   Filename = CacheLookup.MappedName;
   if (IsMapped)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-23 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/ClangScanDeps/cl-resource-dir.c:3
+
+// REQUIRES: shell
+

saudi wrote:
> I was wondering whether it could be a concern that this test will be skipped 
> on Windows systems, where `clang-cl` specific development would most likely 
> occur.
> 
> However I'm pretty sure it's ok, since this test is pretty simple and small, 
> has little chances to break during most development iterations, and we would 
> run the tests under linux at some point anyway.
I agree it's not great, but we need to be able to create an executable here (to 
simulate `clang -print-resource-dir`). Since Windows doesn't have the concept 
of shebangs, I don't think there's a way to make this work. I remember also 
trying to achieve this by creating a `.py` script and relying on Windows' "run 
`.py` files with the Python interpreter" rule. Unfortunately, that doesn't kick 
in when we run the command from within Clang.

This page https://llvm.org/docs/GettingStartedVS.html#software says Git for 
Windows with bash tools is required for building LLVM, so I think it's 
reasonable to expect `REQUIRES: shell` will pass for a lot of Windows 
developers. Is that not the case?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121525: [clang][deps] Create lit substitution for deps-to-rsp

2022-03-23 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26053ce05a87: [clang][deps] Create lit substitution for 
deps-to-rsp (authored by jansvoboda11).

Changed prior to commit:
  https://reviews.llvm.org/D121525?vs=414843&id=417608#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121525/new/

https://reviews.llvm.org/D121525

Files:
  clang/test/ClangScanDeps/modulemap-via-vfs.m
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch-common-submodule.c
  clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
  clang/test/ClangScanDeps/modules-pch-dangling.c
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/ClangScanDeps/modules-symlink.c
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -115,6 +115,11 @@
 ('%hmaptool', "'%s' %s" % (config.python_executable,
  os.path.join(config.clang_tools_dir, 'hmaptool'
 
+config.substitutions.append(
+('%deps-to-rsp',
+ '"%s" %s' % (config.python_executable, os.path.join(config.clang_src_dir, 'utils',
+ 'module-deps-to-rsp.py'
+
 config.substitutions.append(('%host_cc', config.host_cc))
 config.substitutions.append(('%host_cxx', config.host_cxx))
 
Index: clang/test/ClangScanDeps/modules-symlink.c
===
--- clang/test/ClangScanDeps/modules-symlink.c
+++ clang/test/ClangScanDeps/modules-symlink.c
@@ -43,10 +43,8 @@
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
 // RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result_pch.json
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=mod > %t/mod.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --tu-index=0 > %t/pch.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=mod > %t/mod.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --tu-index=0 > %t/pch.rsp
 //
 // RUN: %clang @%t/mod.cc1.rsp
 // RUN: %clang @%t/pch.rsp
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -107,14 +107,10 @@
 
 // Explicitly build the PCH:
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=ModCommon1 > %t/mod_common_1.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=ModCommon2 > %t/mod_common_2.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --module-name=ModPCH > %t/mod_pch.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_pch.json \
-// RUN:   --tu-index=0 > %t/pch.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=ModCommon1 > %t/mod_common_1.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=ModCommon2 > %t/mod_common_2.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --module-name=ModPCH > %t/mod_pch.cc1.rsp
+// RUN: %deps-to-rsp %t/result_pch.json --tu-index=0 > %t/pch.rsp
 //
 // RUN: %clang @%t/mod_common_1.cc1.rsp
 // RUN: %clang @%t/mod_common_2.cc1.rsp
@@ -173,10 +169,8 @@
 
 // Explicitly build the TU:
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu.json \
-// RUN:   --module-name=ModTU > %t/mod_tu.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu.json \
-// RUN:   --tu-index=0 > %t/tu.rsp
+// RUN: %deps-to-rsp %t/result_tu.json --module-name=ModTU > %t/mod_tu.cc1.rsp
+// RUN: %deps-to-rsp %t/result_tu.json --tu-index=0 > %t/tu.rsp
 //
 // RUN: %clang @%t/mod_tu.cc1.rsp
 // RUN: %clang @%t/tu.rsp
@@ -235,10 +229,8 @@
 
 // Explicitly build the TU that has common modules with the PCH:
 //
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu_with_common.json \
-// RUN:   --module-name=ModTUWithCommon > %t/mod_tu_with_common.cc1.rsp
-// RUN: %python %S/../../utils/module-deps-to-rsp.py %t/result_tu_with_common.json \
-// RUN:   --tu-index=0 > %t/tu_with_common.rsp
+// RUN: %deps-to-rsp %t/result_tu_with_common.json --module-name=ModTUWithCommon > %t/mod_tu_with_common.cc1.rsp
+// RUN: %deps-to-rsp %t/result_tu_with_common.json --tu-index=0 > %t/tu_with_common.rsp
 //
 // RUN: %clang @%t/mod_tu_with_common.cc1.rsp
 // RUN: %clang @%t/tu_with_common.rsp
Index: clang/test/ClangScanDeps/modules-pch-dangling.c
===
--- clang/test/ClangScanDeps/modules-pch-dangling.c
+++ clang/test/ClangScanDeps/modules-pch-dangling.c
@@ -92,25 +92,2

[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-23 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30cb49b44e4e: [clang][deps] NFC: De-duplicate clang-cl tests 
(authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

Files:
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl_by_mod_name.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/cl-output.c
  clang/test/ClangScanDeps/cl-resource-dir.c
  clang/test/ClangScanDeps/cl-xclang.c
  clang/test/ClangScanDeps/error.cpp
  clang/test/ClangScanDeps/has_include_if_elif.cpp
  clang/test/ClangScanDeps/header_stat_before_open.m
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
  clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules.cpp
  clang/test/ClangScanDeps/no-werror.cpp
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/test/ClangScanDeps/static-analyzer.c
  clang/test/ClangScanDeps/strip_diag_serialize.cpp
  clang/test/ClangScanDeps/target-filename.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp

Index: clang/test/ClangScanDeps/vfsoverlay.cpp
===
--- clang/test/ClangScanDeps/vfsoverlay.cpp
+++ clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/vfsoverlay_input.cpp
-// RUN: cp %s %t.dir/vfsoverlay_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay.yaml > %t.dir/vfsoverlay.yaml
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
@@ -16,7 +15,3 @@
 // CHECK: vfsoverlay_input.o
 // CHECK-NEXT: vfsoverlay_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}header.h
-
-// CHECK: vfsoverlay_input_clangcl.o
-// CHECK-NEXT: vfsoverlay_input_clangcl.cpp
-// CHECK-NEXT: Inputs{{/|\\}}header.h
Index: clang/test/ClangScanDeps/target-filename.cpp
===
--- clang/test/ClangScanDeps/target-filename.cpp
+++ clang/test/ClangScanDeps/target-filename.cpp
@@ -21,27 +21,3 @@
 
 // CHECK: target-filename_input.o:
 // CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-a.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-b.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-c.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-d.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-e.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastf.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lastg.o:
-// CHECK-NEXT: target-filename_input.cpp
-
-// CHECK-NEXT: clangcl-lasth.o:
-// CHECK-NEXT: target-filename_input.cpp
Index: clang/test/ClangScanDeps/strip_diag_serialize.cpp
===
--- clang/test/ClangScanDeps/strip_diag_serialize.cpp
+++ clang/test/ClangScanDeps/strip_diag_serialize.cpp
@@ -2,7 +2,6 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/strip_diag_serialize_input.cpp
-// RUN: cp %s %t.dir/strip_diag_serialize_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/strip_diag_serialize.json > %t.cdb
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 2>&1 | FileCheck %s
Index: clang/test/ClangScanDeps/static-analyzer.c
===
--- clang/test/ClangScanDeps/static-analyzer.c
+++ clang/test/ClangScanDeps/static-analyzer.c
@@ -3,7 +3,6 @@
 // RUN: mkdir -p %t.dir
 // Change file name to avoid false positives in CHECK, since "static-analyzer.c" is found in %S.
 // RUN: cp %s %t.dir/static-analyzer_clang.c
-// RUN: cp %s %t.dir/static-analyzer_clangcl.c
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/analyze_header_input.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/static-analyzer-cdb.json > %t-cdb.json
@@ -16,6 +15,3 @@
 
 // CHECK: static-analyzer_clang.c
 // CHECK-NEXT: analyze_header_input.h
-
-// CHECK: static-analyzer_clangcl.c
-// CHECK-NEXT: analyze_header_input.h
Index: clang/test/ClangScanDep

[PATCH] D123229: [clang][deps] Ensure deterministic file names on case-insensitive filesystems

2022-04-07 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 421221.
jansvoboda11 added a comment.

Windows path separators...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123229/new/

https://reviews.llvm.org/D123229

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/ClangScanDeps/header-search-case-sensitivity.c


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on 
case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 
1 | sed 's:\?:/:g' | FileCheck %s
+
+// In the reversed case, Clang starts by scanning "t2.c". When looking up the 
"arm/lower.h" header,
+// the string is appended to "DIR/dir2". That file ("DIR/dir2/arm/lower.h") 
doesn't exist, but when
+// learning so, the FileManager stats and caches the parent directory 
("DIR/dir2/arm"), using the
+// UID as the key.
+// When scanning "t1.c" later on, the "DIR/dir2/ARM" search directory is 
assigned the **same**
+// directory entry (with lowercase "arm"), since they share the UID on 
case-insensitive filesystems.
+// To preserve the correct case throughout the compiler for any file within 
that directory, it's
+// important to use the spelling actually used, not just the cached one.
+// RUN: clang-scan-deps -compilation-database=%t/cdb-rev.json -format make -j 
1 | sed 's:\?:/:g' | FileCheck %s
+
+// CHECK: ARM/upper.h
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -436,10 +436,10 @@
   SmallString<1024> TmpDir;
   if (isNormalDir()) {
 // Concatenate the requested file onto the directory.
-TmpDir = getDir()->getName();
+TmpDir = getDirRef()->getName();
 llvm::sys::path::append(TmpDir, Filename);
 if (SearchPath) {
-  StringRef SearchPathRef(getDir()->getName());
+  StringRef SearchPathRef(getDirRef()->getName());
   SearchPath->clear();
   SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
 }
Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -91,6 +91,10 @@
 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
   }
 
+  Optional getDirRef() const {
+return isNormalDir() ? Optional(u.Dir) : None;
+  }
+
   /// getFrameworkDir - Return the directory that this framework refers to.
   ///
   const DirectoryEntry *getFrameworkDir() const {


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilati

[PATCH] D123229: [clang][deps] Ensure deterministic filename case

2022-04-08 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb672638dbc7c: [clang][deps] Ensure deterministic filename 
case (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123229/new/

https://reviews.llvm.org/D123229

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/ClangScanDeps/header-search-case-sensitivity.c


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on 
case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 
1 | sed 's:\?:/:g' | FileCheck %s
+
+// In the reversed case, Clang starts by scanning "t2.c". When looking up the 
"arm/lower.h" header,
+// the string is appended to "DIR/dir2". That file ("DIR/dir2/arm/lower.h") 
doesn't exist, but when
+// learning so, the FileManager stats and caches the parent directory 
("DIR/dir2/arm"), using the
+// UID as the key.
+// When scanning "t1.c" later on, the "DIR/dir2/ARM" search directory is 
assigned the **same**
+// directory entry (with lowercase "arm"), since they share the UID on 
case-insensitive filesystems.
+// To preserve the correct case throughout the compiler for any file within 
that directory, it's
+// important to use the spelling actually used, not just the cached one.
+// RUN: clang-scan-deps -compilation-database=%t/cdb-rev.json -format make -j 
1 | sed 's:\?:/:g' | FileCheck %s
+
+// CHECK: ARM/upper.h
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -436,10 +436,10 @@
   SmallString<1024> TmpDir;
   if (isNormalDir()) {
 // Concatenate the requested file onto the directory.
-TmpDir = getDir()->getName();
+TmpDir = getDirRef()->getName();
 llvm::sys::path::append(TmpDir, Filename);
 if (SearchPath) {
-  StringRef SearchPathRef(getDir()->getName());
+  StringRef SearchPathRef(getDirRef()->getName());
   SearchPath->clear();
   SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
 }
Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -91,6 +91,10 @@
 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
   }
 
+  Optional getDirRef() const {
+return isNormalDir() ? Optional(u.Dir) : None;
+  }
+
   /// getFrameworkDir - Return the directory that this framework refers to.
   ///
   const DirectoryEntry *getFrameworkDir() const {


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.templa

[PATCH] D123574: [clang] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective

2022-04-12 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added subscribers: carlosgalvezp, usaxena95, shchenz, kadircet, 
arphaman, kbarton, nemanjai.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

This patch changes type of the `File` parameter in 
`PPCallbacks::InclusionDirective` from `const FileEntry *` to 
`Optional`. This makes it possible to remove some uses of the 
deprecated `FileEntry::getName()` (e.g. in `DependencyGraph.cpp`).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123574

Files:
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/modularize/CoverageChecker.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/PreprocessingRecord.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/CodeGen/MacroPPCallbacks.cpp
  clang/lib/CodeGen/MacroPPCallbacks.h
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/DependencyGraph.cpp
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PreprocessingRecord.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp
  clang/tools/libclang/CXIndexDataConsumer.h
  clang/tools/libclang/Indexing.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp

Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -35,9 +35,9 @@
 public:
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 this->HashLoc = HashLoc;
 this->IncludeTok = IncludeTok;
@@ -56,7 +56,7 @@
   SmallString<16> FileName;
   bool IsAngled;
   CharSourceRange FilenameRange;
-  const FileEntry* File;
+  Optional File;
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
Index: clang/tools/libclang/Indexing.cpp
===
--- clang/tools/libclang/Indexing.cpp
+++ clang/tools/libclang/Indexing.cpp
@@ -261,9 +261,9 @@
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok:

[PATCH] D123574: [clang] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 422763.
jansvoboda11 added a comment.

Rebase, apply review suggestions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123574/new/

https://reviews.llvm.org/D123574

Files:
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/modularize/CoverageChecker.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/PreprocessingRecord.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/CodeGen/MacroPPCallbacks.cpp
  clang/lib/CodeGen/MacroPPCallbacks.h
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/DependencyGraph.cpp
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PreprocessingRecord.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp
  clang/tools/libclang/CXIndexDataConsumer.h
  clang/tools/libclang/Indexing.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp

Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -35,9 +35,9 @@
 public:
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 this->HashLoc = HashLoc;
 this->IncludeTok = IncludeTok;
@@ -56,7 +56,7 @@
   SmallString<16> FileName;
   bool IsAngled;
   CharSourceRange FilenameRange;
-  const FileEntry* File;
+  Optional File;
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
Index: clang/tools/libclang/Indexing.cpp
===
--- clang/tools/libclang/Indexing.cpp
+++ clang/tools/libclang/Indexing.cpp
@@ -261,9 +261,9 @@
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
Index: clang/tools/libclang/CXIndexDataConsumer.h
===
--- clang/tools/libclang/CXIndexDataConsumer.h
+++ clang/tools/libclang/CXIndexDataConsumer.h
@@ -362,9 +362,9 @@
 
   void enteredMainFile(const FileEntry *File);
 
-  void ppIncludedFile(SourceLocation hashLoc,
-  StringRef filename, const FileEntry *File,
-

[PATCH] D123574: [clang] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 marked 3 inline comments as done.
jansvoboda11 added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp:564-565
   IncludeStructure Includes = ExpectedAST.getIncludeStructure();
-  auto MainFE = FM.getFile(testPath("foo.cpp"));
+  auto MainFE = FM.getOptionalFileRef(testPath("foo.cpp"));
   ASSERT_TRUE(MainFE);
   auto MainID = Includes.getOrCreateID(*MainFE);

dexonsmith wrote:
> It might be nice to see the errors here on failures. You could do that with:
> ```
> lang=c++
> Optional MainFE;
> ASSERT_THAT_ERROR(FM.getFileRef(testPath("foo.cpp")).moveInto(MainFE), 
> Succeeded());
> ```
> The `{EXPECT,ASSERT}_THAT_ERROR` live in `llvm/Testing/Support/Error.h`.
That's pretty sweet, thanks for the suggestion!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123574/new/

https://reviews.llvm.org/D123574

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123574: [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective()

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
jansvoboda11 marked an inline comment as done.
Closed by commit rGd79ad2f1dbc2: [clang][lex] NFCI: Use FileEntryRef in 
PPCallbacks::InclusionDirective() (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123574/new/

https://reviews.llvm.org/D123574

Files:
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/modularize/CoverageChecker.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/PreprocessingRecord.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/CodeGen/MacroPPCallbacks.cpp
  clang/lib/CodeGen/MacroPPCallbacks.h
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/DependencyGraph.cpp
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PreprocessingRecord.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp
  clang/tools/libclang/CXIndexDataConsumer.h
  clang/tools/libclang/Indexing.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp

Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -35,9 +35,9 @@
 public:
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 this->HashLoc = HashLoc;
 this->IncludeTok = IncludeTok;
@@ -56,7 +56,7 @@
   SmallString<16> FileName;
   bool IsAngled;
   CharSourceRange FilenameRange;
-  const FileEntry* File;
+  Optional File;
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
Index: clang/tools/libclang/Indexing.cpp
===
--- clang/tools/libclang/Indexing.cpp
+++ clang/tools/libclang/Indexing.cpp
@@ -261,9 +261,9 @@
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
Index: clang/tools/libclang/CXIndexDataConsumer.h
===
--- clang/tools/libclang/CXIndexDataConsumer.h
+++ clang/tools/libclang/CXIndexDataConsumer.

[PATCH] D123767: [clang][parse] NFCI: Use FileEntryRef in Parser::ParseModuleImport()

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes use of the deprecated `DirectoryEntry::getName()` from 
`Parser` by using `{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123767

Files:
  clang/lib/Parse/Parser.cpp


Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2518,8 +2518,8 @@
   // the header is parseable. Emit a warning to make the user aware.
   if (IsObjCAtImport && AtLoc.isValid()) {
 auto &SrcMgr = PP.getSourceManager();
-auto *FE = SrcMgr.getFileEntryForID(SrcMgr.getFileID(AtLoc));
-if (FE && llvm::sys::path::parent_path(FE->getDir()->getName())
+auto FE = SrcMgr.getFileEntryRefForID(SrcMgr.getFileID(AtLoc));
+if (FE && llvm::sys::path::parent_path(FE->getDir().getName())
   .endswith(".framework"))
   Diags.Report(AtLoc, diag::warn_atimport_in_framework_header);
   }


Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2518,8 +2518,8 @@
   // the header is parseable. Emit a warning to make the user aware.
   if (IsObjCAtImport && AtLoc.isValid()) {
 auto &SrcMgr = PP.getSourceManager();
-auto *FE = SrcMgr.getFileEntryForID(SrcMgr.getFileID(AtLoc));
-if (FE && llvm::sys::path::parent_path(FE->getDir()->getName())
+auto FE = SrcMgr.getFileEntryRefForID(SrcMgr.getFileID(AtLoc));
+if (FE && llvm::sys::path::parent_path(FE->getDir().getName())
   .endswith(".framework"))
   Diags.Report(AtLoc, diag::warn_atimport_in_framework_header);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123768: [clang][CodeGen] NFCI: Use FileEntryRef

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes use of the deprecated `DirectoryEntry::getName()` from 
clangCodeGen by using `{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123768

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3862,9 +3862,10 @@
 
 // The path to the source file where this module was declared
 SourceManager &SM = CGM.getContext().getSourceManager();
-const FileEntry *mainFile = SM.getFileEntryForID(SM.getMainFileID());
+Optional mainFile =
+SM.getFileEntryRefForID(SM.getMainFileID());
 std::string path =
-  (Twine(mainFile->getDir()->getName()) + "/" + mainFile->getName()).str();
+(mainFile->getDir().getName() + "/" + mainFile->getName()).str();
 module.add(MakeConstantString(path, ".objc_source_file_name"));
 module.add(symtab);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -519,8 +519,9 @@
   // a relative path, so we look into the actual file entry for the main
   // file to determine the real absolute path for the file.
   std::string MainFileDir;
-  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
-MainFileDir = std::string(MainFile->getDir()->getName());
+  if (Optional MainFile =
+  SM.getFileEntryRefForID(SM.getMainFileID())) {
+MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
   llvm::sys::path::append(MainFileDirSS, MainFileName);


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3862,9 +3862,10 @@
 
 // The path to the source file where this module was declared
 SourceManager &SM = CGM.getContext().getSourceManager();
-const FileEntry *mainFile = SM.getFileEntryForID(SM.getMainFileID());
+Optional mainFile =
+SM.getFileEntryRefForID(SM.getMainFileID());
 std::string path =
-  (Twine(mainFile->getDir()->getName()) + "/" + mainFile->getName()).str();
+(mainFile->getDir().getName() + "/" + mainFile->getName()).str();
 module.add(MakeConstantString(path, ".objc_source_file_name"));
 module.add(symtab);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -519,8 +519,9 @@
   // a relative path, so we look into the actual file entry for the main
   // file to determine the real absolute path for the file.
   std::string MainFileDir;
-  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
-MainFileDir = std::string(MainFile->getDir()->getName());
+  if (Optional MainFile =
+  SM.getFileEntryRefForID(SM.getMainFileID())) {
+MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
   llvm::sys::path::append(MainFileDirSS, MainFileName);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123769: [clang] NFCI: Use DirectoryEntryRef in collectIncludePCH

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes use of the deprecated `DirectoryEntry::getName()` from 
`collectIncludePCH` by using `{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123769

Files:
  clang/lib/Frontend/CompilerInstance.cpp


Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -232,7 +232,7 @@
 
   StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
   FileManager &FileMgr = CI.getFileManager();
-  auto PCHDir = FileMgr.getDirectory(PCHInclude);
+  auto PCHDir = FileMgr.getOptionalDirectoryRef(PCHInclude);
   if (!PCHDir) {
 MDC->addFile(PCHInclude);
 return;
@@ -240,7 +240,7 @@
 
   std::error_code EC;
   SmallString<128> DirNative;
-  llvm::sys::path::native((*PCHDir)->getName(), DirNative);
+  llvm::sys::path::native(PCHDir->getName(), DirNative);
   llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
   SimpleASTReaderListener Validator(CI.getPreprocessor());
   for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;


Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -232,7 +232,7 @@
 
   StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
   FileManager &FileMgr = CI.getFileManager();
-  auto PCHDir = FileMgr.getDirectory(PCHInclude);
+  auto PCHDir = FileMgr.getOptionalDirectoryRef(PCHInclude);
   if (!PCHDir) {
 MDC->addFile(PCHInclude);
 return;
@@ -240,7 +240,7 @@
 
   std::error_code EC;
   SmallString<128> DirNative;
-  llvm::sys::path::native((*PCHDir)->getName(), DirNative);
+  llvm::sys::path::native(PCHDir->getName(), DirNative);
   llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
   SimpleASTReaderListener Validator(CI.getPreprocessor());
   for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   6   7   8   9   10   >