[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-23 Thread Alexandre Ganea via cfe-commits

aganea wrote:

> I will say, `-fno-eliminate-unused-debug-types` is a really heavy hammer that 
> makes debug info much larger - and my understanding was that games tended to 
> have trouble with large debug builds, so I'd be surprised if this was a great 
> path forward.

Absolutely, this is only a short term hack until I figure out a better way to 
fix it.

> Do you have a small example of where Clang and MSVC differ in emitting some 
> particular unreferenced type? I would imagine MSVC isn't emitting /every/ 
> written type...

It's essentially the examples in 
https://github.com/llvm/llvm-project/issues/46924. A class that is only used to 
hold some const/constexpr values. These values are then used by the .NATVIS 
file. With `/Z7`, MSVC seems to always emit them as `S_CONSTANT`s. But in Clang 
since the type isn't used, it is never emitted by 
`CGDebugInfo::EmitAndRetainType()`. Setting `DebugInfo == 
llvm::codegenoptions::UnusedTypeInfo` fixes the problem. Is there a better way?

https://github.com/llvm/llvm-project/pull/95259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-19 Thread Alexandre Ganea via cfe-commits

aganea wrote:

> Yes, feel free to take over that part, thanks!

@amykhuang : I took a look at https://reviews.llvm.org/D89286. It works but 
doesn't fix the most problematic case where the `constexpr` member needs an 
evaluation that relies on dependent values:
```
template 
struct C {
static constexpr int constexprVal_C = VAL;
};
C<200> globalC;
```
I've tried your suggestion, that is forcing evaluation of `constexpr` members 
upon instantiation:

> Actually, can we just instantiate the initializer for static constexpr data 
> members?
> 
> currently [it delays creating the initializer for inline static data 
> members](https://github.com/llvm/llvm-project/blob/683b308c07bf827255fe1403056413f790e03729/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L5062);
>  can we not do that if it's a constexpr?

While this works for the above example, it fails a few tests in Clang, like 
[this 
one](https://github.com/llvm/llvm-project/blob/main/clang/test/CXX/expr/expr.const/p6.cpp).
 It might be because the constexpr expressions are only supposed to be 
evaluated when used. I'm not sure what a good way forward would be if we wanted 
to fix this. @zygoloid (note: this is only to generate constants in the debug 
info).

Overall this is a minor issue and I've fixed it by switching to a plain 
`const`. The root issue is that we have .NATVIS files that are referencing 
these otherwise unused members. If we wanted to do things the right way, 
perhaps NATVIS merged into the PDB would need to be evaluated at compile time, 
but that sounds like a lot of work. Also, NATVIS come too late in the process, 
at link time. Hopefully, Visual Studio has a debug mode where failed NATVIS 
evaluations are shown in the debug output, so they are easy to spot.

https://github.com/llvm/llvm-project/pull/95259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-15 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea closed https://github.com/llvm/llvm-project/pull/95259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-15 Thread Alexandre Ganea via cfe-commits

aganea wrote:

Thanks @amykhuang for taking a look!

I won't close https://github.com/llvm/llvm-project/issues/46924 right away, 
since we also need https://reviews.llvm.org/D89286. Do you mind if I took 
ownership of that patch and send a PR crediting you?

https://github.com/llvm/llvm-project/pull/95259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-15 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/95259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-12 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/95259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-12 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea created 
https://github.com/llvm/llvm-project/pull/95259

This is used to set DebugInfoKind to "UnusedTypeInfo". This helps in the 
context Unreal Engine and NATVIS files that reference unused otherwise `static 
constexpr` class members. See 
https://udn.unrealengine.com/s/question/0D5QP0N012h0AB/fname-debug-visualizer-fails-to-work-with-the-clang-compiler

This fixes https://github.com/llvm/llvm-project/issues/46924

>From 75fd0578766ac923a989b0fb5d98f779f9af1f14 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 12 Jun 2024 09:44:21 -0400
Subject: [PATCH] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to
 clang-cl

This fixes https://github.com/llvm/llvm-project/issues/46924
---
 clang/docs/UsersManual.rst| 3 +++
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/Driver/cl-options.c| 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index f954857b0235a..d36db8a01949c 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3338,6 +3338,9 @@ below. If multiple flags are present, the last one is 
used.
   By default, Clang does not emit type information for types that are defined
   but not used in a program. To retain the debug info for these unused types,
   the negation **-fno-eliminate-unused-debug-types** can be used.
+  This can be particulary useful on Windows, when using NATVIS files that
+  can reference const symbols that would otherwise be stripped, even in full
+  debug or standalone debug modes.
 
 Controlling Macro Debug Info Generation
 ^^^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9f7904dd94b94..b75d67551bc97 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2120,7 +2120,7 @@ def fno_elide_type : Flag<["-"], "fno-elide-type">, 
Group,
 MarshallingInfoNegativeFlag>;
 def feliminate_unused_debug_symbols : Flag<["-"], 
"feliminate-unused-debug-symbols">, Group;
 defm eliminate_unused_debug_types : 
OptOutCC1FFlag<"eliminate-unused-debug-types",
-  "Do not emit ", "Emit ", " debug info for defined but unused types">;
+  "Do not emit ", "Emit ", " debug info for defined but unused types", 
[ClangOption, CLOption]>;
 def femit_all_decls : Flag<["-"], "femit-all-decls">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Emit all declarations, even if unused">,
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 2c17459dde656..d7d7c5c825815 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -696,6 +696,8 @@
 // RUN: -Wunused-variable \
 // RUN: -fmacro-backtrace-limit=0 \
 // RUN: -fstandalone-debug \
+// RUN: -feliminate-unused-debug-types \
+// RUN: -fno-eliminate-unused-debug-types \
 // RUN: -flimit-debug-info \
 // RUN: -flto \
 // RUN: -fmerge-all-constants \

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea closed https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-24 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/89950

>From 13c411018e491fc2be4f4118a56f9b8cf2e5b76f Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 17 Apr 2024 16:28:21 -0400
Subject: [PATCH 1/5] [clang-scan-deps] Expand response files before the
 argument ajuster

Previously, since response (.rsp) files weren't expanded, we only parsed
the command-line as provided in the Clang CDB file. Unfortunately, when
using Unreal Engine, arguments are always generated in a .rsp file.

After this patch, /Fo can be parsed and added to the final command-line.
Without this option, the make targets that are emitted are made up from the
input file name alone. We have some cases where the same input in the project
generates several output files, so we end up with duplicate make targets
in the scan-deps emitted dependency file.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17..7b7f10c4be742 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   llvm::cl::PrintOptionValues();
 
+  // Expand response files in advance, so that we can "see" all the arguments
+  // when adjusting below.
+  auto ResponseExpander = expandResponseFiles(std::move(Compilations),
+  llvm::vfs::getRealFileSystem());
+
   // The command options are rewritten to run Clang in preprocessor only mode.
   auto AdjustingCompilations =
   std::make_unique(
-  std::move(Compilations));
+  std::move(ResponseExpander));
   ResourceDirectoryCache ResourceDirCache;
 
   AdjustingCompilations->appendArgumentsAdjuster(

>From d6122c7fe41fb1642560985abafb9444f3e6 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 13:52:55 -0400
Subject: [PATCH 2/5] Add test

---
 .../ClangScanDeps/response-file-clang-cl.c| 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 clang/test/ClangScanDeps/response-file-clang-cl.c

diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
new file mode 100644
index 0..78e3d15deb167
--- /dev/null
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -0,0 +1,32 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Here we ensure that we got a qualified .obj with its full path, since 
that's what we're passing with /Fo
+// CHECK: [[PREFIX]]/tu.obj:
+
+//--- cdb.json.template
+[{
+  "file": "DIR/t.cpp",
+  "directory": "DIR",
+  "command": "clang-cl @DIR/args.rsp"
+}]
+
+//--- args.rsp
+@args_nested.rsp
+/c tu.cpp
+
+//--- args_nested.rsp
+/I include
+
+//--- include/header.h
+
+//--- tu.cpp
+#include "header.h"

>From d74e133dc023d24e66b853940a1b4bb799c0a491 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 17:02:17 -0400
Subject: [PATCH 3/5] Handle /Fo in the Clang driver as well.

---
 clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
 clang/test/ClangScanDeps/response-file-clang-cl.c | 6 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 18de8781e894a..15cf58f9d3339 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1030,7 +1030,7 @@ void Clang::AddPreprocessingOptions(Compilation , const 
JobAction ,
 
   // If user provided -o, that is the dependency target, except
   // when we are only generating a dependency file.
-  Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+  Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
   if (OutputOpt && Output.getType() != types::TY_Dependencies) {
 DepTarget = OutputOpt->getValue();
   } else {
diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
index 78e3d15deb167..77cecfff0b9ca 100644
--- a/clang/test/ClangScanDeps/response-file-clang-cl.c
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -5,8 +5,12 @@
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
 // RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
 
+// RUN: echo /c >> %t/args_nested.rsp
 // RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | 

[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-05-22 Thread Alexandre Ganea via cfe-commits

aganea wrote:

@jansvoboda11 Do you see any further changes for this PR? Can I land it?

https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][deps] Only bypass scanning VFS for the module cache (PR #88800)

2024-05-06 Thread Alexandre Ganea via cfe-commits

aganea wrote:

Ping @jansvoboda11! Are you able to get back to this soon? LG generally, just 
missing a test case above. Thanks!

https://github.com/llvm/llvm-project/pull/88800
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Distinguish unresolved templates in UnresolvedLookupExpr (PR #89019)

2024-05-05 Thread Alexandre Ganea via cfe-commits

aganea wrote:

Hello,
This causes a warning when building LLDB on Windows, 
`clang::BuiltinType::UnresolvedTemplate` isn't handled in the case in the file 
indicated below (sorry my locale is French). Would you have a chance to take a 
look @zyn0217 please?
```
[6325/7521] Building CXX object 
tools\lldb\source\Plugins\TypeSystem\Clang\CMakeFiles\lldbPluginTypeSystemClang.dir\TypeSystemClang.cpp.obj
C:\src\git\llvm-project\lldb\source\Plugins\TypeSystem\Clang\TypeSystemClang.cpp(4999):
 warning C4062: L'énumérateur 'clang::BuiltinType::UnresolvedTemplate' dans le 
commutateur de l'énumération 'clang::BuiltinType::Kind' n'est pas géré.
C:\src\git\llvm-project\clang\include\clang/AST/Type.h(2983): note: voir la 
déclaration de 'clang::BuiltinType::Kind'
```

https://github.com/llvm/llvm-project/pull/89019
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-29 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-29 Thread Alexandre Ganea via cfe-commits


@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   llvm::cl::PrintOptionValues();
 
+  // Expand response files in advance, so that we can "see" all the arguments
+  // when adjusting below.
+  auto ResponseExpander = expandResponseFiles(std::move(Compilations),

aganea wrote:

As suggested.

https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-29 Thread Alexandre Ganea via cfe-commits


@@ -0,0 +1,36 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp

aganea wrote:

Can you elaborate please on "I tried playing around with response files and 
they don't play well with newlines"?
Things we working on my end (empty lines in .rsp files). Also, Unreal Engine 
generates .rsp files with each argument on a new line, so if you're seeing any 
issues there we shall fix them.

https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-29 Thread Alexandre Ganea via cfe-commits


@@ -0,0 +1,36 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json

aganea wrote:

As suggested. We're taking a different codepath when using the immediate mode 
(using `InplaceCompilationDatabase`) and that expands the response files in 
`OptTable::parseArgs()` so I wasn't really covering all the changes in the 
patch. I've added tests for both cases. The immediate mode allowed me to 
uncover a bug in `ParseArgs()`: `Saver` and `Alloc` were local to the function 
but we were using their contents to populate `CommandLine`. I fixed that too.

https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-29 Thread Alexandre Ganea via cfe-commits


@@ -1069,7 +1069,7 @@ void Clang::AddPreprocessingOptions(Compilation , const 
JobAction ,
 
   // If user provided -o, that is the dependency target, except
   // when we are only generating a dependency file.
-  Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+  Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);

aganea wrote:

Added a test.

https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-29 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/89950

>From f2340c98c95e0d72516fc240ff268fead9f15391 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 17 Apr 2024 16:28:21 -0400
Subject: [PATCH 1/5] [clang-scan-deps] Expand response files before the
 argument ajuster

Previously, since response (.rsp) files weren't expanded, we only parsed
the command-line as provided in the Clang CDB file. Unfortunately, when
using Unreal Engine, arguments are always generated in a .rsp file.

After this patch, /Fo can be parsed and added to the final command-line.
Without this option, the make targets that are emitted are made up from the
input file name alone. We have some cases where the same input in the project
generates several output files, so we end up with duplicate make targets
in the scan-deps emitted dependency file.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17a..7b7f10c4be7421 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   llvm::cl::PrintOptionValues();
 
+  // Expand response files in advance, so that we can "see" all the arguments
+  // when adjusting below.
+  auto ResponseExpander = expandResponseFiles(std::move(Compilations),
+  llvm::vfs::getRealFileSystem());
+
   // The command options are rewritten to run Clang in preprocessor only mode.
   auto AdjustingCompilations =
   std::make_unique(
-  std::move(Compilations));
+  std::move(ResponseExpander));
   ResourceDirectoryCache ResourceDirCache;
 
   AdjustingCompilations->appendArgumentsAdjuster(

>From 09e0595fa9f3c9795d6f40a7308d8a912254b1df Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 13:52:55 -0400
Subject: [PATCH 2/5] Add test

---
 .../ClangScanDeps/response-file-clang-cl.c| 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 clang/test/ClangScanDeps/response-file-clang-cl.c

diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
new file mode 100644
index 00..78e3d15deb1678
--- /dev/null
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -0,0 +1,32 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Here we ensure that we got a qualified .obj with its full path, since 
that's what we're passing with /Fo
+// CHECK: [[PREFIX]]/tu.obj:
+
+//--- cdb.json.template
+[{
+  "file": "DIR/t.cpp",
+  "directory": "DIR",
+  "command": "clang-cl @DIR/args.rsp"
+}]
+
+//--- args.rsp
+@args_nested.rsp
+/c tu.cpp
+
+//--- args_nested.rsp
+/I include
+
+//--- include/header.h
+
+//--- tu.cpp
+#include "header.h"

>From 812a14f882995b832599222f0a747761378d31b8 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 17:02:17 -0400
Subject: [PATCH 3/5] Handle /Fo in the Clang driver as well.

---
 clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
 clang/test/ClangScanDeps/response-file-clang-cl.c | 6 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5f5d720cf759f4..69f888fcf323a4 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1069,7 +1069,7 @@ void Clang::AddPreprocessingOptions(Compilation , const 
JobAction ,
 
   // If user provided -o, that is the dependency target, except
   // when we are only generating a dependency file.
-  Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+  Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
   if (OutputOpt && Output.getType() != types::TY_Dependencies) {
 DepTarget = OutputOpt->getValue();
   } else {
diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
index 78e3d15deb1678..77cecfff0b9ca8 100644
--- a/clang/test/ClangScanDeps/response-file-clang-cl.c
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -5,8 +5,12 @@
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
 // RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
 
+// RUN: echo /c >> %t/args_nested.rsp
 // RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+// RUN: cat %t/deps.json | sed 

[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-26 Thread Alexandre Ganea via cfe-commits

aganea wrote:

Thanks for pointing that out @MaskRay !

https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-25 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea closed https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-24 Thread Alexandre Ganea via cfe-commits

aganea wrote:

@jansvoboda11 PTAL.

I've added handling of `/Fo` in the driver, and that solves my case without the 
.rsp expansion in `ClangScanDeps.cpp`. However if we pass `/E` to command-lines 
in the CDB, that change alone doesn't work anymore. This is because 
`Driver::GetNamedOutputPath()` returns "-" here: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/Driver.cpp#L5871

@sylvain-audi worked around that by adding `-o file.o` from the adjuster 
callback, which happens to bypass that condition a bit earlier, here: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/Driver.cpp#L5853

I'm not sure that's right, ideally we should pass `-MT` from the adjuster but 
somehow that doesn't work. This would probably need to be revisited later.

https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-24 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/89950

>From f2340c98c95e0d72516fc240ff268fead9f15391 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 17 Apr 2024 16:28:21 -0400
Subject: [PATCH 1/3] [clang-scan-deps] Expand response files before the
 argument ajuster

Previously, since response (.rsp) files weren't expanded, we only parsed
the command-line as provided in the Clang CDB file. Unfortunately, when
using Unreal Engine, arguments are always generated in a .rsp file.

After this patch, /Fo can be parsed and added to the final command-line.
Without this option, the make targets that are emitted are made up from the
input file name alone. We have some cases where the same input in the project
generates several output files, so we end up with duplicate make targets
in the scan-deps emitted dependency file.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17a..7b7f10c4be7421 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   llvm::cl::PrintOptionValues();
 
+  // Expand response files in advance, so that we can "see" all the arguments
+  // when adjusting below.
+  auto ResponseExpander = expandResponseFiles(std::move(Compilations),
+  llvm::vfs::getRealFileSystem());
+
   // The command options are rewritten to run Clang in preprocessor only mode.
   auto AdjustingCompilations =
   std::make_unique(
-  std::move(Compilations));
+  std::move(ResponseExpander));
   ResourceDirectoryCache ResourceDirCache;
 
   AdjustingCompilations->appendArgumentsAdjuster(

>From 09e0595fa9f3c9795d6f40a7308d8a912254b1df Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 13:52:55 -0400
Subject: [PATCH 2/3] Add test

---
 .../ClangScanDeps/response-file-clang-cl.c| 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 clang/test/ClangScanDeps/response-file-clang-cl.c

diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
new file mode 100644
index 00..78e3d15deb1678
--- /dev/null
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -0,0 +1,32 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Here we ensure that we got a qualified .obj with its full path, since 
that's what we're passing with /Fo
+// CHECK: [[PREFIX]]/tu.obj:
+
+//--- cdb.json.template
+[{
+  "file": "DIR/t.cpp",
+  "directory": "DIR",
+  "command": "clang-cl @DIR/args.rsp"
+}]
+
+//--- args.rsp
+@args_nested.rsp
+/c tu.cpp
+
+//--- args_nested.rsp
+/I include
+
+//--- include/header.h
+
+//--- tu.cpp
+#include "header.h"

>From 812a14f882995b832599222f0a747761378d31b8 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 17:02:17 -0400
Subject: [PATCH 3/3] Handle /Fo in the Clang driver as well.

---
 clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
 clang/test/ClangScanDeps/response-file-clang-cl.c | 6 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5f5d720cf759f4..69f888fcf323a4 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1069,7 +1069,7 @@ void Clang::AddPreprocessingOptions(Compilation , const 
JobAction ,
 
   // If user provided -o, that is the dependency target, except
   // when we are only generating a dependency file.
-  Arg *OutputOpt = Args.getLastArg(options::OPT_o);
+  Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
   if (OutputOpt && Output.getType() != types::TY_Dependencies) {
 DepTarget = OutputOpt->getValue();
   } else {
diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
index 78e3d15deb1678..77cecfff0b9ca8 100644
--- a/clang/test/ClangScanDeps/response-file-clang-cl.c
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -5,8 +5,12 @@
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
 // RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
 
+// RUN: echo /c >> %t/args_nested.rsp
 // RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+// RUN: cat %t/deps.json | sed 

[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-24 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/89950

>From f2340c98c95e0d72516fc240ff268fead9f15391 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 17 Apr 2024 16:28:21 -0400
Subject: [PATCH 1/2] [clang-scan-deps] Expand response files before the
 argument ajuster

Previously, since response (.rsp) files weren't expanded, we only parsed
the command-line as provided in the Clang CDB file. Unfortunately, when
using Unreal Engine, arguments are always generated in a .rsp file.

After this patch, /Fo can be parsed and added to the final command-line.
Without this option, the make targets that are emitted are made up from the
input file name alone. We have some cases where the same input in the project
generates several output files, so we end up with duplicate make targets
in the scan-deps emitted dependency file.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17a..7b7f10c4be7421 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   llvm::cl::PrintOptionValues();
 
+  // Expand response files in advance, so that we can "see" all the arguments
+  // when adjusting below.
+  auto ResponseExpander = expandResponseFiles(std::move(Compilations),
+  llvm::vfs::getRealFileSystem());
+
   // The command options are rewritten to run Clang in preprocessor only mode.
   auto AdjustingCompilations =
   std::make_unique(
-  std::move(Compilations));
+  std::move(ResponseExpander));
   ResourceDirectoryCache ResourceDirCache;
 
   AdjustingCompilations->appendArgumentsAdjuster(

>From 09e0595fa9f3c9795d6f40a7308d8a912254b1df Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 24 Apr 2024 13:52:55 -0400
Subject: [PATCH 2/2] Add test

---
 .../ClangScanDeps/response-file-clang-cl.c| 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 clang/test/ClangScanDeps/response-file-clang-cl.c

diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c 
b/clang/test/ClangScanDeps/response-file-clang-cl.c
new file mode 100644
index 00..78e3d15deb1678
--- /dev/null
+++ b/clang/test/ClangScanDeps/response-file-clang-cl.c
@@ -0,0 +1,32 @@
+// Check that the scanner can adjust arguments by reading .rsp files in 
advance.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: echo /Fo%t/tu.obj >> %t/args_nested.rsp
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Here we ensure that we got a qualified .obj with its full path, since 
that's what we're passing with /Fo
+// CHECK: [[PREFIX]]/tu.obj:
+
+//--- cdb.json.template
+[{
+  "file": "DIR/t.cpp",
+  "directory": "DIR",
+  "command": "clang-cl @DIR/args.rsp"
+}]
+
+//--- args.rsp
+@args_nested.rsp
+/c tu.cpp
+
+//--- args_nested.rsp
+/I include
+
+//--- include/header.h
+
+//--- tu.cpp
+#include "header.h"

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


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-24 Thread Alexandre Ganea via cfe-commits

aganea wrote:

The reason of this `/Fo` output path fiddling code is this: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Clang.cpp#L1072-L1082
It's because that highlighted code doesn't handle the clang-cl case, it doesn't 
consider `/Fo`. Probably because most people don't use `-MT`/`-MF` with 
clang-cl (it has to be escaped on the command-line such as `/clang:-MT 
/clang:-MF...`. I can fix it there (in Clang.cpp) instead, and remove all the 
related code in `clang_scan_deps_main()`.

https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-24 Thread Alexandre Ganea via cfe-commits

aganea wrote:

This is missing a test, I will add one.


https://github.com/llvm/llvm-project/pull/89950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Expand response files before the argument adjuster (PR #89950)

2024-04-24 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea created 
https://github.com/llvm/llvm-project/pull/89950

Previously, since response (.rsp) files weren't expanded at the very beginning 
of clang-scan-deps, we only parsed the command-line as provided in the Clang 
.cdb file. Unfortunately, when using Unreal Engine, arguments are always 
generated in a .rsp file (ie. `/path/to/clang-cl.exe 
@/path/to/filename_args.rsp`).

After this patch, `/Fo` can be parsed and added to the final command-line. 
Without this option, the make targets that are emitted are made up from the 
input file name alone. We have some cases where the same input in the project 
generates several output files, so we end up with duplicate make targets in the 
scan-deps emitted dependency file.

>From f2340c98c95e0d72516fc240ff268fead9f15391 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Wed, 17 Apr 2024 16:28:21 -0400
Subject: [PATCH] [clang-scan-deps] Expand response files before the argument
 ajuster

Previously, since response (.rsp) files weren't expanded, we only parsed
the command-line as provided in the Clang CDB file. Unfortunately, when
using Unreal Engine, arguments are always generated in a .rsp file.

After this patch, /Fo can be parsed and added to the final command-line.
Without this option, the make targets that are emitted are made up from the
input file name alone. We have some cases where the same input in the project
generates several output files, so we end up with duplicate make targets
in the scan-deps emitted dependency file.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index f42af7e330e17a..7b7f10c4be7421 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -792,10 +792,15 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
 
   llvm::cl::PrintOptionValues();
 
+  // Expand response files in advance, so that we can "see" all the arguments
+  // when adjusting below.
+  auto ResponseExpander = expandResponseFiles(std::move(Compilations),
+  llvm::vfs::getRealFileSystem());
+
   // The command options are rewritten to run Clang in preprocessor only mode.
   auto AdjustingCompilations =
   std::make_unique(
-  std::move(Compilations));
+  std::move(ResponseExpander));
   ResourceDirectoryCache ResourceDirCache;
 
   AdjustingCompilations->appendArgumentsAdjuster(

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


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-24 Thread Alexandre Ganea via cfe-commits

aganea wrote:

> LGTM, thanks!

Thanks for the review!

> (Out of interest, what machine are you seeing the contention with?)

It's a ThreadRipper Pro 3975WX 32c/64t running on with Windows 11.

https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-24 Thread Alexandre Ganea via cfe-commits


@@ -1293,6 +1293,10 @@ compileModuleImpl(CompilerInstance , 
SourceLocation ImportLoc,
 diag::remark_module_build_done)
 << ModuleName;
 
+  // Propagate the statistics to the parent FileManager.
+  if (FrontendOpts.ModulesShareFileManager)

aganea wrote:

Yes, you're right, fixed!

https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-24 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/88427

>From 1b11d526e2cde1df64c7c4e05b2698b6d40926c3 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Thu, 11 Apr 2024 13:02:30 -0400
Subject: [PATCH 1/3] [clang-scan-deps] Fix atomic contention when updating
 `TrackingStatistic`s in hot code paths in `FileManager`.

---
 clang/include/clang/Basic/FileManager.h   |  6 -
 .../DependencyScanningService.h   |  6 -
 .../DependencyScanningWorker.h|  2 ++
 clang/lib/Basic/FileManager.cpp   | 23 ---
 clang/lib/Frontend/CompilerInstance.cpp   |  3 ++-
 .../DependencyScanningService.cpp |  4 ++--
 .../DependencyScanningWorker.cpp  |  6 +++--
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |  2 +-
 8 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 2245fd78bfc9f0..24256a7368ccc8 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -114,6 +114,9 @@ class FileManager : public RefCountedBase {
   ///
   unsigned NextFileUID;
 
+  /// Whether we want to print statistics. This impacts the collection of data.
+  bool EnablePrintStats;
+
   // Caching.
   std::unique_ptr StatCache;
 
@@ -134,7 +137,8 @@ class FileManager : public RefCountedBase {
   /// \param FS if non-null, the VFS to use.  Otherwise uses
   /// llvm::vfs::getRealFileSystem().
   FileManager(const FileSystemOptions ,
-  IntrusiveRefCntPtr FS = nullptr);
+  IntrusiveRefCntPtr FS = nullptr,
+  bool PrintStats = false);
   ~FileManager();
 
   /// Installs the provided FileSystemStatCache object within
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index 557f0e547ab4a8..7b869bb7976f2a 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -76,7 +76,7 @@ class DependencyScanningService {
   DependencyScanningService(
   ScanningMode Mode, ScanningOutputFormat Format,
   ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default,
-  bool EagerLoadModules = false);
+  bool EagerLoadModules = false, bool PrintStats = false);
 
   ScanningMode getMode() const { return Mode; }
 
@@ -90,6 +90,8 @@ class DependencyScanningService {
 return SharedCache;
   }
 
+  bool getPrintStats() const { return PrintStats; }
+
 private:
   const ScanningMode Mode;
   const ScanningOutputFormat Format;
@@ -97,6 +99,8 @@ class DependencyScanningService {
   const ScanningOptimizations OptimizeArgs;
   /// Whether to set up command-lines to load PCM files eagerly.
   const bool EagerLoadModules;
+  /// Whether we should collect statistics during execution.
+  const bool PrintStats;
   /// The global file system cache.
   DependencyScanningFilesystemSharedCache SharedCache;
 };
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
index 0f607862194b31..27b96c964ce83d 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -119,6 +119,8 @@ class DependencyScanningWorker {
   ScanningOptimizations OptimizeArgs;
   /// Whether to set up command-lines to load PCM files eagerly.
   bool EagerLoadModules;
+  /// Whether we should collect statistics during execution.
+  bool PrintStats;
 };
 
 } // end namespace dependencies
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index cd520a6375e07e..1071f6ae53dd78 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -50,9 +50,10 @@ ALWAYS_ENABLED_STATISTIC(NumFileCacheMisses, "Number of file 
cache misses.");
 
//===--===//
 
 FileManager::FileManager(const FileSystemOptions ,
- IntrusiveRefCntPtr FS)
+ IntrusiveRefCntPtr FS,
+ bool PrintStats)
 : FS(std::move(FS)), FileSystemOpts(FSO), SeenDirEntries(64),
-  SeenFileEntries(64), NextFileUID(0) {
+  SeenFileEntries(64), NextFileUID(0), EnablePrintStats(PrintStats) {
   // If the caller doesn't provide a virtual file system, just grab the real
   // file system.
   if (!this->FS)
@@ -134,7 +135,8 @@ FileManager::getDirectoryRef(StringRef DirName, bool 
CacheFailure) {
 }
   }
 
-  ++NumDirLookups;
+  if (EnablePrintStats)
+++NumDirLookups;
 
   // See if there was already an entry in the map.  Note that the map
   // contains both virtual and real directories.
@@ -147,7 +149,8 @@ 

[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-17 Thread Alexandre Ganea via cfe-commits

aganea wrote:

> As an alternative approach: could we turn these into member variables, make 
> them non-atomic and take care to update the stats of the superior 
> `FileManager` whenever an inferior `FileManager` goes out of scope? (e.g. 
> after implicitly building a module)

As suggested.

https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-17 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/88427

>From 1b11d526e2cde1df64c7c4e05b2698b6d40926c3 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Thu, 11 Apr 2024 13:02:30 -0400
Subject: [PATCH 1/2] [clang-scan-deps] Fix atomic contention when updating
 `TrackingStatistic`s in hot code paths in `FileManager`.

---
 clang/include/clang/Basic/FileManager.h   |  6 -
 .../DependencyScanningService.h   |  6 -
 .../DependencyScanningWorker.h|  2 ++
 clang/lib/Basic/FileManager.cpp   | 23 ---
 clang/lib/Frontend/CompilerInstance.cpp   |  3 ++-
 .../DependencyScanningService.cpp |  4 ++--
 .../DependencyScanningWorker.cpp  |  6 +++--
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |  2 +-
 8 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 2245fd78bfc9f0..24256a7368ccc8 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -114,6 +114,9 @@ class FileManager : public RefCountedBase {
   ///
   unsigned NextFileUID;
 
+  /// Whether we want to print statistics. This impacts the collection of data.
+  bool EnablePrintStats;
+
   // Caching.
   std::unique_ptr StatCache;
 
@@ -134,7 +137,8 @@ class FileManager : public RefCountedBase {
   /// \param FS if non-null, the VFS to use.  Otherwise uses
   /// llvm::vfs::getRealFileSystem().
   FileManager(const FileSystemOptions ,
-  IntrusiveRefCntPtr FS = nullptr);
+  IntrusiveRefCntPtr FS = nullptr,
+  bool PrintStats = false);
   ~FileManager();
 
   /// Installs the provided FileSystemStatCache object within
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index 557f0e547ab4a8..7b869bb7976f2a 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -76,7 +76,7 @@ class DependencyScanningService {
   DependencyScanningService(
   ScanningMode Mode, ScanningOutputFormat Format,
   ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default,
-  bool EagerLoadModules = false);
+  bool EagerLoadModules = false, bool PrintStats = false);
 
   ScanningMode getMode() const { return Mode; }
 
@@ -90,6 +90,8 @@ class DependencyScanningService {
 return SharedCache;
   }
 
+  bool getPrintStats() const { return PrintStats; }
+
 private:
   const ScanningMode Mode;
   const ScanningOutputFormat Format;
@@ -97,6 +99,8 @@ class DependencyScanningService {
   const ScanningOptimizations OptimizeArgs;
   /// Whether to set up command-lines to load PCM files eagerly.
   const bool EagerLoadModules;
+  /// Whether we should collect statistics during execution.
+  const bool PrintStats;
   /// The global file system cache.
   DependencyScanningFilesystemSharedCache SharedCache;
 };
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
index 0f607862194b31..27b96c964ce83d 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -119,6 +119,8 @@ class DependencyScanningWorker {
   ScanningOptimizations OptimizeArgs;
   /// Whether to set up command-lines to load PCM files eagerly.
   bool EagerLoadModules;
+  /// Whether we should collect statistics during execution.
+  bool PrintStats;
 };
 
 } // end namespace dependencies
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index cd520a6375e07e..1071f6ae53dd78 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -50,9 +50,10 @@ ALWAYS_ENABLED_STATISTIC(NumFileCacheMisses, "Number of file 
cache misses.");
 
//===--===//
 
 FileManager::FileManager(const FileSystemOptions ,
- IntrusiveRefCntPtr FS)
+ IntrusiveRefCntPtr FS,
+ bool PrintStats)
 : FS(std::move(FS)), FileSystemOpts(FSO), SeenDirEntries(64),
-  SeenFileEntries(64), NextFileUID(0) {
+  SeenFileEntries(64), NextFileUID(0), EnablePrintStats(PrintStats) {
   // If the caller doesn't provide a virtual file system, just grab the real
   // file system.
   if (!this->FS)
@@ -134,7 +135,8 @@ FileManager::getDirectoryRef(StringRef DirName, bool 
CacheFailure) {
 }
   }
 
-  ++NumDirLookups;
+  if (EnablePrintStats)
+++NumDirLookups;
 
   // See if there was already an entry in the map.  Note that the map
   // contains both virtual and real directories.
@@ -147,7 +149,8 @@ 

[clang] [clang][deps] Only bypass scanning VFS for the module cache (PR #88800)

2024-04-16 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/88800
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][deps] Only bypass scanning VFS for the module cache (PR #88800)

2024-04-16 Thread Alexandre Ganea via cfe-commits


@@ -201,11 +201,8 @@ const CachedRealPath 
::CacheShard::
   return *StoredRealPath;
 }
 
-static bool shouldCacheStatFailures(StringRef Filename) {
-  StringRef Ext = llvm::sys::path::extension(Filename);
-  if (Ext.empty())
-return false; // This may be the module cache directory.
-  return true;
+bool DependencyScanningWorkerFilesystem::shouldBypass(StringRef Path) const {
+  return BypassedPathPrefix && Path.starts_with(*BypassedPathPrefix);

aganea wrote:

Do we always expect canonical paths here? Are paths always rendered using the 
style of the target platform?

https://github.com/llvm/llvm-project/pull/88800
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][deps] Only bypass scanning VFS for the module cache (PR #88800)

2024-04-16 Thread Alexandre Ganea via cfe-commits


@@ -362,7 +357,7 @@ DependencyScanningWorkerFilesystem::openFileForRead(const 
Twine ) {
   SmallString<256> OwnedFilename;
   StringRef Filename = Path.toStringRef(OwnedFilename);
 
-  if (Filename.ends_with(".pcm"))
+  if (shouldBypass(Filename))

aganea wrote:

Are the .pcm files to be generated in the modules cache path?

https://github.com/llvm/llvm-project/pull/88800
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][deps] Only bypass scanning VFS for the module cache (PR #88800)

2024-04-16 Thread Alexandre Ganea via cfe-commits


@@ -174,3 +174,30 @@ TEST(DependencyScanningFilesystem, CacheStatOnExists) {
   EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
   EXPECT_EQ(InstrumentingFS->NumExistsCalls, 0u);
 }
+
+TEST(DependencyScanningFilesystem, CacheStatFailures) {
+  auto InMemoryFS = llvm::makeIntrusiveRefCnt();
+  InMemoryFS->setCurrentWorkingDirectory("/");
+  InMemoryFS->addFile("/dir/vector", 0, llvm::MemoryBuffer::getMemBuffer(""));
+  InMemoryFS->addFile("/cache/a.pcm", 0, llvm::MemoryBuffer::getMemBuffer(""));
+
+  auto InstrumentingFS =
+  llvm::makeIntrusiveRefCnt(InMemoryFS);
+
+  DependencyScanningFilesystemSharedCache SharedCache;
+  DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
+
+  DepFS.status("/dir");
+  DepFS.status("/dir");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 1u);
+
+  DepFS.status("/dir/vector");
+  DepFS.status("/dir/vector");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
+
+  DepFS.setBypassedPathPrefix("/cache");
+  DepFS.exists("/cache/a.pcm");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 3u);
+  DepFS.exists("/cache/a.pcm");
+  EXPECT_EQ(InstrumentingFS->NumStatusCalls, 4u);

aganea wrote:

Maybe test calling `DepFS.resetBypassedPathPrefix()` also here?

https://github.com/llvm/llvm-project/pull/88800
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-13 Thread Alexandre Ganea via cfe-commits

aganea wrote:

I think in the short term @jansvoboda11's suggestion should be good enough.

Bit if we want `Statistics` to be always cheap, we should make them 
`thread_local` instead, not atomic. `getValue()` could do the "collection" of 
data over all active, or past threads.  It would also need a mechanism for 
collecting data when a thread ends through `pthread_key_create/FlsCallback`s.  
It would be a bit more involved than what's there currently, but that should 
fix the issue I'm seeing (and maybe others).

https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-11 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-11 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/88427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (PR #88427)

2024-04-11 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea created 
https://github.com/llvm/llvm-project/pull/88427

`FileManager::getDirectoryRef` and `FileManager::getFileRef` are hot code paths 
in `clang-scan-deps`. In these functions, we update a couple of atomic 
variables related to printing statistics, which causes contention on high core 
count machines.

![Screenshot 2024-04-10 
214123](https://github.com/llvm/llvm-project/assets/37383324/5756b1bc-cab5-4612-8769-ee7e03a66479)

![Screenshot 2024-04-10 
214246](https://github.com/llvm/llvm-project/assets/37383324/3d560e89-61c7-4fb9-9330-f9e660e8fc8b)

![Screenshot 2024-04-10 
214315](https://github.com/llvm/llvm-project/assets/37383324/006341fc-49d4-4720-a348-7af435c21b17)


After this PR, we update these variables iff the user wants to print statistics.

On my use case, this saves about 49 sec over 1 min 47 sec of `clang-scan-deps` 
run time (1 min 47 sec before, 58 sec after). These figures are after applying 
my suggestion in 
https://github.com/llvm/llvm-project/pull/88152#issuecomment-2049803229, that 
is:
```
static bool shouldCacheStatFailures(StringRef Filename) {
  return true;
}
```
Without that, there's just too much OS noise from the high volume of `status()` 
calls with regular non-module C++ code. Tested on Windows with clang-cl.

>From 1b11d526e2cde1df64c7c4e05b2698b6d40926c3 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Thu, 11 Apr 2024 13:02:30 -0400
Subject: [PATCH] [clang-scan-deps] Fix atomic contention when updating
 `TrackingStatistic`s in hot code paths in `FileManager`.

---
 clang/include/clang/Basic/FileManager.h   |  6 -
 .../DependencyScanningService.h   |  6 -
 .../DependencyScanningWorker.h|  2 ++
 clang/lib/Basic/FileManager.cpp   | 23 ---
 clang/lib/Frontend/CompilerInstance.cpp   |  3 ++-
 .../DependencyScanningService.cpp |  4 ++--
 .../DependencyScanningWorker.cpp  |  6 +++--
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |  2 +-
 8 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 2245fd78bfc9f0..24256a7368ccc8 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -114,6 +114,9 @@ class FileManager : public RefCountedBase {
   ///
   unsigned NextFileUID;
 
+  /// Whether we want to print statistics. This impacts the collection of data.
+  bool EnablePrintStats;
+
   // Caching.
   std::unique_ptr StatCache;
 
@@ -134,7 +137,8 @@ class FileManager : public RefCountedBase {
   /// \param FS if non-null, the VFS to use.  Otherwise uses
   /// llvm::vfs::getRealFileSystem().
   FileManager(const FileSystemOptions ,
-  IntrusiveRefCntPtr FS = nullptr);
+  IntrusiveRefCntPtr FS = nullptr,
+  bool PrintStats = false);
   ~FileManager();
 
   /// Installs the provided FileSystemStatCache object within
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index 557f0e547ab4a8..7b869bb7976f2a 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -76,7 +76,7 @@ class DependencyScanningService {
   DependencyScanningService(
   ScanningMode Mode, ScanningOutputFormat Format,
   ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default,
-  bool EagerLoadModules = false);
+  bool EagerLoadModules = false, bool PrintStats = false);
 
   ScanningMode getMode() const { return Mode; }
 
@@ -90,6 +90,8 @@ class DependencyScanningService {
 return SharedCache;
   }
 
+  bool getPrintStats() const { return PrintStats; }
+
 private:
   const ScanningMode Mode;
   const ScanningOutputFormat Format;
@@ -97,6 +99,8 @@ class DependencyScanningService {
   const ScanningOptimizations OptimizeArgs;
   /// Whether to set up command-lines to load PCM files eagerly.
   const bool EagerLoadModules;
+  /// Whether we should collect statistics during execution.
+  const bool PrintStats;
   /// The global file system cache.
   DependencyScanningFilesystemSharedCache SharedCache;
 };
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
index 0f607862194b31..27b96c964ce83d 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -119,6 +119,8 @@ class DependencyScanningWorker {
   ScanningOptimizations OptimizeArgs;
   /// Whether to set up command-lines to load PCM files eagerly.
   bool EagerLoadModules;
+  /// Whether we should collect statistics during execution.
+  bool PrintStats;
 };
 
 } // end namespace 

[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-11 Thread Alexandre Ganea via cfe-commits

aganea wrote:

> In the meantime, are you able to work around this for your non-modular 
> use-case by applying your change when building your own compiler downstream?

Yes I fixed it in our downstream. I am more worried about other users, since 
the initial version that @hyp committed a while ago in 
e1f4c4aad27992d6b8a0b8d85af42c14fa68c298 didn't suffer of these issues.

> Also, just to be sure, this is not a regression, correct?

Not per se, not from the latest commits. It seems the issue was introduced when 
module support was added in 9ab6d8236b176bf9dd43741f4d874a8afebed99c. 
Unfortunately there are users like us with big C++ codebases and stuck with 
regular #includes, no modules for now.

https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-11 Thread Alexandre Ganea via cfe-commits

aganea wrote:

> > Not sure @jansvoboda11 perhaps if we want to cherry pick 
> > [b768a8c](https://github.com/llvm/llvm-project/commit/b768a8c1db85b9e84fd8b356570a3a8fbe37acf6)
> >  on `release/18.x`? Or should we land just a simple PR with just the 
> > function change above?
> 
> I can try pulling 
> [b768a8c](https://github.com/llvm/llvm-project/commit/b768a8c1db85b9e84fd8b356570a3a8fbe37acf6)
>  into the release branch.

Sorry I've been misleading, pushing b768a8c on 18.x doesn't fix the issue. The 
problem is around the directory queries and the function in b768a8c returns 
`false` for that case (thus no caching of errors).

Running with:
```
static bool shouldCacheStatFailures(StringRef Filename) {
  StringRef Ext = llvm::sys::path::extension(Filename);
  if (Ext.empty())
return false; // This may be the module cache directory.
  return true;
}
```
Takes 4 min 8 sec.

Then running with:
```
static bool shouldCacheStatFailures(StringRef Filename) {
  return true;
}
```
Takes 1 min 47 sec.

I think something more involved would be needed here. @jansvoboda11 in which 
case we don't want to consider the file system immutable during the execution 
of clang-scan-deps?

https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-10 Thread Alexandre Ganea via cfe-commits


@@ -201,6 +201,21 @@ class ErrorDummyFileSystem : public DummyFileSystem {
   }
 };
 
+/// A version of \c DummyFileSystem that aborts on \c status() to test that
+/// \c exists() is being used.
+class NoStatusDummyFileSystem : public DummyFileSystem {
+public:
+  ErrorOr status(const Twine ) override {
+llvm::report_fatal_error(
+"unexpected call to NoStatusDummyFileSystem::status");
+  }
+
+  bool exists(const Twine ) override {
+auto Status = DummyFileSystem::status(Path);

aganea wrote:

Explicit return type here too.

https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-10 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea approved this pull request.

Otherwise this PR LGTM.

https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-10 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-10 Thread Alexandre Ganea via cfe-commits

aganea wrote:

> This patch doesn`t improve my usage, it seems I'm hitting a different 
> codepath than you do. I'll investigate.

Ah I see, the commit 
https://github.com/llvm/llvm-project/commit/b768a8c1db85b9e84fd8b356570a3a8fbe37acf6
 didn't make it in time for the 18.x branch. The issue I'm seeing here is with 
regular C++ code, no PCH, no modules. It is related to 
`shouldCacheStatFailures()` which currently in `release/18.x` happens to return 
`false` for directories. The searching behavior for `#include` files with 
`clang-cl` (not sure about plain clang) is essentially to query every include 
path passed on the command-line. That creates lots of OS `status()` calls, like 
shown in my profile above. Going back to the previous behavior as on `main` 
solves my issue, ie:
```
static bool shouldCacheStatFailures(StringRef Filename) {
  StringRef Ext = llvm::sys::path::extension(Filename);
  if (Ext.empty())
return false; // This may be the module cache directory.
  return true;
}
```
As an order of magnitude, the Unreal Engine target I'm testing consists of 
17,801 TUs, generating 1,2 billion status() calls in total (by counting the 
calls to `FileManager::getStatValue`) out of which  8,3 millions are real OS 
calls after the change above (by counting the calls to 
`llvm::sys::windows::status()`.

Not sure @jansvoboda11 perhaps if we want to cherry pick 
b768a8c1db85b9e84fd8b356570a3a8fbe37acf6 on `release/18.x`? Or should we land 
just a simple PR with just the function change above?

https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-09 Thread Alexandre Ganea via cfe-commits

aganea wrote:

This patch doesn`t improve my usage, it seems I'm hitting a different codepath 
than you do. I'll investigate.

https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-09 Thread Alexandre Ganea via cfe-commits


@@ -270,6 +270,12 @@ DependencyScanningWorkerFilesystem::status(const Twine 
) {
   return Result->getStatus();
 }
 
+bool
+DependencyScanningWorkerFilesystem::exists(const Twine ) {
+  auto Status = status(Path);

aganea wrote:

The return type is unclear at first sight, I would suggest replacing the `auto` 
with the concrete type. Please see 
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable

https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-09 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea commented:

Thanks for the change! Quite interestingly I was just looking precisely at this 
issue today :smile: Things are worst on Windows, where mini-filter drivers 
kick-in and bring performance to its knees. I'll try your patch, see how that 
improves my usage!

https://github.com/llvm/llvm-project/assets/37383324/f6fc28e2-8039-4cfc-aaa8-bfbbfe234394;>


https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][deps] Overload `Filesystem::exists` in `DependencyScanningFilesystem` to have it use cached `status` (PR #88152)

2024-04-09 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/88152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] Rename `ThreadPool::getThreadCount()` to `getMaxConcurrency()` (NFC) (PR #82296)

2024-02-19 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea approved this pull request.

Lg, thanks!

https://github.com/llvm/llvm-project/pull/82296
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ee15e2b - [clang] Silence warning when building with MSVC targetting x86

2024-01-25 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2024-01-25T09:34:17-05:00
New Revision: ee15e2bd32a4677c40d927c732b26d33f88d7865

URL: 
https://github.com/llvm/llvm-project/commit/ee15e2bd32a4677c40d927c732b26d33f88d7865
DIFF: 
https://github.com/llvm/llvm-project/commit/ee15e2bd32a4677c40d927c732b26d33f88d7865.diff

LOG: [clang] Silence warning when building with MSVC targetting x86

This fixes:
```
[3786/6996] Building CXX object 
tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\AttrDocTable.cpp.obj
C:\git\llvm-project\clang\lib\AST\AttrDocTable.cpp(24): warning C4018: '<': 
signed/unsigned mismatch
```

Added: 


Modified: 
clang/lib/AST/AttrDocTable.cpp

Removed: 




diff  --git a/clang/lib/AST/AttrDocTable.cpp b/clang/lib/AST/AttrDocTable.cpp
index df7e3d63a6c355a..56a143b9ed29be6 100644
--- a/clang/lib/AST/AttrDocTable.cpp
+++ b/clang/lib/AST/AttrDocTable.cpp
@@ -21,7 +21,7 @@ static const llvm::StringRef AttrDoc[] = {
 };
 
 llvm::StringRef clang::Attr::getDocumentation(clang::attr::Kind K) {
-  if (K < std::size(AttrDoc))
+  if (K < (int)std::size(AttrDoc))
 return AttrDoc[K];
   return "";
 }



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


[clang-tools-extra] f33f5a0 - [clangd] Silence warning when compiling with MSVC targetting x86

2024-01-25 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2024-01-25T09:34:17-05:00
New Revision: f33f5a04e9feeb9b473694825d84da8322f87df9

URL: 
https://github.com/llvm/llvm-project/commit/f33f5a04e9feeb9b473694825d84da8322f87df9
DIFF: 
https://github.com/llvm/llvm-project/commit/f33f5a04e9feeb9b473694825d84da8322f87df9.diff

LOG: [clangd] Silence warning when compiling with MSVC targetting x86

This fixes:
```
[5240/6995] Building CXX object 
tools\clang\tools\extra\clangd\CMakeFiles\obj.clangDaemon.dir\InlayHints.cpp.obj
C:\git\llvm-project\clang-tools-extra\clangd\InlayHints.cpp(1098): warning 
C4018: '<': signed/unsigned mismatch
```

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 5722ca8f66eb720..c7dce041474a1c8 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -1095,7 +1095,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   if (auto *Def = Callee->getDefinition()) {
 auto I = std::distance(Callee->param_begin(),
llvm::find(Callee->parameters(), P));
-if (I < Callee->getNumParams()) {
+if (I < (int)Callee->getNumParams()) {
   return Def->getParamDecl(I);
 }
   }



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


[clang] 419d6ea - [clang] Silence warning when compiling with MSVC targetting x86

2024-01-25 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2024-01-25T09:34:17-05:00
New Revision: 419d6ea135dd205e1eaab368a58ae14f9f52f699

URL: 
https://github.com/llvm/llvm-project/commit/419d6ea135dd205e1eaab368a58ae14f9f52f699
DIFF: 
https://github.com/llvm/llvm-project/commit/419d6ea135dd205e1eaab368a58ae14f9f52f699.diff

LOG: [clang] Silence warning when compiling with MSVC targetting x86

This fixes:
```
[3963/6996] Building CXX object 
tools\clang\lib\CodeGen\CMakeFiles\obj.clangCodeGen.dir\CGExpr.cpp.obj
C:\git\llvm-project\clang\lib\CodeGen\CGExpr.cpp(3808): warning C4018: '<=': 
signed/unsigned mismatch
```

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index c5f6b6d3a99f0b2..9196c953145b214 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3805,7 +3805,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
-  if (TrapBBs.size() <= CheckHandlerID)
+  if ((int)TrapBBs.size() <= CheckHandlerID)
 TrapBBs.resize(CheckHandlerID + 1);
 
   llvm::BasicBlock * = TrapBBs[CheckHandlerID];



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


[clang] [llvm] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2024-01-24 Thread Alexandre Ganea via cfe-commits

aganea wrote:

Can you please send separate PRs for the Support changes?

https://github.com/llvm/llvm-project/pull/67562
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [lld] [llvm-driver] Fix usage of `InitLLVM` on Windows (PR #76306)

2024-01-11 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea closed https://github.com/llvm/llvm-project/pull/76306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] [llvm-driver] Fix usage of `InitLLVM` on Windows (PR #76306)

2024-01-11 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/76306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] [llvm-driver] Fix usage of `InitLLVM` on Windows (PR #76306)

2024-01-11 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/76306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [llvm-driver] Fix usage of `InitLLVM` on Windows (PR #76306)

2023-12-30 Thread Alexandre Ganea via cfe-commits

aganea wrote:

@MaskRay Can you please take another look?

https://github.com/llvm/llvm-project/pull/76306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [llvm-driver] Fix usage of `InitLLVM` on Windows (PR #76306)

2023-12-30 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea edited https://github.com/llvm/llvm-project/pull/76306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [llvm-driver] Fix usage of `InitLLVM` on Windows (PR #76306)

2023-12-30 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea updated 
https://github.com/llvm/llvm-project/pull/76306

>From 8187e95ea4e04793fbfc85045aa21f9633bbc03d Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Sat, 23 Dec 2023 19:17:06 -0500
Subject: [PATCH 1/2] [llvm-driver] Fix tool re-entrance on Windows.

Previously, some tools such as `clang` or `lld` which require strict order for 
certain command-line options, such as `clang -cc1` or `lld -flavor` would not 
long work on Windows, when these tools were linked as part of `llvm-driver`. 
This was caused by `InitLLVM` which was part of the `main()` function of these 
tools, which in turn calls `windows::GetCommandLineArguments`. This function 
completly replaces argc/argv by new UTF-8 contents, so any ajustements to 
argc/argv made by `llvm-driver` prior to calling these tools would be reset.

We now call `InitLLVM` as part of the `llvm-driver`. Any further usages to 
`InitLLVM` on the stack, after the first call in the process would have no 
effect. In the same way, the last `InitLLVM` on the stack will clear the 
`ManagedStatics` as usual.
---
 llvm/cmake/modules/llvm-driver-template.cpp.in | 2 ++
 llvm/lib/Support/InitLLVM.cpp  | 6 ++
 llvm/tools/llvm-driver/llvm-driver.cpp | 6 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/llvm/cmake/modules/llvm-driver-template.cpp.in 
b/llvm/cmake/modules/llvm-driver-template.cpp.in
index 16c4fb34714638..71aca6cd140cb5 100644
--- a/llvm/cmake/modules/llvm-driver-template.cpp.in
+++ b/llvm/cmake/modules/llvm-driver-template.cpp.in
@@ -8,9 +8,11 @@
 
 #include "llvm/Support/LLVMDriver.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/InitLLVM.h"
 
 int @TOOL_NAME@_main(int argc, char **, const llvm::ToolContext &);
 
 int main(int argc, char **argv) {
+  llvm::InitLLVM X(argc, argv);
   return @TOOL_NAME@_main(argc, argv, {argv[0], nullptr, false});
 }
diff --git a/llvm/lib/Support/InitLLVM.cpp b/llvm/lib/Support/InitLLVM.cpp
index 7f475f42f3cb81..2a2e6c254c795a 100644
--- a/llvm/lib/Support/InitLLVM.cpp
+++ b/llvm/lib/Support/InitLLVM.cpp
@@ -36,8 +36,12 @@ void CleanupStdHandles(void *Cookie) {
 using namespace llvm;
 using namespace llvm::sys;
 
+static std::atomic UsageCount{0};
+
 InitLLVM::InitLLVM(int , const char **,
bool InstallPipeSignalExitHandler) {
+  if (UsageCount++)
+return;
 #ifdef __MVS__
   // Bring stdin/stdout/stderr into a known state.
   sys::AddSignalHandler(CleanupStdHandles, nullptr);
@@ -94,6 +98,8 @@ InitLLVM::InitLLVM(int , const char **,
 }
 
 InitLLVM::~InitLLVM() {
+  if (--UsageCount)
+return;
 #ifdef __MVS__
   CleanupStdHandles(nullptr);
 #endif
diff --git a/llvm/tools/llvm-driver/llvm-driver.cpp 
b/llvm/tools/llvm-driver/llvm-driver.cpp
index a0f1ca831d93b6..53a8b9357e3780 100644
--- a/llvm/tools/llvm-driver/llvm-driver.cpp
+++ b/llvm/tools/llvm-driver/llvm-driver.cpp
@@ -10,6 +10,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/LLVMDriver.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/WithColor.h"
@@ -79,4 +80,7 @@ static int findTool(int Argc, char **Argv, const char *Argv0) 
{
   return 1;
 }
 
-int main(int Argc, char **Argv) { return findTool(Argc, Argv, Argv[0]); }
+int main(int Argc, char **Argv) {
+  llvm::InitLLVM X(Argc, Argv);
+  return findTool(Argc, Argv, Argv[0]);
+}

>From 03d24462dbc2e113bf0f740f3d95f519367c1abd Mon Sep 17 00:00:00 2001
From: Alexandre Ganea 
Date: Sat, 30 Dec 2023 22:45:58 -0500
Subject: [PATCH 2/2] Remove `InitLLVM` from all the tools participating in the
 `llvm-driver`.

---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |  2 --
 clang/tools/driver/driver.cpp |  2 --
 lld/Common/DriverDispatcher.cpp   |  1 -
 lld/tools/lld/lld.cpp |  2 --
 llvm/lib/Support/InitLLVM.cpp | 11 +--
 llvm/tools/dsymutil/dsymutil.cpp  |  3 ---
 llvm/tools/llvm-ar/llvm-ar.cpp|  2 --
 llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp  |  2 --
 llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp|  2 --
 llvm/tools/llvm-dwp/llvm-dwp.cpp  |  3 ---
 .../tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp |  2 --
 llvm/tools/llvm-lipo/llvm-lipo.cpp|  2 --
 llvm/tools/llvm-ml/llvm-ml.cpp|  2 --
 llvm/tools/llvm-mt/llvm-mt.cpp|  3 ---
 llvm/tools/llvm-nm/llvm-nm.cpp|  2 --
 llvm/tools/llvm-objcopy/llvm-objcopy.cpp  |  2 --
 llvm/tools/llvm-objdump/llvm-objdump.cpp  |  2 --
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  2 --
 llvm/tools/llvm-rc/llvm-rc.cpp|  2 --
 llvm/tools/llvm-readobj/llvm-readobj.cpp  |  2 --
 

[clang] -fsanitize=function: fix MSVC hashing to sugared type (PR #66816)

2023-10-02 Thread Alexandre Ganea via cfe-commits


@@ -3838,13 +3838,13 @@ void MicrosoftMangleContextImpl::mangleSEHFinallyBlock(
   Mangler.mangleName(EnclosingDecl);
 }
 
-void MicrosoftMangleContextImpl::mangleTypeName(
+void MicrosoftMangleContextImpl::mangleCanonicalTypeName(
 QualType T, raw_ostream , bool NormalizeIntegers = false) {
   // This is just a made up unique string for the purposes of tbaa.  undname
   // does *not* know how to demangle it.
   MicrosoftCXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << '?';
-  Mangler.mangleType(T, SourceRange());
+  Mangler.mangleType(T.getCanonicalType(), SourceRange());

aganea wrote:

Like @mizvekov suggested, we could only backport this line to `release/17.x` 
with a comment above, pointing to this patch?

https://github.com/llvm/llvm-project/pull/66816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Update GoogleTest to v1.14.0 (PR #65823)

2023-09-30 Thread Alexandre Ganea via cfe-commits

aganea wrote:

I managed to repro. It is actually this, still open, issue: 
https://github.com/microsoft/STL/issues/1066

https://github.com/llvm/llvm-project/pull/65823
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Update GoogleTest to v1.14.0 (PR #65823)

2023-09-29 Thread Alexandre Ganea via cfe-commits

aganea wrote:

@zmodem I haven’t been able to repro with the recipe posted on 
https://crbug.com/1487548. I am using latest rpmalloc (main branch), latest VS 
2022, latest WinSDK. I am running on Win11, on a AMD Ryzen9 CPU. Are you 
running on WinServer2022? Are able to give more precision on the conditions for 
reproducing?

https://github.com/llvm/llvm-project/pull/65823
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Update GoogleTest to v1.14.0 (PR #65823)

2023-09-28 Thread Alexandre Ganea via cfe-commits

aganea wrote:

@zmodem Can you add `ENABLE_ASSERTS` on [this 
line](https://github.com/llvm/llvm-project/blob/720e3bacbd9fdba05645a4d621d43ad712c44df3/llvm/lib/Support/CMakeLists.txt#L107)
 and run the test again, see if that gives something interesting?



https://github.com/llvm/llvm-project/pull/65823
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eded23d - [Clang] Silence a "unused variable" warning when building with MSVC

2023-01-09 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2023-01-09T23:45:20-05:00
New Revision: eded23dfdaf050793b70351d5f42400016d57c15

URL: 
https://github.com/llvm/llvm-project/commit/eded23dfdaf050793b70351d5f42400016d57c15
DIFF: 
https://github.com/llvm/llvm-project/commit/eded23dfdaf050793b70351d5f42400016d57c15.diff

LOG: [Clang] Silence a "unused variable" warning when building with MSVC

Added: 


Modified: 
clang/lib/Lex/LiteralSupport.cpp

Removed: 




diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 05575e8d6e2a7..fb2b14601a6ae 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -515,8 +515,9 @@ static void DiagnoseInvalidUnicodeCharacterName(
 
 std::string Str;
 llvm::UTF32 V = Match.Value;
-LLVM_ATTRIBUTE_UNUSED bool Converted =
+bool Converted =
 llvm::convertUTF32ToUTF8String(llvm::ArrayRef(, 1), 
Str);
+(void)Converted;
 assert(Converted && "Found a match wich is not a unicode character");
 
 Diag(Diags, Features, Loc, TokBegin, TokRangeBegin, TokRangeEnd,



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


[clang] ae918c7 - [clang-format] Add .inc extension to git-clang-format

2022-12-03 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-12-03T09:24:03-05:00
New Revision: ae918c78b51ae7e19053b9ae9deb9fee35084256

URL: 
https://github.com/llvm/llvm-project/commit/ae918c78b51ae7e19053b9ae9deb9fee35084256
DIFF: 
https://github.com/llvm/llvm-project/commit/ae918c78b51ae7e19053b9ae9deb9fee35084256.diff

LOG: [clang-format] Add .inc extension to git-clang-format

Differential Revision: https://reviews.llvm.org/D138746

Added: 


Modified: 
clang/tools/clang-format/git-clang-format

Removed: 




diff  --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 7ce6b60a8e65..054978c3dbdf 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -88,7 +88,7 @@ def main():
   'c', 'h',  # C
   'm',  # ObjC
   'mm',  # ObjC++
-  'cc', 'cp', 'cpp', 'c++', 'cxx', 'hh', 'hpp', 'hxx',  # C++
+  'cc', 'cp', 'cpp', 'c++', 'cxx', 'hh', 'hpp', 'hxx', 'inc',  # C++
   'ccm', 'cppm', 'cxxm', 'c++m',  # C++ Modules
   'cu', 'cuh',  # CUDA
   # Other languages that clang-format supports



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


[clang] 49e483d - [CodeView] Replace GHASH hasher by BLAKE3

2022-11-19 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-11-19T15:17:42-05:00
New Revision: 49e483d3d62f6f62beb323e9c4160bab9e0ad619

URL: 
https://github.com/llvm/llvm-project/commit/49e483d3d62f6f62beb323e9c4160bab9e0ad619
DIFF: 
https://github.com/llvm/llvm-project/commit/49e483d3d62f6f62beb323e9c4160bab9e0ad619.diff

LOG: [CodeView] Replace GHASH hasher by BLAKE3

Previously, we used SHA-1 for hashing the CodeView type records.
SHA-1 in `GloballyHashedType::hashType()` is coming top in the profiles. By 
simply replacing with BLAKE3, the link time is reduced in our case from 15 sec 
to 13 sec. I am only using MSVC .OBJs in this case. As a reference, the 
resulting .PDB is approx 2.1GiB and .EXE is approx 250MiB.

Differential Revision: https://reviews.llvm.org/D137101

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
lld/COFF/DebugTypes.cpp
lld/docs/ReleaseNotes.rst
llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/DebugInfo/CodeView/TypeHashing.cpp
llvm/test/DebugInfo/COFF/global-type-hashes.ll
llvm/test/DebugInfo/PDB/obj-globalhash.test

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 640c52096c4a1..dcb5f132fce1b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -519,6 +519,8 @@ Windows Support
   ``/guard:cf,nochecks`` in clang-cl) for enabling Control Flow Guard checks
   and generation of address-taken function table.
 
+- Switched from SHA1 to BLAKE3 for PDB type hashing / ``-gcodeview-ghash``
+
 AIX Support
 ---
 * When using ``-shared``, the clang driver now invokes llvm-nm to create an

diff  --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp
index ff469685fb7fa..6786d064ca8df 100644
--- a/lld/COFF/DebugTypes.cpp
+++ b/lld/COFF/DebugTypes.cpp
@@ -275,7 +275,7 @@ static bool canUseDebugH(ArrayRef debugH) {
   debugH = debugH.drop_front(sizeof(object::debug_h_header));
   return header->Magic == COFF::DEBUG_HASHES_SECTION_MAGIC &&
  header->Version == 0 &&
- header->HashAlgorithm == uint16_t(GlobalTypeHashAlg::SHA1_8) &&
+ header->HashAlgorithm == uint16_t(GlobalTypeHashAlg::BLAKE3) &&
  (debugH.size() % 8 == 0);
 }
 

diff  --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index 744baaf62efcf..0e9029bdcc097 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -43,6 +43,8 @@ COFF Improvements
 * The linker command line entry in ``S_ENVBLOCK`` of the PDB is now stripped
   from input files, to align with MSVC behavior.
   (`D137723 `_)
+* Switched from SHA1 to BLAKE3 for PDB type hashing / ``-gcodeview-ghash``
+  (`D137101 `_)
 
 MinGW Improvements
 --

diff  --git a/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h 
b/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h
index f49bc9b8e7909..1914f499f0ed4 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h
@@ -61,7 +61,8 @@ struct LocallyHashedType {
 
 enum class GlobalTypeHashAlg : uint16_t {
   SHA1 = 0, // standard 20-byte SHA1 hash
-  SHA1_8// last 8-bytes of standard SHA1 hash
+  SHA1_8,   // last 8-bytes of standard SHA1 hash
+  BLAKE3,   // truncated 8-bytes BLAKE3
 };
 
 /// A globally hashed type represents a hash value that is sufficient to

diff  --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp 
b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 3bb0df4eeac93..7fd38b7b789fc 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -760,7 +760,7 @@ void CodeViewDebug::emitTypeGlobalHashes() {
   OS.AddComment("Section Version");
   OS.emitInt16(0);
   OS.AddComment("Hash Algorithm");
-  OS.emitInt16(uint16_t(GlobalTypeHashAlg::SHA1_8));
+  OS.emitInt16(uint16_t(GlobalTypeHashAlg::BLAKE3));
 
   TypeIndex TI(TypeIndex::FirstNonSimpleIndex);
   for (const auto  : TypeTable.hashes()) {

diff  --git a/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp 
b/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp
index fc85d8186eaad..877fde79ddd09 100644
--- a/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp
+++ b/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp
@@ -9,7 +9,7 @@
 #include "llvm/DebugInfo/CodeView/TypeHashing.h"
 
 #include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
-#include "llvm/Support/SHA1.h"
+#include "llvm/Support/BLAKE3.h"
 
 using namespace llvm;
 using namespace llvm::codeview;
@@ -35,7 +35,7 @@ GloballyHashedType::hashType(ArrayRef RecordData,
  ArrayRef PreviousIds) {
   SmallVector Refs;
   discoverTypeIndices(RecordData, Refs);
-  SHA1 S;
+  TruncatedBLAKE3<8> S;
   S.init();
   uint32_t Off = 0;
   S.update(RecordData.take_front(sizeof(RecordPrefix)));
@@ -76,6 +76,5 @@ 

[clang] 0880b9d - [Clang][unittests] Silence trucation warning with MSVC 2022

2022-07-05 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-07-05T20:31:54-04:00
New Revision: 0880b9d52620ca3c46456095f6040a2e4de6c871

URL: 
https://github.com/llvm/llvm-project/commit/0880b9d52620ca3c46456095f6040a2e4de6c871
DIFF: 
https://github.com/llvm/llvm-project/commit/0880b9d52620ca3c46456095f6040a2e4de6c871.diff

LOG: [Clang][unittests] Silence trucation warning with MSVC 2022

Differential Revision: https://reviews.llvm.org/D129152

Added: 


Modified: 
clang/unittests/StaticAnalyzer/RangeSetTest.cpp

Removed: 




diff  --git a/clang/unittests/StaticAnalyzer/RangeSetTest.cpp 
b/clang/unittests/StaticAnalyzer/RangeSetTest.cpp
index 91a6351c8e3b3..892c1ac23f92f 100644
--- a/clang/unittests/StaticAnalyzer/RangeSetTest.cpp
+++ b/clang/unittests/StaticAnalyzer/RangeSetTest.cpp
@@ -88,6 +88,12 @@ template  struct TestValues {
   template 
   static constexpr T X555TruncZeroOf = TruncZeroOf; // 0x'5600
 
+// Silence 'warning C4309: 'initializing': truncation of constant value'
+//   in RangeSetCastToPromotionConversionTest.
+#if defined(_MSC_VER) && !defined(__clang__)
+#pragma warning(push)
+#pragma warning(disable : 4309)
+#endif
   // Numbers for ranges with the same bits in the lowest byte.
   // 0x'AA2A
   static constexpr T FromA = ClearLowBytes + 42;
@@ -95,6 +101,10 @@ template  struct TestValues {
   // 0x'552A
   static constexpr T FromB = ClearLowBytes + 42;
   static constexpr T ToB = FromB + 2; // 0x'552C
+
+#if defined(_MSC_VER) && !defined(__clang__)
+#pragma warning(pop)
+#endif
 };
 
 template 



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


[clang] 18f230a - [Clang] Silence warning when building with MSVC 2022

2022-07-05 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-07-05T20:31:54-04:00
New Revision: 18f230a89aa234ac58be4fb8cee2bfa95ea67be4

URL: 
https://github.com/llvm/llvm-project/commit/18f230a89aa234ac58be4fb8cee2bfa95ea67be4
DIFF: 
https://github.com/llvm/llvm-project/commit/18f230a89aa234ac58be4fb8cee2bfa95ea67be4.diff

LOG: [Clang] Silence warning when building with MSVC 2022

Previously, the warning seen:

[22/95] Building CXX object 
tools\clang\lib\StaticAnalyzer\Checker...bj.clangStaticAnalyzerCheckers.dir\NoReturnFunctionChecker.cpp.objC:\git\llvm-project\clang\lib\StaticAnalyzer\Checkers\NoReturnFunctionChecker.cpp(149):
 warning C4305: 'if': truncation from 'size_t' to 'bool'
C:\git\llvm-project\clang\include\clang/Analysis/SelectorExtras.h(28): note: 
see reference to function template instantiation 'clang::Selector 
clang::getKeywordSelector(clang::ASTContext &,const char *,const char *,const char *,const char *)' 
being compiled
C:\git\llvm-project\clang\lib\StaticAnalyzer\Checkers\NoReturnFunctionChecker.cpp(125):
 note: see reference to function template instantiation 'void 
clang::lazyInitKeywordSelector(clang::Selector &,clang::ASTContext &,const char *,const char *,const 
char *,const char *)' being compiled

Added: 


Modified: 
clang/include/clang/Analysis/SelectorExtras.h

Removed: 




diff  --git a/clang/include/clang/Analysis/SelectorExtras.h 
b/clang/include/clang/Analysis/SelectorExtras.h
index 278f20e87cc69..1e1daf5706bbf 100644
--- a/clang/include/clang/Analysis/SelectorExtras.h
+++ b/clang/include/clang/Analysis/SelectorExtras.h
@@ -16,7 +16,7 @@ namespace clang {
 template 
 static inline Selector getKeywordSelector(ASTContext ,
   IdentifierInfos *... IIs) {
-  static_assert(sizeof...(IdentifierInfos),
+  static_assert(sizeof...(IdentifierInfos) > 0,
 "keyword selectors must have at least one argument");
   SmallVector II({(IIs)...});
 



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


[clang] 5fa4cf8 - [Clang] Separate the 'debug-info-hotpatch' test in two parts: one for ARM and another for AArch64

2022-01-20 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-01-20T14:11:10-05:00
New Revision: 5fa4cf82dfa075e7983ce92d0042480b7b8f4fbc

URL: 
https://github.com/llvm/llvm-project/commit/5fa4cf82dfa075e7983ce92d0042480b7b8f4fbc
DIFF: 
https://github.com/llvm/llvm-project/commit/5fa4cf82dfa075e7983ce92d0042480b7b8f4fbc.diff

LOG: [Clang] Separate the 'debug-info-hotpatch' test in two parts: one for ARM 
and another for AArch64

After 5af2433e1794ebf7e58e848aa612c7912d71dc78, this shall fix: 
https://lab.llvm.org/buildbot/#/builders/188/builds/8400 - if not I'll revert 
this patch and 5af2433e1794ebf7e58e848aa612c7912d71dc78.

Added: 
clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp

Modified: 
clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp 
b/clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp
new file mode 100644
index ..10fb1750f2c5
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-hotpatch-aarch64.cpp
@@ -0,0 +1,23 @@
+// REQUIRES: aarch64-registered-target
+///
+/// Check that using /hotpatch doesn't generate an error.
+/// Binaries are always hotpatchable on ARM/ARM64.
+///
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c /hotpatch /Z7 -- %s 2>&1
+///
+/// Ensure that we set the hotpatchable flag in the debug information.
+///
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c /Z7 -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=HOTPATCH
+// HOTPATCH: S_COMPILE3 [size = [[#]]]
+// HOTPATCH: flags = hot patchable
+///
+/// Unfortunately we need /Z7, Clang does not systematically generate 
S_COMPILE3.
+///
+// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=NO-HOTPATCH
+// NO-HOTPATCH-NOT: flags = hot patchable
+
+int main() {
+  return 0;
+}

diff  --git a/clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp 
b/clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp
index 6176f1788760..48a61f7fb197 100644
--- a/clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp
+++ b/clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp
@@ -1,23 +1,20 @@
-// REQUIRES: aarch64-registered-target || arm-registered-target
+// REQUIRES: arm-registered-target
 ///
 /// Check that using /hotpatch doesn't generate an error.
 /// Binaries are always hotpatchable on ARM/ARM64.
 ///
 // RUN: %clang_cl --target=arm-pc-windows-msvc /c /hotpatch /Z7 -- %s 2>&1
-// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c /hotpatch /Z7 -- %s 2>&1
 ///
 /// Ensure that we set the hotpatchable flag in the debug information.
 ///
 // RUN: %clang_cl --target=arm-pc-windows-msvc /c /Z7 -o %t.obj -- %s
 // RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=HOTPATCH
-// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c /Z7 -o %t.obj -- %s
-// RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=HOTPATCH
 // HOTPATCH: S_COMPILE3 [size = [[#]]]
 // HOTPATCH: flags = hot patchable
 ///
 /// Unfortunately we need /Z7, Clang does not systematically generate 
S_COMPILE3.
 ///
-// RUN: %clang_cl --target=aarch64-pc-windows-msvc /c -o %t.obj -- %s
+// RUN: %clang_cl --target=arm-pc-windows-msvc /c -o %t.obj -- %s
 // RUN: llvm-pdbutil dump -symbols %t.obj | FileCheck %s 
--check-prefix=NO-HOTPATCH
 // NO-HOTPATCH-NOT: flags = hot patchable
 



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


[clang] 5af2433 - [clang-cl] Support the /HOTPATCH flag

2022-01-20 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-01-20T12:57:19-05:00
New Revision: 5af2433e1794ebf7e58e848aa612c7912d71dc78

URL: 
https://github.com/llvm/llvm-project/commit/5af2433e1794ebf7e58e848aa612c7912d71dc78
DIFF: 
https://github.com/llvm/llvm-project/commit/5af2433e1794ebf7e58e848aa612c7912d71dc78.diff

LOG: [clang-cl] Support the /HOTPATCH flag

This patch adds support for the MSVC /HOTPATCH flag: 
https://docs.microsoft.com/sv-se/cpp/build/reference/hotpatch-create-hotpatchable-image?view=msvc-170=vs-2019

The flag is translated to a new -fms-hotpatch flag, which in turn adds a 
'patchable-function' attribute for each function in the TU. This is then picked 
up by the PatchableFunction pass which would generate a 
TargetOpcode::PATCHABLE_OP of minsize = 2 (which means the target instruction 
must resolve to at least two bytes). TargetOpcode::PATCHABLE_OP is only 
implemented for x86/x64. When targetting ARM/ARM64, /HOTPATCH isn't required 
(instructions are always 2/4 bytes and suitable for hotpatching).

Additionally, when using /Z7, we generate a 'hot patchable' flag in the 
CodeView debug stream, in the S_COMPILE3 record. This flag is then picked up by 
LLD (or link.exe) and is used in conjunction with the linker /FUNCTIONPADMIN 
flag to generate extra space before each function, to accommodate for live 
patching long jumps. Please see: 
https://github.com/llvm/llvm-project/blob/d703b922961e0d02a5effdd4bfbb23ad50a3cc9f/lld/COFF/Writer.cpp#L1298

The outcome is that we can finally use Live++ or Recode along with clang-cl.

NOTE: It seems that MSVC cl.exe always enables /HOTPATCH on x64 by default, 
although if we did the same I thought we might generate sub-optimal code (if 
this flag was active by default). Additionally, MSVC always generates a 
.debug$S section and a S_COMPILE3 record, which Clang doesn't do without /Z7. 
Therefore, the following MSVC command-line "cl /c file.cpp" would have to be 
written with Clang such as "clang-cl /c file.cpp /HOTPATCH /Z7" in order to 
obtain the same result.

Depends on D43002, D80833 and D81301 for the full feature.

Differential Revision: https://reviews.llvm.org/D116511

Added: 
clang/test/CodeGenCXX/debug-info-hotpatch-arm.cpp
clang/test/CodeGenCXX/debug-info-hotpatch.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/MSVC.cpp
clang/test/CodeGen/patchable-function-entry.c
clang/test/Driver/cl-options.c
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/test/DebugInfo/COFF/ARMNT/arm-register-variables.ll
llvm/test/MC/AArch64/coff-debug.ll

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index de395b5d035ec..08e4d75299d2b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -136,6 +136,16 @@ Windows Support
   or pass ``/permissive`` to disable C++ operator names altogether. See
   `PR42427 ` for more info.
 
+- Add support for MSVC-compatible ``/hotpatch`` flag in clang-cl, and 
equivalent
+  -cc1 flag ``-fms-hotpatch``. Along with the linker flag ``/functionpadmin``
+  this creates executable images suitable for runtime code patching. This flag
+  is only required for x86/x64 targets; ARM/ARM64 simply needs the linker
+  ``/functionpadmin``.
+
+  With this addition, clang-cl can be used in live code patching scenarios,
+  along with tools such as Live++ or Recode. Microsoft Edit and Continue isn't
+  currently supported.
+
 C Language Changes in Clang
 ---
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d4742cddd00c9..3526b8a4a9044 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -139,6 +139,9 @@ VALUE_CODEGENOPT(XRaySelectedFunctionGroup, 32, 0)
 VALUE_CODEGENOPT(PatchableFunctionEntryCount , 32, 0) ///< Number of NOPs at 
function entry
 VALUE_CODEGENOPT(PatchableFunctionEntryOffset , 32, 0)
 
+CODEGENOPT(HotPatch, 1, 0) ///< Supports the Microsoft /HOTPATCH flag and
+   ///< generates a 'patchable-function' attribute.
+
 CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
 CODEGENOPT(CallFEntry , 1, 0) ///< Set when -mfentry is enabled.
 CODEGENOPT(MNopMCount , 1, 0) ///< Set when -mnop-mcount is enabled.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1a9fd61328f83..b66363b1d3e92 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2498,6 +2498,9 @@ defm pascal_strings : 

[clang] aba5b91 - Re-land [CodeView] Add full repro to LF_BUILDINFO record

2022-01-19 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-01-19T19:44:37-05:00
New Revision: aba5b91b699c556da0ee04418321b581bd33611e

URL: 
https://github.com/llvm/llvm-project/commit/aba5b91b699c556da0ee04418321b581bd33611e
DIFF: 
https://github.com/llvm/llvm-project/commit/aba5b91b699c556da0ee04418321b581bd33611e.diff

LOG: Re-land [CodeView] Add full repro to LF_BUILDINFO record

This patch writes the full -cc1 command into the resulting .OBJ, like MSVC 
does. This allows for external tools (Recode, Live++) to rebuild a source file 
without any external dependency but the .OBJ itself (other than the compiler) 
and without knowledge of the build system.

The LF_BUILDINFO record stores a full path to the compiler, the PWD (CWD at 
program startup), a relative or absolute path to the source, and the full CC1 
command line. The stored command line is self-standing (does not depend on the 
environment). In the same way, MSVC doesn't exactly store the provided 
command-line, but an expanded version (a somehow equivalent of CC1) which is 
also self-standing.

For more information see PR36198 and D43002.

Differential Revision: https://reviews.llvm.org/D80833

Added: 
clang/test/CodeGen/debug-info-codeview-buildinfo.c

Modified: 
clang/cmake/caches/BaremetalARM.cmake
clang/cmake/caches/CrossWinToARMLinux.cmake
clang/cmake/caches/Fuchsia-stage2.cmake
lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
lld/test/COFF/Inputs/pdb_lines_2_relative.yaml
lld/test/COFF/pdb-relative-source-lines.test
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/test/DebugInfo/COFF/build-info.ll
llvm/test/DebugInfo/COFF/global-type-hashes.ll
llvm/test/DebugInfo/COFF/types-basic.ll
llvm/test/DebugInfo/COFF/types-data-members.ll

Removed: 




diff  --git a/clang/cmake/caches/BaremetalARM.cmake 
b/clang/cmake/caches/BaremetalARM.cmake
index 85295d9db392a..e44355cfcbd74 100644
--- a/clang/cmake/caches/BaremetalARM.cmake
+++ b/clang/cmake/caches/BaremetalARM.cmake
@@ -31,6 +31,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-dwarfdump
   llvm-nm
   llvm-objdump
+  llvm-pdbutil
   llvm-ranlib
   llvm-readobj
   llvm-size

diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index f015c67e3b9ce..dd03a37b4b8f9 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -182,6 +182,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-lib
   llvm-nm
   llvm-objdump
+  llvm-pdbutil
   llvm-profdata
   llvm-ranlib
   llvm-readobj

diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 0d572b670541e..de8ac89fbfaa0 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -277,6 +277,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-objcopy
   llvm-objdump
   llvm-otool
+  llvm-pdbutil
   llvm-profdata
   llvm-rc
   llvm-ranlib

diff  --git a/clang/test/CodeGen/debug-info-codeview-buildinfo.c 
b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
new file mode 100644
index 0..93810e829c6d9
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
@@ -0,0 +1,26 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj 
-fdebug-compilation-dir=. -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
+
+int main() { return 42; }
+
+// CHECK:   Types (.debug$T)
+// CHECK: 
+// CHECK: 0x[[PWD:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[PWDVAL:.+]]
+// CHECK: 0x[[FILEPATH:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: [[FILEPATHVAL:.+[\\/]debug-info-codeview-buildinfo.c]]
+// CHECK: 0x[[ZIPDB:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String:
+// CHECK: 0x[[TOOL:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[TOOLVAL:.+[\\/]clang.*]]
+// CHECK: 0x[[CMDLINE:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: "-cc1
+// CHECK: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// CHECK:  0x[[PWD]]: `[[PWDVAL]]`
+// CHECK:  0x[[TOOL]]: `[[TOOLVAL]]`
+// CHECK:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
+// CHECK:  0x[[ZIPDB]]: ``
+// CHECK:  0x[[CMDLINE]]: `"-cc1
+
+// RELATIVE:   Types (.debug$T)
+// RELATIVE: 
+// RELATIVE: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// RELATIVE:  0x{{.+}}: `.`

diff  --git a/lld/test/COFF/Inputs/pdb_lines_1_relative.yaml 
b/lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
index 947de419d6b8b..9a6b192e1d0d2 100644
--- a/lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
+++ b/lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
@@ -19,6 +19,7 @@ 

[clang] a5af260 - Silence warning with MSVC compiler.

2022-01-06 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-01-06T16:51:37-05:00
New Revision: a5af260d3e8b00a3353e813b73f83391edbef493

URL: 
https://github.com/llvm/llvm-project/commit/a5af260d3e8b00a3353e813b73f83391edbef493
DIFF: 
https://github.com/llvm/llvm-project/commit/a5af260d3e8b00a3353e813b73f83391edbef493.diff

LOG: Silence warning with MSVC compiler.

D:\git\llvm-project\clang\unittests\Analysis\FlowSensitive\MultiVarConstantPropagationTest.cpp(104)
 : warning C4715: 'clang::dataflow::`anonymous namespace'::operator<<': not all 
control paths return a value

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
index c5b792a64d557..d5275b10e946e 100644
--- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -101,6 +101,7 @@ std::ostream <<(std::ostream , const 
ValueLattice ) {
   case ValueLattice::ValueState::Defined:
 return OS << "Any";
   }
+  llvm_unreachable("unknown ValueState!");
 }
 
 using ConstantPropagationLattice = VarMapLattice;



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


[clang] e32936a - [MSVC] Silence -Wnon-virtual-dtor on DIA APIs

2022-01-03 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2022-01-03T13:29:08-05:00
New Revision: e32936aef4a2e7da471e84b72d3be3499adf0a21

URL: 
https://github.com/llvm/llvm-project/commit/e32936aef4a2e7da471e84b72d3be3499adf0a21
DIFF: 
https://github.com/llvm/llvm-project/commit/e32936aef4a2e7da471e84b72d3be3499adf0a21.diff

LOG: [MSVC] Silence -Wnon-virtual-dtor on DIA APIs

Differential Revision: https://reviews.llvm.org/D116313

Added: 


Modified: 
clang/lib/Driver/ToolChains/MSVCSetupApi.h
llvm/lib/DebugInfo/PDB/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/MSVCSetupApi.h 
b/clang/lib/Driver/ToolChains/MSVCSetupApi.h
index a890b85fd5e98..28e6e3e08e37f 100644
--- a/clang/lib/Driver/ToolChains/MSVCSetupApi.h
+++ b/clang/lib/Driver/ToolChains/MSVCSetupApi.h
@@ -28,6 +28,11 @@
 
 #pragma once
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
+
 // Constants
 //
 #ifndef E_NOTFOUND
@@ -512,3 +517,7 @@ STDMETHODIMP GetSetupConfiguration(_Out_ 
ISetupConfiguration **ppConfiguration,
 #ifdef __cplusplus
 }
 #endif
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif

diff  --git a/llvm/lib/DebugInfo/PDB/CMakeLists.txt 
b/llvm/lib/DebugInfo/PDB/CMakeLists.txt
index 090711c834041..851c5c3dc03c4 100644
--- a/llvm/lib/DebugInfo/PDB/CMakeLists.txt
+++ b/llvm/lib/DebugInfo/PDB/CMakeLists.txt
@@ -4,7 +4,7 @@ macro(add_pdb_impl_folder group)
 endmacro()
 
 if(LLVM_ENABLE_DIA_SDK)
-  include_directories(${MSVC_DIA_SDK_DIR}/include)
+  include_directories(SYSTEM ${MSVC_DIA_SDK_DIR}/include)
   set(LIBPDB_LINK_FOLDERS "${MSVC_DIA_SDK_DIR}\\lib")
 
   if ("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm64")



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


[clang] a282ea4 - Reland - [CodeView] Emit S_OBJNAME record

2021-12-21 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-12-21T19:02:14-05:00
New Revision: a282ea4898efe2b2e57a93b44e90c9e497520cfb

URL: 
https://github.com/llvm/llvm-project/commit/a282ea4898efe2b2e57a93b44e90c9e497520cfb
DIFF: 
https://github.com/llvm/llvm-project/commit/a282ea4898efe2b2e57a93b44e90c9e497520cfb.diff

LOG: Reland - [CodeView] Emit S_OBJNAME record

Reland integrates build fixes & further review suggestions.

Thanks to @zturner for the initial S_OBJNAME patch!

Differential Revision: https://reviews.llvm.org/D43002

Added: 
clang/test/CodeGenCXX/debug-info-objname.cpp

Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Job.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CMakeLists.txt
llvm/include/llvm/MC/MCTargetOptions.h
llvm/include/llvm/Support/Caching.h
llvm/include/llvm/Support/ToolOutputFile.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Support/Caching.cpp
llvm/test/DebugInfo/COFF/globals.ll
llvm/test/DebugInfo/COFF/multifunction.ll
llvm/test/DebugInfo/COFF/pr28747.ll
llvm/test/DebugInfo/COFF/simple.ll
llvm/test/DebugInfo/COFF/vframe-fpo.ll
llvm/test/MC/AArch64/coff-debug.ll
llvm/test/MC/ARM/coff-debugging-secrel.ll
llvm/test/MC/COFF/cv-compiler-info.ll
llvm/tools/llc/llc.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 960aa419b490e..33ec03a171362 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -227,6 +227,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Output filename for the split debug info, not used in the skeleton CU.
   std::string SplitDwarfOutput;
 
+  /// Output filename used in the COFF debug information.
+  std::string ObjectFilenameForDebug;
+
   /// The name of the relocation model to use.
   llvm::Reloc::Model RelocationModel;
 

diff  --git a/clang/include/clang/Driver/Job.h 
b/clang/include/clang/Driver/Job.h
index 8b287638a271d..6e3b51f2a7995 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -204,6 +204,10 @@ class Command {
   /// from the parent process will be used.
   virtual void setEnvironment(llvm::ArrayRef NewEnvironment);
 
+  void replaceArguments(llvm::opt::ArgStringList List) {
+Arguments = std::move(List);
+  }
+
   const char *getExecutable() const { return Executable; }
 
   const llvm::opt::ArgStringList () const { return Arguments; }

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3b47512501d39..08e9e1a3432ae 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3802,6 +3802,11 @@ def o : JoinedOrSeparate<["-"], "o">, 
Flags<[NoXarchOption, RenderAsInput,
   CC1Option, CC1AsOption, FC1Option, FlangOption]>,
   HelpText<"Write output to ">, MetaVarName<"">,
   MarshallingInfoString>;
+def object_file_name_EQ : Joined<["-"], "object-file-name=">, 
Flags<[CC1Option, CC1AsOption, CoreOption]>,
+  HelpText<"Set the output  for debug infos">, MetaVarName<"">,
+  MarshallingInfoString>;
+def object_file_name : Separate<["-"], "object-file-name">, Flags<[CC1Option, 
CC1AsOption, CoreOption]>,
+Alias;
 def pagezero__size : JoinedOrSeparate<["-"], "pagezero_size">;
 def pass_exit_codes : Flag<["-", "--"], "pass-exit-codes">, 
Flags<[Unsupported]>;
 def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, 
Group, Flags<[CC1Option]>,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 3195615ae561c..5e16d3525b383 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -646,6 +646,7 @@ static bool initTargetOptions(DiagnosticsEngine ,
   Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
   Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
+  Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
 
   return true;
 }
@@ -1583,7 +1584,8 @@ static void runThinLTOBackend(
 return;
 
   auto AddStream = [&](size_t Task) {
-return std::make_unique(std::move(OS));
+return std::make_unique(std::move(OS),
+  CGOpts.ObjectFilenameForDebug);
   };
   lto::Config Conf;
   if (CGOpts.SaveTempsFilePrefix != "") {

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d76f810f1a7f0..2a3723975568b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ 

[clang] 5bb5142 - Revert [CodeView] Emit S_OBJNAME record

2021-12-21 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-12-21T19:02:14-05:00
New Revision: 5bb5142e80c9c6eb1a948d6d2ff4834e4e69741f

URL: 
https://github.com/llvm/llvm-project/commit/5bb5142e80c9c6eb1a948d6d2ff4834e4e69741f
DIFF: 
https://github.com/llvm/llvm-project/commit/5bb5142e80c9c6eb1a948d6d2ff4834e4e69741f.diff

LOG: Revert [CodeView] Emit S_OBJNAME record

Also revert all subsequent fixes:
- abd1cbf5e543f0f114d2742e109ead7d7ddbf9c4 [Clang] Disable 
debug-info-objname.cpp test on Unix until I sort out the issue.
- 00ec441253048f5e30540ea26bb0a28c42a5fc18 [Clang] debug-info-objname.cpp test: 
explictly encode a x86 target when using %clang_cl to avoid falling back to a 
native CPU triple.
- cd407f6e52b09cce2bef24c74b7f36fedc94991b [Clang] Fix build by restricting 
debug-info-objname.cpp test to x86.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Job.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CMakeLists.txt
llvm/include/llvm/MC/MCTargetOptions.h
llvm/include/llvm/Support/Caching.h
llvm/include/llvm/Support/ToolOutputFile.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Support/Caching.cpp
llvm/test/DebugInfo/COFF/globals.ll
llvm/test/DebugInfo/COFF/multifunction.ll
llvm/test/DebugInfo/COFF/pr28747.ll
llvm/test/DebugInfo/COFF/simple.ll
llvm/test/DebugInfo/COFF/vframe-fpo.ll
llvm/test/MC/AArch64/coff-debug.ll
llvm/test/MC/ARM/coff-debugging-secrel.ll
llvm/test/MC/COFF/cv-compiler-info.ll
llvm/tools/llc/llc.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 
clang/test/CodeGenCXX/debug-info-objname.cpp



diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 33ec03a171362..960aa419b490e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -227,9 +227,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Output filename for the split debug info, not used in the skeleton CU.
   std::string SplitDwarfOutput;
 
-  /// Output filename used in the COFF debug information.
-  std::string ObjectFilenameForDebug;
-
   /// The name of the relocation model to use.
   llvm::Reloc::Model RelocationModel;
 

diff  --git a/clang/include/clang/Driver/Job.h 
b/clang/include/clang/Driver/Job.h
index 6e3b51f2a7995..8b287638a271d 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -204,10 +204,6 @@ class Command {
   /// from the parent process will be used.
   virtual void setEnvironment(llvm::ArrayRef NewEnvironment);
 
-  void replaceArguments(llvm::opt::ArgStringList List) {
-Arguments = std::move(List);
-  }
-
   const char *getExecutable() const { return Executable; }
 
   const llvm::opt::ArgStringList () const { return Arguments; }

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 08e9e1a3432ae..3b47512501d39 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3802,11 +3802,6 @@ def o : JoinedOrSeparate<["-"], "o">, 
Flags<[NoXarchOption, RenderAsInput,
   CC1Option, CC1AsOption, FC1Option, FlangOption]>,
   HelpText<"Write output to ">, MetaVarName<"">,
   MarshallingInfoString>;
-def object_file_name_EQ : Joined<["-"], "object-file-name=">, 
Flags<[CC1Option, CC1AsOption, CoreOption]>,
-  HelpText<"Set the output  for debug infos">, MetaVarName<"">,
-  MarshallingInfoString>;
-def object_file_name : Separate<["-"], "object-file-name">, Flags<[CC1Option, 
CC1AsOption, CoreOption]>,
-Alias;
 def pagezero__size : JoinedOrSeparate<["-"], "pagezero_size">;
 def pass_exit_codes : Flag<["-", "--"], "pass-exit-codes">, 
Flags<[Unsupported]>;
 def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, 
Group, Flags<[CC1Option]>,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 5e16d3525b383..3195615ae561c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -646,7 +646,6 @@ static bool initTargetOptions(DiagnosticsEngine ,
   Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
   Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
-  Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
 
   return true;
 }
@@ -1584,8 +1583,7 @@ static void runThinLTOBackend(
 return;
 
   auto AddStream = [&](size_t Task) {
-return std::make_unique(std::move(OS),
-  CGOpts.ObjectFilenameForDebug);
+return std::make_unique(std::move(OS));
   };
   lto::Config 

[clang] d26520f - [Clang] Own the CommandLineArgs in CodeGenOptions

2021-12-21 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-12-21T17:41:35-05:00
New Revision: d26520f6f78785b0c4c296a8a992f2adb656c6ec

URL: 
https://github.com/llvm/llvm-project/commit/d26520f6f78785b0c4c296a8a992f2adb656c6ec
DIFF: 
https://github.com/llvm/llvm-project/commit/d26520f6f78785b0c4c296a8a992f2adb656c6ec.diff

LOG: [Clang] Own the CommandLineArgs in CodeGenOptions

Fixes PR52704 : https://github.com/llvm/llvm-project/issues/52704

Differential Revision: https://reviews.llvm.org/D116011

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/lib/Driver/Job.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/MC/MCTargetOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index d4781b647b877..33ec03a171362 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -398,7 +398,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Executable and command-line used to create a given CompilerInvocation.
   /// Most of the time this will be the full -cc1 command.
   const char *Argv0 = nullptr;
-  ArrayRef CommandLineArgs;
+  std::vector CommandLineArgs;
 
   /// The minimum hotness value a diagnostic needs in order to be included in
   /// optimization diagnostics.

diff  --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index 5b87106b6565d..f63763effaffe 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -388,6 +388,8 @@ int CC1Command::Execute(ArrayRef> 
Redirects,
   Argv.push_back(getExecutable());
   Argv.append(getArguments().begin(), getArguments().end());
   Argv.push_back(nullptr);
+  Argv.pop_back(); // The terminating null element shall not be part of the
+   // slice (main() behavior).
 
   // This flag simply indicates that the program couldn't start, which isn't
   // applicable here.

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 106da642f3619..b71addd84bfd9 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4518,7 +4518,7 @@ bool CompilerInvocation::CreateFromArgsImpl(
 
   // Store the command-line for using in the CodeView backend.
   Res.getCodeGenOpts().Argv0 = Argv0;
-  Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs;
+  append_range(Res.getCodeGenOpts().CommandLineArgs, CommandLineArgs);
 
   FixupInvocation(Res, Diags, Args, DashX);
 

diff  --git a/llvm/include/llvm/MC/MCTargetOptions.h 
b/llvm/include/llvm/MC/MCTargetOptions.h
index b006bb321819b..3510eeca89538 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -65,7 +65,7 @@ class MCTargetOptions {
   std::string COFFOutputFilename;
 
   const char *Argv0 = nullptr;
-  ArrayRef CommandLineArgs;
+  ArrayRef CommandLineArgs;
 
   /// Additional paths to search for `.include` directives when using the
   /// integrated assembler.



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


[clang] cd407f6 - [Clang] Fix build by restricting debug-info-objname.cpp test to x86.

2021-12-21 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-12-21T12:22:25-05:00
New Revision: cd407f6e52b09cce2bef24c74b7f36fedc94991b

URL: 
https://github.com/llvm/llvm-project/commit/cd407f6e52b09cce2bef24c74b7f36fedc94991b
DIFF: 
https://github.com/llvm/llvm-project/commit/cd407f6e52b09cce2bef24c74b7f36fedc94991b.diff

LOG: [Clang] Fix build by restricting debug-info-objname.cpp test to x86.

See: https://lab.llvm.org/buildbot/#/builders/188/builds/7188

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-objname.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-objname.cpp 
b/clang/test/CodeGenCXX/debug-info-objname.cpp
index 1a9a6cfa2081..d80d805b8b41 100644
--- a/clang/test/CodeGenCXX/debug-info-objname.cpp
+++ b/clang/test/CodeGenCXX/debug-info-objname.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: x86-registered-target
 // RUN: cp %s %T/debug-info-objname.cpp
 // RUN: cd %T
 



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


[clang] 00ec441 - [Clang] debug-info-objname.cpp test: explictly encode a x86 target when using %clang_cl to avoid falling back to a native CPU triple.

2021-12-21 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-12-21T11:54:19-05:00
New Revision: 00ec441253048f5e30540ea26bb0a28c42a5fc18

URL: 
https://github.com/llvm/llvm-project/commit/00ec441253048f5e30540ea26bb0a28c42a5fc18
DIFF: 
https://github.com/llvm/llvm-project/commit/00ec441253048f5e30540ea26bb0a28c42a5fc18.diff

LOG: [Clang] debug-info-objname.cpp test: explictly encode a x86 target when 
using %clang_cl to avoid falling back to a native CPU triple.

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-objname.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-objname.cpp 
b/clang/test/CodeGenCXX/debug-info-objname.cpp
index 078d2338bcff7..1a9a6cfa2081e 100644
--- a/clang/test/CodeGenCXX/debug-info-objname.cpp
+++ b/clang/test/CodeGenCXX/debug-info-objname.cpp
@@ -1,34 +1,32 @@
-// REQUIRES: system-windows
-
 // RUN: cp %s %T/debug-info-objname.cpp
 // RUN: cd %T
 
 // No output file provided, input file is relative, we emit an absolute path 
(MSVC behavior).
-// RUN: %clang_cl /c /Z7 -nostdinc debug-info-objname.cpp
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -nostdinc 
debug-info-objname.cpp
 // RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s 
--check-prefix=ABSOLUTE
 
 // No output file provided, input file is absolute, we emit an absolute path 
(MSVC behavior).
-// RUN: %clang_cl /c /Z7 -nostdinc -- %T/debug-info-objname.cpp
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -nostdinc -- 
%T/debug-info-objname.cpp
 // RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s 
--check-prefix=ABSOLUTE
 
 // The output file is provided as an absolute path, we emit an absolute path.
-// RUN: %clang_cl /c /Z7 -nostdinc /Fo%T/debug-info-objname.obj -- 
%T/debug-info-objname.cpp
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -nostdinc 
/Fo%T/debug-info-objname.obj -- %T/debug-info-objname.cpp
 // RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s 
--check-prefix=ABSOLUTE
 
 // The output file is provided as relative path, -working-dir is provided, we 
emit an absolute path.
-// RUN: %clang_cl /c /Z7 -nostdinc -working-dir=%T debug-info-objname.cpp
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -nostdinc 
-working-dir=%T debug-info-objname.cpp
 // RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s 
--check-prefix=ABSOLUTE
 
 // The input file name is relative and we specify -fdebug-compilation-dir, we 
emit a relative path.
-// RUN: %clang_cl /c /Z7 -nostdinc -fdebug-compilation-dir=. 
debug-info-objname.cpp
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -nostdinc 
-fdebug-compilation-dir=. debug-info-objname.cpp
 // RUN: llvm-pdbutil dump -all debug-info-objname.obj | FileCheck %s 
--check-prefix=RELATIVE
 
 // Ensure /FA emits an .asm file which contains the path to the final .obj, 
not the .asm
-// RUN: %clang_cl /c /Z7 -nostdinc -fdebug-compilation-dir=. /FA 
debug-info-objname.cpp
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -nostdinc 
-fdebug-compilation-dir=. /FA debug-info-objname.cpp
 // RUN: cat debug-info-objname.asm | FileCheck %s --check-prefix=ASM
 
 // Same thing for -save-temps
-// RUN: %clang_cl /c /Z7 -nostdinc -fdebug-compilation-dir=. 
/clang:-save-temps debug-info-objname.cpp
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -nostdinc 
-fdebug-compilation-dir=. /clang:-save-temps debug-info-objname.cpp
 // RUN: cat debug-info-objname.asm | FileCheck %s --check-prefix=ASM
 
 int main() {



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


[clang] abd1cbf - [Clang] Disable debug-info-objname.cpp test on Unix until I sort out the issue.

2021-12-21 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-12-21T10:32:43-05:00
New Revision: abd1cbf5e543f0f114d2742e109ead7d7ddbf9c4

URL: 
https://github.com/llvm/llvm-project/commit/abd1cbf5e543f0f114d2742e109ead7d7ddbf9c4
DIFF: 
https://github.com/llvm/llvm-project/commit/abd1cbf5e543f0f114d2742e109ead7d7ddbf9c4.diff

LOG: [Clang] Disable debug-info-objname.cpp test on Unix until I sort out the 
issue.

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-objname.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-objname.cpp 
b/clang/test/CodeGenCXX/debug-info-objname.cpp
index 07c0618c9a4d..078d2338bcff 100644
--- a/clang/test/CodeGenCXX/debug-info-objname.cpp
+++ b/clang/test/CodeGenCXX/debug-info-objname.cpp
@@ -1,3 +1,5 @@
+// REQUIRES: system-windows
+
 // RUN: cp %s %T/debug-info-objname.cpp
 // RUN: cd %T
 



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


[clang] f44e3fb - [CodeView] Emit S_OBJNAME record

2021-12-21 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-12-21T09:26:36-05:00
New Revision: f44e3fbadd15bc851c6e3c2a40ddf5f0a502151a

URL: 
https://github.com/llvm/llvm-project/commit/f44e3fbadd15bc851c6e3c2a40ddf5f0a502151a
DIFF: 
https://github.com/llvm/llvm-project/commit/f44e3fbadd15bc851c6e3c2a40ddf5f0a502151a.diff

LOG: [CodeView] Emit S_OBJNAME record

Thanks to @zturner for the initial patch!

Differential Revision: https://reviews.llvm.org/D43002

Added: 
clang/test/CodeGenCXX/debug-info-objname.cpp

Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Job.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CMakeLists.txt
llvm/include/llvm/MC/MCTargetOptions.h
llvm/include/llvm/Support/Caching.h
llvm/include/llvm/Support/ToolOutputFile.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Support/Caching.cpp
llvm/test/DebugInfo/COFF/globals.ll
llvm/test/DebugInfo/COFF/multifunction.ll
llvm/test/DebugInfo/COFF/pr28747.ll
llvm/test/DebugInfo/COFF/simple.ll
llvm/test/DebugInfo/COFF/vframe-fpo.ll
llvm/test/MC/AArch64/coff-debug.ll
llvm/test/MC/ARM/coff-debugging-secrel.ll
llvm/test/MC/COFF/cv-compiler-info.ll
llvm/tools/llc/llc.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 664e4998b8dec..d4781b647b877 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -227,6 +227,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Output filename for the split debug info, not used in the skeleton CU.
   std::string SplitDwarfOutput;
 
+  /// Output filename used in the COFF debug information.
+  std::string ObjectFilenameForDebug;
+
   /// The name of the relocation model to use.
   llvm::Reloc::Model RelocationModel;
 

diff  --git a/clang/include/clang/Driver/Job.h 
b/clang/include/clang/Driver/Job.h
index 8b287638a271d..6e3b51f2a7995 100644
--- a/clang/include/clang/Driver/Job.h
+++ b/clang/include/clang/Driver/Job.h
@@ -204,6 +204,10 @@ class Command {
   /// from the parent process will be used.
   virtual void setEnvironment(llvm::ArrayRef NewEnvironment);
 
+  void replaceArguments(llvm::opt::ArgStringList List) {
+Arguments = std::move(List);
+  }
+
   const char *getExecutable() const { return Executable; }
 
   const llvm::opt::ArgStringList () const { return Arguments; }

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3b47512501d39..08e9e1a3432ae 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3802,6 +3802,11 @@ def o : JoinedOrSeparate<["-"], "o">, 
Flags<[NoXarchOption, RenderAsInput,
   CC1Option, CC1AsOption, FC1Option, FlangOption]>,
   HelpText<"Write output to ">, MetaVarName<"">,
   MarshallingInfoString>;
+def object_file_name_EQ : Joined<["-"], "object-file-name=">, 
Flags<[CC1Option, CC1AsOption, CoreOption]>,
+  HelpText<"Set the output  for debug infos">, MetaVarName<"">,
+  MarshallingInfoString>;
+def object_file_name : Separate<["-"], "object-file-name">, Flags<[CC1Option, 
CC1AsOption, CoreOption]>,
+Alias;
 def pagezero__size : JoinedOrSeparate<["-"], "pagezero_size">;
 def pass_exit_codes : Flag<["-", "--"], "pass-exit-codes">, 
Flags<[Unsupported]>;
 def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, 
Group, Flags<[CC1Option]>,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 3195615ae561c..5e16d3525b383 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -646,6 +646,7 @@ static bool initTargetOptions(DiagnosticsEngine ,
   Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
   Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
+  Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
 
   return true;
 }
@@ -1583,7 +1584,8 @@ static void runThinLTOBackend(
 return;
 
   auto AddStream = [&](size_t Task) {
-return std::make_unique(std::move(OS));
+return std::make_unique(std::move(OS),
+  CGOpts.ObjectFilenameForDebug);
   };
   lto::Config Conf;
   if (CGOpts.SaveTempsFilePrefix != "") {

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d76f810f1a7f0..2a3723975568b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -625,8 +625,9 @@ getFramePointerKind(const ArgList , const llvm::Triple 
) {
 }
 
 

[clang] 199c397 - Revert "[clang-scan-deps] Add support for clang-cl"

2021-04-19 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-04-19T17:45:18-04:00
New Revision: 199c39748292cbc89cd148a0d8364ebb1014ec38

URL: 
https://github.com/llvm/llvm-project/commit/199c39748292cbc89cd148a0d8364ebb1014ec38
DIFF: 
https://github.com/llvm/llvm-project/commit/199c39748292cbc89cd148a0d8364ebb1014ec38.diff

LOG: Revert "[clang-scan-deps] Add support for clang-cl"

This reverts commit bb26fa8c286bf524ed9235c3e293ad22ecf3e984.

Added: 


Modified: 
clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
clang/test/ClangScanDeps/Inputs/headerwithdirname.json
clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
clang/test/ClangScanDeps/Inputs/no-werror.json
clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
clang/test/ClangScanDeps/error.cpp
clang/test/ClangScanDeps/has_include_if_elif.cpp
clang/test/ClangScanDeps/header_stat_before_open.m
clang/test/ClangScanDeps/headerwithdirname.cpp
clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
clang/test/ClangScanDeps/modules-full.cpp
clang/test/ClangScanDeps/modules.cpp
clang/test/ClangScanDeps/no-werror.cpp
clang/test/ClangScanDeps/regular_cdb.cpp
clang/test/ClangScanDeps/static-analyzer.c
clang/test/ClangScanDeps/strip_diag_serialize.cpp
clang/test/ClangScanDeps/target-filename.cpp
clang/test/ClangScanDeps/vfsoverlay.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 
clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json



diff  --git a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json 
b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
index 8fcc7ea34a9bc..36ca006b03297 100644
--- a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
+++ b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
@@ -3,10 +3,5 @@
   "directory": "DIR",
   "command": "clang -E DIR/has_include_if_elif2.cpp -IInputs",
   "file": "DIR/has_include_if_elif2.cpp"
-},
-{
-  "directory": "DIR",
-  "command": "clang-cl /E /IInputs -- DIR/has_include_if_elif2_clangcl.cpp",
-  "file": "DIR/has_include_if_elif2_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json 
b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
index b99b541b12986..c5f027e9fd28a 100644
--- a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
@@ -3,10 +3,5 @@
   "directory": "DIR",
   "command": "clang -E DIR/header_stat_before_open_input.m -iframework 
Inputs/frameworks",
   "file": "DIR/header_stat_before_open_input.m"
-},
-{
-  "directory": "DIR",
-  "command": "clang-cl /E -Xclang -iframework -Xclang Inputs/frameworks -- 
DIR/header_stat_before_open_input_clangcl.m",
-  "file": "DIR/header_stat_before_open_input_clangcl.m"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json 
b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
index ac12c92308fda..2ae561935bec3 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
@@ -3,10 +3,5 @@
   "directory": "DIR",
   "command": "clang -c -IDIR -IDIR/foodir -IInputs 
DIR/headerwithdirname_input.cpp",
   "file": "DIR/headerwithdirname_input.cpp"
-},
-{
-  "directory": "DIR",
-  "command": "clang-cl /c /IDIR /IDIR/foodir -IInputs -- 
DIR/headerwithdirname_input_clangcl.cpp",
-  "file": "DIR/headerwithdirname_input_clangcl.cpp"
 }
 ]

diff  --git 
a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json 
b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
index 1886328a9c3e9..de7759d0b110c 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
@@ -3,10 +3,5 @@
   "directory": "DIR",
   "command": "clang -c -IDIR -IInputs DIR/headerwithdirname_input.cpp",
   "file": "DIR/headerwithdirname_input.cpp"
-},
-{
-  "directory": "DIR",
-  "command": "clang-cl /c /IDIR /IInputs -- 
DIR/headerwithdirname_input_clangcl.cpp",
-  "file": "DIR/headerwithdirname_input_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json 
b/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
deleted file mode 100644
index a1f12867c45d5..0
--- a/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
+++ /dev/null
@@ -1,22 +0,0 @@
-[
-{
-  "directory": "DIR",
-  "command": 

[clang] bb26fa8 - [clang-scan-deps] Add support for clang-cl

2021-04-17 Thread Alexandre Ganea via cfe-commits

Author: Sylvain Audi
Date: 2021-04-17T14:22:51-04:00
New Revision: bb26fa8c286bf524ed9235c3e293ad22ecf3e984

URL: 
https://github.com/llvm/llvm-project/commit/bb26fa8c286bf524ed9235c3e293ad22ecf3e984
DIFF: 
https://github.com/llvm/llvm-project/commit/bb26fa8c286bf524ed9235c3e293ad22ecf3e984.diff

LOG: [clang-scan-deps] Add support for clang-cl

clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

Differential Revision: https://reviews.llvm.org/D92191

Added: 
clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json

Modified: 
clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
clang/test/ClangScanDeps/Inputs/headerwithdirname.json
clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
clang/test/ClangScanDeps/Inputs/no-werror.json
clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
clang/test/ClangScanDeps/error.cpp
clang/test/ClangScanDeps/has_include_if_elif.cpp
clang/test/ClangScanDeps/header_stat_before_open.m
clang/test/ClangScanDeps/headerwithdirname.cpp
clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
clang/test/ClangScanDeps/modules-full.cpp
clang/test/ClangScanDeps/modules.cpp
clang/test/ClangScanDeps/no-werror.cpp
clang/test/ClangScanDeps/regular_cdb.cpp
clang/test/ClangScanDeps/static-analyzer.c
clang/test/ClangScanDeps/strip_diag_serialize.cpp
clang/test/ClangScanDeps/target-filename.cpp
clang/test/ClangScanDeps/vfsoverlay.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json 
b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
index 36ca006b03297..8fcc7ea34a9bc 100644
--- a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
+++ b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/has_include_if_elif2.cpp -IInputs",
   "file": "DIR/has_include_if_elif2.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs -- DIR/has_include_if_elif2_clangcl.cpp",
+  "file": "DIR/has_include_if_elif2_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json 
b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
index c5f027e9fd28a..b99b541b12986 100644
--- a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/header_stat_before_open_input.m -iframework 
Inputs/frameworks",
   "file": "DIR/header_stat_before_open_input.m"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E -Xclang -iframework -Xclang Inputs/frameworks -- 
DIR/header_stat_before_open_input_clangcl.m",
+  "file": "DIR/header_stat_before_open_input_clangcl.m"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json 
b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
index 2ae561935bec3..ac12c92308fda 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -c -IDIR -IDIR/foodir -IInputs 
DIR/headerwithdirname_input.cpp",
   "file": "DIR/headerwithdirname_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /c /IDIR /IDIR/foodir -IInputs -- 
DIR/headerwithdirname_input_clangcl.cpp",
+  "file": "DIR/headerwithdirname_input_clangcl.cpp"
 }
 ]

diff  --git 
a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json 
b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
index de7759d0b110c..1886328a9c3e9 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -c -IDIR -IInputs DIR/headerwithdirname_input.cpp",
   "file": "DIR/headerwithdirname_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /c /IDIR /IInputs -- 
DIR/headerwithdirname_input_clangcl.cpp",
+  "file": "DIR/headerwithdirname_input_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json 
b/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
new file mode 100644
index 0..a1f12867c45d5
--- /dev/null
+++ 

[clang] 488a19d - [clang-scan-deps] Support double-dashes in clang command lines

2021-04-17 Thread Alexandre Ganea via cfe-commits

Author: Sylvain Audi
Date: 2021-04-17T14:22:51-04:00
New Revision: 488a19d00cbaec479f8c5c298556d2246978f9e6

URL: 
https://github.com/llvm/llvm-project/commit/488a19d00cbaec479f8c5c298556d2246978f9e6
DIFF: 
https://github.com/llvm/llvm-project/commit/488a19d00cbaec479f8c5c298556d2246978f9e6.diff

LOG: [clang-scan-deps] Support double-dashes in clang command lines

This fixes argument injection in clang command lines, by adding them before 
"--".

Previously, the arguments were injected at the end of the command line and 
could be added after "--", which would be wrongly interpreted as input file 
paths.

This fix is needed for a subsequent patch, see D92191.

Differential Revision: https://reviews.llvm.org/D95099

Added: 


Modified: 
clang/test/ClangScanDeps/Inputs/regular_cdb.json
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/test/ClangScanDeps/Inputs/regular_cdb.json 
b/clang/test/ClangScanDeps/Inputs/regular_cdb.json
index 902c0b7761fb5..938880c1304f1 100644
--- a/clang/test/ClangScanDeps/Inputs/regular_cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/regular_cdb.json
@@ -11,7 +11,7 @@
 },
 {
   "directory": "DIR",
-  "command": "clang -E DIR/regular_cdb_input.cpp -IInputs -o adena.o",
+  "command": "clang -E -IInputs -o adena.o -- DIR/regular_cdb_input.cpp",
   "file": "DIR/regular_cdb_input.cpp"
 }
 ]

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index a8ff42ab104ca..e3ea098d8211a 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -418,14 +418,15 @@ int main(int argc, const char **argv) {
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
-// We need to find the last -o value.
-if (!Args.empty()) {
-  std::size_t Idx = Args.size() - 1;
-  for (auto It = Args.rbegin(); It != Args.rend(); ++It) {
-StringRef Arg = Args[Idx];
+auto FlagsEnd = llvm::find(Args, "--");
+if (FlagsEnd != Args.begin()) {
+  // Reverse scan, starting at the end or at the element before "--".
+  auto R = llvm::make_reverse_iterator(FlagsEnd);
+  for (auto I = R, E = Args.rend(); I != E; ++I) {
+StringRef Arg = *I;
 if (LastO.empty()) {
-  if (Arg == "-o" && It != Args.rbegin())
-LastO = Args[Idx + 1];
+  if (Arg == "-o" && I != R)
+LastO = I[-1]; // Next argument (reverse iterator)
   else if (Arg.startswith("-o"))
 LastO = Arg.drop_front(2).str();
 }
@@ -437,12 +438,11 @@ int main(int argc, const char **argv) {
   HasMD = true;
 if (Arg == "-resource-dir")
   HasResourceDir = true;
---Idx;
   }
 }
 // If there's no -MT/-MQ Driver would add -MT with the value of the 
last
 // -o option.
-tooling::CommandLineArguments AdjustedArgs = Args;
+tooling::CommandLineArguments AdjustedArgs(Args.begin(), FlagsEnd);
 AdjustedArgs.push_back("-o");
 AdjustedArgs.push_back("/dev/null");
 if (!HasMT && !HasMQ) {
@@ -472,6 +472,7 @@ int main(int argc, const char **argv) {
 AdjustedArgs.push_back(std::string(ResourceDir));
   }
 }
+AdjustedArgs.insert(AdjustedArgs.end(), FlagsEnd, Args.end());
 return AdjustedArgs;
   });
   AdjustingCompilations->appendArgumentsAdjuster(



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


[clang] 8fbc05a - [Windows] Add test coverage for line endings when rewriting includes

2021-04-06 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-04-06T15:38:19-04:00
New Revision: 8fbc05acd5531a8bb74f689699e8de2788bcb769

URL: 
https://github.com/llvm/llvm-project/commit/8fbc05acd5531a8bb74f689699e8de2788bcb769
DIFF: 
https://github.com/llvm/llvm-project/commit/8fbc05acd5531a8bb74f689699e8de2788bcb769.diff

LOG: [Windows] Add test coverage for line endings when rewriting includes

Validate that we're properly generating a single line ending on Windows when
using -frewrite-includes. Otherwise we're breaking split-line macros. The test
fails before 23929af383f27a6ddf23704192a25591481152b3.

See discussion in https://reviews.llvm.org/D96363#2650460 and D99426

Differential Revision: https://reviews.llvm.org/D99973

Added: 
clang/test/Frontend/rewrite-includes-macros.cpp

Modified: 


Removed: 




diff  --git a/clang/test/Frontend/rewrite-includes-macros.cpp 
b/clang/test/Frontend/rewrite-includes-macros.cpp
new file mode 100644
index 0..4a2de546d4554
--- /dev/null
+++ b/clang/test/Frontend/rewrite-includes-macros.cpp
@@ -0,0 +1,14 @@
+// REQUIRES: system-windows
+// RUN: %clang_cl /E -Xclang -frewrite-includes %s | %clang_cl /c -Xclang 
-verify /Tp -
+// expected-no-diagnostics
+
+int foo();
+int bar();
+#define HELLO \
+  foo(); \
+  bar();
+
+int main() {
+  HELLO
+  return 0;
+}



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


[clang] e030ce3 - [Tooling] Handle compilation databases containing commands with double dashes

2021-03-24 Thread Alexandre Ganea via cfe-commits

Author: Janusz Nykiel
Date: 2021-03-24T16:01:47-04:00
New Revision: e030ce3ec790a0017ec789b4f487afec99e1cac9

URL: 
https://github.com/llvm/llvm-project/commit/e030ce3ec790a0017ec789b4f487afec99e1cac9
DIFF: 
https://github.com/llvm/llvm-project/commit/e030ce3ec790a0017ec789b4f487afec99e1cac9.diff

LOG: [Tooling] Handle compilation databases containing commands with double 
dashes

As of CMake commit https://gitlab.kitware.com/cmake/cmake/-/commit/d993ebd4,
which first appeared in CMake 3.19.x series, in the compile commands for
clang-cl, CMake puts `--` before the input file. When operating on such a
database, the `InterpolatingCompilationDatabase` - specifically, the
`TransferableCommand` constructor - does not recognize that pattern and so, does
not strip the input, or the double dash when 'transferring' the compile command.
This results in a incorrect compile command - with the double dash and old input
file left in, and the language options and new input file appended after them,
where they're all treated as inputs, including the language version option.

Test files for some tests have names similar enough to be matched to commands
from the database, e.g.:

`.../path-mappings.test.tmp/server/bar.cpp`

can be matched to:

`.../Driver/ToolChains/BareMetal.cpp`

etc. When that happens, the tool being tested tries to use the matched, and
incorrectly 'transferred' compile command, and fails, reporting errors similar
to:

`error: no such file or directory: '/std:c++14'; did you mean '/std:c++14'? 
[clang-diagnostic-error]`

This happens in at least 4 tests:

  Clang Tools :: clang-tidy/checkers/performance-trivially-destructible.cpp
  Clangd :: check-fail.test
  Clangd :: check.test
  Clangd :: path-mappings.test

The fix for `TransferableCommand` removes the `--` and everything after it when
determining the arguments that apply to the new file. `--` is inserted in the
'transferred' command if the new file name starts with `-` and when operating in
clang-cl mode, also `/`. Additionally, other places in the code known to do
argument adjustment without accounting for the `--` and causing the tests to
fail are fixed as well.

Differential Revision: https://reviews.llvm.org/D98824

Added: 


Modified: 
clang/lib/Tooling/ArgumentsAdjusters.cpp
clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
clang/lib/Tooling/Tooling.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp 
b/clang/lib/Tooling/ArgumentsAdjusters.cpp
index bcfb5b39a0770..d94673bd2ab90 100644
--- a/clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -62,7 +62,8 @@ ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
 HasSyntaxOnly = true;
 }
 if (!HasSyntaxOnly)
-  AdjustedArgs.push_back("-fsyntax-only");
+  AdjustedArgs =
+  getInsertArgumentAdjuster("-fsyntax-only")(AdjustedArgs, "");
 return AdjustedArgs;
   };
 }
@@ -137,7 +138,7 @@ ArgumentsAdjuster getInsertArgumentAdjuster(const 
CommandLineArguments ,
 
 CommandLineArguments::iterator I;
 if (Pos == ArgumentInsertPosition::END) {
-  I = Return.end();
+  I = std::find(Return.begin(), Return.end(), "--");
 } else {
   I = Return.begin();
   ++I; // To leave the program name in place

diff  --git a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp 
b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
index 6f97d2867ae5d..3b65504b98ea3 100644
--- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -177,6 +177,10 @@ struct TransferableCommand {
Opt.matches(OPT__SLASH_Fo
 continue;
 
+  // ...including when the inputs are passed after --.
+  if (Opt.matches(OPT__DASH_DASH))
+break;
+
   // Strip -x, but record the overridden language.
   if (const auto GivenType = tryParseTypeArg(*Arg)) {
 Type = *GivenType;
@@ -235,6 +239,8 @@ struct TransferableCommand {
   llvm::Twine(ClangCLMode ? "/std:" : "-std=") +
   LangStandard::getLangStandardForKind(Std).getName()).str());
 }
+if (Filename.startswith("-") || (ClangCLMode && Filename.startswith("/")))
+  Result.CommandLine.push_back("--");
 Result.CommandLine.push_back(std::string(Filename));
 return Result;
   }

diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 79851ac723da0..b28e8f6a7c967 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -440,8 +440,9 @@ static void injectResourceDir(CommandLineArguments , 
const char *Argv0,
   return;
 
   // If there's no override in place add our resource dir.
-  Args.push_back("-resource-dir=" +
- CompilerInvocation::GetResourcesPath(Argv0, MainAddr));
+  Args = 

[clang] 3854b81 - [Clang][Driver] Fix read-after-free when using /clang:

2021-01-07 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-01-07T15:15:13-05:00
New Revision: 3854b81b0fd23adc9bab91bf68918d102dc31f51

URL: 
https://github.com/llvm/llvm-project/commit/3854b81b0fd23adc9bab91bf68918d102dc31f51
DIFF: 
https://github.com/llvm/llvm-project/commit/3854b81b0fd23adc9bab91bf68918d102dc31f51.diff

LOG: [Clang][Driver] Fix read-after-free when using /clang:

Fixes PR42501.

Differential Revision: https://reviews.llvm.org/D93772

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5c3ce478053a..418e1d3e8ec9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1009,13 +1009,15 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   // objects than Args. This copies an Arg from one of those other 
InputArgLists
   // to the ownership of Args.
   auto appendOneArg = [](const Arg *Opt, const Arg *BaseArg) {
-  unsigned Index = Args.MakeIndex(Opt->getSpelling());
-  Arg *Copy = new llvm::opt::Arg(Opt->getOption(), Opt->getSpelling(),
- Index, BaseArg);
-  Copy->getValues() = Opt->getValues();
-  if (Opt->isClaimed())
-Copy->claim();
-  Args.append(Copy);
+unsigned Index = Args.MakeIndex(Opt->getSpelling());
+Arg *Copy = new llvm::opt::Arg(Opt->getOption(), Args.getArgString(Index),
+   Index, BaseArg);
+Copy->getValues() = Opt->getValues();
+if (Opt->isClaimed())
+  Copy->claim();
+Copy->setOwnsValues(Opt->getOwnsValues());
+Opt->setOwnsValues(false);
+Args.append(Copy);
   };
 
   if (HasConfigFile)

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index db70fca5222c..4b6d71ed7b6d 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -686,6 +686,11 @@
 // CLANG-NOT: "--dependent-lib=libcmt"
 // CLANG-NOT: "-vectorize-slp"
 
+// Cover PR42501: clang-cl /clang: pass-through causes read-after-free with 
aliased options.
+// RUN: %clang_cl /clang:-save-temps /clang:-Wl,test1,test2 -### -- %s 2>&1 | 
FileCheck -check-prefix=SAVETEMPS %s
+// SAVETEMPS: "-save-temps=cwd"
+// SAVETEMPS: "test1" "test2"
+
 // Validate that the default triple is used when run an empty tools dir is 
specified
 // RUN: %clang_cl -vctoolsdir "" -### -- %s 2>&1 | FileCheck %s --check-prefix 
VCTOOLSDIR
 // VCTOOLSDIR: "-triple" "{{[a-zA-Z0-9_-]*}}-pc-windows-msvc19.11.0"



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


[clang] d015445 - Silence warning: comparison of integers of different signs: 'const unsigned int' and 'const long' [-Wsign-compare]

2021-01-07 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2021-01-07T13:01:06-05:00
New Revision: d0154456e61c5ab79e25fc9b8bb684ebdca3a7c2

URL: 
https://github.com/llvm/llvm-project/commit/d0154456e61c5ab79e25fc9b8bb684ebdca3a7c2
DIFF: 
https://github.com/llvm/llvm-project/commit/d0154456e61c5ab79e25fc9b8bb684ebdca3a7c2.diff

LOG: Silence warning: comparison of integers of different signs: 'const 
unsigned int' and 'const long' [-Wsign-compare]

(off_t being a signed type)

Added: 


Modified: 
clang/unittests/Basic/FileEntryTest.cpp

Removed: 




diff  --git a/clang/unittests/Basic/FileEntryTest.cpp 
b/clang/unittests/Basic/FileEntryTest.cpp
index a3e03e6c7c29..16c8e57d9a17 100644
--- a/clang/unittests/Basic/FileEntryTest.cpp
+++ b/clang/unittests/Basic/FileEntryTest.cpp
@@ -57,7 +57,7 @@ struct RefMaps {
 
 TEST(FileEntryTest, Constructor) {
   FileEntry FE;
-  EXPECT_EQ(0U, FE.getSize());
+  EXPECT_EQ(0, FE.getSize());
   EXPECT_EQ(0, FE.getModificationTime());
   EXPECT_EQ(nullptr, FE.getDir());
   EXPECT_EQ(0U, FE.getUniqueID().getDevice());



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


[clang] 69132d1 - [Clang] Reverse test to save on indentation. NFC.

2020-12-23 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-12-23T19:24:53-05:00
New Revision: 69132d12deae749a8e4c9def5498ffa354ce1fa6

URL: 
https://github.com/llvm/llvm-project/commit/69132d12deae749a8e4c9def5498ffa354ce1fa6
DIFF: 
https://github.com/llvm/llvm-project/commit/69132d12deae749a8e4c9def5498ffa354ce1fa6.diff

LOG: [Clang] Reverse test to save on indentation. NFC.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenAction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 5b23b6d2b7f5..778d4df3c2e9 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1078,78 +1078,74 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
 }
 
 void CodeGenAction::ExecuteAction() {
-  // If this is an IR file, we have to treat it specially.
-  if (getCurrentFileKind().getLanguage() == Language::LLVM_IR) {
-BackendAction BA = static_cast(Act);
-CompilerInstance  = getCompilerInstance();
-auto  = CI.getCodeGenOpts();
-auto  = CI.getDiagnostics();
-std::unique_ptr OS =
-GetOutputStream(CI, getCurrentFile(), BA);
-if (BA != Backend_EmitNothing && !OS)
-  return;
-
-SourceManager  = CI.getSourceManager();
-FileID FID = SM.getMainFileID();
-Optional MainFile = SM.getBufferOrNone(FID);
-if (!MainFile)
-  return;
+  if (getCurrentFileKind().getLanguage() != Language::LLVM_IR) {
+this->ASTFrontendAction::ExecuteAction();
+return;
+  }
 
-TheModule = loadModule(*MainFile);
-if (!TheModule)
-  return;
+  // If this is an IR file, we have to treat it specially.
+  BackendAction BA = static_cast(Act);
+  CompilerInstance  = getCompilerInstance();
+  auto  = CI.getCodeGenOpts();
+  auto  = CI.getDiagnostics();
+  std::unique_ptr OS =
+  GetOutputStream(CI, getCurrentFile(), BA);
+  if (BA != Backend_EmitNothing && !OS)
+return;
 
-const TargetOptions  = CI.getTargetOpts();
-if (TheModule->getTargetTriple() != TargetOpts.Triple) {
-  Diagnostics.Report(SourceLocation(),
- diag::warn_fe_override_module)
-  << TargetOpts.Triple;
-  TheModule->setTargetTriple(TargetOpts.Triple);
-}
+  SourceManager  = CI.getSourceManager();
+  FileID FID = SM.getMainFileID();
+  Optional MainFile = SM.getBufferOrNone(FID);
+  if (!MainFile)
+return;
 
-EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
-
-LLVMContext  = TheModule->getContext();
-Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
-  );
-
-// Set clang diagnostic handler. To do this we need to create a fake
-// BackendConsumer.
-BackendConsumer Result(BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),
-   CI.getPreprocessorOpts(), CI.getCodeGenOpts(),
-   CI.getTargetOpts(), CI.getLangOpts(),
-   std::move(LinkModules), *VMContext, nullptr);
-// PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
-// true here because the valued names are needed for reading textual IR.
-Ctx.setDiscardValueNames(false);
-Ctx.setDiagnosticHandler(
-std::make_unique(CodeGenOpts, ));
-
-Expected> OptRecordFileOrErr =
-setupLLVMOptimizationRemarks(
-Ctx, CodeGenOpts.OptRecordFile, CodeGenOpts.OptRecordPasses,
-CodeGenOpts.OptRecordFormat, CodeGenOpts.DiagnosticsWithHotness,
-CodeGenOpts.DiagnosticsHotnessThreshold);
-
-if (Error E = OptRecordFileOrErr.takeError()) {
-  reportOptRecordError(std::move(E), Diagnostics, CodeGenOpts);
-  return;
-}
-std::unique_ptr OptRecordFile =
-std::move(*OptRecordFileOrErr);
+  TheModule = loadModule(*MainFile);
+  if (!TheModule)
+return;
 
-EmitBackendOutput(Diagnostics, CI.getHeaderSearchOpts(), CodeGenOpts,
-  TargetOpts, CI.getLangOpts(),
-  CI.getTarget().getDataLayout(), TheModule.get(), BA,
-  std::move(OS));
+  const TargetOptions  = CI.getTargetOpts();
+  if (TheModule->getTargetTriple() != TargetOpts.Triple) {
+Diagnostics.Report(SourceLocation(), diag::warn_fe_override_module)
+<< TargetOpts.Triple;
+TheModule->setTargetTriple(TargetOpts.Triple);
+  }
 
-if (OptRecordFile)
-  OptRecordFile->keep();
+  EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
+
+  LLVMContext  = TheModule->getContext();
+  Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler, );
+
+  // Set clang diagnostic handler. To do this we need to create a fake
+  // BackendConsumer.
+  BackendConsumer Result(BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),
+ CI.getPreprocessorOpts(), CI.getCodeGenOpts(),
+ CI.getTargetOpts(), CI.getLangOpts(),
+ 

[clang] 1dbf05f - [ThinLTO][Documentation] Mention possible values for concurrency flags

2020-10-13 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-10-13T09:57:58-04:00
New Revision: 1dbf05f5b44db17dcd8520b032e83061189ff4f8

URL: 
https://github.com/llvm/llvm-project/commit/1dbf05f5b44db17dcd8520b032e83061189ff4f8
DIFF: 
https://github.com/llvm/llvm-project/commit/1dbf05f5b44db17dcd8520b032e83061189ff4f8.diff

LOG: [ThinLTO][Documentation] Mention possible values for concurrency flags

Differential Revision: https://reviews.llvm.org/D89309

Added: 


Modified: 
clang/docs/ThinLTO.rst

Removed: 




diff  --git a/clang/docs/ThinLTO.rst b/clang/docs/ThinLTO.rst
index 528530c5ae98..0da822f498b9 100644
--- a/clang/docs/ThinLTO.rst
+++ b/clang/docs/ThinLTO.rst
@@ -123,6 +123,11 @@ be reduced to ``N`` via:
 - lld-link:
   ``/opt:lldltojobs=N``
 
+Other possible values for ``N`` are:
+- 0: Use one thread per physical core (default)
+- 1: Use a single thread only (disable multi-threading)
+- all: Use one thread per logical core (uses all hyper-threads)
+
 Incremental
 ---
 .. _incremental:



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


[clang] 66face6 - Re-land [DebugInfo] Add debug location to stubs generated by CGDeclCXX and mark them as artificial

2020-10-08 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-10-08T20:49:17-04:00
New Revision: 66face6aa0f5f68de56067b0dff3295e47fdf66c

URL: 
https://github.com/llvm/llvm-project/commit/66face6aa0f5f68de56067b0dff3295e47fdf66c
DIFF: 
https://github.com/llvm/llvm-project/commit/66face6aa0f5f68de56067b0dff3295e47fdf66c.diff

LOG: Re-land [DebugInfo] Add debug location to stubs generated by CGDeclCXX and 
mark them as artificial

Previously, when clang was compiled with -DLLVM_ENABLE_ASSERTIONS=ON, the added 
tests were displaying:

inlinable function call in a function with debug info must have a !dbg location
  call void @"??1?$c@UBQEAA@XZ"(%struct.c* 
@"?f@?1??d@@YAPEAU?$c@UBXZ@4U2@A")
fatal error: error in backend: Broken module found, compilation aborted!
Stack dump:
0.  Program arguments:  -gcodeview -debug-info-kind=limited
1.   parser at end of file
2.  Per-function optimization

Fixes PR43012

Differential Revision: https://reviews.llvm.org/D66328

Added: 
clang/test/CodeGenCXX/debug-info-atexit-stub.cpp
clang/test/CodeGenCXX/debug-info-destroy-helper.cpp

Modified: 
clang/include/clang/AST/GlobalDecl.h
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
clang/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp
clang/test/CodeGenCXX/debug-info-line.cpp

Removed: 




diff  --git a/clang/include/clang/AST/GlobalDecl.h 
b/clang/include/clang/AST/GlobalDecl.h
index d8ac498be54f..8cb56fb4ae90 100644
--- a/clang/include/clang/AST/GlobalDecl.h
+++ b/clang/include/clang/AST/GlobalDecl.h
@@ -32,6 +32,7 @@ enum class DynamicInitKind : unsigned {
   NoStub = 0,
   Initializer,
   AtExit,
+  GlobalArrayDestructor
 };
 
 enum class KernelReferenceKind : unsigned {

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 88aace8b85dd..71ebd268f630 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2041,7 +2041,8 @@ StringRef CGDebugInfo::getDynamicInitializerName(const 
VarDecl *VD,
  llvm::Function *InitFn) {
   // If we're not emitting codeview, use the mangled name. For Itanium, this is
   // arbitrary.
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView ||
+  StubKind == DynamicInitKind::GlobalArrayDestructor)
 return InitFn->getName();
 
   // Print the normal qualified name for the variable, then break off the last
@@ -2066,6 +2067,7 @@ StringRef CGDebugInfo::getDynamicInitializerName(const 
VarDecl *VD,
 
   switch (StubKind) {
   case DynamicInitKind::NoStub:
+  case DynamicInitKind::GlobalArrayDestructor:
 llvm_unreachable("not an initializer");
   case DynamicInitKind::Initializer:
 OS << "`dynamic initializer for '";
@@ -3832,7 +3834,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
   if (Name.startswith("\01"))
 Name = Name.substr(1);
 
-  if (!HasDecl || D->isImplicit() || D->hasAttr()) {
+  if (!HasDecl || D->isImplicit() || D->hasAttr() ||
+  (isa(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) 
{
 Flags |= llvm::DINode::FlagArtificial;
 // Artificial functions should not silently reuse CurLoc.
 CurLoc = SourceLocation();

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 3f6d0e23c685..b9ff561aa641 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -247,6 +247,8 @@ llvm::Function *CodeGenFunction::createAtExitStub(const 
VarDecl ,
   CGF.StartFunction(GlobalDecl(, DynamicInitKind::AtExit),
 CGM.getContext().VoidTy, fn, FI, FunctionArgList(),
 VD.getLocation(), VD.getInit()->getExprLoc());
+  // Emit an artificial location for this function.
+  auto AL = ApplyDebugLocation::CreateArtificial(CGF);
 
   llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
 
@@ -672,8 +674,9 @@ void 
CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
 
   StartFunction(GlobalDecl(D, DynamicInitKind::Initializer),
 getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(),
-FunctionArgList(), D->getLocation(),
-D->getInit()->getExprLoc());
+FunctionArgList());
+  // Emit an artificial location for this function.
+  auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   // Use guarded initialization if the global variable is weak. This
   // occurs for, e.g., instantiated static data members and
@@ -807,7 +810,10 @@ llvm::Function *CodeGenFunction::generateDestroyHelper(
 
   CurEHLocation = VD->getBeginLoc();
 
-  StartFunction(VD, getContext().VoidTy, fn, FI, args);
+  StartFunction(GlobalDecl(VD, DynamicInitKind::GlobalArrayDestructor),
+getContext().VoidTy, fn, FI, args);
+  // Emit an artificial 

[clang] f5314d1 - [Support] On Unix, let the CrashRecoveryContext return the signal code

2020-09-24 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-09-24T08:21:43-04:00
New Revision: f5314d15af4f4514103ea12c74cb208538b8bef5

URL: 
https://github.com/llvm/llvm-project/commit/f5314d15af4f4514103ea12c74cb208538b8bef5
DIFF: 
https://github.com/llvm/llvm-project/commit/f5314d15af4f4514103ea12c74cb208538b8bef5.diff

LOG: [Support] On Unix, let the CrashRecoveryContext return the signal code

Before this patch, the CrashRecoveryContext was returning -2 upon a signal, 
like ExecuteAndWait does. This didn't match the behavior on Windows, where the 
the exception code was returned.

We now return the signal's code, which optionally allows for re-throwing the 
signal later. Doing so requires all custom handlers to be removed first, 
through llvm::sys::unregisterHandlers() which we made a public API.

This is part of https://reviews.llvm.org/D70378

Added: 


Modified: 
clang/tools/driver/driver.cpp
llvm/include/llvm/Support/Signals.h
llvm/lib/Support/CrashRecoveryContext.cpp
llvm/lib/Support/Unix/Signals.inc
llvm/lib/Support/Windows/Signals.inc
llvm/unittests/Support/CrashRecoveryTest.cpp

Removed: 




diff  --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index f24fd61e61a5..f67af6790fff 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -531,6 +531,13 @@ int main(int argc_, const char **argv_) {
   IsCrash = CommandRes < 0 || CommandRes == 70;
 #ifdef _WIN32
   IsCrash |= CommandRes == 3;
+#endif
+#if LLVM_ON_UNIX
+  // When running in integrated-cc1 mode, the CrashRecoveryContext returns
+  // the same codes as if the program crashed. See section "Exit Status for
+  // Commands":
+  // 
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html
+  IsCrash |= CommandRes > 128;
 #endif
   if (IsCrash) {
 TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);

diff  --git a/llvm/include/llvm/Support/Signals.h 
b/llvm/include/llvm/Support/Signals.h
index c5b94f5ac776..44f5a750ff5c 100644
--- a/llvm/include/llvm/Support/Signals.h
+++ b/llvm/include/llvm/Support/Signals.h
@@ -117,6 +117,8 @@ namespace sys {
   /// Context is a system-specific failure context: it is the signal type on
   /// Unix; the ExceptionContext on Windows.
   void CleanupOnSignal(uintptr_t Context);
+
+  void unregisterHandlers();
 } // End sys namespace
 } // End llvm namespace
 

diff  --git a/llvm/lib/Support/CrashRecoveryContext.cpp 
b/llvm/lib/Support/CrashRecoveryContext.cpp
index 2a41754c7786..7609f04cf68c 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -375,9 +375,10 @@ static void CrashRecoverySignalHandler(int Signal) {
   sigaddset(, Signal);
   sigprocmask(SIG_UNBLOCK, , nullptr);
 
-  // As per convention, -2 indicates a crash or timeout as opposed to failure 
to
-  // execute (see llvm/include/llvm/Support/Program.h)
-  int RetCode = -2;
+  // Return the same error code as if the program crashed, as mentioned in the
+  // section "Exit Status for Commands":
+  // https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html
+  int RetCode = 128 + Signal;
 
   // Don't consider a broken pipe as a crash (see clang/lib/Driver/Driver.cpp)
   if (Signal == SIGPIPE)

diff  --git a/llvm/lib/Support/Unix/Signals.inc 
b/llvm/lib/Support/Unix/Signals.inc
index 50b2ad4b5772..03181a713257 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -331,7 +331,7 @@ static void RegisterHandlers() { // Not signal-safe.
 registerHandler(S, SignalKind::IsInfo);
 }
 
-static void UnregisterHandlers() {
+void sys::unregisterHandlers() {
   // Restore all of the signal handlers to how they were before we showed up.
   for (unsigned i = 0, e = NumRegisteredSignals.load(); i != e; ++i) {
 sigaction(RegisteredSignalInfo[i].SigNo,
@@ -367,7 +367,7 @@ static RETSIGTYPE SignalHandler(int Sig) {
   // crashes when we return and the signal reissues.  This also ensures that if
   // we crash in our signal handler that the program will terminate immediately
   // instead of recursing in the signal handler.
-  UnregisterHandlers();
+  sys::unregisterHandlers();
 
   // Unmask all potentially blocked kill signals.
   sigset_t SigMask;

diff  --git a/llvm/lib/Support/Windows/Signals.inc 
b/llvm/lib/Support/Windows/Signals.inc
index 71dc6324e99f..3758582b35f7 100644
--- a/llvm/lib/Support/Windows/Signals.inc
+++ b/llvm/lib/Support/Windows/Signals.inc
@@ -869,3 +869,5 @@ static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) 
{
  #pragma GCC diagnostic warning "-Wformat"
  #pragma GCC diagnostic warning "-Wformat-extra-args"
 #endif
+
+void sys::unregisterHandlers() {}

diff  --git a/llvm/unittests/Support/CrashRecoveryTest.cpp 
b/llvm/unittests/Support/CrashRecoveryTest.cpp
index a8040dc0110e..fc65bf6329b3 100644
--- 

[clang] 33ce275 - [Clang] Fix tests following rG087047144210

2020-08-26 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-08-26T11:32:46-04:00
New Revision: 33ce275fc156c8b015acfad918937028b2cc235c

URL: 
https://github.com/llvm/llvm-project/commit/33ce275fc156c8b015acfad918937028b2cc235c
DIFF: 
https://github.com/llvm/llvm-project/commit/33ce275fc156c8b015acfad918937028b2cc235c.diff

LOG: [Clang] Fix tests following rG087047144210

Added: 


Modified: 
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index f4d2d66129b0..89dbdebbaf69 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -688,7 +688,7 @@
 
 // Validate that built-in include paths are based on the supplied path
 // RUN: %clang_cl -vctoolsdir "/fake" -### -- %s 2>&1 | FileCheck %s 
--check-prefix FAKEDIR
-// FAKEDIR: "-internal-isystem" "/fake{{.}}include"
-// FAKEDIR: "-internal-isystem" "/fake{{.}}atlmfc{{.}}include"
+// FAKEDIR: "-internal-isystem" "/fake{{/|}}include"
+// FAKEDIR: "-internal-isystem" "/fake{{/|}}atlmfc{{/|}}include"
 
 void f() { }



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


[clang] 98e01f5 - Revert "Re-Re-land: [CodeView] Add full repro to LF_BUILDINFO record"

2020-08-17 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-08-17T15:49:18-04:00
New Revision: 98e01f56b0a117f0f32ed2f9b7d61e85830c

URL: 
https://github.com/llvm/llvm-project/commit/98e01f56b0a117f0f32ed2f9b7d61e85830c
DIFF: 
https://github.com/llvm/llvm-project/commit/98e01f56b0a117f0f32ed2f9b7d61e85830c.diff

LOG: Revert "Re-Re-land: [CodeView] Add full repro to LF_BUILDINFO record"

This reverts commit a3036b386383f1c1e9d32c2c8dba995087959da3.

As requested in: https://reviews.llvm.org/D80833#2221866
Bug report: https://crbug.com/1117026

Added: 


Modified: 
clang/cmake/caches/BaremetalARM.cmake
clang/cmake/caches/CrossWinToARMLinux.cmake
clang/cmake/caches/Fuchsia-stage2.cmake
clang/test/CMakeLists.txt
lld/COFF/PDB.cpp
lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
lld/test/COFF/Inputs/pdb_lines_2_relative.yaml
lld/test/COFF/pdb-relative-source-lines.test
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/test/DebugInfo/COFF/build-info.ll
llvm/test/DebugInfo/COFF/global-type-hashes.ll
llvm/test/DebugInfo/COFF/types-basic.ll
llvm/test/DebugInfo/COFF/types-data-members.ll

Removed: 
clang/test/CodeGen/debug-info-codeview-buildinfo.c
lld/test/COFF/pdb-relative-source-lines2.test



diff  --git a/clang/cmake/caches/BaremetalARM.cmake 
b/clang/cmake/caches/BaremetalARM.cmake
index e44355cfcbd7..85295d9db392 100644
--- a/clang/cmake/caches/BaremetalARM.cmake
+++ b/clang/cmake/caches/BaremetalARM.cmake
@@ -31,7 +31,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-dwarfdump
   llvm-nm
   llvm-objdump
-  llvm-pdbutil
   llvm-ranlib
   llvm-readobj
   llvm-size

diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index ccfccce3cb89..9aa0efa8049f 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -137,7 +137,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-lib
   llvm-nm
   llvm-objdump
-  llvm-pdbutil
   llvm-profdata
   llvm-ranlib
   llvm-readobj

diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7cefeedf1bad..e00b64073ca5 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -242,7 +242,6 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-nm
   llvm-objcopy
   llvm-objdump
-  llvm-pdbutil
   llvm-profdata
   llvm-rc
   llvm-ranlib

diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 3ace9f2521b0..334a90498d0d 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -117,7 +117,6 @@ if( NOT CLANG_BUILT_STANDALONE )
 llvm-nm
 llvm-objcopy
 llvm-objdump
-llvm-pdbutil
 llvm-profdata
 llvm-readelf
 llvm-readobj

diff  --git a/clang/test/CodeGen/debug-info-codeview-buildinfo.c 
b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
deleted file mode 100644
index 93810e829c6d..
--- a/clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ /dev/null
@@ -1,26 +0,0 @@
-// REQUIRES: x86-registered-target
-// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
-// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
-// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj 
-fdebug-compilation-dir=. -- %s
-// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
-
-int main() { return 42; }
-
-// CHECK:   Types (.debug$T)
-// CHECK: 
-// CHECK: 0x[[PWD:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[PWDVAL:.+]]
-// CHECK: 0x[[FILEPATH:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: [[FILEPATHVAL:.+[\\/]debug-info-codeview-buildinfo.c]]
-// CHECK: 0x[[ZIPDB:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String:
-// CHECK: 0x[[TOOL:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[TOOLVAL:.+[\\/]clang.*]]
-// CHECK: 0x[[CMDLINE:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: "-cc1
-// CHECK: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
-// CHECK:  0x[[PWD]]: `[[PWDVAL]]`
-// CHECK:  0x[[TOOL]]: `[[TOOLVAL]]`
-// CHECK:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
-// CHECK:  0x[[ZIPDB]]: ``
-// CHECK:  0x[[CMDLINE]]: `"-cc1
-
-// RELATIVE:   Types (.debug$T)
-// RELATIVE: 
-// RELATIVE: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
-// RELATIVE:  0x{{.+}}: `.`

diff  --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 5738eae7d6c4..49d04add5be0 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -250,72 +250,6 @@ static void addTypeInfo(pdb::TpiStreamBuilder ,
   });
 }
 
-// LF_BUILDINFO records might contain relative paths, and we want to make them
-// absolute. We do this remapping only after the type records were merged,
-// because the full types graph isn't known during merging. In addition, we 
plan

[clang] a3036b3 - Re-Re-land: [CodeView] Add full repro to LF_BUILDINFO record

2020-08-10 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-08-10T13:36:30-04:00
New Revision: a3036b386383f1c1e9d32c2c8dba995087959da3

URL: 
https://github.com/llvm/llvm-project/commit/a3036b386383f1c1e9d32c2c8dba995087959da3
DIFF: 
https://github.com/llvm/llvm-project/commit/a3036b386383f1c1e9d32c2c8dba995087959da3.diff

LOG: Re-Re-land: [CodeView] Add full repro to LF_BUILDINFO record

This patch adds the missing information to the LF_BUILDINFO record, which 
allows for rebuilding a .CPP without any external dependency but the .OBJ 
itself (other than the compiler).

Some external tools that we are using (Recode, Live++) are extracting the 
information to reproduce a build without any knowledge of the build system. The 
LF_BUILDINFO stores a full path to the compiler, the PWD (CWD at program 
startup), a relative or absolute path to the TU, and the full CC1 command line. 
The command line needs to be freestanding (not depend on any environment 
variables). In the same way, MSVC doesn't store the provided command-line, but 
an expanded version (somehow their equivalent of CC1) which is also 
freestanding.

For more information see PR36198 and D43002.

Differential Revision: https://reviews.llvm.org/D80833

Added: 
clang/test/CodeGen/debug-info-codeview-buildinfo.c
lld/test/COFF/pdb-relative-source-lines2.test

Modified: 
clang/cmake/caches/BaremetalARM.cmake
clang/cmake/caches/CrossWinToARMLinux.cmake
clang/cmake/caches/Fuchsia-stage2.cmake
clang/test/CMakeLists.txt
lld/COFF/PDB.cpp
lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
lld/test/COFF/Inputs/pdb_lines_2_relative.yaml
lld/test/COFF/pdb-relative-source-lines.test
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/test/DebugInfo/COFF/build-info.ll
llvm/test/DebugInfo/COFF/global-type-hashes.ll
llvm/test/DebugInfo/COFF/types-basic.ll
llvm/test/DebugInfo/COFF/types-data-members.ll

Removed: 




diff  --git a/clang/cmake/caches/BaremetalARM.cmake 
b/clang/cmake/caches/BaremetalARM.cmake
index 85295d9db392a..e44355cfcbd74 100644
--- a/clang/cmake/caches/BaremetalARM.cmake
+++ b/clang/cmake/caches/BaremetalARM.cmake
@@ -31,6 +31,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-dwarfdump
   llvm-nm
   llvm-objdump
+  llvm-pdbutil
   llvm-ranlib
   llvm-readobj
   llvm-size

diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 9aa0efa8049fb..ccfccce3cb890 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -137,6 +137,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-lib
   llvm-nm
   llvm-objdump
+  llvm-pdbutil
   llvm-profdata
   llvm-ranlib
   llvm-readobj

diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index e00b64073ca52..7cefeedf1bada 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -242,6 +242,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-nm
   llvm-objcopy
   llvm-objdump
+  llvm-pdbutil
   llvm-profdata
   llvm-rc
   llvm-ranlib

diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 38bbc5be90d52..b2777fded0ae5 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -126,6 +126,7 @@ if( NOT CLANG_BUILT_STANDALONE )
 llvm-nm
 llvm-objcopy
 llvm-objdump
+llvm-pdbutil
 llvm-profdata
 llvm-readelf
 llvm-readobj

diff  --git a/clang/test/CodeGen/debug-info-codeview-buildinfo.c 
b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
new file mode 100644
index 0..93810e829c6d9
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
@@ -0,0 +1,26 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj 
-fdebug-compilation-dir=. -- %s
+// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
+
+int main() { return 42; }
+
+// CHECK:   Types (.debug$T)
+// CHECK: 
+// CHECK: 0x[[PWD:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[PWDVAL:.+]]
+// CHECK: 0x[[FILEPATH:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: [[FILEPATHVAL:.+[\\/]debug-info-codeview-buildinfo.c]]
+// CHECK: 0x[[ZIPDB:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String:
+// CHECK: 0x[[TOOL:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[TOOLVAL:.+[\\/]clang.*]]
+// CHECK: 0x[[CMDLINE:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: "-cc1
+// CHECK: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
+// CHECK:  0x[[PWD]]: `[[PWDVAL]]`
+// CHECK:  0x[[TOOL]]: `[[TOOLVAL]]`
+// CHECK:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
+// CHECK:  0x[[ZIPDB]]: ``
+// CHECK:  0x[[CMDLINE]]: `"-cc1
+
+// 

RE: [PATCH] D80833: [CodeView] Add full repro to LF_BUILDINFO record

2020-07-10 Thread Alexandre Ganea via cfe-commits
Thanks for letting me know Eric. What test fails exactly? What config?

De : Eric Christopher 
Envoyé : July 10, 2020 7:04 PM
À : reviews+d80833+public+da87cf0eabdca...@reviews.llvm.org; Alexandre Ganea 
via Phabricator 
Cc : Alexandre Ganea ; Hans Wennborg 
; Adrian McCarthy ; Martin Storsjo 
; Amy Huang ; dma...@mozilla.com; 
john.rea...@vmssoftware.com; ztur...@roblox.com; ...@gmail.com; 
llvm-commits ; 
stefan.reinal...@molecular-matters.com; Ulrich Weigand 
; mlek...@skidmore.edu; Clang Commits 
; Han Shen 
Objet : Re: [PATCH] D80833: [CodeView] Add full repro to LF_BUILDINFO record

I'm seeing tests fail with a crash. Can we revert the patch and attempted fixes 
and start working from there?

Stacktrace for the curious :)

@ 0x56420187cbbe  llvm::MCStreamer::emitIntValue()
@ 0x5641fec38899  llvm::MCStreamer::emitInt16()
@ 0x5641ff73b337  llvm::CodeViewDebug::emitCompilerInformation()
@ 0x5641ff73ac73  llvm::CodeViewDebug::endModule()
@ 0x5641ff718e83  llvm::AsmPrinter::doFinalization()
@ 0x5642016fd9ca  llvm::FPPassManager::doFinalization()
@ 0x5642016f954e  (anonymous namespace)::MPPassManager::runOnModule()

-eric

On Tue, Jun 30, 2020 at 11:56 AM Alexandre Ganea via Phabricator via 
cfe-commits mailto:cfe-commits@lists.llvm.org>> 
wrote:
aganea added a comment.

In D80833#2109172 , @uweigand wrote:

> Hmm, with clang-cl it seems the driver is trying to use this:
>  Target: s390x-pc-windows-msvc
>  which of course doesn't exist.  Not sure what is supposed to be happening 
> here, but it seems that it's falling back on s390x-linux since on s390x, 
> Linux is currently the only supported OS.


I'm seeing some of the tests are setting the target explicitly `%clang_cl 
--target=x86_64-windows-msvc`. Would that work on your machine? Or should I do 
`UNSUPPORTED: s390x` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80833



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


[clang] 41d2813 - [PDB] Attempt fix for debug-info-codeview-buildinfo.c test

2020-07-10 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-07-10T18:52:52-04:00
New Revision: 41d2813a5faea1c18b7d329109e0287c5cd9ffea

URL: 
https://github.com/llvm/llvm-project/commit/41d2813a5faea1c18b7d329109e0287c5cd9ffea
DIFF: 
https://github.com/llvm/llvm-project/commit/41d2813a5faea1c18b7d329109e0287c5cd9ffea.diff

LOG: [PDB] Attempt fix for debug-info-codeview-buildinfo.c test

This is a bit a shot in the dark, as it doesn't occur on my Windows 10 
machines, nor on x64 Linux Ubuntu 18.04.
This patch tries to fix the following kind of error:
- 
http://lab.llvm.org:8011/builders/clang-ppc64le-linux/builds/31511/steps/cmake%20stage%201/logs/stdio
- 
http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/25150/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Adebug-info-codeview-buildinfo.c
- 
http://lab.llvm.org:8011/builders/fuchsia-x86_64-linux/builds/7947/steps/check/logs/stdio

Added: 


Modified: 
clang/cmake/caches/BaremetalARM.cmake
clang/cmake/caches/CrossWinToARMLinux.cmake
clang/cmake/caches/Fuchsia-stage2.cmake
clang/test/CMakeLists.txt
clang/test/CodeGen/debug-info-codeview-buildinfo.c

Removed: 




diff  --git a/clang/cmake/caches/BaremetalARM.cmake 
b/clang/cmake/caches/BaremetalARM.cmake
index 85295d9db392..e44355cfcbd7 100644
--- a/clang/cmake/caches/BaremetalARM.cmake
+++ b/clang/cmake/caches/BaremetalARM.cmake
@@ -31,6 +31,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-dwarfdump
   llvm-nm
   llvm-objdump
+  llvm-pdbutil
   llvm-ranlib
   llvm-readobj
   llvm-size

diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 9aa0efa8049f..ccfccce3cb89 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -137,6 +137,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-lib
   llvm-nm
   llvm-objdump
+  llvm-pdbutil
   llvm-profdata
   llvm-ranlib
   llvm-readobj

diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 259684ff2b0d..8b5e9d0c4181 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -240,6 +240,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-nm
   llvm-objcopy
   llvm-objdump
+  llvm-pdbutil
   llvm-profdata
   llvm-ranlib
   llvm-readelf

diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 38bbc5be90d5..b2777fded0ae 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -126,6 +126,7 @@ if( NOT CLANG_BUILT_STANDALONE )
 llvm-nm
 llvm-objcopy
 llvm-objdump
+llvm-pdbutil
 llvm-profdata
 llvm-readelf
 llvm-readobj

diff  --git a/clang/test/CodeGen/debug-info-codeview-buildinfo.c 
b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
index 3434f5f86579..e1082d2532b2 100644
--- a/clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
@@ -1,7 +1,6 @@
-// UNSUPPORTED: s390x
-// RUN: %clang_cl /c /Z7 /Fo%t.obj -- %s
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
-// RUN: %clang_cl /c /Z7 /Fo%t.obj -fdebug-compilation-dir . -- %s
+// RUN: %clang_cl --target=i686-windows-msvc /c /Z7 /Fo%t.obj 
-fdebug-compilation-dir=. -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
 
 int main() { return 42; }



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


[clang] 2ae0df5 - [CodeView] Revert 8374bf43634725dc02a262a77b5f940fca25938c and 403f9537924b8910ed4f741ed96c61f5e657915b

2020-06-18 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-06-18T16:18:46-04:00
New Revision: 2ae0df5be7408a79524743762b6c74953f31b805

URL: 
https://github.com/llvm/llvm-project/commit/2ae0df5be7408a79524743762b6c74953f31b805
DIFF: 
https://github.com/llvm/llvm-project/commit/2ae0df5be7408a79524743762b6c74953f31b805.diff

LOG: [CodeView] Revert 8374bf43634725dc02a262a77b5f940fca25938c and 
403f9537924b8910ed4f741ed96c61f5e657915b

This reverts:
8374bf43634725dc02a262a77b5f940fca25938c [CodeView] Fix generated command-line 
expansion in LF_BUILDINFO. Fix the 'pdb' entry which was previously a null 
reference, now an empty string.
403f9537924b8910ed4f741ed96c61f5e657915b [CodeView] Add full repro to 
LF_BUILDINFO record

This is causing the lld/test/COFF/pdb-relative-source-lines.test to fail: 
http://lab.llvm.org:8011/builders/lld-x86_64-win/builds/1096/steps/test-check-all/logs/FAIL%3A%20lld%3A%3Apdb-relative-source-lines.test
And clang/test/CodeGen/debug-info-codeview-buildinfo.c fails as well: 
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/33346/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Adebug-info-codeview-buildinfo.c

Added: 


Modified: 
lld/COFF/PDB.cpp
lld/test/COFF/Inputs/pdb_lines_1_relative.yaml
lld/test/COFF/Inputs/pdb_lines_2_relative.yaml
lld/test/COFF/pdb-relative-source-lines.test
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/test/DebugInfo/COFF/build-info.ll
llvm/test/DebugInfo/COFF/global-type-hashes.ll
llvm/test/DebugInfo/COFF/types-basic.ll
llvm/test/DebugInfo/COFF/types-data-members.ll

Removed: 
clang/test/CodeGen/debug-info-codeview-buildinfo.c



diff  --git a/clang/test/CodeGen/debug-info-codeview-buildinfo.c 
b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
deleted file mode 100644
index 5d37162b7325..
--- a/clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cl /c /Z7 /Fo%t.obj -- %s
-// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
-// RUN: %clang_cl /c /Z7 /Fo%t.obj -fdebug-compilation-dir . -- %s
-// RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
-
-int main() { return 42; }
-
-// CHECK:   Types (.debug$T)
-// CHECK: 
-// CHECK: 0x[[PWD:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[PWDVAL:.+]]
-// CHECK: 0x[[FILEPATH:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: [[FILEPATHVAL:.+[\\/]debug-info-codeview-buildinfo.c]]
-// CHECK: 0x[[ZIPDB:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String:
-// CHECK: 0x[[TOOL:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[TOOLVAL:.+[\\/]clang.*]]
-// CHECK: 0x[[CMDLINE:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: "-cc1
-// CHECK: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
-// CHECK:  0x[[PWD]]: `[[PWDVAL]]`
-// CHECK:  0x[[TOOL]]: `[[TOOLVAL]]`
-// CHECK:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
-// CHECK:  0x[[ZIPDB]]: ``
-// CHECK:  0x[[CMDLINE]]: `"-cc1
-
-// RELATIVE:   Types (.debug$T)
-// RELATIVE: 
-// RELATIVE: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
-// RELATIVE:  0x{{.+}}: `.`

diff  --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 75884ed11308..be6af13f3647 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -250,72 +250,6 @@ static void addTypeInfo(pdb::TpiStreamBuilder ,
   });
 }
 
-// LF_BUILDINFO records might contain relative paths, and we want to make them
-// absolute. We do this remapping only after the type records were merged,
-// because the full types graph isn't known during merging. In addition, we 
plan
-// to multi-thread the type merging, and the change below needs to be done
-// atomically, single-threaded.
-
-// A complication could arise when a LF_STRING_ID record already exists with 
the
-// same content as the new absolutized path. In that case, we simply redirect
-// LF_BUILDINFO's CurrentDirectory index to reference the existing LF_STRING_ID
-// record.
-
-static void remapBuildInfo(TypeCollection ) {
-  SimpleTypeSerializer s;
-  idTable.ForEachRecord([&](TypeIndex ti, const CVType ) {
-if (type.kind() != LF_BUILDINFO)
-  return;
-BuildInfoRecord bi;
-cantFail(TypeDeserializer::deserializeAs(const_cast(type), bi));
-
-auto makeAbsoluteRecord =
-[&](BuildInfoRecord::BuildInfoArg recordType) -> Optional {
-  TypeIndex recordTi = bi.getArgs()[recordType];
-  if (recordTi.isNoneType())
-return None;
-  CVType recordRef = idTable.getType(recordTi);
-
-  StringIdRecord record;
-  cantFail(TypeDeserializer::deserializeAs(recordRef, record));
-
-  SmallString<128> abolutizedPath(record.getString());
-  pdbMakeAbsolute(abolutizedPath);
-
-  if (abolutizedPath == record.getString())
-return None; // 

[clang] cab3fc5 - Fix linker error in clang-fuzzer following 89ea0b05207d45c145fb525df554b3b986ae379b.

2020-06-18 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-06-18T10:07:31-04:00
New Revision: cab3fc53d2e173243a462e9c8e914af58ddbeaba

URL: 
https://github.com/llvm/llvm-project/commit/cab3fc53d2e173243a462e9c8e914af58ddbeaba
DIFF: 
https://github.com/llvm/llvm-project/commit/cab3fc53d2e173243a462e9c8e914af58ddbeaba.diff

LOG: Fix linker error in clang-fuzzer following 
89ea0b05207d45c145fb525df554b3b986ae379b.

This fixes:
tools/clang/tools/clang-fuzzer/handle-cxx/CMakeFiles/obj.clangHandleCXX.dir/handle_cxx.cpp.o:handle_cxx.cpp:function
 clang_fuzzer::HandleCXX(std::__cxx11::basic_string, std::allocator > const&, char const*, 
std::vector > const&): error: 
undefined reference to 
'clang::tooling::newInvocation(clang::DiagnosticsEngine*, 
llvm::SmallVector const&)'

Added: 


Modified: 
clang/include/clang/Tooling/Tooling.h
clang/tools/clang-fuzzer/handle-cxx/handle_cxx.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index ced2405f6e83..4fb0c18be95e 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -505,7 +505,8 @@ void 
addTargetAndModeForProgramName(std::vector ,
 
 /// Creates a \c CompilerInvocation.
 CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
-  const llvm::opt::ArgStringList );
+  const llvm::opt::ArgStringList ,
+  const char *const BinaryName);
 
 } // namespace tooling
 

diff  --git a/clang/tools/clang-fuzzer/handle-cxx/handle_cxx.cpp 
b/clang/tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
index 32d351f4c3e9..14204021d262 100644
--- a/clang/tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
+++ b/clang/tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
@@ -37,7 +37,7 @@ void clang_fuzzer::HandleCXX(const std::string ,
   IntrusiveRefCntPtr(new DiagnosticIDs()), 
&*DiagOpts,
   , false);
   std::unique_ptr Invocation(
-  tooling::newInvocation(, CC1Args));
+  tooling::newInvocation(, CC1Args, /*BinaryName=*/nullptr));
   std::unique_ptr Input =
   llvm::MemoryBuffer::getMemBuffer(S);
   Invocation->getPreprocessorOpts().addRemappedFile(FileName,



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


[clang] 8374bf4 - [CodeView] Fix generated command-line expansion in LF_BUILDINFO. Fix the 'pdb' entry which was previously a null reference, now an empty string.

2020-06-18 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-06-18T10:07:30-04:00
New Revision: 8374bf43634725dc02a262a77b5f940fca25938c

URL: 
https://github.com/llvm/llvm-project/commit/8374bf43634725dc02a262a77b5f940fca25938c
DIFF: 
https://github.com/llvm/llvm-project/commit/8374bf43634725dc02a262a77b5f940fca25938c.diff

LOG: [CodeView] Fix generated command-line expansion in LF_BUILDINFO. Fix the 
'pdb' entry which was previously a null reference, now an empty string.

Previously, the DIA SDK didn't like the empty reference in the 'pdb' entry.

Added: 


Modified: 
clang/test/CodeGen/debug-info-codeview-buildinfo.c
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/test/DebugInfo/COFF/build-info.ll
llvm/test/DebugInfo/COFF/global-type-hashes.ll
llvm/test/DebugInfo/COFF/types-basic.ll
llvm/test/DebugInfo/COFF/types-data-members.ll

Removed: 




diff  --git a/clang/test/CodeGen/debug-info-codeview-buildinfo.c 
b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
index d08fadbbf1a9..5d37162b7325 100644
--- a/clang/test/CodeGen/debug-info-codeview-buildinfo.c
+++ b/clang/test/CodeGen/debug-info-codeview-buildinfo.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cl /c /Z7 /Fo%t.obj -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s
-// RUN: %clang_cl /c /Z7 %s /Fo%t.obj -fdebug-compilation-dir .
+// RUN: %clang_cl /c /Z7 /Fo%t.obj -fdebug-compilation-dir . -- %s
 // RUN: llvm-pdbutil dump --types %t.obj | FileCheck %s --check-prefix RELATIVE
 
 int main() { return 42; }
@@ -9,13 +9,14 @@ int main() { return 42; }
 // CHECK: 
 // CHECK: 0x[[PWD:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[PWDVAL:.+]]
 // CHECK: 0x[[FILEPATH:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: [[FILEPATHVAL:.+[\\/]debug-info-codeview-buildinfo.c]]
+// CHECK: 0x[[ZIPDB:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String:
 // CHECK: 0x[[TOOL:.+]] | LF_STRING_ID [size = {{.+}}] ID: , String: 
[[TOOLVAL:.+[\\/]clang.*]]
 // CHECK: 0x[[CMDLINE:.+]] | LF_STRING_ID [size = {{.+}}] ID: , 
String: "-cc1
 // CHECK: 0x{{.+}} | LF_BUILDINFO [size = {{.+}}]
 // CHECK:  0x[[PWD]]: `[[PWDVAL]]`
 // CHECK:  0x[[TOOL]]: `[[TOOLVAL]]`
 // CHECK:  0x[[FILEPATH]]: `[[FILEPATHVAL]]`
-// CHECK:  : ``
+// CHECK:  0x[[ZIPDB]]: ``
 // CHECK:  0x[[CMDLINE]]: `"-cc1
 
 // RELATIVE:   Types (.debug$T)

diff  --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp 
b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 7f47849e3aa8..cf3c38c57f6d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -849,10 +849,11 @@ static std::string flattenCommandLine(ArrayRef Args,
   continue;
 }
 if (!LastArg.empty())
-  FlatCmdLine += " ";
+  OS << " ";
 llvm::sys::printArg(OS, Arg, /*Quote=*/true);
 LastArg = Arg;
   }
+  OS.flush();
   return FlatCmdLine;
 }
 
@@ -876,6 +877,9 @@ void CodeViewDebug::emitBuildInfo() {
   getStringIdTypeIdx(TypeTable, MainSourceFile->getDirectory());
   BuildInfoArgs[BuildInfoRecord::SourceFile] =
   getStringIdTypeIdx(TypeTable, MainSourceFile->getFilename());
+  // FIXME: PDB is intentionally blank unless we implement /Zi type servers.
+  BuildInfoArgs[BuildInfoRecord::TypeServerPDB] =
+  getStringIdTypeIdx(TypeTable, "");
   if (Asm->TM.Options.MCOptions.Argv0 != nullptr) {
 BuildInfoArgs[BuildInfoRecord::BuildTool] =
 getStringIdTypeIdx(TypeTable, Asm->TM.Options.MCOptions.Argv0);
@@ -883,7 +887,6 @@ void CodeViewDebug::emitBuildInfo() {
 TypeTable, 
flattenCommandLine(Asm->TM.Options.MCOptions.CommandLineArgs,
   MainSourceFile->getFilename()));
   }
-  // FIXME: PDB is intentionally blank unless we implement /Zi type servers.
   BuildInfoRecord BIR(BuildInfoArgs);
   TypeIndex BuildInfoIndex = TypeTable.writeLeafType(BIR);
 

diff  --git a/llvm/test/DebugInfo/COFF/build-info.ll 
b/llvm/test/DebugInfo/COFF/build-info.ll
index 94f006c3b093..983aa22214bc 100644
--- a/llvm/test/DebugInfo/COFF/build-info.ll
+++ b/llvm/test/DebugInfo/COFF/build-info.ll
@@ -5,7 +5,7 @@
 ; CHECK-NEXT:  0x{{.*}}: `D:\src\scopes\clang`
 ; CHECK-NEXT:  : ``
 ; CHECK-NEXT:  0x{{.*}}: `D:\src\scopes\foo.cpp`
-; CHECK-NEXT:  : ``
+; CHECK-NEXT:  0x{{.*}}: ``
 ; CHECK-NEXT:  : ``
 
 ; CHECK: {{.*}} | S_BUILDINFO [size = 8] BuildId = `[[INFO_IDX]]`

diff  --git a/llvm/test/DebugInfo/COFF/global-type-hashes.ll 
b/llvm/test/DebugInfo/COFF/global-type-hashes.ll
index 70f9df156a5b..3c6c27301b20 100644
--- a/llvm/test/DebugInfo/COFF/global-type-hashes.ll
+++ b/llvm/test/DebugInfo/COFF/global-type-hashes.ll
@@ -295,7 +295,8 @@ attributes #2 = { noinline nounwind optnone 
"correctly-rounded-divide-sqrt-fp-ma
 ; YAML: - 4470750F2E319329
 ; YAML:  

  1   2   >