[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)
dwblaikie 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 #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? Ah, I'll take up the discussion on the issue, I think - thanks for pointing that out. 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)
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)
dwblaikie 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. 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... 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)
dwblaikie wrote: Yes, the initializers do have to be lazyily evaluated to be a conforming C++ compiler. eg: this code must compile without error so far as I understand: ``` template struct t1 { static constexpr int x = 3 / Value; }; t1<0> v1; ``` Though it seems MSVC doesn't implement this correctly? https://godbolt.org/z/c1f6xKn3T One way I've seen someone force the instantiation of the variable definition, and thus get the constant emitted into the DWARF, is using a static_assert: ``` template struct t1 { static constexpr int x = 3 / Value; static_assert(x, true); }; t1<1> v1; ``` (of course, in this case, `t1<0>` can no longer be instantiated) 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)
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)
amykhuang wrote: Yes, feel free to take over that part, thanks! 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)
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)
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)
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)
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)
https://github.com/amykhuang approved this pull request. Looks reasonable to me. 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)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Alexandre Ganea (aganea) Changes 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 --- Full diff: https://github.com/llvm/llvm-project/pull/95259.diff 3 Files Affected: - (modified) clang/docs/UsersManual.rst (+3) - (modified) clang/include/clang/Driver/Options.td (+1-1) - (modified) clang/test/Driver/cl-options.c (+2) ``diff 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 \ `` 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)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Alexandre Ganea (aganea) Changes 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 --- Full diff: https://github.com/llvm/llvm-project/pull/95259.diff 3 Files Affected: - (modified) clang/docs/UsersManual.rst (+3) - (modified) clang/include/clang/Driver/Options.td (+1-1) - (modified) clang/test/Driver/cl-options.c (+2) ``diff 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 \ `` 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)
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