[PATCH] D90646: [clang] Add warning when `-include-pch` is passed multiple times

2021-02-09 Thread Keith Smiley via Phabricator via cfe-commits
keith added a comment.

Yea seems like a reasonable request, looking through the uses nothing 
immediately pops out as being not supporting multiple PCHs but I guess before I 
went down that path I'd want someone who knew the code better to agree on that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90646

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


[PATCH] D90646: [clang] Add warning when `-include-pch` is passed multiple times

2021-02-09 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

Is there any reason that `-include-pch` shouldn't follow the precedent of 
`-include`, which can be used multiple times? If not, then the end goal should 
be to support multiple uses, but in the mean time a warning is helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90646

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


[PATCH] D90646: [clang] Add warning when `-include-pch` is passed multiple times

2021-01-25 Thread Keith Smiley via Phabricator via cfe-commits
keith added a comment.

Fair question! I think this case is a bit different since it's quite subtle. 
The strange thing here is that the header you're intending to provide a pch for 
can still be read successfully, but not getting the benefits of the pch that 
you were expecting without knowing about it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90646

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


[PATCH] D90646: [clang] Add warning when `-include-pch` is passed multiple times

2021-01-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

There are many options whether the latter one overrides the previous ones. How 
is this special?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90646

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


[PATCH] D90646: [clang] Add warning when `-include-pch` is passed multiple times

2021-01-25 Thread Keith Smiley via Phabricator via cfe-commits
keith updated this revision to Diff 319138.
keith added a comment.
Herald added a reviewer: jansvoboda11.

Add group to warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90646

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/PCH/multiple-include-pch-warning.c


Index: clang/test/PCH/multiple-include-pch-warning.c
===
--- /dev/null
+++ clang/test/PCH/multiple-include-pch-warning.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -emit-pch -o %t1.pch %s
+// RUN: %clang_cc1 -emit-pch -o %t2.pch %s
+// RUN: %clang_cc1 %s -include-pch %t1.pch -include-pch %t2.pch 2>&1 | 
FileCheck %s
+
+// CHECK: warning: -include-pch passed multiple times but only the last 
'{{.*\.pch}}' is being used
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2779,6 +2779,14 @@
 static void ParsePreprocessorArgs(PreprocessorOptions , ArgList ,
   DiagnosticsEngine ,
   frontend::ActionKind Action) {
+  auto allPchFiles = Args.getAllArgValues(OPT_include_pch);
+  if (!allPchFiles.empty()) {
+Opts.ImplicitPCHInclude = std::string(allPchFiles.back());
+if (allPchFiles.size() > 1)
+  Diags.Report(diag::warn_drv_multiple_include_pch)
+  << Opts.ImplicitPCHInclude;
+  }
+
   Opts.PCHWithHdrStop = Args.hasArg(OPT_pch_through_hdrstop_create) ||
 Args.hasArg(OPT_pch_through_hdrstop_use);
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -332,6 +332,9 @@
   InGroup;
 def warn_drv_pch_not_first_include : Warning<
   "precompiled header '%0' was ignored because '%1' is not first '-include'">;
+def warn_drv_multiple_include_pch : Warning<
+  "-include-pch passed multiple times but only the last '%0' is being used">,
+   InGroup;
 def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
   InGroup>;
 def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting 
'%1'">,


Index: clang/test/PCH/multiple-include-pch-warning.c
===
--- /dev/null
+++ clang/test/PCH/multiple-include-pch-warning.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -emit-pch -o %t1.pch %s
+// RUN: %clang_cc1 -emit-pch -o %t2.pch %s
+// RUN: %clang_cc1 %s -include-pch %t1.pch -include-pch %t2.pch 2>&1 | FileCheck %s
+
+// CHECK: warning: -include-pch passed multiple times but only the last '{{.*\.pch}}' is being used
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2779,6 +2779,14 @@
 static void ParsePreprocessorArgs(PreprocessorOptions , ArgList ,
   DiagnosticsEngine ,
   frontend::ActionKind Action) {
+  auto allPchFiles = Args.getAllArgValues(OPT_include_pch);
+  if (!allPchFiles.empty()) {
+Opts.ImplicitPCHInclude = std::string(allPchFiles.back());
+if (allPchFiles.size() > 1)
+  Diags.Report(diag::warn_drv_multiple_include_pch)
+  << Opts.ImplicitPCHInclude;
+  }
+
   Opts.PCHWithHdrStop = Args.hasArg(OPT_pch_through_hdrstop_create) ||
 Args.hasArg(OPT_pch_through_hdrstop_use);
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -332,6 +332,9 @@
   InGroup;
 def warn_drv_pch_not_first_include : Warning<
   "precompiled header '%0' was ignored because '%1' is not first '-include'">;
+def warn_drv_multiple_include_pch : Warning<
+  "-include-pch passed multiple times but only the last '%0' is being used">,
+   InGroup;
 def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
   InGroup>;
 def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting '%1'">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90646: [clang] Add warning when `-include-pch` is passed multiple times

2020-11-02 Thread Keith Smiley via Phabricator via cfe-commits
keith created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
keith requested review of this revision.

Previously this argument passed multiple times would result in the first
being silently ignored.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90646

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/PCH/multiple-include-pch-warning.c


Index: clang/test/PCH/multiple-include-pch-warning.c
===
--- /dev/null
+++ clang/test/PCH/multiple-include-pch-warning.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -emit-pch -o %t1.pch %s
+// RUN: %clang_cc1 -emit-pch -o %t2.pch %s
+// RUN: %clang_cc1 %s -include-pch %t1.pch -include-pch %t2.pch 2>&1 | 
FileCheck %s
+
+// CHECK: warning: -include-pch passed multiple times but only the last 
'{{.*\.pch}}' is being used
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3576,7 +3576,13 @@
 static void ParsePreprocessorArgs(PreprocessorOptions , ArgList ,
   DiagnosticsEngine ,
   frontend::ActionKind Action) {
-  Opts.ImplicitPCHInclude = std::string(Args.getLastArgValue(OPT_include_pch));
+  auto allPchFiles = Args.getAllArgValues(OPT_include_pch);
+  if (!allPchFiles.empty()) {
+Opts.ImplicitPCHInclude = std::string(allPchFiles.back());
+if (allPchFiles.size() > 1)
+  Diags.Report(diag::warn_drv_multiple_include_pch)
+  << Opts.ImplicitPCHInclude;
+  }
   Opts.PCHWithHdrStop = Args.hasArg(OPT_pch_through_hdrstop_create) ||
 Args.hasArg(OPT_pch_through_hdrstop_use);
   Opts.PCHWithHdrStopCreate = Args.hasArg(OPT_pch_through_hdrstop_create);
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -329,6 +329,8 @@
   InGroup;
 def warn_drv_pch_not_first_include : Warning<
   "precompiled header '%0' was ignored because '%1' is not first '-include'">;
+def warn_drv_multiple_include_pch : Warning<
+  "-include-pch passed multiple times but only the last '%0' is being used">;
 def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
   InGroup>;
 def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting 
'%1'">,


Index: clang/test/PCH/multiple-include-pch-warning.c
===
--- /dev/null
+++ clang/test/PCH/multiple-include-pch-warning.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -emit-pch -o %t1.pch %s
+// RUN: %clang_cc1 -emit-pch -o %t2.pch %s
+// RUN: %clang_cc1 %s -include-pch %t1.pch -include-pch %t2.pch 2>&1 | FileCheck %s
+
+// CHECK: warning: -include-pch passed multiple times but only the last '{{.*\.pch}}' is being used
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3576,7 +3576,13 @@
 static void ParsePreprocessorArgs(PreprocessorOptions , ArgList ,
   DiagnosticsEngine ,
   frontend::ActionKind Action) {
-  Opts.ImplicitPCHInclude = std::string(Args.getLastArgValue(OPT_include_pch));
+  auto allPchFiles = Args.getAllArgValues(OPT_include_pch);
+  if (!allPchFiles.empty()) {
+Opts.ImplicitPCHInclude = std::string(allPchFiles.back());
+if (allPchFiles.size() > 1)
+  Diags.Report(diag::warn_drv_multiple_include_pch)
+  << Opts.ImplicitPCHInclude;
+  }
   Opts.PCHWithHdrStop = Args.hasArg(OPT_pch_through_hdrstop_create) ||
 Args.hasArg(OPT_pch_through_hdrstop_use);
   Opts.PCHWithHdrStopCreate = Args.hasArg(OPT_pch_through_hdrstop_create);
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -329,6 +329,8 @@
   InGroup;
 def warn_drv_pch_not_first_include : Warning<
   "precompiled header '%0' was ignored because '%1' is not first '-include'">;
+def warn_drv_multiple_include_pch : Warning<
+  "-include-pch passed multiple times but only the last '%0' is being used">;
 def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
   InGroup>;
 def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting '%1'">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits