[PATCH] D153670: [clang/HeaderSearch] Make sure `loadSubdirectoryModuleMaps` doesn't cause loading of regular files

2023-06-26 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG03a0f4b61ca5: [clang/HeaderSearch] Make sure 
`loadSubdirectoryModuleMaps` doesnt cause… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153670

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp


Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -239,3 +239,65 @@
   EXPECT_EQ(convert_to_slash(DepFile),
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
+
+TEST(DependencyScanner, ScanDepsWithModuleLookup) {
+  std::vector CommandLine = {
+  "clang",
+  "-target",
+  "x86_64-apple-macosx10.7",
+  "-c",
+  "test.m",
+  "-o"
+  "test.m.o",
+  "-fmodules",
+  "-I/root/SomeSources",
+  };
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string OtherPath =
+  std::string(llvm::formatv("{0}root{0}SomeSources{0}other.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.m", Sept));
+
+  VFS->addFile(OtherPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("@import 
Foo;\n"));
+
+  struct InterceptorFS : llvm::vfs::ProxyFileSystem {
+std::vector StatPaths;
+std::vector ReadFiles;
+
+InterceptorFS(IntrusiveRefCntPtr UnderlyingFS)
+: ProxyFileSystem(UnderlyingFS) {}
+
+llvm::ErrorOr status(const Twine ) override {
+  StatPaths.push_back(Path.str());
+  return ProxyFileSystem::status(Path);
+}
+
+llvm::ErrorOr>
+openFileForRead(const Twine ) override {
+  ReadFiles.push_back(Path.str());
+  return ProxyFileSystem::openFileForRead(Path);
+}
+  };
+
+  auto InterceptFS = llvm::makeIntrusiveRefCnt(VFS);
+
+  DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
+ScanningOutputFormat::Make);
+  DependencyScanningTool ScanTool(Service, InterceptFS);
+
+  // This will fail with "fatal error: module 'Foo' not found" but it doesn't
+  // matter, the point of the test is to check that files are not read
+  // unnecessarily.
+  std::string DepFile;
+  ASSERT_THAT_ERROR(
+  ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
+  llvm::Failed());
+
+  EXPECT_TRUE(llvm::find(InterceptFS->StatPaths, OtherPath) ==
+  InterceptFS->StatPaths.end());
+  EXPECT_EQ(InterceptFS->ReadFiles, std::vector{"test.m"});
+}
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1917,6 +1917,8 @@
   llvm::vfs::FileSystem  = FileMgr.getVirtualFileSystem();
   for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;
Dir != DirEnd && !EC; Dir.increment(EC)) {
+if (Dir->type() == llvm::sys::fs::file_type::regular_file)
+  continue;
 bool IsFramework = llvm::sys::path::extension(Dir->path()) == ".framework";
 if (IsFramework == SearchDir.isFramework())
   loadModuleMapFile(Dir->path(), SearchDir.isSystemHeaderDirectory(),


Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -239,3 +239,65 @@
   EXPECT_EQ(convert_to_slash(DepFile),
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
+
+TEST(DependencyScanner, ScanDepsWithModuleLookup) {
+  std::vector CommandLine = {
+  "clang",
+  "-target",
+  "x86_64-apple-macosx10.7",
+  "-c",
+  "test.m",
+  "-o"
+  "test.m.o",
+  "-fmodules",
+  "-I/root/SomeSources",
+  };
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string OtherPath =
+  std::string(llvm::formatv("{0}root{0}SomeSources{0}other.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.m", Sept));
+
+  VFS->addFile(OtherPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("@import Foo;\n"));
+
+  struct InterceptorFS : llvm::vfs::ProxyFileSystem {
+std::vector StatPaths;
+std::vector ReadFiles;
+
+InterceptorFS(IntrusiveRefCntPtr UnderlyingFS)
+: ProxyFileSystem(UnderlyingFS) {}
+
+llvm::ErrorOr status(const Twine ) override {
+  StatPaths.push_back(Path.str());
+  return 

[PATCH] D153670: [clang/HeaderSearch] Make sure `loadSubdirectoryModuleMaps` doesn't cause loading of regular files

2023-06-23 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi marked an inline comment as done.
akyrtzi added inline comments.



Comment at: clang/unittests/Tooling/DependencyScannerTest.cpp:274
+llvm::ErrorOr>
+openFileForRead(const Twine ) override {
+  ReadFiles.push_back(Path.str());

benlangmuir wrote:
> Should we add `status` override as well? I think we don't want to stat it 
> either.
Good idea, see updated patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153670

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


[PATCH] D153670: [clang/HeaderSearch] Make sure `loadSubdirectoryModuleMaps` doesn't cause loading of regular files

2023-06-23 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 534123.
akyrtzi added a comment.

For the test also check for unnecessary `stat` call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153670

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp


Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -239,3 +239,65 @@
   EXPECT_EQ(convert_to_slash(DepFile),
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
+
+TEST(DependencyScanner, ScanDepsWithModuleLookup) {
+  std::vector CommandLine = {
+  "clang",
+  "-target",
+  "x86_64-apple-macosx10.7",
+  "-c",
+  "test.m",
+  "-o"
+  "test.m.o",
+  "-fmodules",
+  "-I/root/SomeSources",
+  };
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string OtherPath =
+  std::string(llvm::formatv("{0}root{0}SomeSources{0}other.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.m", Sept));
+
+  VFS->addFile(OtherPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("@import 
Foo;\n"));
+
+  struct InterceptorFS : llvm::vfs::ProxyFileSystem {
+std::vector StatPaths;
+std::vector ReadFiles;
+
+InterceptorFS(IntrusiveRefCntPtr UnderlyingFS)
+: ProxyFileSystem(UnderlyingFS) {}
+
+llvm::ErrorOr status(const Twine ) override {
+  StatPaths.push_back(Path.str());
+  return ProxyFileSystem::status(Path);
+}
+
+llvm::ErrorOr>
+openFileForRead(const Twine ) override {
+  ReadFiles.push_back(Path.str());
+  return ProxyFileSystem::openFileForRead(Path);
+}
+  };
+
+  auto InterceptFS = llvm::makeIntrusiveRefCnt(VFS);
+
+  DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
+ScanningOutputFormat::Make);
+  DependencyScanningTool ScanTool(Service, InterceptFS);
+
+  // This will fail with "fatal error: module 'Foo' not found" but it doesn't
+  // matter, the point of the test is to check that files are not read
+  // unnecessarily.
+  std::string DepFile;
+  ASSERT_THAT_ERROR(
+  ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
+  llvm::Failed());
+
+  EXPECT_TRUE(llvm::find(InterceptFS->StatPaths, OtherPath) ==
+  InterceptFS->StatPaths.end());
+  EXPECT_EQ(InterceptFS->ReadFiles, std::vector{"test.m"});
+}
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1917,6 +1917,8 @@
   llvm::vfs::FileSystem  = FileMgr.getVirtualFileSystem();
   for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;
Dir != DirEnd && !EC; Dir.increment(EC)) {
+if (Dir->type() == llvm::sys::fs::file_type::regular_file)
+  continue;
 bool IsFramework = llvm::sys::path::extension(Dir->path()) == ".framework";
 if (IsFramework == SearchDir.isFramework())
   loadModuleMapFile(Dir->path(), SearchDir.isSystemHeaderDirectory(),


Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -239,3 +239,65 @@
   EXPECT_EQ(convert_to_slash(DepFile),
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
+
+TEST(DependencyScanner, ScanDepsWithModuleLookup) {
+  std::vector CommandLine = {
+  "clang",
+  "-target",
+  "x86_64-apple-macosx10.7",
+  "-c",
+  "test.m",
+  "-o"
+  "test.m.o",
+  "-fmodules",
+  "-I/root/SomeSources",
+  };
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string OtherPath =
+  std::string(llvm::formatv("{0}root{0}SomeSources{0}other.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.m", Sept));
+
+  VFS->addFile(OtherPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("@import Foo;\n"));
+
+  struct InterceptorFS : llvm::vfs::ProxyFileSystem {
+std::vector StatPaths;
+std::vector ReadFiles;
+
+InterceptorFS(IntrusiveRefCntPtr UnderlyingFS)
+: ProxyFileSystem(UnderlyingFS) {}
+
+llvm::ErrorOr status(const Twine ) override {
+  StatPaths.push_back(Path.str());
+  return ProxyFileSystem::status(Path);
+}
+
+llvm::ErrorOr>
+

[PATCH] D153670: [clang/HeaderSearch] Make sure `loadSubdirectoryModuleMaps` doesn't cause loading of regular files

2023-06-23 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`HeaderSearch::loadSubdirectoryModuleMaps` `stat`s all the files in a directory 
which causes the dependency scanning
service to load and cache their contents. This is problematic because a file 
may be in the process of being generated
and could be cached by the dep-scan service while it is still incomplete.

To address this change `loadSubdirectoryModuleMaps` to ignore regular files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153670

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp


Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -239,3 +239,57 @@
   EXPECT_EQ(convert_to_slash(DepFile),
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
+
+TEST(DependencyScanner, ScanDepsWithModuleLookup) {
+  std::vector CommandLine = {
+  "clang",
+  "-target",
+  "x86_64-apple-macosx10.7",
+  "-c",
+  "test.m",
+  "-o"
+  "test.m.o",
+  "-fmodules",
+  "-I/root/SomeSources",
+  };
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string OtherPath =
+  std::string(llvm::formatv("{0}root{0}SomeSources{0}other.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.m", Sept));
+
+  VFS->addFile(OtherPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("@import 
Foo;\n"));
+
+  struct InterceptorFS : llvm::vfs::ProxyFileSystem {
+std::vector ReadFiles;
+
+InterceptorFS(IntrusiveRefCntPtr UnderlyingFS)
+: ProxyFileSystem(UnderlyingFS) {}
+
+llvm::ErrorOr>
+openFileForRead(const Twine ) override {
+  ReadFiles.push_back(Path.str());
+  return ProxyFileSystem::openFileForRead(Path);
+}
+  };
+
+  auto InterceptFS = llvm::makeIntrusiveRefCnt(VFS);
+
+  DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
+ScanningOutputFormat::Make);
+  DependencyScanningTool ScanTool(Service, InterceptFS);
+
+  // This will fail with "fatal error: module 'Foo' not found" but it doesn't
+  // matter, the point of the test is to check that files are not read
+  // unnecessarily.
+  std::string DepFile;
+  ASSERT_THAT_ERROR(
+  ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
+  llvm::Failed());
+
+  EXPECT_EQ(InterceptFS->ReadFiles, std::vector{"test.m"});
+}
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1917,6 +1917,8 @@
   llvm::vfs::FileSystem  = FileMgr.getVirtualFileSystem();
   for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;
Dir != DirEnd && !EC; Dir.increment(EC)) {
+if (Dir->type() == llvm::sys::fs::file_type::regular_file)
+  continue;
 bool IsFramework = llvm::sys::path::extension(Dir->path()) == ".framework";
 if (IsFramework == SearchDir.isFramework())
   loadModuleMapFile(Dir->path(), SearchDir.isSystemHeaderDirectory(),


Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -239,3 +239,57 @@
   EXPECT_EQ(convert_to_slash(DepFile),
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
+
+TEST(DependencyScanner, ScanDepsWithModuleLookup) {
+  std::vector CommandLine = {
+  "clang",
+  "-target",
+  "x86_64-apple-macosx10.7",
+  "-c",
+  "test.m",
+  "-o"
+  "test.m.o",
+  "-fmodules",
+  "-I/root/SomeSources",
+  };
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string OtherPath =
+  std::string(llvm::formatv("{0}root{0}SomeSources{0}other.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.m", Sept));
+
+  VFS->addFile(OtherPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("@import Foo;\n"));
+
+  struct InterceptorFS : llvm::vfs::ProxyFileSystem {
+std::vector ReadFiles;
+
+InterceptorFS(IntrusiveRefCntPtr UnderlyingFS)
+: ProxyFileSystem(UnderlyingFS) {}
+
+llvm::ErrorOr>
+openFileForRead(const Twine ) override {
+  ReadFiles.push_back(Path.str());
+  return 

[PATCH] D150473: [clang/Driver] Also consider `gnu++` standard when checking for modules support

2023-05-18 Thread Argyrios Kyrtzidis 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 rG5e975d4f67c0: [clang/Driver] Also consider `gnu++` standard 
when checking for modules support (authored by akyrtzi).

Changed prior to commit:
  https://reviews.llvm.org/D150473?vs=521762=523511#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150473

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.cpp


Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -4,6 +4,7 @@
 // Check compiling a module interface to a .pcm file.
 //
 // RUN: %clang -std=c++2a -x c++-module --precompile %s -o %t/module.pcm -v 
2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
+// RUN: %clang -std=gnu++2a -x c++-module --precompile %s -o %t/module-gnu.pcm 
-v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
 //
 // CHECK-PRECOMPILE: -cc1 {{.*}} -emit-module-interface
 // CHECK-PRECOMPILE-SAME: -o {{.*}}.pcm
@@ -23,6 +24,7 @@
 //
 // RUN: %clang -std=c++2a -fmodule-file=%t/module.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 // RUN: %clang -std=c++20 -fmodule-file=%t/module.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
+// RUN: %clang -std=gnu++20 -fmodule-file=%t/module-gnu.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 //
 // CHECK-USE: -cc1 {{.*}} {{-emit-obj|-S}}
 // CHECK-USE-SAME: -fmodule-file={{.*}}.pcm
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3692,10 +3692,13 @@
   // modules support by default.
   bool HaveStdCXXModules =
   IsCXX && Std &&
-  (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
-   Std->containsValue("c++2b") || Std->containsValue("c++23") ||
-   Std->containsValue("c++2c") || Std->containsValue("c++26") ||
-   Std->containsValue("c++latest"));
+  (Std->containsValue("c++2a") || Std->containsValue("gnu++2a") ||
+   Std->containsValue("c++20") || Std->containsValue("gnu++20") ||
+   Std->containsValue("c++2b") || Std->containsValue("gnu++2b") ||
+   Std->containsValue("c++23") || Std->containsValue("gnu++23") ||
+   Std->containsValue("c++2c") || Std->containsValue("gnu++2c") ||
+   Std->containsValue("c++26") || Std->containsValue("gnu++26") ||
+   Std->containsValue("c++latest") || Std->containsValue("gnu++latest"));
   bool HaveModules = HaveStdCXXModules;
 
   // -fmodules enables the use of precompiled modules (off by default).


Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -4,6 +4,7 @@
 // Check compiling a module interface to a .pcm file.
 //
 // RUN: %clang -std=c++2a -x c++-module --precompile %s -o %t/module.pcm -v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
+// RUN: %clang -std=gnu++2a -x c++-module --precompile %s -o %t/module-gnu.pcm -v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
 //
 // CHECK-PRECOMPILE: -cc1 {{.*}} -emit-module-interface
 // CHECK-PRECOMPILE-SAME: -o {{.*}}.pcm
@@ -23,6 +24,7 @@
 //
 // RUN: %clang -std=c++2a -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 // RUN: %clang -std=c++20 -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
+// RUN: %clang -std=gnu++20 -fmodule-file=%t/module-gnu.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 //
 // CHECK-USE: -cc1 {{.*}} {{-emit-obj|-S}}
 // CHECK-USE-SAME: -fmodule-file={{.*}}.pcm
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3692,10 +3692,13 @@
   // modules support by default.
   bool HaveStdCXXModules =
   IsCXX && Std &&
-  (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
-   Std->containsValue("c++2b") || Std->containsValue("c++23") ||
-   Std->containsValue("c++2c") || Std->containsValue("c++26") ||
-   Std->containsValue("c++latest"));
+  (Std->containsValue("c++2a") || Std->containsValue("gnu++2a") ||
+   Std->containsValue("c++20") || Std->containsValue("gnu++20") ||
+   Std->containsValue("c++2b") || Std->containsValue("gnu++2b") ||
+   Std->containsValue("c++23") || Std->containsValue("gnu++23") ||
+   Std->containsValue("c++2c") || Std->containsValue("gnu++2c") ||
+   Std->containsValue("c++26") || 

[PATCH] D150473: [clang/Driver] Also consider `gnu++` standard when checking for modules support

2023-05-18 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Ping 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150473

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


[PATCH] D150473: [clang/Driver] Also consider `gnu++` standard when checking for modules support

2023-05-12 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150473

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.cpp


Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -4,6 +4,7 @@
 // Check compiling a module interface to a .pcm file.
 //
 // RUN: %clang -std=c++2a -x c++-module --precompile %s -o %t/module.pcm -v 
2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
+// RUN: %clang -std=gnu++2a -x c++-module --precompile %s -o %t/module-gnu.pcm 
-v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
 //
 // CHECK-PRECOMPILE: -cc1 {{.*}} -emit-module-interface
 // CHECK-PRECOMPILE-SAME: -o {{.*}}.pcm
@@ -23,6 +24,7 @@
 //
 // RUN: %clang -std=c++2a -fmodule-file=%t/module.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 // RUN: %clang -std=c++20 -fmodule-file=%t/module.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
+// RUN: %clang -std=gnu++20 -fmodule-file=%t/module-gnu.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 //
 // CHECK-USE: -cc1 {{.*}} {{-emit-obj|-S}}
 // CHECK-USE-SAME: -fmodule-file={{.*}}.pcm
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3672,9 +3672,11 @@
   // modules support by default.
   bool HaveStdCXXModules =
   IsCXX && Std &&
-  (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
-   Std->containsValue("c++2b") || Std->containsValue("c++23") ||
-   Std->containsValue("c++latest"));
+  (Std->containsValue("c++2a") || Std->containsValue("gnu++2a") ||
+   Std->containsValue("c++20") || Std->containsValue("gnu++20") ||
+   Std->containsValue("c++2b") || Std->containsValue("gnu++2b") ||
+   Std->containsValue("c++23") || Std->containsValue("gnu++23") ||
+   Std->containsValue("c++latest") || Std->containsValue("gnu++latest"));
   bool HaveModules = HaveStdCXXModules;
 
   // -fmodules enables the use of precompiled modules (off by default).


Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -4,6 +4,7 @@
 // Check compiling a module interface to a .pcm file.
 //
 // RUN: %clang -std=c++2a -x c++-module --precompile %s -o %t/module.pcm -v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
+// RUN: %clang -std=gnu++2a -x c++-module --precompile %s -o %t/module-gnu.pcm -v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
 //
 // CHECK-PRECOMPILE: -cc1 {{.*}} -emit-module-interface
 // CHECK-PRECOMPILE-SAME: -o {{.*}}.pcm
@@ -23,6 +24,7 @@
 //
 // RUN: %clang -std=c++2a -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 // RUN: %clang -std=c++20 -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
+// RUN: %clang -std=gnu++20 -fmodule-file=%t/module-gnu.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 //
 // CHECK-USE: -cc1 {{.*}} {{-emit-obj|-S}}
 // CHECK-USE-SAME: -fmodule-file={{.*}}.pcm
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3672,9 +3672,11 @@
   // modules support by default.
   bool HaveStdCXXModules =
   IsCXX && Std &&
-  (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
-   Std->containsValue("c++2b") || Std->containsValue("c++23") ||
-   Std->containsValue("c++latest"));
+  (Std->containsValue("c++2a") || Std->containsValue("gnu++2a") ||
+   Std->containsValue("c++20") || Std->containsValue("gnu++20") ||
+   Std->containsValue("c++2b") || Std->containsValue("gnu++2b") ||
+   Std->containsValue("c++23") || Std->containsValue("gnu++23") ||
+   Std->containsValue("c++latest") || Std->containsValue("gnu++latest"));
   bool HaveModules = HaveStdCXXModules;
 
   // -fmodules enables the use of precompiled modules (off by default).
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-30 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

`CodeGen` has the same issue:

  $ ninja 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/TargetInfo.cpp.o
  In file included from /llvm-project/clang/lib/CodeGen/TargetInfo.cpp:36:
  /llvm-project/llvm/include/llvm/TargetParser/RISCVTargetParser.h:32:10: fatal 
error: 'llvm/TargetParser/RISCVTargetParserDef.inc' file not found


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Hi @craig.topper , this patch is causing a build failure:

  In file included from /llvm-project/clang/lib/Sema/SemaType.cpp:43:
  /llvm-project/llvm/include/llvm/TargetParser/RISCVTargetParser.h:32:10: fatal 
error: 'llvm/TargetParser/RISCVTargetParserDef.inc' file not found

To reproduce, configure from a clean build directory like this:

  cmake -G Ninja /path/to/llvm-project/llvm \
-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DLLVM_ENABLE_PROJECTS="clang"

Then run:

  ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaType.cpp.o

Could you take a look? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D148369: [DependencyScanning] Canonicalize `CodeGenOptions.RelaxAll`

2023-04-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 515085.
akyrtzi added a comment.

Rebase on top of `main`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148369

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  clang/tools/clang-scan-deps/Opts.td

Index: clang/tools/clang-scan-deps/Opts.td
===
--- clang/tools/clang-scan-deps/Opts.td
+++ clang/tools/clang-scan-deps/Opts.td
@@ -33,6 +33,8 @@
 
 def verbose : F<"v", "Use verbose output">;
 
+def brief_result : F<"brief", "Use brief dependency info output">;
+
 def round_trip_args : F<"round-trip-args", "verify that command-line arguments are canonical by parsing and re-serializing">;
 
 def DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>;
\ No newline at end of file
Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -90,6 +90,7 @@
 static bool DeprecatedDriverCommand;
 static ResourceDirRecipeKind ResourceDirRecipe;
 static bool Verbose;
+static bool BriefResult;
 static std::vector CommandLine;
 
 #ifndef NDEBUG
@@ -201,6 +202,7 @@
   }
 
   Verbose = Args.hasArg(OPT_verbose);
+  BriefResult = Args.hasArg(OPT_brief_result);
 
   RoundTripArgs = Args.hasArg(OPT_round_trip_args);
 
@@ -462,6 +464,8 @@
 OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
   }
 
+  size_t getNumModules() const { return Modules.size(); }
+
 private:
   struct IndexedModuleID {
 ModuleID ID;
@@ -950,6 +954,11 @@
 if (FD && FD->roundTripCommands(llvm::errs()))
   HadErrors = true;
 
+  if (BriefResult && FD) {
+llvm::outs() << "num modules: " << FD->getNumModules() << '\n';
+return HadErrors;
+  }
+
   if (Format == ScanningOutputFormat::Full)
 FD->printFullOutput(llvm::outs());
   else if (Format == ScanningOutputFormat::P1689)
Index: clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.debug.template > %t/cdb.debug.json
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.release.template > %t/cdb.release.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.debug.json -format=experimental-full -brief | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.release.json -format=experimental-full -brief | FileCheck %s
+// CHECK: num modules: 1
+
+//--- cdb.json.debug.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -O0 -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -O0 -g"
+}]
+//--- cdb.json.release.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -Os -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -Os -g"
+}]
+
+//--- include/module.modulemap
+module Top { header "top.h" }
+//--- include/top.h
+#define TOP int
+//--- tu.c
+#include "top.h"
+TOP fn(void);
+//--- tu.prefix.h
+#include "top.h"
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -102,6 +102,7 @@
 CI.getCodeGenOpts().CoverageCompilationDir.clear();
 CI.getCodeGenOpts().CoverageDataFile.clear();
 CI.getCodeGenOpts().CoverageNotesFile.clear();
+CI.getCodeGenOpts().RelaxAll = false;
   }
 
   // Map output paths that affect behaviour to "-" so their existence is in the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148369: [DependencyScanning] Canonicalize `CodeGenOptions.RelaxAll`

2023-04-17 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:905
+  if (BriefResult) {
+llvm::outs() << "num modules: " << FD->getNumModules() << '\n';
+return HadErrors;

jansvoboda11 wrote:
> akyrtzi wrote:
> > jansvoboda11 wrote:
> > > This assumes `FD` is not empty, i.e. the `-format experimental-full` 
> > > argument. We should probably error out early if that's not the case.
> > > 
> > > WDYT about changing the new `-brief` flag into something like `-format 
> > > experimental-brief`? We could avoid the dependency between arguments and 
> > > we'd also make it clear the `make` and `p1689` don't have a brief variant.
> > > This assumes FD is not empty,
> > 
> > Ah, good catch! I'll fix.
> > 
> > > WDYT about changing the new -brief flag into something like -format 
> > > experimental-brief? 
> > 
> > I consider `-brief` orthogonal to the format kind, there's no reason we 
> > can't have brief versions of the other formats.
> > I consider `-brief` orthogonal to the format kind, there's no reason we 
> > can't have brief versions of the other formats.
> 
> How would a brief make or P1689 output look like?
`make` could print the number of file dependencies and `P1689` maybe also 
prints the number of modules (I'm not familiar with that).

In [the apple 
fork](https://github.com/apple/llvm-project/blob/871776e79523b121f3a0d0b06cf582092445369f/clang/tools/clang-scan-deps/ClangScanDeps.cpp#L145)
 there are additional formats added that would have the same `-brief` output as 
in this patch, without any changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148369

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


[PATCH] D147815: [clang][deps] Print timing information

2023-04-15 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

> Could you also add a -terse option, to avoid printing the full dependency info

Note I added something like this in https://reviews.llvm.org/D148369, so ignore 
it for this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147815

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


[PATCH] D148369: [DependencyScanning] Canonicalize `CodeGenOptions.RelaxAll`

2023-04-14 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 513828.
akyrtzi added a comment.

Remove `-optimize-args` from the test invocations since it's not relevant for 
the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148369

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/shared-module-for-tu-and-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
@@ -226,6 +226,12 @@
 llvm::cl::init(false),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt
+BriefResult("brief", llvm::cl::Optional,
+llvm::cl::desc("Use brief dependency info output."),
+llvm::cl::init(false),
+llvm::cl::cat(DependencyScannerCategory));
+
 } // end anonymous namespace
 
 /// Takes the result of a dependency scan and prints error / dependency files
@@ -402,6 +408,8 @@
 OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
   }
 
+  size_t getNumModules() const { return Modules.size(); }
+
 private:
   struct IndexedModuleID {
 ModuleID ID;
@@ -893,6 +901,11 @@
 if (FD && FD->roundTripCommands(llvm::errs()))
   HadErrors = true;
 
+  if (BriefResult && FD) {
+llvm::outs() << "num modules: " << FD->getNumModules() << '\n';
+return HadErrors;
+  }
+
   if (Format == ScanningOutputFormat::Full)
 FD->printFullOutput(llvm::outs());
   else if (Format == ScanningOutputFormat::P1689)
Index: clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.debug.template > %t/cdb.debug.json
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.release.template > %t/cdb.release.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.debug.json 
-format=experimental-full -brief | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.release.json 
-format=experimental-full -brief | FileCheck %s
+// CHECK: num modules: 1
+
+//--- cdb.json.debug.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules 
-fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -O0 -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules 
-gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o 
DIR/tu.pch -O0 -g"
+}]
+//--- cdb.json.release.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules 
-fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -Os -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules 
-gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o 
DIR/tu.pch -Os -g"
+}]
+
+//--- include/module.modulemap
+module Top { header "top.h" }
+//--- include/top.h
+#define TOP int
+//--- tu.c
+#include "top.h"
+TOP fn(void);
+//--- tu.prefix.h
+#include "top.h"
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -102,6 +102,7 @@
 CI.getCodeGenOpts().CoverageCompilationDir.clear();
 CI.getCodeGenOpts().CoverageDataFile.clear();
 CI.getCodeGenOpts().CoverageNotesFile.clear();
+CI.getCodeGenOpts().RelaxAll = false;
   }
 
   // Map output paths that affect behaviour to "-" so their existence is in the


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -226,6 +226,12 @@
 llvm::cl::init(false),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt
+BriefResult("brief", llvm::cl::Optional,
+llvm::cl::desc("Use brief dependency info output."),
+llvm::cl::init(false),
+llvm::cl::cat(DependencyScannerCategory));
+
 } // end anonymous namespace
 
 /// Takes the result of a dependency scan and prints error / dependency files
@@ -402,6 +408,8 @@
 OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
   }
 
+  size_t getNumModules() const { return 

[PATCH] D148369: [DependencyScanning] Canonicalize `CodeGenOptions.RelaxAll`

2023-04-14 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 513751.
akyrtzi added a comment.

Make sure to check `FD` is valid.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148369

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/shared-module-for-tu-and-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
@@ -226,6 +226,12 @@
 llvm::cl::init(false),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt
+BriefResult("brief", llvm::cl::Optional,
+llvm::cl::desc("Use brief dependency info output."),
+llvm::cl::init(false),
+llvm::cl::cat(DependencyScannerCategory));
+
 } // end anonymous namespace
 
 /// Takes the result of a dependency scan and prints error / dependency files
@@ -402,6 +408,8 @@
 OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
   }
 
+  size_t getNumModules() const { return Modules.size(); }
+
 private:
   struct IndexedModuleID {
 ModuleID ID;
@@ -893,6 +901,11 @@
 if (FD && FD->roundTripCommands(llvm::errs()))
   HadErrors = true;
 
+  if (BriefResult && FD) {
+llvm::outs() << "num modules: " << FD->getNumModules() << '\n';
+return HadErrors;
+  }
+
   if (Format == ScanningOutputFormat::Full)
 FD->printFullOutput(llvm::outs());
   else if (Format == ScanningOutputFormat::P1689)
Index: clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.debug.template > %t/cdb.debug.json
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.release.template > %t/cdb.release.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.debug.json 
-format=experimental-full -optimize-args -brief | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.release.json 
-format=experimental-full -optimize-args -brief | FileCheck %s
+// CHECK: num modules: 1
+
+//--- cdb.json.debug.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules 
-fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -O0 -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules 
-gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o 
DIR/tu.pch -O0 -g"
+}]
+//--- cdb.json.release.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules 
-fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -Os -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules 
-gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o 
DIR/tu.pch -Os -g"
+}]
+
+//--- include/module.modulemap
+module Top { header "top.h" }
+//--- include/top.h
+#define TOP int
+//--- tu.c
+#include "top.h"
+TOP fn(void);
+//--- tu.prefix.h
+#include "top.h"
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -102,6 +102,7 @@
 CI.getCodeGenOpts().CoverageCompilationDir.clear();
 CI.getCodeGenOpts().CoverageDataFile.clear();
 CI.getCodeGenOpts().CoverageNotesFile.clear();
+CI.getCodeGenOpts().RelaxAll = false;
   }
 
   // Map output paths that affect behaviour to "-" so their existence is in the


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -226,6 +226,12 @@
 llvm::cl::init(false),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt
+BriefResult("brief", llvm::cl::Optional,
+llvm::cl::desc("Use brief dependency info output."),
+llvm::cl::init(false),
+llvm::cl::cat(DependencyScannerCategory));
+
 } // end anonymous namespace
 
 /// Takes the result of a dependency scan and prints error / dependency files
@@ -402,6 +408,8 @@
 OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
   }
 
+  size_t getNumModules() const { return Modules.size(); }
+
 private:
 

[PATCH] D148369: [DependencyScanning] Canonicalize `CodeGenOptions.RelaxAll`

2023-04-14 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:905
+  if (BriefResult) {
+llvm::outs() << "num modules: " << FD->getNumModules() << '\n';
+return HadErrors;

jansvoboda11 wrote:
> This assumes `FD` is not empty, i.e. the `-format experimental-full` 
> argument. We should probably error out early if that's not the case.
> 
> WDYT about changing the new `-brief` flag into something like `-format 
> experimental-brief`? We could avoid the dependency between arguments and we'd 
> also make it clear the `make` and `p1689` don't have a brief variant.
> This assumes FD is not empty,

Ah, good catch! I'll fix.

> WDYT about changing the new -brief flag into something like -format 
> experimental-brief? 

I consider `-brief` orthogonal to the format kind, there's no reason we can't 
have brief versions of the other formats.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148369

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


[PATCH] D148369: [DependencyScanning] Canonicalize `CodeGenOptions.RelaxAll`

2023-04-14 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is particularly useful to avoid diverging the modules between a PCH and a 
translation-unit compilation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148369

Files:
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/shared-module-for-tu-and-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
@@ -226,6 +226,12 @@
 llvm::cl::init(false),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt
+BriefResult("brief", llvm::cl::Optional,
+llvm::cl::desc("Use brief dependency info output."),
+llvm::cl::init(false),
+llvm::cl::cat(DependencyScannerCategory));
+
 } // end anonymous namespace
 
 /// Takes the result of a dependency scan and prints error / dependency files
@@ -402,6 +408,8 @@
 OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
   }
 
+  size_t getNumModules() const { return Modules.size(); }
+
 private:
   struct IndexedModuleID {
 ModuleID ID;
@@ -893,6 +901,11 @@
 if (FD && FD->roundTripCommands(llvm::errs()))
   HadErrors = true;
 
+  if (BriefResult) {
+llvm::outs() << "num modules: " << FD->getNumModules() << '\n';
+return HadErrors;
+  }
+
   if (Format == ScanningOutputFormat::Full)
 FD->printFullOutput(llvm::outs());
   else if (Format == ScanningOutputFormat::P1689)
Index: clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.debug.template > %t/cdb.debug.json
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.release.template > %t/cdb.release.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.debug.json 
-format=experimental-full -optimize-args -brief | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.release.json 
-format=experimental-full -optimize-args -brief | FileCheck %s
+// CHECK: num modules: 1
+
+//--- cdb.json.debug.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules 
-fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -O0 -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules 
-gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o 
DIR/tu.pch -O0 -g"
+}]
+//--- cdb.json.release.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules 
-fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -Os -g"
+},
+{
+  "directory": "DIR",
+  "file": "DIR/tu.prefix.h",
+  "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules 
-gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o 
DIR/tu.pch -Os -g"
+}]
+
+//--- include/module.modulemap
+module Top { header "top.h" }
+//--- include/top.h
+#define TOP int
+//--- tu.c
+#include "top.h"
+TOP fn(void);
+//--- tu.prefix.h
+#include "top.h"
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -102,6 +102,7 @@
 CI.getCodeGenOpts().CoverageCompilationDir.clear();
 CI.getCodeGenOpts().CoverageDataFile.clear();
 CI.getCodeGenOpts().CoverageNotesFile.clear();
+CI.getCodeGenOpts().RelaxAll = false;
   }
 
   // Map output paths that affect behaviour to "-" so their existence is in the


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -226,6 +226,12 @@
 llvm::cl::init(false),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::opt
+BriefResult("brief", llvm::cl::Optional,
+llvm::cl::desc("Use brief dependency info output."),
+llvm::cl::init(false),
+llvm::cl::cat(DependencyScannerCategory));
+
 } // end anonymous namespace
 
 /// Takes the result of a dependency scan and prints error / dependency files
@@ -402,6 +408,8 @@
 OS << llvm::formatv("{0:2}\n", 

[PATCH] D147815: [clang][deps] Print timing information

2023-04-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Could you also add a `-terse` option, to avoid printing the full dependency 
info, if you mainly want to get the timing? Something like this:

  T.stopTimer();
  if (PrintTiming)
llvm::errs() << llvm::format(
"clang-scan-deps timing: %0.2fs wall, %0.2fs process\n",
T.getTotalTime().getWallTime(), T.getTotalTime().getProcessTime());
  
  if (Terse) {
if (Format == ScanningOutputFormat::Full ||
   Format == ScanningOutputFormat::FullTree ||
   Format == ScanningOutputFormat::FullIncludeTree) {
  llvm::errs() << "num modules: " << FD->getNumModules() << '\n';
}
  
return HadErrors;
  }

Where `getNumModules()` is

  size_t getNumModules() const {
return Modules.size();
  }

So you still get some very high-level info but not the whole dump of info.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147815

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-03-13 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a subscriber: bnbarham.
akyrtzi added inline comments.



Comment at: clang/lib/Index/USRGeneration.cpp:1032
+  case TemplateArgument::UncommonValue:
+// FIXME: Visit value.
+break;

erichkeane wrote:
> bolshakov-a wrote:
> > aaron.ballman wrote:
> > > Any particular reason this isn't being handled now?
> > I need some guidance here. Which characters are allowed in the USR? Could 
> > the mangling algorithm from `CXXNameMangler::mangleValueInTemplateArg` be 
> > moved into some common place and reused here?
> I have no idea what is valid here.  BUT @akyrtzi and @gribozavr (or 
> @gribozavr2 ?) seem to be the ones that touch these files the most?
Adding @bnbarham to review the `Index` changes.


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

https://reviews.llvm.org/D140996

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


[PATCH] D145473: [test/ARCMT/verify.m] Add lit test for `5e035651fd3acbb2645abbe80cae332d90eac78a` commit

2023-03-07 Thread Argyrios Kyrtzidis 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 rGb3283bf192c6: [test/ARCMT/verify.m] Add lit test for 
`5e035651fd3acbb2645abbe80cae332d90eac78… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145473

Files:
  clang/test/ARCMT/verify.m


Index: clang/test/ARCMT/verify.m
===
--- clang/test/ARCMT/verify.m
+++ clang/test/ARCMT/verify.m
@@ -8,6 +8,9 @@
 #error should not be ignored
 // expected-error@-1 {{should not be ignored}}
 
+#error
+// expected-error@-1 {{}}
+
 //  CHECK: error: no expected directives found: consider use of 
'expected-no-diagnostics'
 // CHECK-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'


Index: clang/test/ARCMT/verify.m
===
--- clang/test/ARCMT/verify.m
+++ clang/test/ARCMT/verify.m
@@ -8,6 +8,9 @@
 #error should not be ignored
 // expected-error@-1 {{should not be ignored}}
 
+#error
+// expected-error@-1 {{}}
+
 //  CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
 // CHECK-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145256: [clang/Diagnostic] Use `optional` to disambiguate between a `StoredDiagMessage` that is not set vs set as empty string

2023-03-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

> Is this observable from a clang command line tool? Be nice to have a lit test.

Added lit test here: https://reviews.llvm.org/D145473


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145256

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


[PATCH] D145473: [test/ARCMT/verify.m] Add lit test for `5e035651fd3acbb2645abbe80cae332d90eac78a` commit

2023-03-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145473

Files:
  clang/test/ARCMT/verify.m


Index: clang/test/ARCMT/verify.m
===
--- clang/test/ARCMT/verify.m
+++ clang/test/ARCMT/verify.m
@@ -8,6 +8,9 @@
 #error should not be ignored
 // expected-error@-1 {{should not be ignored}}
 
+#error
+// expected-error@-1 {{}}
+
 //  CHECK: error: no expected directives found: consider use of 
'expected-no-diagnostics'
 // CHECK-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'


Index: clang/test/ARCMT/verify.m
===
--- clang/test/ARCMT/verify.m
+++ clang/test/ARCMT/verify.m
@@ -8,6 +8,9 @@
 #error should not be ignored
 // expected-error@-1 {{should not be ignored}}
 
+#error
+// expected-error@-1 {{}}
+
 //  CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
 // CHECK-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145256: [clang/Diagnostic] Use `optional` to disambiguate between a `StoredDiagMessage` that is not set vs set as empty string

2023-03-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e035651fd3a: [clang/Diagnostic] Use `optional` to 
disambiguate between a `StoredDiagMessage`… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145256

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/unittests/Basic/DiagnosticTest.cpp


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,26 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions);
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic ) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl ) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,26 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions);
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic ) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl ) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}

[PATCH] D145256: [clang/Diagnostic] Use `optional` to disambiguate between a `StoredDiagMessage` that is not set vs set as empty string

2023-03-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 502201.
akyrtzi added a comment.

Avoid passing a new `IgnoringDiagConsumer` for the test since it's unused.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145256

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/unittests/Basic/DiagnosticTest.cpp


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,26 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions);
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic ) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl ) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,26 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions);
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic ) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl ) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}
___
cfe-commits mailing 

[PATCH] D145256: [clang/Diagnostic] Use `optional` to disambiguate between a `StoredDiagMessage` that is not set vs set as empty string

2023-03-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

"But when would you have a completely empty diagnostic message", you ask dear 
reader?
That is when there is an empty "#warning" in code.

rdar://106155415


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145256

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/unittests/Basic/DiagnosticTest.cpp


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,27 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic ) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl ) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const DiagnosticsEngine *DiagObj;
-  StringRef StoredDiagMessage;
+  std::optional StoredDiagMessage;
 
 public:
   explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}


Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticError.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticLex.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -128,4 +129,27 @@
   EXPECT_EQ(*Value, std::make_pair(20, 1));
   EXPECT_EQ(Value->first, 20);
 }
+
+TEST(DiagnosticTest, storedDiagEmptyWarning) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+SmallVector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic ) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+
+  CaptureDiagnosticConsumer CaptureConsumer;
+  Diags.setClient(, /*ShouldOwnClient=*/false);
+  Diags.Report(diag::pp_hash_warning) << "";
+  ASSERT_TRUE(CaptureConsumer.StoredDiags.size() == 1);
+
+  // Make sure an empty warning can round-trip with \c StoredDiagnostic.
+  Diags.Report(CaptureConsumer.StoredDiags.front());
+}
 }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -793,8 +793,8 @@
 /// array.
 void Diagnostic::
 FormatDiagnostic(SmallVectorImpl ) const {
-  if (!StoredDiagMessage.empty()) {
-OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+  if (StoredDiagMessage.has_value()) {
+OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
 return;
   }
 
Index: clang/include/clang/Basic/Diagnostic.h
===
--- clang/include/clang/Basic/Diagnostic.h
+++ clang/include/clang/Basic/Diagnostic.h
@@ -1565,7 +1565,7 @@
 /// currently in-flight diagnostic.
 class Diagnostic {
   const 

[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-02-08 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D141910#4112144 , @domada wrote:

> @akyrtzi Thank you for your feedback. Can I land the patch?

Fine be me.


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

https://reviews.llvm.org/D141910

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


[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-02-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D141910#4111048 , @domada wrote:

> Added changes in `clang/lib/AST/CMakeLists.txt` to address build issue 
> reported by @akyrtzi .
>
> I modified CMakeLists.txt so that it requires generation of missing 
> `Attributes.inc`.
>
> @akyrtzi  Please let me know if it solves your issue

This fixes the build issue , thank you!


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

https://reviews.llvm.org/D141910

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


[PATCH] D143461: [ClangScanDeps] Fix data race in `clang-scan-deps` tool

2023-02-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi abandoned this revision.
akyrtzi added a comment.

In D143461#4110405 , @benlangmuir 
wrote:

> Dupe of https://reviews.llvm.org/D143428 ?

Indeed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143461

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


[PATCH] D143461: [ClangScanDeps] Fix data race in `clang-scan-deps` tool

2023-02-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Found using TSan.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143461

Files:
  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
@@ -260,6 +260,8 @@
 mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);
 ID.DriverCommandLine = std::move(TUDeps.DriverCommandLine);
 ID.Commands = std::move(TUDeps.Commands);
+
+std::unique_lock ul(Lock);
 Inputs.push_back(std::move(ID));
   }
 


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -260,6 +260,8 @@
 mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);
 ID.DriverCommandLine = std::move(TUDeps.DriverCommandLine);
 ID.Commands = std::move(TUDeps.Commands);
+
+std::unique_lock ul(Lock);
 Inputs.push_back(std::move(ID));
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141625: [DeclContext] Sort the Decls before adding into DeclContext

2023-02-02 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

> would be great to test it more in a semantic way if possible

Keep in mind that the specific order of the decls doesn't matter for the 
purposes of this test, what matters is that the order is the same every time 
for the same input.

I personally think that the addition of "Spot check entries to make sure they 
are in current ordering" is counter-productive, because if later on some clang 
changes end up changing the order then the test will fail, and will need 
update, but that it is not what the test should care about, it should only fail 
if the order is non-deterministic.
But I don't feel strongly about it, I'm fine with adding the ordered check even 
though I don't think it's a good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141625

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


[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-01-31 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

I've reverted this change from `main` branch, let me know if there's anything I 
can do to help with addressing the build issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141910

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


[PATCH] D141910: [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend

2023-01-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Hi @domada, these changes break compilation of clang, with such build error:

  FAILED: tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o 
  
  In file included from /llvm-project/clang/lib/AST/ASTContext.cpp:81:
  In file included from 
/llvm-project/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:17:
  In file included from 
/llvm-project/llvm/include/llvm/Analysis/MemorySSAUpdater.h:37:
  In file included from /llvm-project/llvm/include/llvm/Analysis/MemorySSA.h:93:
  In file included from 
/llvm-project/llvm/include/llvm/Analysis/AliasAnalysis.h:44:
  In file included from /llvm-project/llvm/include/llvm/IR/PassManager.h:45:
  In file included from /llvm-project/llvm/include/llvm/IR/Function.h:25:
  In file included from /llvm-project/llvm/include/llvm/IR/Argument.h:17:
  /llvm-project/llvm/include/llvm/IR/Attributes.h:90:14: fatal error: 
'llvm/IR/Attributes.inc' file not found

Reproduction steps:

1. Configure to build clang using `ninja`:

  cmake -G Ninja /path/to/llvm-project/llvm \
-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DLLVM_ENABLE_PROJECTS="clang"

2. Build `ASTContext.cpp.o` with a clean build directory.

  ninja clean && ninja 
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/ASTContext.cpp.o

Are you able to take a look? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141910

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


[PATCH] D142238: [clang/CodeGenActionTest] Use the platform's path separator for the `DebugInfoCWDCodeGen` test

2023-01-20 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2b078adc2d0: [clang/CodeGenActionTest] Use the 
platforms path separator for the… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142238

Files:
  clang/unittests/Frontend/CodeGenActionTest.cpp


Index: clang/unittests/Frontend/CodeGenActionTest.cpp
===
--- clang/unittests/Frontend/CodeGenActionTest.cpp
+++ clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -82,9 +82,10 @@
   // Check that debug info is accessing the current working directory from the
   // VFS instead of calling \p llvm::sys::fs::current_path() directly.
 
-  auto VFS = std::make_unique();
-  VFS->setCurrentWorkingDirectory("/in-memory-fs-cwd");
   auto Sept = llvm::sys::path::get_separator();
+  auto VFS = std::make_unique();
+  VFS->setCurrentWorkingDirectory(
+  std::string(llvm::formatv("{0}in-memory-fs-cwd", Sept)));
   std::string TestPath =
   std::string(llvm::formatv("{0}in-memory-fs-cwd{0}test.cpp", Sept));
   VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("int x;\n"));


Index: clang/unittests/Frontend/CodeGenActionTest.cpp
===
--- clang/unittests/Frontend/CodeGenActionTest.cpp
+++ clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -82,9 +82,10 @@
   // Check that debug info is accessing the current working directory from the
   // VFS instead of calling \p llvm::sys::fs::current_path() directly.
 
-  auto VFS = std::make_unique();
-  VFS->setCurrentWorkingDirectory("/in-memory-fs-cwd");
   auto Sept = llvm::sys::path::get_separator();
+  auto VFS = std::make_unique();
+  VFS->setCurrentWorkingDirectory(
+  std::string(llvm::formatv("{0}in-memory-fs-cwd", Sept)));
   std::string TestPath =
   std::string(llvm::formatv("{0}in-memory-fs-cwd{0}test.cpp", Sept));
   VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("int x;\n"));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142236: [clang/driver] Add `-gno-modules` as the negative version of `-gmodules`

2023-01-20 Thread Argyrios Kyrtzidis 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 rG1ff8a687ae15: [clang/driver] Add `-gno-modules` as the 
negative version of `-gmodules` (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142236

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -300,6 +300,9 @@
 // RUN: %clang -### -target %itanium_abi_triple -gmodules 
-gline-directives-only %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GLIO_ONLY %s
 //
+// RUN: %clang -### -gmodules -gno-modules %s 2>&1 \
+// RUN:| FileCheck -check-prefix=NOGEXTREFS %s
+//
 // NOG_PS: "-cc1"
 // NOG_PS-NOT: "-dwarf-version=
 // NOG_PS: "-generate-arange-section"
@@ -407,6 +410,7 @@
 //
 // GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj"
 // GEXTREFS: "-debug-info-kind={{standalone|constructor}}"
+// NOGEXTREFS-NOT: -dwarf-ext-refs
 
 // RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck 
-check-prefix=BADSTRING1 %s
 // BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4219,9 +4219,11 @@
 CmdArgs.push_back("-gno-column-info");
 
   // FIXME: Move backend command line options to the module.
-  // If -gline-tables-only or -gline-directives-only is the last option it 
wins.
-  if (const Arg *A = Args.getLastArg(options::OPT_gmodules))
-if (checkDebugInfoOption(A, Args, D, TC)) {
+  if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules, false)) {
+// If -gline-tables-only or -gline-directives-only is the last option it
+// wins.
+if (checkDebugInfoOption(Args.getLastArg(options::OPT_gmodules), Args, D,
+ TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
 DebugInfoKind = codegenoptions::DebugInfoConstructor;
@@ -4229,6 +4231,7 @@
 CmdArgs.push_back("-fmodule-format=obj");
   }
 }
+  }
 
   if (T.isOSBinFormatELF() && SplitDWARFInlining)
 CmdArgs.push_back("-fsplit-dwarf-inlining");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3292,6 +3292,7 @@
 def gmodules : Flag <["-"], "gmodules">, Group,
   HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
+def gno_modules : Flag <["-"], "gno-modules">, Group;
 def gz_EQ : Joined<["-"], "gz=">, Group,
 HelpText<"DWARF debug sections compression type">;
 def gz : Flag<["-"], "gz">, Alias, AliasArgs<["zlib"]>, 
Group;


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -300,6 +300,9 @@
 // RUN: %clang -### -target %itanium_abi_triple -gmodules -gline-directives-only %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GLIO_ONLY %s
 //
+// RUN: %clang -### -gmodules -gno-modules %s 2>&1 \
+// RUN:| FileCheck -check-prefix=NOGEXTREFS %s
+//
 // NOG_PS: "-cc1"
 // NOG_PS-NOT: "-dwarf-version=
 // NOG_PS: "-generate-arange-section"
@@ -407,6 +410,7 @@
 //
 // GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj"
 // GEXTREFS: "-debug-info-kind={{standalone|constructor}}"
+// NOGEXTREFS-NOT: -dwarf-ext-refs
 
 // RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
 // BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4219,9 +4219,11 @@
 CmdArgs.push_back("-gno-column-info");
 
   // FIXME: Move backend command line options to the module.
-  // If -gline-tables-only or -gline-directives-only is the last option it wins.
-  if (const Arg *A = Args.getLastArg(options::OPT_gmodules))
-if (checkDebugInfoOption(A, Args, D, TC)) {
+  if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules, false)) {
+// If -gline-tables-only or -gline-directives-only is the last option it
+// wins.
+if (checkDebugInfoOption(Args.getLastArg(options::OPT_gmodules), Args, D,
+ TC)) {
   if (DebugInfoKind != 

[PATCH] D142238: [clang/CodeGenActionTest] Use the platform's path separator for the `DebugInfoCWDCodeGen` test

2023-01-20 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes a failure in some Windows configuration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142238

Files:
  clang/unittests/Frontend/CodeGenActionTest.cpp


Index: clang/unittests/Frontend/CodeGenActionTest.cpp
===
--- clang/unittests/Frontend/CodeGenActionTest.cpp
+++ clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -82,9 +82,10 @@
   // Check that debug info is accessing the current working directory from the
   // VFS instead of calling \p llvm::sys::fs::current_path() directly.
 
-  auto VFS = std::make_unique();
-  VFS->setCurrentWorkingDirectory("/in-memory-fs-cwd");
   auto Sept = llvm::sys::path::get_separator();
+  auto VFS = std::make_unique();
+  VFS->setCurrentWorkingDirectory(
+  std::string(llvm::formatv("{0}in-memory-fs-cwd", Sept)));
   std::string TestPath =
   std::string(llvm::formatv("{0}in-memory-fs-cwd{0}test.cpp", Sept));
   VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("int x;\n"));


Index: clang/unittests/Frontend/CodeGenActionTest.cpp
===
--- clang/unittests/Frontend/CodeGenActionTest.cpp
+++ clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -82,9 +82,10 @@
   // Check that debug info is accessing the current working directory from the
   // VFS instead of calling \p llvm::sys::fs::current_path() directly.
 
-  auto VFS = std::make_unique();
-  VFS->setCurrentWorkingDirectory("/in-memory-fs-cwd");
   auto Sept = llvm::sys::path::get_separator();
+  auto VFS = std::make_unique();
+  VFS->setCurrentWorkingDirectory(
+  std::string(llvm::formatv("{0}in-memory-fs-cwd", Sept)));
   std::string TestPath =
   std::string(llvm::formatv("{0}in-memory-fs-cwd{0}test.cpp", Sept));
   VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("int x;\n"));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142236: [clang/driver] Add `-gno-modules` as the negative version of `-gmodules`

2023-01-20 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142236

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -300,6 +300,9 @@
 // RUN: %clang -### -target %itanium_abi_triple -gmodules 
-gline-directives-only %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GLIO_ONLY %s
 //
+// RUN: %clang -### -gmodules -gno-modules %s 2>&1 \
+// RUN:| FileCheck -check-prefix=NOGEXTREFS %s
+//
 // NOG_PS: "-cc1"
 // NOG_PS-NOT: "-dwarf-version=
 // NOG_PS: "-generate-arange-section"
@@ -407,6 +410,7 @@
 //
 // GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj"
 // GEXTREFS: "-debug-info-kind={{standalone|constructor}}"
+// NOGEXTREFS-NOT: -dwarf-ext-refs
 
 // RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck 
-check-prefix=BADSTRING1 %s
 // BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4219,9 +4219,11 @@
 CmdArgs.push_back("-gno-column-info");
 
   // FIXME: Move backend command line options to the module.
-  // If -gline-tables-only or -gline-directives-only is the last option it 
wins.
-  if (const Arg *A = Args.getLastArg(options::OPT_gmodules))
-if (checkDebugInfoOption(A, Args, D, TC)) {
+  if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules, false)) {
+// If -gline-tables-only or -gline-directives-only is the last option it
+// wins.
+if (checkDebugInfoOption(Args.getLastArg(options::OPT_gmodules), Args, D,
+ TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
 DebugInfoKind = codegenoptions::DebugInfoConstructor;
@@ -4229,6 +4231,7 @@
 CmdArgs.push_back("-fmodule-format=obj");
   }
 }
+  }
 
   if (T.isOSBinFormatELF() && SplitDWARFInlining)
 CmdArgs.push_back("-fsplit-dwarf-inlining");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3292,6 +3292,7 @@
 def gmodules : Flag <["-"], "gmodules">, Group,
   HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
+def gno_modules : Flag <["-"], "gno-modules">, Group;
 def gz_EQ : Joined<["-"], "gz=">, Group,
 HelpText<"DWARF debug sections compression type">;
 def gz : Flag<["-"], "gz">, Alias, AliasArgs<["zlib"]>, 
Group;


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -300,6 +300,9 @@
 // RUN: %clang -### -target %itanium_abi_triple -gmodules -gline-directives-only %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GLIO_ONLY %s
 //
+// RUN: %clang -### -gmodules -gno-modules %s 2>&1 \
+// RUN:| FileCheck -check-prefix=NOGEXTREFS %s
+//
 // NOG_PS: "-cc1"
 // NOG_PS-NOT: "-dwarf-version=
 // NOG_PS: "-generate-arange-section"
@@ -407,6 +410,7 @@
 //
 // GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj"
 // GEXTREFS: "-debug-info-kind={{standalone|constructor}}"
+// NOGEXTREFS-NOT: -dwarf-ext-refs
 
 // RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
 // BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4219,9 +4219,11 @@
 CmdArgs.push_back("-gno-column-info");
 
   // FIXME: Move backend command line options to the module.
-  // If -gline-tables-only or -gline-directives-only is the last option it wins.
-  if (const Arg *A = Args.getLastArg(options::OPT_gmodules))
-if (checkDebugInfoOption(A, Args, D, TC)) {
+  if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules, false)) {
+// If -gline-tables-only or -gline-directives-only is the last option it
+// wins.
+if (checkDebugInfoOption(Args.getLastArg(options::OPT_gmodules), Args, D,
+ TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
 DebugInfoKind = 

[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
akyrtzi marked an inline comment as done.
Closed by commit rGed6d09dd4ead: [Lex] For dependency directive lexing, angled 
includes in `__has_include`… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/ClangScanDeps/depscan-lex-has-include.c


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | 
FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi marked an inline comment as done.
akyrtzi added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:4415
+if (Result.isNot(tok::header_name))
+  return true;
+// Advance the index of lexed tokens.

benlangmuir wrote:
> This case is missing a test I think.
Added a test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

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


[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 490629.
akyrtzi added a comment.

Add test case for dependency directive lexing of ill-formed include inside 
`__has_include`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/ClangScanDeps/depscan-lex-has-include.c


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | 
FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:4420
+  DepDirectives.front().Tokens[NextDepDirectiveTokenIndex];
+  if (BufferStart + NextTok.Offset >= BufferPtr)
+break;

benlangmuir wrote:
> How do we know this will terminate?
If `LexAngledStringLiteral()` returns `tok::header_name` there were valid 
tokens that formed a header include and it has set `BufferPtr` after the `>` 
token. I can't think of reason it would not terminate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

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


[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rdar://104386604


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142143

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/ClangScanDeps/depscan-lex-has-include.c


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+
+// CHECK: t.c
+// CHECK: something.h
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -4408,6 +4408,22 @@
 MIOpt.ReadToken();
   }
 
+  if (ParsingFilename && DDTok.is(tok::less)) {
+BufferPtr = BufferStart + DDTok.Offset;
+LexAngledStringLiteral(Result, BufferPtr + 1);
+if (Result.isNot(tok::header_name))
+  return true;
+// Advance the index of lexed tokens.
+while (true) {
+  const dependency_directives_scan::Token  =
+  DepDirectives.front().Tokens[NextDepDirectiveTokenIndex];
+  if (BufferStart + NextTok.Offset >= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+
+// CHECK: t.c
+// CHECK: something.h
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -4408,6 +4408,22 @@
 MIOpt.ReadToken();
   }
 
+  if (ParsingFilename && DDTok.is(tok::less)) {
+BufferPtr = BufferStart + DDTok.Offset;
+LexAngledStringLiteral(Result, BufferPtr + 1);
+if (Result.isNot(tok::header_name))
+  return true;
+// Advance the index of lexed tokens.
+while (true) {
+  const dependency_directives_scan::Token  =
+  DepDirectives.front().Tokens[NextDepDirectiveTokenIndex];
+  if (BufferStart + NextTok.Offset >= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142028: [clang] remove SUBMODULE_TOPHEADER

2023-01-18 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

This is useful for functionality, like in an IDE, to show the top headers of a 
module import for navigational purposes.
Is it reasonable to at least have an alternative implementation for it (e.g. 
from the module headers find the headers that were not included from other 
headers), not sure if it'd be straightforward or not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142028

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


[PATCH] D141625: [DeclContext] Sort the Decls before adding into DeclContext

2023-01-13 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Yeah, you mainly need more than 32 decls to exceed the small storage of 
`Scope::DeclSetTy`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141625

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


[PATCH] D141625: [DeclContext] Sort the Decls before adding into DeclContext

2023-01-13 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi accepted this revision.
akyrtzi added a comment.
This revision is now accepted and ready to land.

Is it impractical to add a test for this? Otherwise LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141625

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


[PATCH] D140164: [clang/Lexer] Enhance `Lexer::getImmediateMacroNameForDiagnostics` to return a result from non-file buffers

2022-12-15 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59df56413bdc: [clang/Lexer] Enhance 
`Lexer::getImmediateMacroNameForDiagnostics` to return a… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140164

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/Modules/build-fail-notes.m
  clang/test/Modules/epic-fail.m


Index: clang/test/Modules/epic-fail.m
===
--- clang/test/Modules/epic-fail.m
+++ clang/test/Modules/epic-fail.m
@@ -6,7 +6,7 @@
 
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: fatal error: could not build module 'Module'
Index: clang/test/Modules/build-fail-notes.m
===
--- clang/test/Modules/build-fail-notes.m
+++ clang/test/Modules/build-fail-notes.m
@@ -6,7 +6,7 @@
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: fatal error: could not build module 'DependsOnModule'
 // CHECK-NOT: error:
@@ -24,7 +24,7 @@
 // CHECK-SDIAG: Module.h:9:13: error: expected ';' after top level declarator
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 
'DependsOnModule' imported from
 // CHECK-SDIAG: DependsOnModule.h:1:10: note: while building module 'Module' 
imported from
-// CHECK-SDIAG: note: expanded from here
+// CHECK-SDIAG: note: expanded from macro 'getModuleVersion'
 // CHECK-SDIAG: warning: umbrella header for module 'Module' does not include 
header 'NotInModule.h' [-Wincomplete-umbrella]
 // CHECK-SDIAG: DependsOnModule.h:1:10: fatal: could not build module 'Module'
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 
'DependsOnModule' imported from
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1047,9 +1047,11 @@
   while (SM.isMacroArgExpansion(Loc))
 Loc = SM.getImmediateExpansionRange(Loc).getBegin();
 
-  // If the macro's spelling has no FileID, then it's actually a token paste
-  // or stringization (or similar) and not a macro at all.
-  if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc
+  // If the macro's spelling isn't FileID or from scratch space, then it's
+  // actually a token paste or stringization (or similar) and not a macro at
+  // all.
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+  if (!SpellLoc.isFileID() || SM.isWrittenInScratchSpace(SpellLoc))
 return {};
 
   // Find the spelling location of the start of the non-argument expansion


Index: clang/test/Modules/epic-fail.m
===
--- clang/test/Modules/epic-fail.m
+++ clang/test/Modules/epic-fail.m
@@ -6,7 +6,7 @@
 
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: fatal error: could not build module 'Module'
Index: clang/test/Modules/build-fail-notes.m
===
--- clang/test/Modules/build-fail-notes.m
+++ clang/test/Modules/build-fail-notes.m
@@ -6,7 +6,7 @@
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: fatal error: could not build module 'DependsOnModule'
 // CHECK-NOT: error:
@@ -24,7 +24,7 @@
 // CHECK-SDIAG: Module.h:9:13: error: expected ';' after top level declarator
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 'DependsOnModule' imported from
 // CHECK-SDIAG: DependsOnModule.h:1:10: note: while building module 'Module' imported from
-// CHECK-SDIAG: note: expanded from here
+// CHECK-SDIAG: note: expanded from macro 'getModuleVersion'
 // CHECK-SDIAG: warning: umbrella header for module 'Module' does not include header 'NotInModule.h' [-Wincomplete-umbrella]
 // CHECK-SDIAG: 

[PATCH] D140164: [clang/Lexer] Enhance `Lexer::getImmediateMacroNameForDiagnostics` to return a result from non-file buffers

2022-12-15 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 483370.
akyrtzi added a comment.

Adjust code comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140164

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/Modules/build-fail-notes.m
  clang/test/Modules/epic-fail.m


Index: clang/test/Modules/epic-fail.m
===
--- clang/test/Modules/epic-fail.m
+++ clang/test/Modules/epic-fail.m
@@ -6,7 +6,7 @@
 
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: fatal error: could not build module 'Module'
Index: clang/test/Modules/build-fail-notes.m
===
--- clang/test/Modules/build-fail-notes.m
+++ clang/test/Modules/build-fail-notes.m
@@ -6,7 +6,7 @@
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: fatal error: could not build module 'DependsOnModule'
 // CHECK-NOT: error:
@@ -24,7 +24,7 @@
 // CHECK-SDIAG: Module.h:9:13: error: expected ';' after top level declarator
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 
'DependsOnModule' imported from
 // CHECK-SDIAG: DependsOnModule.h:1:10: note: while building module 'Module' 
imported from
-// CHECK-SDIAG: note: expanded from here
+// CHECK-SDIAG: note: expanded from macro 'getModuleVersion'
 // CHECK-SDIAG: warning: umbrella header for module 'Module' does not include 
header 'NotInModule.h' [-Wincomplete-umbrella]
 // CHECK-SDIAG: DependsOnModule.h:1:10: fatal: could not build module 'Module'
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 
'DependsOnModule' imported from
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1047,9 +1047,11 @@
   while (SM.isMacroArgExpansion(Loc))
 Loc = SM.getImmediateExpansionRange(Loc).getBegin();
 
-  // If the macro's spelling has no FileID, then it's actually a token paste
-  // or stringization (or similar) and not a macro at all.
-  if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc
+  // If the macro's spelling isn't FileID or from scratch space, then it's
+  // actually a token paste or stringization (or similar) and not a macro at
+  // all.
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+  if (!SpellLoc.isFileID() || SM.isWrittenInScratchSpace(SpellLoc))
 return {};
 
   // Find the spelling location of the start of the non-argument expansion


Index: clang/test/Modules/epic-fail.m
===
--- clang/test/Modules/epic-fail.m
+++ clang/test/Modules/epic-fail.m
@@ -6,7 +6,7 @@
 
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: fatal error: could not build module 'Module'
Index: clang/test/Modules/build-fail-notes.m
===
--- clang/test/Modules/build-fail-notes.m
+++ clang/test/Modules/build-fail-notes.m
@@ -6,7 +6,7 @@
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: fatal error: could not build module 'DependsOnModule'
 // CHECK-NOT: error:
@@ -24,7 +24,7 @@
 // CHECK-SDIAG: Module.h:9:13: error: expected ';' after top level declarator
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 'DependsOnModule' imported from
 // CHECK-SDIAG: DependsOnModule.h:1:10: note: while building module 'Module' imported from
-// CHECK-SDIAG: note: expanded from here
+// CHECK-SDIAG: note: expanded from macro 'getModuleVersion'
 // CHECK-SDIAG: warning: umbrella header for module 'Module' does not include header 'NotInModule.h' [-Wincomplete-umbrella]
 // CHECK-SDIAG: DependsOnModule.h:1:10: fatal: could not build module 'Module'
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 

[PATCH] D140164: [clang/Lexer] Enhance `Lexer::getImmediateMacroNameForDiagnostics` to return a result from non-file buffers

2022-12-15 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use `SourceManager::isWrittenInScratchSpace()` to specifically check for token 
paste or stringization, instead of
excluding all non-file buffers. This allows diagnostics to mention macro names 
that were defined from the command-line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140164

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/Modules/build-fail-notes.m
  clang/test/Modules/epic-fail.m


Index: clang/test/Modules/epic-fail.m
===
--- clang/test/Modules/epic-fail.m
+++ clang/test/Modules/epic-fail.m
@@ -6,7 +6,7 @@
 
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: fatal error: could not build module 'Module'
Index: clang/test/Modules/build-fail-notes.m
===
--- clang/test/Modules/build-fail-notes.m
+++ clang/test/Modules/build-fail-notes.m
@@ -6,7 +6,7 @@
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: fatal error: could not build module 'DependsOnModule'
 // CHECK-NOT: error:
@@ -24,7 +24,7 @@
 // CHECK-SDIAG: Module.h:9:13: error: expected ';' after top level declarator
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 
'DependsOnModule' imported from
 // CHECK-SDIAG: DependsOnModule.h:1:10: note: while building module 'Module' 
imported from
-// CHECK-SDIAG: note: expanded from here
+// CHECK-SDIAG: note: expanded from macro 'getModuleVersion'
 // CHECK-SDIAG: warning: umbrella header for module 'Module' does not include 
header 'NotInModule.h' [-Wincomplete-umbrella]
 // CHECK-SDIAG: DependsOnModule.h:1:10: fatal: could not build module 'Module'
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 
'DependsOnModule' imported from
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1047,9 +1047,11 @@
   while (SM.isMacroArgExpansion(Loc))
 Loc = SM.getImmediateExpansionRange(Loc).getBegin();
 
-  // If the macro's spelling has no FileID, then it's actually a token paste
-  // or stringization (or similar) and not a macro at all.
-  if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc
+  // If the macro's spelling isn't FileID or came from the scratch space, then
+  // it's actually a token paste or stringization (or similar) and not a macro
+  // at all.
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+  if (!SpellLoc.isFileID() || SM.isWrittenInScratchSpace(SpellLoc))
 return {};
 
   // Find the spelling location of the start of the non-argument expansion


Index: clang/test/Modules/epic-fail.m
===
--- clang/test/Modules/epic-fail.m
+++ clang/test/Modules/epic-fail.m
@@ -6,7 +6,7 @@
 
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: fatal error: could not build module 'Module'
Index: clang/test/Modules/build-fail-notes.m
===
--- clang/test/Modules/build-fail-notes.m
+++ clang/test/Modules/build-fail-notes.m
@@ -6,7 +6,7 @@
 // CHECK: While building module 'DependsOnModule' imported from
 // CHECK: While building module 'Module' imported from
 // CHECK: error: expected ';' after top level declarator
-// CHECK: note: expanded from here
+// CHECK: note: expanded from macro 'getModuleVersion'
 // CHECK: fatal error: could not build module 'Module'
 // CHECK: fatal error: could not build module 'DependsOnModule'
 // CHECK-NOT: error:
@@ -24,7 +24,7 @@
 // CHECK-SDIAG: Module.h:9:13: error: expected ';' after top level declarator
 // CHECK-SDIAG: build-fail-notes.m:4:9: note: while building module 'DependsOnModule' imported from
 // CHECK-SDIAG: DependsOnModule.h:1:10: note: while building module 'Module' imported from
-// CHECK-SDIAG: note: expanded from here
+// CHECK-SDIAG: note: expanded from macro 'getModuleVersion'
 // CHECK-SDIAG: 

[PATCH] D139052: [NFC][Profile] Access profile through VirtualFileSystem

2022-12-08 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: llvm/include/llvm/Support/PGOOptions.h:18
 #include "llvm/Support/Error.h"
+#include "llvm/Support/VirtualFileSystem.h"
 

steven_wu wrote:
> akyrtzi wrote:
> > akyrtzi wrote:
> > > I'd suggest to consider moving the `PGOOptions` constructor out-of-line, 
> > > along with
> > > ```
> > >   PGOOptions =(const PGOOptions );
> > >   PGOOptions(const PGOOptions&);
> > >   ~PGOOptions();
> > > ```
> > >  in order to forward-declare here and avoid including the header, 
> > > avoiding the additional include dependencies for many cpp files.
> > > The default parameter needs to instantiate here and pretty much all 
> > > references to `PGOOptions` has `Optional` which requires 
> > > including VFS. I will leave this one since `PGOOptions.h` is a rare 
> > > header to include.
> > 
> > `PGOOptions.h` is transitively included by many files, if I touch that 
> > header, and then compile `clang`, there are 225 files that need to be 
> > re-compiled.
> > 
> > I thought that moving the `PGOOptions` members I mentioned out-of-line 
> > would be enough to avoid the need to include `VirtualFileSystem.h`, is this 
> > not the case?
> I see. It is included in two different headers in the backend, both of them 
> has `Optional`. During my experiment, to instantiate 
> `Optional`, it needs full declaration for PGOOptions, thus 
> FileSystem. I could be wrong but I don't see a way around that.
With this diff on top of your patch everything compiles fine, without a need to 
include the header in `PGOOptions.h`:

```
diff --git a/llvm/include/llvm/Support/PGOOptions.h 
b/llvm/include/llvm/Support/PGOOptions.h
--- a/llvm/include/llvm/Support/PGOOptions.h
+++ b/llvm/include/llvm/Support/PGOOptions.h
@@ -14,11 +14,15 @@
 #ifndef LLVM_SUPPORT_PGOOPTIONS_H
 #define LLVM_SUPPORT_PGOOPTIONS_H
 
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/VirtualFileSystem.h"
 
 namespace llvm {
 
+namespace vfs {
+class FileSystem;
+} // namespace vfs
+
 /// A struct capturing PGO tunables.
 struct PGOOptions {
   enum PGOAction { NoAction, IRInstr, IRUse, SampleUse };
@@ -28,35 +32,13 @@ struct PGOOptions {
  IntrusiveRefCntPtr FS = nullptr,
  PGOAction Action = NoAction, CSPGOAction CSAction = NoCSAction,
  bool DebugInfoForProfiling = false,
- bool PseudoProbeForProfiling = false)
-  : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
-ProfileRemappingFile(ProfileRemappingFile), Action(Action),
-CSAction(CSAction), DebugInfoForProfiling(DebugInfoForProfiling ||
-  (Action == SampleUse &&
-   !PseudoProbeForProfiling)),
-PseudoProbeForProfiling(PseudoProbeForProfiling), FS(std::move(FS)) {
-// Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
-// callback with IRUse action without ProfileFile.
-
-// If there is a CSAction, PGOAction cannot be IRInstr or SampleUse.
-assert(this->CSAction == NoCSAction ||
-   (this->Action != IRInstr && this->Action != SampleUse));
-
-// For CSIRInstr, CSProfileGenFile also needs to be nonempty.
-assert(this->CSAction != CSIRInstr || !this->CSProfileGenFile.empty());
-
-// If CSAction is CSIRUse, PGOAction needs to be IRUse as they share
-// a profile.
-assert(this->CSAction != CSIRUse || this->Action == IRUse);
+ bool PseudoProbeForProfiling = false);
 
-// If neither Action nor CSAction, DebugInfoForProfiling or
-// PseudoProbeForProfiling needs to be true.
-assert(this->Action != NoAction || this->CSAction != NoCSAction ||
-   this->DebugInfoForProfiling || this->PseudoProbeForProfiling);
+  // Out-of-line so we don't have to include `VirtualFileSystem.h` header.
+  PGOOptions(const PGOOptions&);
+  ~PGOOptions();
+  PGOOptions =(const PGOOptions );
 
-// If we need to use the profile, the VFS cannot be nullptr.
-assert(this->FS || !(this->Action == IRUse || this->CSAction == CSIRUse));
-  }
   std::string ProfileFile;
   std::string CSProfileGenFile;
   std::string ProfileRemappingFile;
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -201,6 +201,7 @@ add_llvm_component_library(LLVMSupport
   OptimizedStructLayout.cpp
   Optional.cpp
   Parallel.cpp
+  PGOOptions.cpp
   PluginLoader.cpp
   PrettyStackTrace.cpp
   RandomNumberGenerator.cpp
diff --git a/llvm/lib/Support/PGOOptions.cpp b/llvm/lib/Support/PGOOptions.cpp
new file mode 100644
--- /dev/null
+++ b/llvm/lib/Support/PGOOptions.cpp
@@ -0,0 +1,53 @@
+//===-- PGOOptions.cpp -- PGO option tunables --*- C++ 
-*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See 

[PATCH] D139115: [clang][ExtractAPI] Add support for single symbol SGF

2022-12-08 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/include/clang-c/Documentation.h:549
 
+typedef struct CXAPISetImpl *CXAPISet;
+

benlangmuir wrote:
> @dang please document what this type represents.
> 
> @akyrtzi what's the preferred implementation type name for opaque typedef 
> types? I see we have a mix right now:
> * `void *`
> * `CXOpaqueFoo *`
> * `CXFooImpl *`
There's no consistency in libclang APIs  This typedef LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139115

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


[PATCH] D139052: [NFC][Profile] Access profile through VirtualFileSystem

2022-12-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1729
+  if (!Opts.ProfileInstrumentUsePath.empty()) {
+auto FS = llvm::vfs::getRealFileSystem();
+setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath, *FS, Diags);

steven_wu wrote:
> akyrtzi wrote:
> > Could we propagate the VFS that the `CompilerInvocation` is going to create 
> > here? Otherwise this seems like a hidden "landmine" that someone is bound 
> > to trip on later on.
> Currently, Profile look up doesn't go through any VFS, so vfs overlay has no 
> effect on profiles. Putting through VFS is changing behavior, even I think it 
> is for good.
> 
> It also has the potential to make code harder to read because creating VFS 
> relies on a compiler invocation which we are creating here.
> 
> Let me add a fixme here first. 
> Currently, Profile look up doesn't go through any VFS, so vfs overlay has no 
> effect on profiles. Putting through VFS is changing behavior, even I think it 
> is for good.

Your patch is already changing behavior; CodeGen will load profiles using 
clang's VFS, so vfs overlay will affect how profiles are loaded. The mismatch 
is that CodeGen will load the path using clang's VFS but 
`setPGOUseInstrumentor` will load it directly from real file-system, so they 
can be out-of-sync.

On second look, `setPGOUseInstrumentor` seems to create a throw-away 
`IndexedInstrProfReader` just for reading a couple of settings to set some 
flags. This seems redundant, could we move the determination of these flags at 
the point where `CodeGenModule` is creating its own `IndexedInstrProfReader` 
and remove `setPGOUseInstrumentor` from `CompilerInvocation::ParseCodeGenArgs` 
entirely?



Comment at: llvm/include/llvm/Support/PGOOptions.h:18
 #include "llvm/Support/Error.h"
+#include "llvm/Support/VirtualFileSystem.h"
 

akyrtzi wrote:
> I'd suggest to consider moving the `PGOOptions` constructor out-of-line, 
> along with
> ```
>   PGOOptions =(const PGOOptions );
>   PGOOptions(const PGOOptions&);
>   ~PGOOptions();
> ```
>  in order to forward-declare here and avoid including the header, avoiding 
> the additional include dependencies for many cpp files.
> The default parameter needs to instantiate here and pretty much all 
> references to `PGOOptions` has `Optional` which requires 
> including VFS. I will leave this one since `PGOOptions.h` is a rare header to 
> include.

`PGOOptions.h` is transitively included by many files, if I touch that header, 
and then compile `clang`, there are 225 files that need to be re-compiled.

I thought that moving the `PGOOptions` members I mentioned out-of-line would be 
enough to avoid the need to include `VirtualFileSystem.h`, is this not the case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139052

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


[PATCH] D139052: [NFC][Profile] Access profile through VirtualFileSystem

2022-12-02 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/include/clang/CodeGen/BackendUtil.h:14
 #include "llvm/IR/ModuleSummaryIndex.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include 

Recommend to forward declare instead of including the header.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1729
+  if (!Opts.ProfileInstrumentUsePath.empty()) {
+auto FS = llvm::vfs::getRealFileSystem();
+setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath, *FS, Diags);

Could we propagate the VFS that the `CompilerInvocation` is going to create 
here? Otherwise this seems like a hidden "landmine" that someone is bound to 
trip on later on.



Comment at: llvm/include/llvm/CodeGen/MIRSampleProfile.h:20
 #include "llvm/Support/Discriminator.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include 

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/CodeGen/MIRSampleProfile.h:63
+
+  IntrusiveRefCntPtr FS;
 };

AFAICT this member is not used, you could remove it.



Comment at: llvm/include/llvm/Passes/PassBuilder.h:24
 #include "llvm/Support/PGOOptions.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h:31
 #include "llvm/Support/Error.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/ProfileData/InstrProf.h:35
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"

This is not used in this file, you could remove the include from here.



Comment at: llvm/include/llvm/ProfileData/InstrProfReader.h:29
 #include "llvm/Support/SwapByteOrder.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include 

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/ProfileData/SampleProfReader.h:241
 #include "llvm/Support/SymbolRemappingReader.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include 

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/Support/PGOOptions.h:18
 #include "llvm/Support/Error.h"
+#include "llvm/Support/VirtualFileSystem.h"
 

I'd suggest to consider moving the `PGOOptions` constructor out-of-line, along 
with
```
  PGOOptions =(const PGOOptions );
  PGOOptions(const PGOOptions&);
  ~PGOOptions();
```
 in order to forward-declare here and avoid including the header, avoiding the 
additional include dependencies for many cpp files.



Comment at: llvm/include/llvm/Support/PGOOptions.h:37
!PseudoProbeForProfiling)),
-PseudoProbeForProfiling(PseudoProbeForProfiling) {
+PseudoProbeForProfiling(PseudoProbeForProfiling), FS(FS) {
 // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can





Comment at: llvm/include/llvm/Transforms/IPO/SampleProfile.h:19
 #include "llvm/Pass.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include 

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/Transforms/IPO/SampleProfile.h:34
   : ProfileFileName(File), ProfileRemappingFileName(RemappingFile),
 LTOPhase(LTOPhase) {}
 





Comment at: llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h:20
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include 

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h:40
 #include "llvm/Support/GenericDomTree.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"

Recommend to forward declare instead of including the header.



Comment at: llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h:86
+  IntrusiveRefCntPtr FS)
+  : Filename(Name), RemappingFilename(RemapName), FS(FS) {}
   void dump() { Reader->dump(); }





Comment at: llvm/lib/ProfileData/InstrProf.cpp:1228
   CountSumOrPercent ) -> Error {
-auto ReaderOrErr = InstrProfReader::create(Filename);
+auto FS = vfs::getRealFileSystem();
+auto ReaderOrErr = InstrProfReader::create(Filename, *FS);

Could 

[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-11 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

@nikic, it seems to have recovered 
(http://llvm-compile-time-tracker.com/compare.php?from=c49cde6467f9bf200640db763152a9dc7f009520=0456acbfb942f127359a8defd1b4f1f44420df3e=instructions)
 let me know if you have concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D135490: [clang/Sema] Follow-up for fix of non-deterministic order of `-Wunused-variable` diagnostic

2022-10-11 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0456acbfb942: [clang/Sema] Follow-up for fix of 
non-deterministic order of `-Wunused… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135490

Files:
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp

Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2091,20 +2091,31 @@
 }
 
 void Sema::DiagnoseUnusedNestedTypedefs(const RecordDecl *D) {
+  DiagnoseUnusedNestedTypedefs(
+  D, [this](SourceLocation Loc, PartialDiagnostic PD) { Diag(Loc, PD); });
+}
+
+void Sema::DiagnoseUnusedNestedTypedefs(const RecordDecl *D,
+DiagReceiverTy DiagReceiver) {
   if (D->getTypeForDecl()->isDependentType())
 return;
 
   for (auto *TmpD : D->decls()) {
 if (const auto *T = dyn_cast(TmpD))
-  DiagnoseUnusedDecl(T);
+  DiagnoseUnusedDecl(T, DiagReceiver);
 else if(const auto *R = dyn_cast(TmpD))
-  DiagnoseUnusedNestedTypedefs(R);
+  DiagnoseUnusedNestedTypedefs(R, DiagReceiver);
   }
 }
 
+void Sema::DiagnoseUnusedDecl(const NamedDecl *D) {
+  DiagnoseUnusedDecl(
+  D, [this](SourceLocation Loc, PartialDiagnostic PD) { Diag(Loc, PD); });
+}
+
 /// DiagnoseUnusedDecl - Emit warnings about declarations that are not used
 /// unless they are marked attr(unused).
-void Sema::DiagnoseUnusedDecl(const NamedDecl *D) {
+void Sema::DiagnoseUnusedDecl(const NamedDecl *D, DiagReceiverTy DiagReceiver) {
   if (!ShouldDiagnoseUnusedDecl(D))
 return;
 
@@ -2126,10 +2137,11 @@
   else
 DiagID = diag::warn_unused_variable;
 
-  Diag(D->getLocation(), DiagID) << D << Hint;
+  DiagReceiver(D->getLocation(), PDiag(DiagID) << D << Hint);
 }
 
-void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
+void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD,
+DiagReceiverTy DiagReceiver) {
   // If it's not referenced, it can't be set. If it has the Cleanup attribute,
   // it's not really unused.
   if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
@@ -2175,10 +2187,11 @@
 return;
   unsigned DiagID = isa(VD) ? diag::warn_unused_but_set_parameter
  : diag::warn_unused_but_set_variable;
-  Diag(VD->getLocation(), DiagID) << VD;
+  DiagReceiver(VD->getLocation(), PDiag(DiagID) << VD);
 }
 
-static void CheckPoppedLabel(LabelDecl *L, Sema ) {
+static void CheckPoppedLabel(LabelDecl *L, Sema ,
+ Sema::DiagReceiverTy DiagReceiver) {
   // Verify that we have no forward references left.  If so, there was a goto
   // or address of a label taken, but no definition of it.  Label fwd
   // definitions are indicated with a null substmt which is also not a resolved
@@ -2189,7 +2202,8 @@
   else
 Diagnose = L->getStmt() == nullptr;
   if (Diagnose)
-S.Diag(L->getLocation(), diag::err_undeclared_label_use) << L;
+DiagReceiver(L->getLocation(), S.PDiag(diag::err_undeclared_label_use)
+   << L);
 }
 
 void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
@@ -2199,6 +2213,24 @@
   assert((S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) &&
  "Scope shouldn't contain decls!");
 
+  /// We visit the decls in non-deterministic order, but we want diagnostics
+  /// emitted in deterministic order. Collect any diagnostic that may be emitted
+  /// and sort the diagnostics before emitting them, after we visited all decls.
+  struct LocAndDiag {
+SourceLocation Loc;
+Optional PreviousDeclLoc;
+PartialDiagnostic PD;
+  };
+  SmallVector DeclDiags;
+  auto addDiag = [](SourceLocation Loc, PartialDiagnostic PD) {
+DeclDiags.push_back(LocAndDiag{Loc, None, std::move(PD)});
+  };
+  auto addDiagWithPrev = [](SourceLocation Loc,
+  SourceLocation PreviousDeclLoc,
+  PartialDiagnostic PD) {
+DeclDiags.push_back(LocAndDiag{Loc, PreviousDeclLoc, std::move(PD)});
+  };
+
   for (auto *TmpD : S->decls()) {
 assert(TmpD && "This decl didn't get pushed??");
 
@@ -2207,11 +2239,11 @@
 
 // Diagnose unused variables in this scope.
 if (!S->hasUnrecoverableErrorOccurred()) {
-  DiagnoseUnusedDecl(D);
+  DiagnoseUnusedDecl(D, addDiag);
   if (const auto *RD = dyn_cast(D))
-DiagnoseUnusedNestedTypedefs(RD);
+DiagnoseUnusedNestedTypedefs(RD, addDiag);
   if (VarDecl *VD = dyn_cast(D)) {
-DiagnoseUnusedButSetDecl(VD);
+DiagnoseUnusedButSetDecl(VD, addDiag);
 RefsMinusAssignments.erase(VD);
   }
 }
@@ -2220,7 +2252,7 @@
 
 // If this was a forward reference to a label, verify it was 

[PATCH] D135634: [clang][modules] Serialize VFS overlay paths into PCMs

2022-10-11 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4715
+  return createVFSFromOverlayFiles(CI.getHeaderSearchOpts().VFSOverlayFiles,
+   Diags, BaseFS);
+}

A bit nitpick but I'd suggest changing to `std::move(BaseFS)`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135634

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


[PATCH] D135634: [clang][modules] Serialize VFS overlay paths into PCMs

2022-10-11 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

This seems fine to me but note that we no longer depend on the functionality 
that `test/Index/index-module-with-vfs.m` is testing (and not sure anyone else 
does), so if there is another change affecting it that is more complicated we 
could consider removing the test.




Comment at: clang/include/clang/Frontend/CompilerInvocation.h:298
+IntrusiveRefCntPtr
+createVFSFromOverlayFiles(const std::vector ,
+  DiagnosticsEngine ,

The idiomatic LLVM way is to use `ArrayRef` for the parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135634

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


[PATCH] D135490: [clang/Sema] Follow-up for fix of non-deterministic order of `-Wunused-variable` diagnostic

2022-10-10 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D135490#3847454 , @steven_wu wrote:

> I don't know too much about this. I guess have a DiagReceiver to force the 
> emitting order is a good thing but it is kind of weird to have this just for 
> unused warning.
>
> I am guessing my suspect of removing decl from the scope is the cause of the 
> slow down. Maybe we just force order on iteration?

Ordering the decls every time `ActOnPopScope` is called is not cheap; ordering 
only the diagnostics (if any is emitted) is the most efficient way I could find.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135490

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D135118#3840259 , @akyrtzi wrote:

> In D135118#3839442 , @nikic wrote:
>
>> FYI this caused a noticeable compile-time regression (about 0.4% geomean at 
>> `-O0`): 
>> http://llvm-compile-time-tracker.com/compare.php?from=92233159035d1b50face95d886901cf99035bd99=371883f46dc23f8464cbf578e2d12a4f92e61917=instructions
>
> Thanks for letting me know! I'll take a look.

Opened https://reviews.llvm.org/D135490


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D135490: [clang/Sema] Follow-up for fix of non-deterministic order of `-Wunused-variable` diagnostic

2022-10-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a subscriber: mgrang.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Commit `371883f46dc23f8464cbf578e2d12a4f92e61917` caused a noticeable 
compile-time regression (about 0.4% geomean at -O0):
http://llvm-compile-time-tracker.com/compare.php?from=92233159035d1b50face95d886901cf99035bd99=371883f46dc23f8464cbf578e2d12a4f92e61917=instructions

To address this switch `Scope::DeclSetTy` back to a `SmallPtrSet` and change 
`Sema::ActOnPopScope` to explicitly order the diagnostics that this function 
emits.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135490

Files:
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp

Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2089,20 +2089,31 @@
 }
 
 void Sema::DiagnoseUnusedNestedTypedefs(const RecordDecl *D) {
+  DiagnoseUnusedNestedTypedefs(
+  D, [this](SourceLocation Loc, PartialDiagnostic PD) { Diag(Loc, PD); });
+}
+
+void Sema::DiagnoseUnusedNestedTypedefs(const RecordDecl *D,
+DiagReceiverTy DiagReceiver) {
   if (D->getTypeForDecl()->isDependentType())
 return;
 
   for (auto *TmpD : D->decls()) {
 if (const auto *T = dyn_cast(TmpD))
-  DiagnoseUnusedDecl(T);
+  DiagnoseUnusedDecl(T, DiagReceiver);
 else if(const auto *R = dyn_cast(TmpD))
-  DiagnoseUnusedNestedTypedefs(R);
+  DiagnoseUnusedNestedTypedefs(R, DiagReceiver);
   }
 }
 
+void Sema::DiagnoseUnusedDecl(const NamedDecl *D) {
+  DiagnoseUnusedDecl(
+  D, [this](SourceLocation Loc, PartialDiagnostic PD) { Diag(Loc, PD); });
+}
+
 /// DiagnoseUnusedDecl - Emit warnings about declarations that are not used
 /// unless they are marked attr(unused).
-void Sema::DiagnoseUnusedDecl(const NamedDecl *D) {
+void Sema::DiagnoseUnusedDecl(const NamedDecl *D, DiagReceiverTy DiagReceiver) {
   if (!ShouldDiagnoseUnusedDecl(D))
 return;
 
@@ -2124,10 +2135,11 @@
   else
 DiagID = diag::warn_unused_variable;
 
-  Diag(D->getLocation(), DiagID) << D << Hint;
+  DiagReceiver(D->getLocation(), PDiag(DiagID) << D << Hint);
 }
 
-void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
+void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD,
+DiagReceiverTy DiagReceiver) {
   // If it's not referenced, it can't be set. If it has the Cleanup attribute,
   // it's not really unused.
   if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
@@ -2173,10 +2185,11 @@
 return;
   unsigned DiagID = isa(VD) ? diag::warn_unused_but_set_parameter
  : diag::warn_unused_but_set_variable;
-  Diag(VD->getLocation(), DiagID) << VD;
+  DiagReceiver(VD->getLocation(), PDiag(DiagID) << VD);
 }
 
-static void CheckPoppedLabel(LabelDecl *L, Sema ) {
+static void CheckPoppedLabel(LabelDecl *L, Sema ,
+ Sema::DiagReceiverTy DiagReceiver) {
   // Verify that we have no forward references left.  If so, there was a goto
   // or address of a label taken, but no definition of it.  Label fwd
   // definitions are indicated with a null substmt which is also not a resolved
@@ -2187,7 +2200,8 @@
   else
 Diagnose = L->getStmt() == nullptr;
   if (Diagnose)
-S.Diag(L->getLocation(), diag::err_undeclared_label_use) << L;
+DiagReceiver(L->getLocation(), S.PDiag(diag::err_undeclared_label_use)
+   << L);
 }
 
 void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
@@ -2197,6 +2211,24 @@
   assert((S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) &&
  "Scope shouldn't contain decls!");
 
+  /// We visit the decls in non-deterministic order, but we want diagnostics
+  /// emitted in deterministic order. Collect any diagnostic that may be emitted
+  /// and sort the diagnostics before emitting them, after we visited all decls.
+  struct LocAndDiag {
+SourceLocation Loc;
+Optional PreviousDeclLoc;
+PartialDiagnostic PD;
+  };
+  SmallVector DeclDiags;
+  auto addDiag = [](SourceLocation Loc, PartialDiagnostic PD) {
+DeclDiags.push_back(LocAndDiag{Loc, None, std::move(PD)});
+  };
+  auto addDiagWithPrev = [](SourceLocation Loc,
+  SourceLocation PreviousDeclLoc,
+  PartialDiagnostic PD) {
+DeclDiags.push_back(LocAndDiag{Loc, PreviousDeclLoc, std::move(PD)});
+  };
+
   for (auto *TmpD : S->decls()) {
 assert(TmpD && "This decl didn't get pushed??");
 
@@ -2205,11 +2237,11 @@
 
 // Diagnose unused variables in this scope.
 if (!S->hasUnrecoverableErrorOccurred()) {
-  DiagnoseUnusedDecl(D);
+  DiagnoseUnusedDecl(D, addDiag);
   if (const auto *RD = 

[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D135118#3839442 , @nikic wrote:

> FYI this caused a noticeable compile-time regression (about 0.4% geomean at 
> `-O0`): 
> http://llvm-compile-time-tracker.com/compare.php?from=92233159035d1b50face95d886901cf99035bd99=371883f46dc23f8464cbf578e2d12a4f92e61917=instructions

Thanks for letting me know! I'll take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-05 Thread Argyrios Kyrtzidis 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 rG371883f46dc2: [clang/Sema] Fix non-deterministic order for 
certain kind of diagnostics (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Sema/Scope.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  clang/test/Sema/deterministic-diagnostics-order.m

Index: clang/test/Sema/deterministic-diagnostics-order.m
===
--- /dev/null
+++ clang/test/Sema/deterministic-diagnostics-order.m
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wobjc-property-implementation -Watomic-property-with-user-defined-accessor -Wunused 2> %t.err
+// RUN: FileCheck -input-file=%t.err %s
+
+@interface I
+@end
+
+@interface I(cat)
+@property id prop1;
+@property id prop2;
+@property id prop3;
+@end
+
+@implementation I(cat)
+@end
+
+// CHECK: warning: property 'prop1' requires method
+// CHECK: warning: property 'prop2' requires method
+// CHECK: warning: property 'prop3' requires method
+
+@interface I2
+@property int prop1;
+@property int prop2;
+@property int prop3;
+@end
+
+@implementation I2
+@synthesize prop1, prop2, prop3;
+-(int) prop1 { return 0; }
+-(int) prop2 { return 0; }
+-(int) prop3 { return 0; }
+@end
+
+// CHECK: warning: writable atomic property 'prop1'
+// CHECK: warning: writable atomic property 'prop2'
+// CHECK: warning: writable atomic property 'prop3'
+
+void test_unused() {
+  // Add enough variables to exceed the small storage of Scope::DeclSetTy.
+  int v1;
+  int v2;
+  int v3;
+  int v4;
+  int v5;
+  int v6;
+  int v7;
+  int v8;
+  int v9;
+  int v10;
+  int v11;
+  int v12;
+  int v13;
+  int v14;
+  int v15;
+  int v16;
+  int v17;
+  int v18;
+  int v19;
+  int v20;
+  int v21;
+  int v22;
+  int v23;
+  int v24;
+  int v25;
+  int v26;
+  int v27;
+  int v28;
+  int v29;
+  int v30;
+  int v31;
+  int v32;
+  int v33;
+  int v34;
+  int v35;
+  int v36;
+  int v37;
+  int v38;
+}
+
+// CHECK: warning: unused variable 'v1'
+// CHECK: warning: unused variable 'v2'
+// CHECK: warning: unused variable 'v3'
+// CHECK: warning: unused variable 'v4'
+// CHECK: warning: unused variable 'v5'
+// CHECK: warning: unused variable 'v6'
+// CHECK: warning: unused variable 'v7'
+// CHECK: warning: unused variable 'v8'
+// CHECK: warning: unused variable 'v9'
+// CHECK: warning: unused variable 'v10'
+// CHECK: warning: unused variable 'v11'
+// CHECK: warning: unused variable 'v12'
+// CHECK: warning: unused variable 'v13'
+// CHECK: warning: unused variable 'v14'
+// CHECK: warning: unused variable 'v15'
+// CHECK: warning: unused variable 'v16'
+// CHECK: warning: unused variable 'v17'
+// CHECK: warning: unused variable 'v18'
+// CHECK: warning: unused variable 'v19'
+// CHECK: warning: unused variable 'v20'
+// CHECK: warning: unused variable 'v21'
+// CHECK: warning: unused variable 'v22'
+// CHECK: warning: unused variable 'v23'
+// CHECK: warning: unused variable 'v24'
+// CHECK: warning: unused variable 'v25'
+// CHECK: warning: unused variable 'v26'
+// CHECK: warning: unused variable 'v27'
+// CHECK: warning: unused variable 'v28'
+// CHECK: warning: unused variable 'v29'
+// CHECK: warning: unused variable 'v30'
+// CHECK: warning: unused variable 'v31'
+// CHECK: warning: unused variable 'v32'
+// CHECK: warning: unused variable 'v33'
+// CHECK: warning: unused variable 'v34'
+// CHECK: warning: unused variable 'v35'
+// CHECK: warning: unused variable 'v36'
+// CHECK: warning: unused variable 'v37'
+// CHECK: warning: unused variable 'v38'
Index: clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
@@ -379,8 +379,7 @@
   IvarToPropMapTy IvarToPopertyMap;
 
   ObjCInterfaceDecl::PropertyMap PropMap;
-  ObjCInterfaceDecl::PropertyDeclOrder PropOrder;
-  InterfaceD->collectPropertiesToImplement(PropMap, PropOrder);
+  InterfaceD->collectPropertiesToImplement(PropMap);
 
   for (ObjCInterfaceDecl::PropertyMap::iterator
   I = PropMap.begin(), E = PropMap.end(); I != E; ++I) {
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1822,9 +1822,8 @@
 static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
 ObjCInterfaceDecl::PropertyMap ) {
   if (ObjCInterfaceDecl *SDecl = CDecl->getSuperClass()) {
-

[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi marked an inline comment as done.
akyrtzi added inline comments.



Comment at: clang/include/clang/AST/DeclObjC.h:1091
   virtual void collectPropertiesToImplement(PropertyMap ,
 PropertyDeclOrder ) const {}
 

akyrtzi wrote:
> benlangmuir wrote:
> > Can we use the existing `PropertyDeclOrder` instead of changing the map 
> > type? Or else get rid of the `PO` parameter to functions using 
> > `PropertyMap` if we keep the MapVector?
> I'll take a look.
See updated patch.

The diagnostic machinery (e.g. in `DiagnoseUnimplementedProperties`) for these 
ObjC diagnostics is using `PropertyMap` separately from the 
`collectPropertiesToImplement` functions, so I kept the map type change and 
removed `PropertyDeclOrder` from these functions accepting `PropertyMap`.
This is better for maintainance since it'd be an easy mistake to add new code 
that iterates the `DenseMap` instead of the vector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 465241.
akyrtzi added a comment.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: NoQ.

Remove `PropertyDeclOrder` parameter from the `collectPropertiesToImplement` 
functions. This is not necessary with `PropertyMap` becoming a `MapVector`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Sema/Scope.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  clang/test/Sema/deterministic-diagnostics-order.m

Index: clang/test/Sema/deterministic-diagnostics-order.m
===
--- /dev/null
+++ clang/test/Sema/deterministic-diagnostics-order.m
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wobjc-property-implementation -Watomic-property-with-user-defined-accessor -Wunused 2> %t.err
+// RUN: FileCheck -input-file=%t.err %s
+
+@interface I
+@end
+
+@interface I(cat)
+@property id prop1;
+@property id prop2;
+@property id prop3;
+@end
+
+@implementation I(cat)
+@end
+
+// CHECK: warning: property 'prop1' requires method
+// CHECK: warning: property 'prop2' requires method
+// CHECK: warning: property 'prop3' requires method
+
+@interface I2
+@property int prop1;
+@property int prop2;
+@property int prop3;
+@end
+
+@implementation I2
+@synthesize prop1, prop2, prop3;
+-(int) prop1 { return 0; }
+-(int) prop2 { return 0; }
+-(int) prop3 { return 0; }
+@end
+
+// CHECK: warning: writable atomic property 'prop1'
+// CHECK: warning: writable atomic property 'prop2'
+// CHECK: warning: writable atomic property 'prop3'
+
+void test_unused() {
+  // Add enough variables to exceed the small storage of Scope::DeclSetTy.
+  int v1;
+  int v2;
+  int v3;
+  int v4;
+  int v5;
+  int v6;
+  int v7;
+  int v8;
+  int v9;
+  int v10;
+  int v11;
+  int v12;
+  int v13;
+  int v14;
+  int v15;
+  int v16;
+  int v17;
+  int v18;
+  int v19;
+  int v20;
+  int v21;
+  int v22;
+  int v23;
+  int v24;
+  int v25;
+  int v26;
+  int v27;
+  int v28;
+  int v29;
+  int v30;
+  int v31;
+  int v32;
+  int v33;
+  int v34;
+  int v35;
+  int v36;
+  int v37;
+  int v38;
+}
+
+// CHECK: warning: unused variable 'v1'
+// CHECK: warning: unused variable 'v2'
+// CHECK: warning: unused variable 'v3'
+// CHECK: warning: unused variable 'v4'
+// CHECK: warning: unused variable 'v5'
+// CHECK: warning: unused variable 'v6'
+// CHECK: warning: unused variable 'v7'
+// CHECK: warning: unused variable 'v8'
+// CHECK: warning: unused variable 'v9'
+// CHECK: warning: unused variable 'v10'
+// CHECK: warning: unused variable 'v11'
+// CHECK: warning: unused variable 'v12'
+// CHECK: warning: unused variable 'v13'
+// CHECK: warning: unused variable 'v14'
+// CHECK: warning: unused variable 'v15'
+// CHECK: warning: unused variable 'v16'
+// CHECK: warning: unused variable 'v17'
+// CHECK: warning: unused variable 'v18'
+// CHECK: warning: unused variable 'v19'
+// CHECK: warning: unused variable 'v20'
+// CHECK: warning: unused variable 'v21'
+// CHECK: warning: unused variable 'v22'
+// CHECK: warning: unused variable 'v23'
+// CHECK: warning: unused variable 'v24'
+// CHECK: warning: unused variable 'v25'
+// CHECK: warning: unused variable 'v26'
+// CHECK: warning: unused variable 'v27'
+// CHECK: warning: unused variable 'v28'
+// CHECK: warning: unused variable 'v29'
+// CHECK: warning: unused variable 'v30'
+// CHECK: warning: unused variable 'v31'
+// CHECK: warning: unused variable 'v32'
+// CHECK: warning: unused variable 'v33'
+// CHECK: warning: unused variable 'v34'
+// CHECK: warning: unused variable 'v35'
+// CHECK: warning: unused variable 'v36'
+// CHECK: warning: unused variable 'v37'
+// CHECK: warning: unused variable 'v38'
Index: clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
@@ -379,8 +379,7 @@
   IvarToPropMapTy IvarToPopertyMap;
 
   ObjCInterfaceDecl::PropertyMap PropMap;
-  ObjCInterfaceDecl::PropertyDeclOrder PropOrder;
-  InterfaceD->collectPropertiesToImplement(PropMap, PropOrder);
+  InterfaceD->collectPropertiesToImplement(PropMap);
 
   for (ObjCInterfaceDecl::PropertyMap::iterator
   I = PropMap.begin(), E = PropMap.end(); I != E; ++I) {
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1822,9 +1822,8 @@
 static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
 ObjCInterfaceDecl::PropertyMap ) {
   if (ObjCInterfaceDecl *SDecl = 

[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/include/clang/AST/DeclObjC.h:1091
   virtual void collectPropertiesToImplement(PropertyMap ,
 PropertyDeclOrder ) const {}
 

benlangmuir wrote:
> Can we use the existing `PropertyDeclOrder` instead of changing the map type? 
> Or else get rid of the `PO` parameter to functions using `PropertyMap` if we 
> keep the MapVector?
I'll take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-04 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D135118#3833978 , @steven_wu wrote:

> LGTM.
>
> `RemoveDecl` does become more expensive but I don't have better solution.

Luckily AFAICT this is not a "hot" function.

> I am also wondering if as follow up we should add an option to 
> `VerifyDiagnosticConsumer` to be location aware (so the diagnostics from a 
> file is emitted in order) to prevent more problem like this.

Interesting idea! Something to keep in mind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a subscriber: mgrang.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the context of caching clang invocations it is important to emit diagnostics 
in deterministic order;
the same clang invocation should result in the same diagnostic output.

rdar://100336989


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135118

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Sema/Scope.h
  clang/test/Sema/deterministic-diagnostics-order.m

Index: clang/test/Sema/deterministic-diagnostics-order.m
===
--- /dev/null
+++ clang/test/Sema/deterministic-diagnostics-order.m
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wobjc-property-implementation -Watomic-property-with-user-defined-accessor -Wunused 2> %t.err
+// RUN: FileCheck -input-file=%t.err %s
+
+@interface I
+@end
+
+@interface I(cat)
+@property id prop1;
+@property id prop2;
+@property id prop3;
+@end
+
+@implementation I(cat)
+@end
+
+// CHECK: warning: property 'prop1' requires method
+// CHECK: warning: property 'prop2' requires method
+// CHECK: warning: property 'prop3' requires method
+
+@interface I2
+@property int prop1;
+@property int prop2;
+@property int prop3;
+@end
+
+@implementation I2
+@synthesize prop1, prop2, prop3;
+-(int) prop1 { return 0; }
+-(int) prop2 { return 0; }
+-(int) prop3 { return 0; }
+@end
+
+// CHECK: warning: writable atomic property 'prop1'
+// CHECK: warning: writable atomic property 'prop2'
+// CHECK: warning: writable atomic property 'prop3'
+
+void test_unused() {
+  // Add enough variables to exceed the small storage of Scope::DeclSetTy.
+  int v1;
+  int v2;
+  int v3;
+  int v4;
+  int v5;
+  int v6;
+  int v7;
+  int v8;
+  int v9;
+  int v10;
+  int v11;
+  int v12;
+  int v13;
+  int v14;
+  int v15;
+  int v16;
+  int v17;
+  int v18;
+  int v19;
+  int v20;
+  int v21;
+  int v22;
+  int v23;
+  int v24;
+  int v25;
+  int v26;
+  int v27;
+  int v28;
+  int v29;
+  int v30;
+  int v31;
+  int v32;
+  int v33;
+  int v34;
+  int v35;
+  int v36;
+  int v37;
+  int v38;
+}
+
+// CHECK: warning: unused variable 'v1'
+// CHECK: warning: unused variable 'v2'
+// CHECK: warning: unused variable 'v3'
+// CHECK: warning: unused variable 'v4'
+// CHECK: warning: unused variable 'v5'
+// CHECK: warning: unused variable 'v6'
+// CHECK: warning: unused variable 'v7'
+// CHECK: warning: unused variable 'v8'
+// CHECK: warning: unused variable 'v9'
+// CHECK: warning: unused variable 'v10'
+// CHECK: warning: unused variable 'v11'
+// CHECK: warning: unused variable 'v12'
+// CHECK: warning: unused variable 'v13'
+// CHECK: warning: unused variable 'v14'
+// CHECK: warning: unused variable 'v15'
+// CHECK: warning: unused variable 'v16'
+// CHECK: warning: unused variable 'v17'
+// CHECK: warning: unused variable 'v18'
+// CHECK: warning: unused variable 'v19'
+// CHECK: warning: unused variable 'v20'
+// CHECK: warning: unused variable 'v21'
+// CHECK: warning: unused variable 'v22'
+// CHECK: warning: unused variable 'v23'
+// CHECK: warning: unused variable 'v24'
+// CHECK: warning: unused variable 'v25'
+// CHECK: warning: unused variable 'v26'
+// CHECK: warning: unused variable 'v27'
+// CHECK: warning: unused variable 'v28'
+// CHECK: warning: unused variable 'v29'
+// CHECK: warning: unused variable 'v30'
+// CHECK: warning: unused variable 'v31'
+// CHECK: warning: unused variable 'v32'
+// CHECK: warning: unused variable 'v33'
+// CHECK: warning: unused variable 'v34'
+// CHECK: warning: unused variable 'v35'
+// CHECK: warning: unused variable 'v36'
+// CHECK: warning: unused variable 'v37'
+// CHECK: warning: unused variable 'v38'
Index: clang/include/clang/Sema/Scope.h
===
--- clang/include/clang/Sema/Scope.h
+++ clang/include/clang/Sema/Scope.h
@@ -16,6 +16,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
@@ -196,7 +197,7 @@
   /// popped, these declarations are removed from the IdentifierTable's notion
   /// of current declaration.  It is up to the current Action implementation to
   /// implement these semantics.
-  using DeclSetTy = llvm::SmallPtrSet;
+  using DeclSetTy = llvm::SmallSetVector;
   DeclSetTy DeclsInScope;
 
   /// The DeclContext with which this scope is associated. For
@@ -321,9 +322,7 @@
 DeclsInScope.insert(D);
   }
 
-  void RemoveDecl(Decl *D) {
-DeclsInScope.erase(D);
-  }
+  void RemoveDecl(Decl *D) { DeclsInScope.remove(D); }
 
   void incrementMSManglingNumber() {
 if (Scope *MSLMP = getMSLastManglingParent()) {
@@ -351,7 +350,9 @@
 
   /// isDeclScope - Return true if 

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

2022-09-13 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb340c5ae4221: [Lex/DependencyDirectivesScanner] Handle the 
case where the source line starts… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133674

Files:
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp


Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -124,6 +124,21 @@
   EXPECT_STREQ("#define MACRO a\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) {
+  SmallVector Out;
+
+  StringRef Source = R"(
+#define S
+#if 0
+  ##pragma cool
+  ##include "t.h"
+#endif
+#define E
+)";
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+  EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, Define) {
   SmallVector Out;
   SmallVector Tokens;
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -742,6 +742,14 @@
 
   // Lex '#'.
   const dependency_directives_scan::Token  = lexToken(First, End);
+  if (HashTok.is(tok::hashhash)) {
+// A \p tok::hashhash at this location is passed by the preprocessor to the
+// parser to interpret, like any other token. So for dependency scanning
+// skip it like a normal token not affecting the preprocessor.
+skipLine(First, End);
+assert(First <= End);
+return false;
+  }
   assert(HashTok.is(tok::hash));
   (void)HashTok;
 


Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -124,6 +124,21 @@
   EXPECT_STREQ("#define MACRO a\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) {
+  SmallVector Out;
+
+  StringRef Source = R"(
+#define S
+#if 0
+  ##pragma cool
+  ##include "t.h"
+#endif
+#define E
+)";
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+  EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, Define) {
   SmallVector Out;
   SmallVector Tokens;
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -742,6 +742,14 @@
 
   // Lex '#'.
   const dependency_directives_scan::Token  = lexToken(First, End);
+  if (HashTok.is(tok::hashhash)) {
+// A \p tok::hashhash at this location is passed by the preprocessor to the
+// parser to interpret, like any other token. So for dependency scanning
+// skip it like a normal token not affecting the preprocessor.
+skipLine(First, End);
+assert(First <= End);
+return false;
+  }
   assert(HashTok.is(tok::hash));
   (void)HashTok;
 
___
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 Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D133674#3784710 , @akyrtzi wrote:

> In D133674#3784602 , @jansvoboda11 
> wrote:
>
>> 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.
>
> `##` is lexed as `tok::hashhash`; it is ignored by the preprocessor (it is 
> not treated as the start of a preprocessor directive) and passed on to the 
> parser to interpret, like any other token.

@jansvoboda11 I've added a comment in code to make it clear why it skips.


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 Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 459888.
akyrtzi added a comment.

Add comment to clarify why we skip if `tok::hashhash` is encountered.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133674

Files:
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp


Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -124,6 +124,21 @@
   EXPECT_STREQ("#define MACRO a\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) {
+  SmallVector Out;
+
+  StringRef Source = R"(
+#define S
+#if 0
+  ##pragma cool
+  ##include "t.h"
+#endif
+#define E
+)";
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+  EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, Define) {
   SmallVector Out;
   SmallVector Tokens;
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -742,6 +742,14 @@
 
   // Lex '#'.
   const dependency_directives_scan::Token  = lexToken(First, End);
+  if (HashTok.is(tok::hashhash)) {
+// A \p tok::hashhash at this location is passed by the preprocessor to the
+// parser to interpret, like any other token. So for dependency scanning
+// skip it like a normal token not affecting the preprocessor.
+skipLine(First, End);
+assert(First <= End);
+return false;
+  }
   assert(HashTok.is(tok::hash));
   (void)HashTok;
 


Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -124,6 +124,21 @@
   EXPECT_STREQ("#define MACRO a\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) {
+  SmallVector Out;
+
+  StringRef Source = R"(
+#define S
+#if 0
+  ##pragma cool
+  ##include "t.h"
+#endif
+#define E
+)";
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+  EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, Define) {
   SmallVector Out;
   SmallVector Tokens;
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -742,6 +742,14 @@
 
   // Lex '#'.
   const dependency_directives_scan::Token  = lexToken(First, End);
+  if (HashTok.is(tok::hashhash)) {
+// A \p tok::hashhash at this location is passed by the preprocessor to the
+// parser to interpret, like any other token. So for dependency scanning
+// skip it like a normal token not affecting the preprocessor.
+skipLine(First, End);
+assert(First <= End);
+return false;
+  }
   assert(HashTok.is(tok::hash));
   (void)HashTok;
 
___
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 Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D133674#3784602 , @jansvoboda11 
wrote:

> 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.

`##` is lexed as `tok::hashhash`; it is ignored by the preprocessor (it is not 
treated as the start of a preprocessor directive) and passed on to the parser 
to interpret, like any other token.


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-11 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133674

Files:
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp


Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -124,6 +124,21 @@
   EXPECT_STREQ("#define MACRO a\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) {
+  SmallVector Out;
+
+  StringRef Source = R"(
+#define S
+#if 0
+  ##pragma cool
+  ##include "t.h"
+#endif
+#define E
+)";
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+  EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, Define) {
   SmallVector Out;
   SmallVector Tokens;
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -742,6 +742,11 @@
 
   // Lex '#'.
   const dependency_directives_scan::Token  = lexToken(First, End);
+  if (HashTok.is(tok::hashhash)) {
+skipLine(First, End);
+assert(First <= End);
+return false;
+  }
   assert(HashTok.is(tok::hash));
   (void)HashTok;
 


Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -124,6 +124,21 @@
   EXPECT_STREQ("#define MACRO a\n", Out.data());
 }
 
+TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) {
+  SmallVector Out;
+
+  StringRef Source = R"(
+#define S
+#if 0
+  ##pragma cool
+  ##include "t.h"
+#endif
+#define E
+)";
+  ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+  EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data());
+}
+
 TEST(MinimizeSourceToDependencyDirectivesTest, Define) {
   SmallVector Out;
   SmallVector Tokens;
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -742,6 +742,11 @@
 
   // Lex '#'.
   const dependency_directives_scan::Token  = lexToken(First, End);
+  if (HashTok.is(tok::hashhash)) {
+skipLine(First, End);
+assert(First <= End);
+return false;
+  }
   assert(HashTok.is(tok::hash));
   (void)HashTok;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-07 Thread Argyrios Kyrtzidis 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 rGaa484c90cf59: [Lex/DependencyDirectivesScanner] Keep track 
of the presence of tokens between… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

Files:
  clang/include/clang/Lex/DependencyDirectivesScanner.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Lexer.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -0,0 +1,148 @@
+//===- unittests/Lex/PPDependencyDirectivesTest.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/DependencyDirectivesScanner.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class PPDependencyDirectivesTest : public ::testing::Test {
+protected:
+  PPDependencyDirectivesTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-macos12";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+class IncludeCollector : public PPCallbacks {
+public:
+  Preprocessor 
+  SmallVectorImpl 
+
+  IncludeCollector(Preprocessor , SmallVectorImpl )
+  : PP(PP), IncludedFiles(IncludedFiles) {}
+
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override {
+if (Reason != LexedFileChangeReason::EnterFile)
+  return;
+if (FID == PP.getPredefinesFileID())
+  return;
+StringRef Filename =
+PP.getSourceManager().getSLocEntry(FID).getFile().getName();
+IncludedFiles.push_back(Filename);
+  }
+};
+
+TEST_F(PPDependencyDirectivesTest, MacroGuard) {
+  // "head1.h" has a macro guard and should only be included once.
+  // "head2.h" and "head3.h" have tokens following the macro check, they should
+  // be included multiple times.
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->addFile(
+  "head1.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n"));
+  VFS->addFile(
+  "head2.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H2_H\n#define H2_H\n#endif\n\n"
+   "extern int foo;\n"));
+  VFS->addFile("head3.h", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#ifndef H3_H\n#define H3_H\n#endif\n\n"
+   "#ifdef SOMEMAC\nextern int foo;\n#endif\n"));
+  VFS->addFile("main.c", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#include \"head1.h\"\n#include \"head1.h\"\n"
+   "#include \"head2.h\"\n#include \"head2.h\"\n"
+   "#include \"head3.h\"\n#include \"head3.h\"\n"));
+  FileMgr.setVirtualFileSystem(VFS);
+
+  Optional FE;
+  ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
+llvm::Succeeded());
+  SourceMgr.setMainFileID(
+  SourceMgr.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
+
+  struct DepDirectives {
+SmallVector Tokens;
+SmallVector Directives;
+  };
+  SmallVector> DepDirectivesObjects;
+
+  auto getDependencyDirectives = [&](FileEntryRef File)
+  -> Optional> {
+DepDirectivesObjects.push_back(std::make_unique());
+StringRef Input = (*FileMgr.getBufferForFile(File))->getBuffer();
+bool Err = 

[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 458499.
akyrtzi added a comment.

Remove leftover doc-comment parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

Files:
  clang/include/clang/Lex/DependencyDirectivesScanner.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Lexer.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -0,0 +1,148 @@
+//===- unittests/Lex/PPDependencyDirectivesTest.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/DependencyDirectivesScanner.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class PPDependencyDirectivesTest : public ::testing::Test {
+protected:
+  PPDependencyDirectivesTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-macos12";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+class IncludeCollector : public PPCallbacks {
+public:
+  Preprocessor 
+  SmallVectorImpl 
+
+  IncludeCollector(Preprocessor , SmallVectorImpl )
+  : PP(PP), IncludedFiles(IncludedFiles) {}
+
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override {
+if (Reason != LexedFileChangeReason::EnterFile)
+  return;
+if (FID == PP.getPredefinesFileID())
+  return;
+StringRef Filename =
+PP.getSourceManager().getSLocEntry(FID).getFile().getName();
+IncludedFiles.push_back(Filename);
+  }
+};
+
+TEST_F(PPDependencyDirectivesTest, MacroGuard) {
+  // "head1.h" has a macro guard and should only be included once.
+  // "head2.h" and "head3.h" have tokens following the macro check, they should
+  // be included multiple times.
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->addFile(
+  "head1.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n"));
+  VFS->addFile(
+  "head2.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H2_H\n#define H2_H\n#endif\n\n"
+   "extern int foo;\n"));
+  VFS->addFile("head3.h", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#ifndef H3_H\n#define H3_H\n#endif\n\n"
+   "#ifdef SOMEMAC\nextern int foo;\n#endif\n"));
+  VFS->addFile("main.c", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#include \"head1.h\"\n#include \"head1.h\"\n"
+   "#include \"head2.h\"\n#include \"head2.h\"\n"
+   "#include \"head3.h\"\n#include \"head3.h\"\n"));
+  FileMgr.setVirtualFileSystem(VFS);
+
+  Optional FE;
+  ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
+llvm::Succeeded());
+  SourceMgr.setMainFileID(
+  SourceMgr.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
+
+  struct DepDirectives {
+SmallVector Tokens;
+SmallVector Directives;
+  };
+  SmallVector> DepDirectivesObjects;
+
+  auto getDependencyDirectives = [&](FileEntryRef File)
+  -> Optional> {
+DepDirectivesObjects.push_back(std::make_unique());
+StringRef Input = (*FileMgr.getBufferForFile(File))->getBuffer();
+bool Err = scanSourceForDependencyDirectives(
+Input, DepDirectivesObjects.back()->Tokens,
+DepDirectivesObjects.back()->Directives);
+EXPECT_FALSE(Err);
+return 

[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi marked 4 inline comments as done.
akyrtzi added a comment.

@benlangmuir see latest diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

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


[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 458360.
akyrtzi added a comment.

Always print `tokens_present_before_eof` and print it as "" for 
clarity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

Files:
  clang/include/clang/Lex/DependencyDirectivesScanner.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Lexer.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -0,0 +1,148 @@
+//===- unittests/Lex/PPDependencyDirectivesTest.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/DependencyDirectivesScanner.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class PPDependencyDirectivesTest : public ::testing::Test {
+protected:
+  PPDependencyDirectivesTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-macos12";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+class IncludeCollector : public PPCallbacks {
+public:
+  Preprocessor 
+  SmallVectorImpl 
+
+  IncludeCollector(Preprocessor , SmallVectorImpl )
+  : PP(PP), IncludedFiles(IncludedFiles) {}
+
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override {
+if (Reason != LexedFileChangeReason::EnterFile)
+  return;
+if (FID == PP.getPredefinesFileID())
+  return;
+StringRef Filename =
+PP.getSourceManager().getSLocEntry(FID).getFile().getName();
+IncludedFiles.push_back(Filename);
+  }
+};
+
+TEST_F(PPDependencyDirectivesTest, MacroGuard) {
+  // "head1.h" has a macro guard and should only be included once.
+  // "head2.h" and "head3.h" have tokens following the macro check, they should
+  // be included multiple times.
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->addFile(
+  "head1.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n"));
+  VFS->addFile(
+  "head2.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H2_H\n#define H2_H\n#endif\n\n"
+   "extern int foo;\n"));
+  VFS->addFile("head3.h", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#ifndef H3_H\n#define H3_H\n#endif\n\n"
+   "#ifdef SOMEMAC\nextern int foo;\n#endif\n"));
+  VFS->addFile("main.c", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#include \"head1.h\"\n#include \"head1.h\"\n"
+   "#include \"head2.h\"\n#include \"head2.h\"\n"
+   "#include \"head3.h\"\n#include \"head3.h\"\n"));
+  FileMgr.setVirtualFileSystem(VFS);
+
+  Optional FE;
+  ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
+llvm::Succeeded());
+  SourceMgr.setMainFileID(
+  SourceMgr.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
+
+  struct DepDirectives {
+SmallVector Tokens;
+SmallVector Directives;
+  };
+  SmallVector> DepDirectivesObjects;
+
+  auto getDependencyDirectives = [&](FileEntryRef File)
+  -> Optional> {
+DepDirectivesObjects.push_back(std::make_unique());
+StringRef Input = (*FileMgr.getBufferForFile(File))->getBuffer();
+bool Err = scanSourceForDependencyDirectives(
+Input, DepDirectivesObjects.back()->Tokens,
+DepDirectivesObjects.back()->Directives);
+

[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/include/clang/Lex/DependencyDirectivesScanner.h:131
+/// \p dependency_directives_scan::tokens_present_before_eof, otherwise this
+/// directive will be ignored.
 ///

benlangmuir wrote:
> benlangmuir wrote:
> > akyrtzi wrote:
> > > benlangmuir wrote:
> > > > Why would you want to print without this? It seems important for 
> > > > correctness of the output.  I would have expected we would always print 
> > > > it.
> > > The `-print-dependency-directives-minimized-source` clang option is using 
> > > this function, and if you print the sources with "" at the end 
> > > then the source text will not be parsable.
> > > 
> > > But the tests that pass `-print-dependency-directives-minimized-source` 
> > > don't try to parse the code, so I think I can switch the default to be 
> > > `true` for printing the "tokens-before-eof marker" and if a caller has a 
> > > need to ignore it it can pass `false` for the parameter.
> > If someone uses `-print-dependency-directives-minimized-source` and creates 
> > a minimized file for each header, it will "parse", but it won't behave 
> > correctly for multiple includes, right?  My preference is we don't allow 
> > printing this without the TokBEOF.  If we care about making it parse, we 
> > should add a real token of some kind -- maybe there is a no-op `#pragma` or 
> > something?
> Oops, missed half my comment. Meant to also add:
> 
> > But the tests that pass -print-dependency-directives-minimized-source don't 
> > try to parse the code, so I think I can switch the default to be true for 
> > printing the "tokens-before-eof marker" and if a caller has a need to 
> > ignore it it can pass false for the parameter.
> 
> SGTM
Ok, you convinced me that we should just always print it. This function is for 
testing purposes only anyway, if later on we actually have a need to parse back 
the minimized source we can re-evaluate what to do with that directive marker.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

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


[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/include/clang/Lex/DependencyDirectivesScanner.h:131
+/// \p dependency_directives_scan::tokens_present_before_eof, otherwise this
+/// directive will be ignored.
 ///

benlangmuir wrote:
> Why would you want to print without this? It seems important for correctness 
> of the output.  I would have expected we would always print it.
The `-print-dependency-directives-minimized-source` clang option is using this 
function, and if you print the sources with "" at the end then the 
source text will not be parsable.

But the tests that pass `-print-dependency-directives-minimized-source` don't 
try to parse the code, so I think I can switch the default to be `true` for 
printing the "tokens-before-eof marker" and if a caller has a need to ignore it 
it can pass `false` for the parameter.



Comment at: clang/lib/Lex/DependencyDirectivesScanner.cpp:868
+PrintMarkerForTokensBeforeEOF)
+  OS << "";
 Optional PrevTokenKind;

benlangmuir wrote:
> How about "TokBeforeEOF"?  I think "BEOF" is too cryptic.
SGTM 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

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


[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 458173.
akyrtzi added a comment.

Remove a couple of unused local variables.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133357

Files:
  clang/include/clang/Lex/DependencyDirectivesScanner.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Lexer.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -0,0 +1,148 @@
+//===- unittests/Lex/PPDependencyDirectivesTest.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/DependencyDirectivesScanner.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class PPDependencyDirectivesTest : public ::testing::Test {
+protected:
+  PPDependencyDirectivesTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-macos12";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+class IncludeCollector : public PPCallbacks {
+public:
+  Preprocessor 
+  SmallVectorImpl 
+
+  IncludeCollector(Preprocessor , SmallVectorImpl )
+  : PP(PP), IncludedFiles(IncludedFiles) {}
+
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override {
+if (Reason != LexedFileChangeReason::EnterFile)
+  return;
+if (FID == PP.getPredefinesFileID())
+  return;
+StringRef Filename =
+PP.getSourceManager().getSLocEntry(FID).getFile().getName();
+IncludedFiles.push_back(Filename);
+  }
+};
+
+TEST_F(PPDependencyDirectivesTest, MacroGuard) {
+  // "head1.h" has a macro guard and should only be included once.
+  // "head2.h" and "head3.h" have tokens following the macro check, they should
+  // be included multiple times.
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->addFile(
+  "head1.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n"));
+  VFS->addFile(
+  "head2.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H2_H\n#define H2_H\n#endif\n\n"
+   "extern int foo;\n"));
+  VFS->addFile("head3.h", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#ifndef H3_H\n#define H3_H\n#endif\n\n"
+   "#ifdef SOMEMAC\nextern int foo;\n#endif\n"));
+  VFS->addFile("main.c", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#include \"head1.h\"\n#include \"head1.h\"\n"
+   "#include \"head2.h\"\n#include \"head2.h\"\n"
+   "#include \"head3.h\"\n#include \"head3.h\"\n"));
+  FileMgr.setVirtualFileSystem(VFS);
+
+  Optional FE;
+  ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
+llvm::Succeeded());
+  SourceMgr.setMainFileID(
+  SourceMgr.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
+
+  struct DepDirectives {
+SmallVector Tokens;
+SmallVector Directives;
+  };
+  SmallVector> DepDirectivesObjects;
+
+  auto getDependencyDirectives = [&](FileEntryRef File)
+  -> Optional> {
+DepDirectivesObjects.push_back(std::make_unique());
+StringRef Input = (*FileMgr.getBufferForFile(File))->getBuffer();
+bool Err = scanSourceForDependencyDirectives(
+Input, DepDirectivesObjects.back()->Tokens,
+DepDirectivesObjects.back()->Directives);
+EXPECT_FALSE(Err);
+return 

[PATCH] D133357: [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF

2022-09-06 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Directive `dependency_directives_scan::tokens_present_before_eof` is introduced 
to indicate there were tokens present before
the last scanned dependency directive and EOF.
This is useful to ensure we correctly identify the macro guards when lexing 
using the dependency directives.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133357

Files:
  clang/include/clang/Lex/DependencyDirectivesScanner.h
  clang/lib/Lex/DependencyDirectivesScanner.cpp
  clang/lib/Lex/Lexer.cpp
  clang/unittests/Lex/CMakeLists.txt
  clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
  clang/unittests/Lex/PPDependencyDirectivesTest.cpp

Index: clang/unittests/Lex/PPDependencyDirectivesTest.cpp
===
--- /dev/null
+++ clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -0,0 +1,150 @@
+//===- unittests/Lex/PPDependencyDirectivesTest.cpp -=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Lex/DependencyDirectivesScanner.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class PPDependencyDirectivesTest : public ::testing::Test {
+protected:
+  PPDependencyDirectivesTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-macos12";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  std::shared_ptr TargetOpts;
+  IntrusiveRefCntPtr Target;
+};
+
+class IncludeCollector : public PPCallbacks {
+public:
+  Preprocessor 
+  SmallVectorImpl 
+
+  IncludeCollector(Preprocessor , SmallVectorImpl )
+  : PP(PP), IncludedFiles(IncludedFiles) {}
+
+  void LexedFileChanged(FileID FID, LexedFileChangeReason Reason,
+SrcMgr::CharacteristicKind FileType, FileID PrevFID,
+SourceLocation Loc) override {
+if (Reason != LexedFileChangeReason::EnterFile)
+  return;
+if (FID == PP.getPredefinesFileID())
+  return;
+StringRef Filename =
+PP.getSourceManager().getSLocEntry(FID).getFile().getName();
+IncludedFiles.push_back(Filename);
+  }
+};
+
+TEST_F(PPDependencyDirectivesTest, MacroGuard) {
+  // "head1.h" has a macro guard and should only be included once.
+  // "head2.h" and "head3.h" have tokens following the macro check, they should
+  // be included multiple times.
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->addFile(
+  "head1.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H1_H\n#define H1_H\n#endif\n"));
+  VFS->addFile(
+  "head2.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("#ifndef H2_H\n#define H2_H\n#endif\n\n"
+   "extern int foo;\n"));
+  VFS->addFile("head3.h", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#ifndef H3_H\n#define H3_H\n#endif\n\n"
+   "#ifdef SOMEMAC\nextern int foo;\n#endif\n"));
+  VFS->addFile("main.c", 0,
+   llvm::MemoryBuffer::getMemBuffer(
+   "#include \"head1.h\"\n#include \"head1.h\"\n"
+   "#include \"head2.h\"\n#include \"head2.h\"\n"
+   "#include \"head3.h\"\n#include \"head3.h\"\n"));
+  FileMgr.setVirtualFileSystem(VFS);
+
+  Optional FE;
+  ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
+llvm::Succeeded());
+  SourceMgr.setMainFileID(
+  SourceMgr.createFileID(*FE, SourceLocation(), SrcMgr::C_User));
+
+  struct DepDirectives {
+SmallVector Tokens;
+SmallVector Directives;
+  };
+  SmallVector> DepDirectivesObjects;
+
+  auto getDependencyDirectives = [&](FileEntryRef File)
+  -> Optional> {
+

[PATCH] D133229: [driver] Prune module-map related flags, if they are not going to be needed

2022-09-02 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D133229#3768101 , @rsmith wrote:

> I think the approach you're taking here is probably doomed -- too many things 
> in Clang depend on whether we've read module map files, and it seems unlikely 
> to me that you'll be able to catch all of them from the driver.

I see, the driver approach does seem like a non-starter, thank you for the 
feedback! This needs reevaluation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133229

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


[PATCH] D132801: [driver] Additional ignoring of module-map related flags, if modules are disabled

2022-09-02 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D132801#3761253 , @akyrtzi wrote:

> In D132801#3760014 , @rsmith wrote:
>
>> This doesn't look right to me -- we still use module maps when modules are 
>> disabled to enforce layering checking, and when 
>> `-fmodules-local-submodule-visibility` is enabled but `-fmodules` is 
>> disabled we'll use them to provide modular semantics without pre-building 
>> modules. I'm going to revert.
>
> Sorry, I wasn't aware of that. Could `-fmodule-map-file=` be pruned out when 
> `-fmodules-local-submodule-visibility` or `-fmodules-decluse` are not enabled?

I've opened https://reviews.llvm.org/D133229 for your consideration, let me 
know whether this addresses your concerns 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132801

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


[PATCH] D133229: [driver] Prune module-map related flags, if they are not going to be needed

2022-09-02 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

This is follow-up from https://reviews.llvm.org/D132801, but taking into 
account the conditions
where the module-map flags are still used even when `-fmodules` is disabled.

This useful for removing unnecessary input dependencies from the cc1 invocation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133229

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.m


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -75,8 +75,13 @@
 // RUN: %clang -fno-modules -fbuild-session-timestamp=123 -### %s 2>&1 | 
FileCheck -check-prefix=SESSION_FLAG %s
 // SESSION_FLAG-NOT: -fbuild-session-timestamp
 
-// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -### %s 
2>&1 | FileCheck -check-prefix=VALIDATE_ONCE_FLAG %s
-// VALIDATE_ONCE_FLAG-NOT: -fmodules-validate-once-per-build-session
-
-// RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | 
FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
-// VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session 
-fmodules-validate-system-headers -fmodule-map-file=module.modulemap \
+// RUN:   -### %s 2>&1 | FileCheck -check-prefix=IGNORED_FLAGS %s
+// IGNORED_FLAGS-NOT: -fmodules-validate-once-per-build-session
+// IGNORED_FLAGS-NOT: -fmodules-validate-system-headers
+// IGNORED_FLAGS-NOT: -fmodule-map-file
+
+// RUN: %clang -fno-modules -fmodules-decluse 
-fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck 
-check-prefix=MMAPFILE %s
+// RUN: %clang -fno-modules -fmodules-strict-decluse 
-fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck 
-check-prefix=MMAPFILE %s
+// RUN: %clang -fno-modules -Xclang -fmodules-local-submodule-visibility 
-fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck 
-check-prefix=MMAPFILE %s
+// MMAPFILE: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3735,23 +3735,47 @@
   CmdArgs.push_back("-fvalidate-ast-input-files-content");
   }
 
-  // -fmodule-name specifies the module that is currently being built (or
-  // used for header checking by -fmodule-maps).
-  Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
-
-  // -fmodule-map-file can be used to specify files containing module
-  // definitions.
-  Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
-  // -fbuiltin-module-map can be used to load the clang
-  // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
-SmallString<128> BuiltinModuleMap(D.ResourceDir);
-llvm::sys::path::append(BuiltinModuleMap, "include");
-llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
-if (llvm::sys::fs::exists(BuiltinModuleMap))
-  CmdArgs.push_back(
-  Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+  // Check whether any "-fmodule-map-file=" flags are relevant or not. This is
+  // useful for pruning the cc1 arguments and removing unnecessary input
+  // dependencies.
+  bool ModuleMapsAreRelevant = [&]() -> bool {
+if (HaveModules)
+  return true;
+if (Args.hasFlag(options::OPT_fmodules_decluse,
+ options::OPT_fno_modules_decluse, false) ||
+Args.hasFlag(options::OPT_fmodules_strict_decluse,
+ options::OPT_fno_modules_strict_decluse, false))
+  return true;
+for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+  if (StringRef(Arg->getValue()) == "-fmodules-local-submodule-visibility")
+return true;
+}
+return false;
+  }();
+
+  if (ModuleMapsAreRelevant) {
+// -fmodule-name specifies the module that is currently being built (or
+// used for header checking by -fmodule-maps).
+Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
+
+// -fmodule-map-file can be used to specify files containing module
+// definitions.
+Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
+
+// -fbuiltin-module-map can be used to load the clang
+// builtin headers modulemap file.
+if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
+  SmallString<128> BuiltinModuleMap(D.ResourceDir);
+  llvm::sys::path::append(BuiltinModuleMap, "include");
+  llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
+  if (llvm::sys::fs::exists(BuiltinModuleMap))
+CmdArgs.push_back(
+Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+}
+  } else {
+Args.ClaimAllArgs(options::OPT_fmodule_name_EQ);
+

[PATCH] D132801: [driver] Additional ignoring of module-map related flags, if modules are disabled

2022-08-31 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D132801#3760014 , @rsmith wrote:

> This doesn't look right to me -- we still use module maps when modules are 
> disabled to enforce layering checking, and when 
> `-fmodules-local-submodule-visibility` is enabled but `-fmodules` is disabled 
> we'll use them to provide modular semantics without pre-building modules. I'm 
> going to revert.

Sorry, I wasn't aware of that. Could `-fmodule-map-file=` be pruned out when 
`-fmodules-local-submodule-visibility` or `-fmodules-decluse` are not enabled?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132801

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


[PATCH] D132801: [driver] Additional ignoring of module-map related flags, if modules are disabled

2022-08-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
akyrtzi marked an inline comment as done.
Closed by commit rG33162a81d4c9: [driver] Additional ignoring of module-map 
related flags, if modules are… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132801

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.m


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -75,8 +75,8 @@
 // RUN: %clang -fno-modules -fbuild-session-timestamp=123 -### %s 2>&1 | 
FileCheck -check-prefix=SESSION_FLAG %s
 // SESSION_FLAG-NOT: -fbuild-session-timestamp
 
-// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -### %s 
2>&1 | FileCheck -check-prefix=VALIDATE_ONCE_FLAG %s
-// VALIDATE_ONCE_FLAG-NOT: -fmodules-validate-once-per-build-session
-
-// RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | 
FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
-// VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session 
-fmodules-validate-system-headers -fmodule-map-file=module.modulemap \
+// RUN:   -### %s 2>&1 | FileCheck -check-prefix=IGNORED_FLAGS %s
+// IGNORED_FLAGS-NOT: -fmodules-validate-once-per-build-session
+// IGNORED_FLAGS-NOT: -fmodules-validate-system-headers
+// IGNORED_FLAGS-NOT: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3726,25 +3726,29 @@
  options::OPT_fno_modules_validate_input_files_content,
  false))
   CmdArgs.push_back("-fvalidate-ast-input-files-content");
-  }
-
-  // -fmodule-name specifies the module that is currently being built (or
-  // used for header checking by -fmodule-maps).
-  Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
 
-  // -fmodule-map-file can be used to specify files containing module
-  // definitions.
-  Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
-  // -fbuiltin-module-map can be used to load the clang
-  // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
-SmallString<128> BuiltinModuleMap(D.ResourceDir);
-llvm::sys::path::append(BuiltinModuleMap, "include");
-llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
-if (llvm::sys::fs::exists(BuiltinModuleMap))
-  CmdArgs.push_back(
-  Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+// -fmodule-name specifies the module that is currently being built (or
+// used for header checking by -fmodule-maps).
+Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
+
+// -fmodule-map-file can be used to specify files containing module
+// definitions.
+Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
+
+// -fbuiltin-module-map can be used to load the clang
+// builtin headers modulemap file.
+if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
+  SmallString<128> BuiltinModuleMap(D.ResourceDir);
+  llvm::sys::path::append(BuiltinModuleMap, "include");
+  llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
+  if (llvm::sys::fs::exists(BuiltinModuleMap))
+CmdArgs.push_back(
+Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+}
+  } else {
+Args.ClaimAllArgs(options::OPT_fmodule_name_EQ);
+Args.ClaimAllArgs(options::OPT_fmodule_map_file);
+Args.ClaimAllArgs(options::OPT_fbuiltin_module_map);
   }
 
   // The -fmodule-file== form specifies the mapping of module


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -75,8 +75,8 @@
 // RUN: %clang -fno-modules -fbuild-session-timestamp=123 -### %s 2>&1 | FileCheck -check-prefix=SESSION_FLAG %s
 // SESSION_FLAG-NOT: -fbuild-session-timestamp
 
-// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_ONCE_FLAG %s
-// VALIDATE_ONCE_FLAG-NOT: -fmodules-validate-once-per-build-session
-
-// RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
-// VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -fmodules-validate-system-headers -fmodule-map-file=module.modulemap \
+// RUN:   -### %s 2>&1 | FileCheck -check-prefix=IGNORED_FLAGS %s
+// IGNORED_FLAGS-NOT: -fmodules-validate-once-per-build-session
+// IGNORED_FLAGS-NOT: -fmodules-validate-system-headers
+// 

[PATCH] D132801: [driver] Additional ignoring of module-map related flags, if modules are disabled

2022-08-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi marked an inline comment as done.
akyrtzi added inline comments.



Comment at: clang/test/Driver/modules.m:81
 
 // RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | 
FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
 // VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers

MaskRay wrote:
> You may combine `-fmodule-map-file=module.modulemap` with this RUN line to 
> avoid introducing a new RUN line (every run makes testsuite slightly slower).
Good suggestion, I merged the last existing 2 `RUN` lines along with the new 
one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132801

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


[PATCH] D132801: [driver] Additional ignoring of module-map related flags, if modules are disabled

2022-08-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 456483.
akyrtzi added a comment.

Merge the new `RUN` line together with the prior 2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132801

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.m


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -75,8 +75,8 @@
 // RUN: %clang -fno-modules -fbuild-session-timestamp=123 -### %s 2>&1 | 
FileCheck -check-prefix=SESSION_FLAG %s
 // SESSION_FLAG-NOT: -fbuild-session-timestamp
 
-// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -### %s 
2>&1 | FileCheck -check-prefix=VALIDATE_ONCE_FLAG %s
-// VALIDATE_ONCE_FLAG-NOT: -fmodules-validate-once-per-build-session
-
-// RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | 
FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
-// VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session 
-fmodules-validate-system-headers -fmodule-map-file=module.modulemap \
+// RUN:   -### %s 2>&1 | FileCheck -check-prefix=IGNORED_FLAGS %s
+// IGNORED_FLAGS-NOT: -fmodules-validate-once-per-build-session
+// IGNORED_FLAGS-NOT: -fmodules-validate-system-headers
+// IGNORED_FLAGS-NOT: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3726,25 +3726,29 @@
  options::OPT_fno_modules_validate_input_files_content,
  false))
   CmdArgs.push_back("-fvalidate-ast-input-files-content");
-  }
-
-  // -fmodule-name specifies the module that is currently being built (or
-  // used for header checking by -fmodule-maps).
-  Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
 
-  // -fmodule-map-file can be used to specify files containing module
-  // definitions.
-  Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
-  // -fbuiltin-module-map can be used to load the clang
-  // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
-SmallString<128> BuiltinModuleMap(D.ResourceDir);
-llvm::sys::path::append(BuiltinModuleMap, "include");
-llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
-if (llvm::sys::fs::exists(BuiltinModuleMap))
-  CmdArgs.push_back(
-  Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+// -fmodule-name specifies the module that is currently being built (or
+// used for header checking by -fmodule-maps).
+Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
+
+// -fmodule-map-file can be used to specify files containing module
+// definitions.
+Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
+
+// -fbuiltin-module-map can be used to load the clang
+// builtin headers modulemap file.
+if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
+  SmallString<128> BuiltinModuleMap(D.ResourceDir);
+  llvm::sys::path::append(BuiltinModuleMap, "include");
+  llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
+  if (llvm::sys::fs::exists(BuiltinModuleMap))
+CmdArgs.push_back(
+Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+}
+  } else {
+Args.ClaimAllArgs(options::OPT_fmodule_name_EQ);
+Args.ClaimAllArgs(options::OPT_fmodule_map_file);
+Args.ClaimAllArgs(options::OPT_fbuiltin_module_map);
   }
 
   // The -fmodule-file== form specifies the mapping of module


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -75,8 +75,8 @@
 // RUN: %clang -fno-modules -fbuild-session-timestamp=123 -### %s 2>&1 | FileCheck -check-prefix=SESSION_FLAG %s
 // SESSION_FLAG-NOT: -fbuild-session-timestamp
 
-// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_ONCE_FLAG %s
-// VALIDATE_ONCE_FLAG-NOT: -fmodules-validate-once-per-build-session
-
-// RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
-// VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -fmodules-validate-system-headers -fmodule-map-file=module.modulemap \
+// RUN:   -### %s 2>&1 | FileCheck -check-prefix=IGNORED_FLAGS %s
+// IGNORED_FLAGS-NOT: -fmodules-validate-once-per-build-session
+// IGNORED_FLAGS-NOT: -fmodules-validate-system-headers
+// IGNORED_FLAGS-NOT: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp

[PATCH] D132801: [driver] Additional ignoring of module-map related flags, if modules are disabled

2022-08-27 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132801

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.m


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -80,3 +80,6 @@
 
 // RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | 
FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
 // VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+
+// RUN: %clang -fno-modules -fmodule-map-file=module.modulemap -### %s 2>&1 | 
FileCheck -check-prefix=MODULE_MAP_FILE %s
+// MODULE_MAP_FILE-NOT: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3726,25 +3726,29 @@
  options::OPT_fno_modules_validate_input_files_content,
  false))
   CmdArgs.push_back("-fvalidate-ast-input-files-content");
-  }
-
-  // -fmodule-name specifies the module that is currently being built (or
-  // used for header checking by -fmodule-maps).
-  Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
 
-  // -fmodule-map-file can be used to specify files containing module
-  // definitions.
-  Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
-  // -fbuiltin-module-map can be used to load the clang
-  // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
-SmallString<128> BuiltinModuleMap(D.ResourceDir);
-llvm::sys::path::append(BuiltinModuleMap, "include");
-llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
-if (llvm::sys::fs::exists(BuiltinModuleMap))
-  CmdArgs.push_back(
-  Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+// -fmodule-name specifies the module that is currently being built (or
+// used for header checking by -fmodule-maps).
+Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
+
+// -fmodule-map-file can be used to specify files containing module
+// definitions.
+Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
+
+// -fbuiltin-module-map can be used to load the clang
+// builtin headers modulemap file.
+if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
+  SmallString<128> BuiltinModuleMap(D.ResourceDir);
+  llvm::sys::path::append(BuiltinModuleMap, "include");
+  llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
+  if (llvm::sys::fs::exists(BuiltinModuleMap))
+CmdArgs.push_back(
+Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+}
+  } else {
+Args.ClaimAllArgs(options::OPT_fmodule_name_EQ);
+Args.ClaimAllArgs(options::OPT_fmodule_map_file);
+Args.ClaimAllArgs(options::OPT_fbuiltin_module_map);
   }
 
   // The -fmodule-file== form specifies the mapping of module


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -80,3 +80,6 @@
 
 // RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
 // VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+
+// RUN: %clang -fno-modules -fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck -check-prefix=MODULE_MAP_FILE %s
+// MODULE_MAP_FILE-NOT: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3726,25 +3726,29 @@
  options::OPT_fno_modules_validate_input_files_content,
  false))
   CmdArgs.push_back("-fvalidate-ast-input-files-content");
-  }
-
-  // -fmodule-name specifies the module that is currently being built (or
-  // used for header checking by -fmodule-maps).
-  Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
 
-  // -fmodule-map-file can be used to specify files containing module
-  // definitions.
-  Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
-  // -fbuiltin-module-map can be used to load the clang
-  // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
-SmallString<128> BuiltinModuleMap(D.ResourceDir);
-llvm::sys::path::append(BuiltinModuleMap, "include");
-llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
-if (llvm::sys::fs::exists(BuiltinModuleMap))
-  CmdArgs.push_back(
-  Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+// -fmodule-name 

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

2022-08-05 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6635f48e4aba: [Serialization] Remove `ORIGINAL_PCH_DIR` 
record (authored by akyrtzi).

Changed prior to commit:
  https://reviews.llvm.org/D131124?vs=449808=450439#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131124

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GeneratePCH.cpp
  clang/test/Modules/relative-original-dir.m
  clang/test/PCH/pch-output-path-independent.c

Index: clang/test/PCH/pch-output-path-independent.c
===
--- clang/test/PCH/pch-output-path-independent.c
+++ clang/test/PCH/pch-output-path-independent.c
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t && mkdir -p %t/a %t/b
 
-// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch -fpcm-output-path-independent
-// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch -fpcm-output-path-independent
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch
 
 // RUN: diff %t/a/t1.pch %t/b/t2.pch
Index: clang/test/Modules/relative-original-dir.m
===
--- clang/test/Modules/relative-original-dir.m
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: rm -rf %t/normal-module-map
-// RUN: mkdir -p %t
-// RUN: cp -r %S/Inputs/normal-module-map %t
-// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fmodule-name=libA -emit-module %t/normal-module-map/module.map -o %t/normal-module-map/outdir/mod.pcm
-// RUN: llvm-bcanalyzer --dump --disable-histogram %t/normal-module-map/outdir/mod.pcm | FileCheck %s
-
-// CHECK:  blob data = 'outdir'
Index: clang/lib/Serialization/GeneratePCH.cpp
===
--- clang/lib/Serialization/GeneratePCH.cpp
+++ clang/lib/Serialization/GeneratePCH.cpp
@@ -25,14 +25,13 @@
 StringRef OutputFile, StringRef isysroot, std::shared_ptr Buffer,
 ArrayRef> Extensions,
 bool AllowASTWithErrors, bool IncludeTimestamps,
-bool ShouldCacheASTInMemory, bool OutputPathIndependent)
+bool ShouldCacheASTInMemory)
 : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
   SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
   Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
  IncludeTimestamps),
   AllowASTWithErrors(AllowASTWithErrors),
-  ShouldCacheASTInMemory(ShouldCacheASTInMemory),
-  OutputPathIndependent(OutputPathIndependent) {
+  ShouldCacheASTInMemory(ShouldCacheASTInMemory) {
   this->Buffer->IsComplete = false;
 }
 
@@ -71,7 +70,7 @@
   // For serialization we are lenient if the errors were
   // only warn-as-error kind.
   PP.getDiagnostics().hasUncompilableErrorOccurred(),
-  ShouldCacheASTInMemory, OutputPathIndependent);
+  ShouldCacheASTInMemory);
 
   Buffer->IsComplete = true;
 }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -786,7 +786,6 @@
   RECORD(MODULE_MAP_FILE);
   RECORD(IMPORTS);
   RECORD(ORIGINAL_FILE);
-  RECORD(ORIGINAL_PCH_DIR);
   RECORD(ORIGINAL_FILE_ID);
   RECORD(INPUT_FILE_OFFSETS);
 
@@ -1187,7 +1186,7 @@
 
 /// Write the control block.
 void ASTWriter::WriteControlBlock(Preprocessor , ASTContext ,
-  StringRef isysroot, StringRef OutputFile) {
+  StringRef isysroot) {
   using namespace llvm;
 
   Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
@@ -1470,21 +1469,6 @@
   Record.push_back(SM.getMainFileID().getOpaqueValue());
   Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
 
-  // Original PCH directory
-  if (!OutputFile.empty() && OutputFile != "-") {
-auto Abbrev = std::make_shared();
-Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR));
-Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
-unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
-
-SmallString<128> OutputPath(OutputFile);
-PreparePathForOutput(OutputPath);
-StringRef origDir = llvm::sys::path::parent_path(OutputPath);
-
-RecordData::value_type Record[] = {ORIGINAL_PCH_DIR};
-Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
-  }
-
   std::set AffectingModuleMaps;
   if 

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

2022-08-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use of `ORIGINAL_PCH_DIR` record has been superseeded by making PCH/PCM files 
with relocatable paths at write time.
Removing this record is useful for producing an output-path-independent PCH 
file and enable sharing of the same PCH file even
when it was intended for a different output path.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131124

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GeneratePCH.cpp
  clang/test/Modules/relative-original-dir.m
  clang/test/PCH/pch-output-path-independent.c

Index: clang/test/PCH/pch-output-path-independent.c
===
--- clang/test/PCH/pch-output-path-independent.c
+++ clang/test/PCH/pch-output-path-independent.c
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t && mkdir -p %t/a %t/b
 
-// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch -fpcm-output-path-independent
-// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch -fpcm-output-path-independent
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch
 
 // RUN: diff %t/a/t1.pch %t/b/t2.pch
Index: clang/test/Modules/relative-original-dir.m
===
--- clang/test/Modules/relative-original-dir.m
+++ /dev/null
@@ -1,7 +0,0 @@
-// RUN: rm -rf %t/normal-module-map
-// RUN: mkdir -p %t
-// RUN: cp -r %S/Inputs/normal-module-map %t
-// RUN: %clang_cc1 -fmodules -fno-implicit-modules -fmodule-name=libA -emit-module %t/normal-module-map/module.map -o %t/normal-module-map/outdir/mod.pcm
-// RUN: llvm-bcanalyzer --dump --disable-histogram %t/normal-module-map/outdir/mod.pcm | FileCheck %s
-
-// CHECK:  blob data = 'outdir'
Index: clang/lib/Serialization/GeneratePCH.cpp
===
--- clang/lib/Serialization/GeneratePCH.cpp
+++ clang/lib/Serialization/GeneratePCH.cpp
@@ -25,14 +25,13 @@
 StringRef OutputFile, StringRef isysroot, std::shared_ptr Buffer,
 ArrayRef> Extensions,
 bool AllowASTWithErrors, bool IncludeTimestamps,
-bool ShouldCacheASTInMemory, bool OutputPathIndependent)
+bool ShouldCacheASTInMemory)
 : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
   SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
   Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
  IncludeTimestamps),
   AllowASTWithErrors(AllowASTWithErrors),
-  ShouldCacheASTInMemory(ShouldCacheASTInMemory),
-  OutputPathIndependent(OutputPathIndependent) {
+  ShouldCacheASTInMemory(ShouldCacheASTInMemory) {
   this->Buffer->IsComplete = false;
 }
 
@@ -71,7 +70,7 @@
   // For serialization we are lenient if the errors were
   // only warn-as-error kind.
   PP.getDiagnostics().hasUncompilableErrorOccurred(),
-  ShouldCacheASTInMemory, OutputPathIndependent);
+  ShouldCacheASTInMemory);
 
   Buffer->IsComplete = true;
 }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -786,7 +786,6 @@
   RECORD(MODULE_MAP_FILE);
   RECORD(IMPORTS);
   RECORD(ORIGINAL_FILE);
-  RECORD(ORIGINAL_PCH_DIR);
   RECORD(ORIGINAL_FILE_ID);
   RECORD(INPUT_FILE_OFFSETS);
 
@@ -1187,7 +1186,7 @@
 
 /// Write the control block.
 void ASTWriter::WriteControlBlock(Preprocessor , ASTContext ,
-  StringRef isysroot, StringRef OutputFile) {
+  StringRef isysroot) {
   using namespace llvm;
 
   Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
@@ -1470,21 +1469,6 @@
   Record.push_back(SM.getMainFileID().getOpaqueValue());
   Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
 
-  // Original PCH directory
-  if (!OutputFile.empty() && OutputFile != "-") {
-auto Abbrev = std::make_shared();
-Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR));
-Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name
-unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
-
-SmallString<128> OutputPath(OutputFile);
-PreparePathForOutput(OutputPath);
-StringRef origDir = llvm::sys::path::parent_path(OutputPath);
-
-RecordData::value_type 

[PATCH] D130710: [ASTWriter] Provide capability to output a PCM/PCH file that does not write out information about its output path

2022-07-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG944a86de7c50: [ASTWriter] Provide capability to output a 
PCM/PCH file that does not write out… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130710

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GeneratePCH.cpp
  clang/test/PCH/pch-output-path-independent.c

Index: clang/test/PCH/pch-output-path-independent.c
===
--- /dev/null
+++ clang/test/PCH/pch-output-path-independent.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t/a %t/b
+
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch -fpcm-output-path-independent
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch -fpcm-output-path-independent
+
+// RUN: diff %t/a/t1.pch %t/b/t2.pch
Index: clang/lib/Serialization/GeneratePCH.cpp
===
--- clang/lib/Serialization/GeneratePCH.cpp
+++ clang/lib/Serialization/GeneratePCH.cpp
@@ -25,13 +25,14 @@
 StringRef OutputFile, StringRef isysroot, std::shared_ptr Buffer,
 ArrayRef> Extensions,
 bool AllowASTWithErrors, bool IncludeTimestamps,
-bool ShouldCacheASTInMemory)
+bool ShouldCacheASTInMemory, bool OutputPathIndependent)
 : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
   SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
   Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
  IncludeTimestamps),
   AllowASTWithErrors(AllowASTWithErrors),
-  ShouldCacheASTInMemory(ShouldCacheASTInMemory) {
+  ShouldCacheASTInMemory(ShouldCacheASTInMemory),
+  OutputPathIndependent(OutputPathIndependent) {
   this->Buffer->IsComplete = false;
 }
 
@@ -70,7 +71,7 @@
   // For serialization we are lenient if the errors were
   // only warn-as-error kind.
   PP.getDiagnostics().hasUncompilableErrorOccurred(),
-  ShouldCacheASTInMemory);
+  ShouldCacheASTInMemory, OutputPathIndependent);
 
   Buffer->IsComplete = true;
 }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4483,7 +4483,8 @@
 ASTFileSignature ASTWriter::WriteAST(Sema , StringRef OutputFile,
  Module *WritingModule, StringRef isysroot,
  bool hasErrors,
- bool ShouldCacheASTInMemory) {
+ bool ShouldCacheASTInMemory,
+ bool OutputPathIndependent) {
   WritingAST = true;
 
   ASTHasCompilerErrors = hasErrors;
@@ -4499,8 +4500,9 @@
   Context = 
   PP = 
   this->WritingModule = WritingModule;
-  ASTFileSignature Signature =
-  WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule);
+  ASTFileSignature Signature = WriteASTCore(
+  SemaRef, isysroot, OutputPathIndependent ? StringRef() : OutputFile,
+  WritingModule);
   Context = nullptr;
   PP = nullptr;
   this->WritingModule = nullptr;
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -140,7 +140,8 @@
   CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
   FrontendOpts.ModuleFileExtensions,
   CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
-  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH));
+  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH,
+  FrontendOpts.OutputPathIndependentPCM));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, std::string(InFile), OutputFile, std::move(OS), Buffer));
 
@@ -203,7 +204,9 @@
   /*IncludeTimestamps=*/
   +CI.getFrontendOpts().BuildingImplicitModule,
   /*ShouldCacheASTInMemory=*/
-  +CI.getFrontendOpts().BuildingImplicitModule));
+  +CI.getFrontendOpts().BuildingImplicitModule,
+  /*OutputPathIndependent=*/
+  +CI.getFrontendOpts().OutputPathIndependentPCM));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, std::string(InFile), OutputFile, std::move(OS), Buffer));
   return std::make_unique(std::move(Consumers));
Index: clang/include/clang/Serialization/ASTWriter.h

[PATCH] D130710: [ASTWriter] Provide capability to output a PCM/PCH file that does not write out information about its output path

2022-07-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D130710#3685436 , @benlangmuir 
wrote:

> Is the functionality provided by `ORIGINAL_PCH_DIR` still useful for making 
> it possible to move a PCH and its referenced headers?  It's not completely 
> clear to me when this feature is used in practice.  It would be nice to 
> remove it or change the default behaviour if possible, rather than require a 
> new option, but I'm open to this approach if we think we can't change the 
> default.

Given that there was a recent change  related 
to `ORIGINAL_PCH_DIR`, I'm reluctant to change the default at this point, I 
added a `FIXME` for following up to see if we can remove it or change the 
default later on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130710

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


[PATCH] D130710: [ASTWriter] Provide capability to output a PCM/PCH file that does not write out information about its output path

2022-07-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 448715.
akyrtzi added a comment.

Add `FIXME` comment to consider either removing `ORIGINAL_PCH_DIR` or changing 
the default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130710

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GeneratePCH.cpp
  clang/test/PCH/pch-output-path-independent.c

Index: clang/test/PCH/pch-output-path-independent.c
===
--- /dev/null
+++ clang/test/PCH/pch-output-path-independent.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t/a %t/b
+
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch -fpcm-output-path-independent
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch -fpcm-output-path-independent
+
+// RUN: diff %t/a/t1.pch %t/b/t2.pch
Index: clang/lib/Serialization/GeneratePCH.cpp
===
--- clang/lib/Serialization/GeneratePCH.cpp
+++ clang/lib/Serialization/GeneratePCH.cpp
@@ -25,13 +25,14 @@
 StringRef OutputFile, StringRef isysroot, std::shared_ptr Buffer,
 ArrayRef> Extensions,
 bool AllowASTWithErrors, bool IncludeTimestamps,
-bool ShouldCacheASTInMemory)
+bool ShouldCacheASTInMemory, bool OutputPathIndependent)
 : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
   SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
   Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
  IncludeTimestamps),
   AllowASTWithErrors(AllowASTWithErrors),
-  ShouldCacheASTInMemory(ShouldCacheASTInMemory) {
+  ShouldCacheASTInMemory(ShouldCacheASTInMemory),
+  OutputPathIndependent(OutputPathIndependent) {
   this->Buffer->IsComplete = false;
 }
 
@@ -70,7 +71,7 @@
   // For serialization we are lenient if the errors were
   // only warn-as-error kind.
   PP.getDiagnostics().hasUncompilableErrorOccurred(),
-  ShouldCacheASTInMemory);
+  ShouldCacheASTInMemory, OutputPathIndependent);
 
   Buffer->IsComplete = true;
 }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4483,7 +4483,8 @@
 ASTFileSignature ASTWriter::WriteAST(Sema , StringRef OutputFile,
  Module *WritingModule, StringRef isysroot,
  bool hasErrors,
- bool ShouldCacheASTInMemory) {
+ bool ShouldCacheASTInMemory,
+ bool OutputPathIndependent) {
   WritingAST = true;
 
   ASTHasCompilerErrors = hasErrors;
@@ -4499,8 +4500,9 @@
   Context = 
   PP = 
   this->WritingModule = WritingModule;
-  ASTFileSignature Signature =
-  WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule);
+  ASTFileSignature Signature = WriteASTCore(
+  SemaRef, isysroot, OutputPathIndependent ? StringRef() : OutputFile,
+  WritingModule);
   Context = nullptr;
   PP = nullptr;
   this->WritingModule = nullptr;
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -140,7 +140,8 @@
   CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
   FrontendOpts.ModuleFileExtensions,
   CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
-  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH));
+  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH,
+  FrontendOpts.OutputPathIndependentPCM));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, std::string(InFile), OutputFile, std::move(OS), Buffer));
 
@@ -203,7 +204,9 @@
   /*IncludeTimestamps=*/
   +CI.getFrontendOpts().BuildingImplicitModule,
   /*ShouldCacheASTInMemory=*/
-  +CI.getFrontendOpts().BuildingImplicitModule));
+  +CI.getFrontendOpts().BuildingImplicitModule,
+  /*OutputPathIndependent=*/
+  +CI.getFrontendOpts().OutputPathIndependentPCM));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, std::string(InFile), OutputFile, std::move(OS), Buffer));
   return std::make_unique(std::move(Consumers));
Index: clang/include/clang/Serialization/ASTWriter.h
===
--- 

[PATCH] D130710: [ASTWriter] Provide capability to output a PCM/PCH file that does not write out information about its output path

2022-07-28 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D130710#3685509 , @v.g.vassilev 
wrote:

> In D130710#3685470 , @akyrtzi wrote:
>
>> @v.g.vassilev is the functionality of "write `ORIGINAL_PCH_DIR` and resolve 
>> headers relative to it if PCH file and headers moved together" used by 
>> `Cling`?
>
> We currently use `-fmodules-embed-all-files` which zips all header files in a 
> blob in the PCH/PCM that gives us flexibility to not require the headers to 
> be present at a specific location. We have mostly moved to PCMs and the PCH 
> is of less interest to us. Does that patch help making the implicitly built 
> module files easier to relocate?

Not sure whether `ORIGINAL_PCH_DIR` relates to implicitly built module files or 
not, I'm wondering whether `ORIGINAL_PCH_DIR` is still useful and, if I 
understand correctly, it's not useful for `Cling` since it embeds the header 
file contents, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130710

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


[PATCH] D130710: [ASTWriter] Provide capability to output a PCM/PCH file that does not write out information about its output path

2022-07-28 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a subscriber: rmaz.
akyrtzi added a comment.

Also pinging @rmaz who made a related change 
, is this used by Facebook?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130710

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


[PATCH] D130710: [ASTWriter] Provide capability to output a PCM/PCH file that does not write out information about its output path

2022-07-28 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a subscriber: v.g.vassilev.
akyrtzi added a comment.

@v.g.vassilev is the functionality of "write `ORIGINAL_PCH_DIR` and resolve 
headers relative to it if PCH file and headers moved together" used by `Cling`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130710

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


[PATCH] D130710: [ASTWriter] Provide capability to output a PCM/PCH file that does not write out information about its output path

2022-07-28 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is useful to enable sharing of the same PCH file even when it's intended 
for a different output path.

The only information this option disables writing is for `ORIGINAL_PCH_DIR` 
record which is treated as optional and (when present) used as fallback for 
resolving input file paths relative to it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130710

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/GeneratePCH.cpp
  clang/test/PCH/pch-output-path-independent.c

Index: clang/test/PCH/pch-output-path-independent.c
===
--- /dev/null
+++ clang/test/PCH/pch-output-path-independent.c
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t && mkdir -p %t/a %t/b
+
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/a/t1.pch -fpcm-output-path-independent
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -emit-pch %s -o %t/b/t2.pch -fpcm-output-path-independent
+
+// RUN: diff %t/a/t1.pch %t/b/t2.pch
Index: clang/lib/Serialization/GeneratePCH.cpp
===
--- clang/lib/Serialization/GeneratePCH.cpp
+++ clang/lib/Serialization/GeneratePCH.cpp
@@ -25,13 +25,14 @@
 StringRef OutputFile, StringRef isysroot, std::shared_ptr Buffer,
 ArrayRef> Extensions,
 bool AllowASTWithErrors, bool IncludeTimestamps,
-bool ShouldCacheASTInMemory)
+bool ShouldCacheASTInMemory, bool OutputPathIndependent)
 : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()),
   SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data),
   Writer(Stream, this->Buffer->Data, ModuleCache, Extensions,
  IncludeTimestamps),
   AllowASTWithErrors(AllowASTWithErrors),
-  ShouldCacheASTInMemory(ShouldCacheASTInMemory) {
+  ShouldCacheASTInMemory(ShouldCacheASTInMemory),
+  OutputPathIndependent(OutputPathIndependent) {
   this->Buffer->IsComplete = false;
 }
 
@@ -70,7 +71,7 @@
   // For serialization we are lenient if the errors were
   // only warn-as-error kind.
   PP.getDiagnostics().hasUncompilableErrorOccurred(),
-  ShouldCacheASTInMemory);
+  ShouldCacheASTInMemory, OutputPathIndependent);
 
   Buffer->IsComplete = true;
 }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4483,7 +4483,8 @@
 ASTFileSignature ASTWriter::WriteAST(Sema , StringRef OutputFile,
  Module *WritingModule, StringRef isysroot,
  bool hasErrors,
- bool ShouldCacheASTInMemory) {
+ bool ShouldCacheASTInMemory,
+ bool OutputPathIndependent) {
   WritingAST = true;
 
   ASTHasCompilerErrors = hasErrors;
@@ -4499,8 +4500,9 @@
   Context = 
   PP = 
   this->WritingModule = WritingModule;
-  ASTFileSignature Signature =
-  WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule);
+  ASTFileSignature Signature = WriteASTCore(
+  SemaRef, isysroot, OutputPathIndependent ? StringRef() : OutputFile,
+  WritingModule);
   Context = nullptr;
   PP = nullptr;
   this->WritingModule = nullptr;
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -140,7 +140,8 @@
   CI.getPreprocessor(), CI.getModuleCache(), OutputFile, Sysroot, Buffer,
   FrontendOpts.ModuleFileExtensions,
   CI.getPreprocessorOpts().AllowPCHWithCompilerErrors,
-  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH));
+  FrontendOpts.IncludeTimestamps, +CI.getLangOpts().CacheGeneratedPCH,
+  FrontendOpts.OutputPathIndependentPCM));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, std::string(InFile), OutputFile, std::move(OS), Buffer));
 
@@ -203,7 +204,9 @@
   /*IncludeTimestamps=*/
   +CI.getFrontendOpts().BuildingImplicitModule,
   /*ShouldCacheASTInMemory=*/
-  +CI.getFrontendOpts().BuildingImplicitModule));
+  +CI.getFrontendOpts().BuildingImplicitModule,
+  /*OutputPathIndependent=*/
+  +CI.getFrontendOpts().OutputPathIndependentPCM));
   Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
   CI, 

[PATCH] D130443: [CGDebugInfo] Access the current working directory from the `VFS`

2022-07-26 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D130443#3680753 , @thakis wrote:

> Looks like this doesn't build: http://45.33.8.238/linux/82380/step_4.txt

Sorry about that, fixed here: 
https://github.com/llvm/llvm-project/commit/c5ddacb3b6afe2fd507b5f4a10c32ec00ffb245e


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130443

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


[PATCH] D130443: [CGDebugInfo] Access the current working directory from the `VFS`

2022-07-26 Thread Argyrios Kyrtzidis 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 rG8dfaecc4c244: [CGDebugInfo] Access the current working 
directory from the `VFS` (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130443

Files:
  clang/include/clang/CodeGen/ModuleBuilder.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/unittests/CodeGen/TestCompiler.h
  clang/unittests/Frontend/CodeGenActionTest.cpp

Index: clang/unittests/Frontend/CodeGenActionTest.cpp
===
--- clang/unittests/Frontend/CodeGenActionTest.cpp
+++ clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -76,4 +77,40 @@
   bool Success = Compiler.ExecuteAction(Action);
   EXPECT_TRUE(Success);
 }
+
+TEST(CodeGenTest, DebugInfoCWDCodeGen) {
+  // Check that debug info is accessing the current working directory from the
+  // VFS instead of calling \p llvm::sys::fs::current_path() directly.
+
+  auto VFS = std::make_unique();
+  VFS->setCurrentWorkingDirectory("/in-memory-fs-cwd");
+  auto Sept = llvm::sys::path::get_separator();
+  std::string TestPath =
+  std::string(llvm::formatv("{0}in-memory-fs-cwd{0}test.cpp", Sept));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("int x;\n"));
+
+  auto Invocation = std::make_shared();
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cpp", Language::CXX));
+  Invocation->getFrontendOpts().ProgramAction = EmitLLVM;
+  Invocation->getTargetOpts().Triple = "x86_64-unknown-linux-gnu";
+  Invocation->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
+  CompilerInstance Compiler;
+
+  SmallString<256> IRBuffer;
+  Compiler.setOutputStream(std::make_unique(IRBuffer));
+  Compiler.setInvocation(std::move(Invocation));
+  Compiler.createDiagnostics();
+  Compiler.createFileManager(std::move(VFS));
+
+  EmitLLVMAction Action;
+  bool Success = Compiler.ExecuteAction(Action);
+  EXPECT_TRUE(Success);
+
+  SmallString<128> RealCWD;
+  llvm::sys::fs::current_path(RealCWD);
+  EXPECT_TRUE(!RealCWD.empty());
+  EXPECT_FALSE(IRBuffer.str().contains(RealCWD));
+  EXPECT_TRUE(IRBuffer.str().contains("in-memory-fs-cwd"));
+}
 }
Index: clang/unittests/CodeGen/TestCompiler.h
===
--- clang/unittests/CodeGen/TestCompiler.h
+++ clang/unittests/CodeGen/TestCompiler.h
@@ -56,12 +56,10 @@
 
 compiler.createASTContext();
 
-CG.reset(CreateLLVMCodeGen(compiler.getDiagnostics(),
-   "main-module",
-   compiler.getHeaderSearchOpts(),
-   compiler.getPreprocessorOpts(),
-   compiler.getCodeGenOpts(),
-   Context));
+CG.reset(CreateLLVMCodeGen(
+compiler.getDiagnostics(), "main-module",
+(), compiler.getHeaderSearchOpts(),
+compiler.getPreprocessorOpts(), compiler.getCodeGenOpts(), Context));
   }
 
   void init(const char *TestProgram,
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -230,8 +230,9 @@
 llvm::LLVMContext ) {
   StringRef ModuleName("$__module");
   return std::unique_ptr(CreateLLVMCodeGen(
-  CI.getDiagnostics(), ModuleName, CI.getHeaderSearchOpts(),
-  CI.getPreprocessorOpts(), CI.getCodeGenOpts(), LLVMCtx));
+  CI.getDiagnostics(), ModuleName, (),
+  CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getCodeGenOpts(),
+  LLVMCtx));
 }
 } // namespace init_convenience
 
Index: clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===
--- clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -45,6 +45,7 @@
   const std::string OutputFileName;
   ASTContext *Ctx;
   ModuleMap 
+  IntrusiveRefCntPtr FS;
   const HeaderSearchOptions 
   const PreprocessorOptions 
   CodeGenOptions CodeGenOpts;
@@ -144,6 +145,7 @@
   : Diags(CI.getDiagnostics()), MainFileName(MainFileName),
 OutputFileName(OutputFileName), 

[PATCH] D130443: [CGDebugInfo] Access the current working directory from the `VFS`

2022-07-24 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

...instead of calling `llvm::sys::fs::current_path()` directly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130443

Files:
  clang/include/clang/CodeGen/ModuleBuilder.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  clang/unittests/CodeGen/TestCompiler.h
  clang/unittests/Frontend/CodeGenActionTest.cpp

Index: clang/unittests/Frontend/CodeGenActionTest.cpp
===
--- clang/unittests/Frontend/CodeGenActionTest.cpp
+++ clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -76,4 +77,40 @@
   bool Success = Compiler.ExecuteAction(Action);
   EXPECT_TRUE(Success);
 }
+
+TEST(CodeGenTest, DebugInfoCWDCodeGen) {
+  // Check that debug info is accessing the current working directory from the
+  // VFS instead of calling \p llvm::sys::fs::current_path() directly.
+
+  auto VFS = std::make_unique();
+  VFS->setCurrentWorkingDirectory("/in-memory-fs-cwd");
+  auto Sept = llvm::sys::path::get_separator();
+  std::string TestPath =
+  std::string(llvm::formatv("{0}in-memory-fs-cwd{0}test.cpp", Sept));
+  VFS->addFile(TestPath, 0, llvm::MemoryBuffer::getMemBuffer("int x;\n"));
+
+  auto Invocation = std::make_shared();
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cpp", Language::CXX));
+  Invocation->getFrontendOpts().ProgramAction = EmitLLVM;
+  Invocation->getTargetOpts().Triple = "x86_64-unknown-linux-gnu";
+  Invocation->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
+  CompilerInstance Compiler;
+
+  SmallString<256> IRBuffer;
+  Compiler.setOutputStream(std::make_unique(IRBuffer));
+  Compiler.setInvocation(std::move(Invocation));
+  Compiler.createDiagnostics();
+  Compiler.createFileManager(std::move(VFS));
+
+  EmitLLVMAction Action;
+  bool Success = Compiler.ExecuteAction(Action);
+  EXPECT_TRUE(Success);
+
+  SmallString<128> RealCWD;
+  llvm::sys::fs::current_path(RealCWD);
+  EXPECT_TRUE(!RealCWD.empty());
+  EXPECT_FALSE(IRBuffer.str().contains(RealCWD));
+  EXPECT_TRUE(IRBuffer.str().contains("in-memory-fs-cwd"));
+}
 }
Index: clang/unittests/CodeGen/TestCompiler.h
===
--- clang/unittests/CodeGen/TestCompiler.h
+++ clang/unittests/CodeGen/TestCompiler.h
@@ -56,12 +56,10 @@
 
 compiler.createASTContext();
 
-CG.reset(CreateLLVMCodeGen(compiler.getDiagnostics(),
-   "main-module",
-   compiler.getHeaderSearchOpts(),
-   compiler.getPreprocessorOpts(),
-   compiler.getCodeGenOpts(),
-   Context));
+CG.reset(CreateLLVMCodeGen(
+compiler.getDiagnostics(), "main-module",
+(), compiler.getHeaderSearchOpts(),
+compiler.getPreprocessorOpts(), compiler.getCodeGenOpts(), Context));
   }
 
   void init(const char *TestProgram,
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -230,8 +230,9 @@
 llvm::LLVMContext ) {
   StringRef ModuleName("$__module");
   return std::unique_ptr(CreateLLVMCodeGen(
-  CI.getDiagnostics(), ModuleName, CI.getHeaderSearchOpts(),
-  CI.getPreprocessorOpts(), CI.getCodeGenOpts(), LLVMCtx));
+  CI.getDiagnostics(), ModuleName, (),
+  CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getCodeGenOpts(),
+  LLVMCtx));
 }
 } // namespace init_convenience
 
Index: clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===
--- clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -45,6 +45,7 @@
   const std::string OutputFileName;
   ASTContext *Ctx;
   ModuleMap 
+  IntrusiveRefCntPtr FS;
   const HeaderSearchOptions 
   const PreprocessorOptions 
   CodeGenOptions CodeGenOpts;
@@ -144,6 +145,7 @@
   : Diags(CI.getDiagnostics()), MainFileName(MainFileName),
 OutputFileName(OutputFileName), Ctx(nullptr),
 MMap(CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()),
+   

[PATCH] D129912: [Tooling/DependencyScanning] Enable passing a `vfs::FileSystem` object to `DependencyScanningTool`

2022-07-18 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

In D129912#3661181 , 
@hubert.reinterpretcast wrote:

> The added test is not passing on the AIX builder: 
> https://lab.llvm.org/buildbot/#/builders/214/builds/2388/steps/6/logs/FAIL__Clang-Unit__83
>
> Note that Clang on that platform generates assembly by default (then invokes 
> the system assembler).

Sorry about that, it should be fixed via 
https://github.com/llvm/llvm-project/commit/d1b58cada61aa8bc44d8e8ef9c23ed12ef7b549b


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129912

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


[PATCH] D129912: [Tooling/DependencyScanning] Enable passing a `vfs::FileSystem` object to `DependencyScanningTool`

2022-07-18 Thread Argyrios Kyrtzidis 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 rGfbbabd4ca06a: [Tooling/DependencyScanning] Enable passing a 
`vfs::FileSystem` object to… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129912

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp

Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -14,19 +14,21 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CompilationDatabase.h"
-#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 #include 
 #include 
 
 using namespace clang;
 using namespace tooling;
+using namespace dependencies;
 
 namespace {
 
@@ -203,3 +205,33 @@
   EXPECT_EQ(convert_to_slash(Deps[4]), "/root/header.h");
   EXPECT_EQ(convert_to_slash(Deps[5]), "/root/symlink.h");
 }
+
+TEST(DependencyScanner, ScanDepsWithFS) {
+  std::vector CommandLine = {"clang", "-c", "test.cpp",
+  "-o"
+  "test.cpp.o"};
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string HeaderPath =
+  std::string(llvm::formatv("{0}root{0}header.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept));
+
+  VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));
+
+  DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
+ScanningOutputFormat::Make);
+  DependencyScanningTool ScanTool(Service, VFS);
+
+  std::string DepFile;
+  ASSERT_THAT_ERROR(
+  ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
+  llvm::Succeeded());
+  using llvm::sys::path::convert_to_slash;
+  EXPECT_EQ(convert_to_slash(DepFile),
+"test.cpp.o: /root/test.cpp /root/header.h\n");
+}
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -264,7 +264,8 @@
 } // end anonymous namespace
 
 DependencyScanningWorker::DependencyScanningWorker(
-DependencyScanningService )
+DependencyScanningService ,
+llvm::IntrusiveRefCntPtr FS)
 : Format(Service.getFormat()), OptimizeArgs(Service.canOptimizeArgs()) {
   PCHContainerOps = std::make_shared();
   PCHContainerOps->registerReader(
@@ -274,8 +275,8 @@
   PCHContainerOps->registerWriter(
   std::make_unique());
 
-  auto OverlayFS = llvm::makeIntrusiveRefCnt(
-  llvm::vfs::createPhysicalFileSystem());
+  auto OverlayFS =
+  llvm::makeIntrusiveRefCnt(std::move(FS));
   InMemoryFS = llvm::makeIntrusiveRefCnt();
   OverlayFS->pushOverlay(InMemoryFS);
   RealFS = OverlayFS;
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -50,8 +50,9 @@
 }
 
 DependencyScanningTool::DependencyScanningTool(
-DependencyScanningService )
-: Worker(Service) {}
+DependencyScanningService ,
+llvm::IntrusiveRefCntPtr FS)
+: Worker(Service, std::move(FS)) {}
 
 llvm::Expected DependencyScanningTool::getDependencyFile(
 const std::vector , StringRef CWD,
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
===
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -52,7 +52,8 @@
 /// 

[PATCH] D129912: [Tooling/DependencyScanning] Enable passing a `vfs::FileSystem` object to `DependencyScanningTool`

2022-07-15 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Also include a unit test to validate that the `vfs::FileSystem` object is 
properly used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129912

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp

Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -14,19 +14,21 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CompilationDatabase.h"
-#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 #include 
 #include 
 
 using namespace clang;
 using namespace tooling;
+using namespace dependencies;
 
 namespace {
 
@@ -203,3 +205,33 @@
   EXPECT_EQ(convert_to_slash(Deps[4]), "/root/header.h");
   EXPECT_EQ(convert_to_slash(Deps[5]), "/root/symlink.h");
 }
+
+TEST(DependencyScanner, ScanDepsWithFS) {
+  std::vector CommandLine = {"clang", "-c", "test.cpp",
+  "-o"
+  "test.cpp.o"};
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string HeaderPath =
+  std::string(llvm::formatv("{0}root{0}header.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept));
+
+  VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));
+
+  DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
+ScanningOutputFormat::Make);
+  DependencyScanningTool ScanTool(Service, VFS);
+
+  std::string DepFile;
+  ASSERT_THAT_ERROR(
+  ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
+  llvm::Succeeded());
+  using llvm::sys::path::convert_to_slash;
+  EXPECT_EQ(convert_to_slash(DepFile),
+"test.cpp.o: /root/test.cpp /root/header.h\n");
+}
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -264,7 +264,8 @@
 } // end anonymous namespace
 
 DependencyScanningWorker::DependencyScanningWorker(
-DependencyScanningService )
+DependencyScanningService ,
+llvm::IntrusiveRefCntPtr FS)
 : Format(Service.getFormat()), OptimizeArgs(Service.canOptimizeArgs()) {
   PCHContainerOps = std::make_shared();
   PCHContainerOps->registerReader(
@@ -274,8 +275,8 @@
   PCHContainerOps->registerWriter(
   std::make_unique());
 
-  auto OverlayFS = llvm::makeIntrusiveRefCnt(
-  llvm::vfs::createPhysicalFileSystem());
+  auto OverlayFS =
+  llvm::makeIntrusiveRefCnt(std::move(FS));
   InMemoryFS = llvm::makeIntrusiveRefCnt();
   OverlayFS->pushOverlay(InMemoryFS);
   RealFS = OverlayFS;
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -50,8 +50,9 @@
 }
 
 DependencyScanningTool::DependencyScanningTool(
-DependencyScanningService )
-: Worker(Service) {}
+DependencyScanningService ,
+llvm::IntrusiveRefCntPtr FS)
+: Worker(Service, std::move(FS)) {}
 
 llvm::Expected DependencyScanningTool::getDependencyFile(
 const std::vector , StringRef CWD,
Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
===
--- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -52,7 +52,8 @@
 /// using the regular processing run.
 class 

  1   2   3   >