[Bug debug/78322] Debug info still present for fully optimized away functions

2024-04-15 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78322

--- Comment #5 from David Blaikie  ---
(In reply to Andrew Pinski from comment #4)
> (In reply to David Blaikie from comment #2)
> > (In reply to Richard Biener from comment #1)
> > > We produce an abstract copy for use by repeated inline copies.
> > 
> > Yep! Is it still reasonable to consider it a bug (or at least a feature
> > request) that this is still produced even when no inline copies are emitted?
> 
> Not really. 
> 
> Sounds like what you are aiming for is the nodebug attribute that you can
> use with always_inline. Basically in dwarf inline functions are still
> represented as functions (calls) and most folks want that for their
> debugability of their program but in this case you specific inlined
> functions not to have debug info which is exactly what nodebug would do ...

Not sure I follow. I'm not suggesting this function should be `nodebug`.

Specifically: If an abstract origin is unreferenced, it seems like it
should/could be omitted, for brevity.

If the abstract origin is referenced - if there was some remnant of the inlined
code that then caused an inlined_subroutine to be emitted, that would need to
reference the abstract origin and so the latter should be emitted.

This is what clang does, at least - thought it might be nice for gcc to do that
to, to have more compact DWARF output.

https://godbolt.org/z/3doWWK4G4

(though, interestingly, since this bug was filed - in GCC 9, GCC started
putting NOPs in for the inlined code, which is a nice touch - so at -O0 you can
still step into/out of a no-op (or presumably otherwise optimized away? if you
had some optimizations forced on at -O0 somehow) inlined function - but with
optimizations enabled you still see the behavior of an abstract origin emitted
without any uses/references to it)

[Bug debug/99178] Emit .debug_names

2024-01-10 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99178

--- Comment #6 from David Blaikie  ---
(In reply to Tom Tromey from comment #5)
> (In reply to David Blaikie from comment #4)
> 
> I don't remember filing this bug.  At the time maybe I thought it
> would be worthwhile to have "end to end" .debug_names generation,
> that is, to try to have the index and also not slow down
> compilation or link times too much.  Not sure how I feel about it now.

Certainly what's been possible with .debug_gnu_pubnames/types + -Wl,--gdb-index
today. It'd be nice to have that same workflow, but in a more portable form.

> > It'd be great to get GCC/GDB folks take on the name tables - get some
> > practical experience with their contents, file any bugs about missing
> > elements, etc. It's possible they're leaning too heavily towards lldb's
> > style of name lookup since they derived from an existing apple
> > implementation there & it'd be good to generalize them where needed.
> 
> gdb has long done the wrong thing with .debug_names.
> https://sourceware.org/bugzilla/show_bug.cgi?id=24820

Ah, thanks for the link - I followed up there with some context/thoughts.

> I don't really know how/why that happened.  However, I wrote patches to
> fix it:
> 
> https://sourceware.org/pipermail/gdb-patches/2023-December/204949.html
> 
> This version of gdb will look at the augmentation string and only
> allow certain indexes to be used.  This is done to avoid known bugs --
> mainly coming from the "old" (current) gdb, but also clang has some
> issues (from memory, it doesn't include parent info).

Ideally that'd be detected by looking at the abbreviation table, rather than
the augmentation string - if parent info is necessary for a usage of the table,
that'd be a generic way to check for it & ensure the unusable indexes are
ignored while not ignoring usable ones.

> Also, gdb relies on its extensions (see below).

Ah, but yeah, if you need extensions, then positive augmentation string
checking seems likely necessary.

(though this starts to feel like websites checking browser versions,
unfortunately :/ )

> When writing the new scanner, I found a few bugs in DWARF related to
> which names appear in the index.  I don't recall offhand what these are,
> and I didn't file them due to the late unpleasantness (sorry).  

No worries - and totally understandable. If they happen to come to mind at any
point, I'd love to hear about them.

> They could probably be dug up by reading the scanner and comparing to the 
> spec.
> 
> gdb will also emit some extensions.  You can see these in the docs patch:
> 
> https://sourceware.org/pipermail/gdb-patches/2023-December/204947.html

Awesome - appreciate the documentation!

> Generally the goal of these is to avoid having to do any DIE reading
> in order to reject a lookup.  Note that this means gdb relies on
> template parameters being in the name -- something we discussed in
> gdb bugzilla a bit.

Yeah, I'd love to figure out how to deal with that better, but don't have
immediate suggestions.

Any sense of how bad the performance is if names without template parameters
(strawman: this could be communicated via another flag on the entry in the
index) did require DWARF parsing to check template parameters? Is that
something that'd be an option? (especially with a flag in the entry, then it'd
only be a runtime cost to those using this naming mechanism - as much as I'd
like to move to that mechanism being normal/the default, perhaps this would be
a safe transition path)

But I guess Google's probably the only one super interested in the simplified
template names at the moment (& we're mostly investing in lldb these days), so
might be unlikely anyone would be signing up to do that work in gdb.

> With these patches, gdb will not generate or use the hash table.
> This is explained here:
> 
> https://sourceware.org/pipermail/gdb-patches/2023-December/204963.html

Oh, that's got some good details/answers some of my questions - thanks!

> I consider this hash table to be essentially useless in general, due to the 
> name canonicalization problem -- while DWARF says that writers should use the 
> system demangling style, (1) this style varies across systems, so it can't 
> truly be relied on; and (2) at least GCC and one other compiler don't 
> actually follow this part of the spec anyway.

Hmm, I missed a step here - perhaps you can help me understand. Maybe,
ultimately, I agree with you here - I've pushed back on the lldb folks relying
on character identical name lookup in the index due to the problems you've
described (there's no real canonical demangling) - but where does DWARF say
that writers should "use the system demangling style"?

> It's important to note, though, that even if the hash was somehow useful, GDB 
> probably still would not use it -- a sorted list of names is needed for 
> completion and performs reasonably well for other lookups, so a hash table is 
> just overhead, IMO.

Oh, that makes 

[Bug debug/99178] Emit .debug_names

2024-01-09 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99178

David Blaikie  changed:

   What|Removed |Added

 CC||dblaikie at gmail dot com

--- Comment #4 from David Blaikie  ---
(In reply to Mark Wielaard from comment #3)
> So if the compiler would emit the .debug_name index would that make any
> link/post-processing steps easier or more efficient?

Right - that's the intent. You can omit the hash table part of .debug_names -
in which case it's just like a newer pubnames/pubtypes - maybe with the
opportunity to have more guaranteed contents (the lack of those guarantees I
think is why debug_gnu_pubnames/types came to be, yeah?).

At least on the lld side, we're working on adding the requisite merging - like
`-Wl,--gdb-index`, except instead of merging debug_gnu_pubnames/pubtypes ->
gdb_index, it merges debug_names -> debug_names.

This is relevant/important/necessary for Split DWARF in particular, where the
linker wouldn't have access to the DWARF to index it anyway (& you don't always
want to run the dwp tool, which would have access to all the DWARF to index it
- but it'd be nice to avoid that in iterative developer scenarios, and save it
only for archival situations) - and even if you do have all the DWARF, it's
certainly faster to merge some tables than to reparse all the DWARF from
scratch.

It'd be great to get GCC/GDB folks take on the name tables - get some practical
experience with their contents, file any bugs about missing elements, etc. It's
possible they're leaning too heavily towards lldb's style of name lookup since
they derived from an existing apple implementation there & it'd be good to
generalize them where needed.

[Bug c++/109114] New: lambdas should be non-pod for ABI

2023-03-13 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109114

Bug ID: 109114
   Summary: lambdas should be non-pod for ABI
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dblaikie at gmail dot com
  Target Milestone: ---

See original bug filed against clang:
https://github.com/llvm/llvm-project/issues/59078
itanium-cxx-abi bug: https://github.com/itanium-cxx-abi/cxx-abi/issues/156

(inverted, so it fails with GCC and passes with Clang) example from the clang
bug: https://godbolt.org/z/45TxsPehe
```
template 
struct Callables : T ... {
  Callables(T ...t) : T(t) ... {}
  using T::operator() ...;
};

inline auto f(int x, char y) {
  Callables callables([x, y](void) {}, [y](int) {});
  static_assert(sizeof(callables) == 8);
  return callables;
}

int main(void) { f(0, 1)(42); }
```

Maybe still an open question about lambdas that don't capture - since they do
have a default ctor, but the spec still says they're non-aggregate.

[Bug c++/107741] Missed member variable name in mangling of externally visible lambdas used in inline initialization of static members

2023-03-06 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107741

--- Comment #2 from David Blaikie  ---
Ping on this? Would love it if someone could check my work/confirm my
diagnosis, even if it's not a priority to fix the bug immediately.

[Bug debug/49130] discrepancies between DW_AT_name and demangler

2023-01-12 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49130

David Blaikie  changed:

   What|Removed |Added

 CC||dblaikie at gmail dot com

--- Comment #12 from David Blaikie  ---
> Note that both DW_AT_name and DW_TAG_template_value_param are
> incorrect.  The demangler gets it right:
> 
>void f(S2)

Yeah, the problem here is that the /type/ is correctly `S2` -
that's the same type no matter how it's written. But the mangling of `f` is
distinct depending on how the expression is written...

I'm not really sure how we should encode that in DWARF - it'd be problematic to
encode a different `S2` instantiation for this context compared to some other
place that names the type differently - in terms of the debugger being able to
treat them as the same type, match declarations and definitions, etc. I guess
S2 could be emitted as an alias/typedef of the
underlying S2?

Or some other way to carry the mangle-equivalent details on the
DW_TAG_template_*_parameter directly?

Though these expression template issues only apply to functions, yeah? Is there
a need to deduplicate function definitions - generally the linker has already
done this & the DWARF describes the function definition - I guess the issue
here is that two different functions will have the same DW_AT_name & confuse
the debugger/user if they're trying to call the functions in an expression
evaluator, etc.

[Bug debug/49312] Make DW_AT_name contain only simple name, no template-id

2023-01-12 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49312

David Blaikie  changed:

   What|Removed |Added

 CC||dblaikie at gmail dot com

--- Comment #4 from David Blaikie  ---
FWIW I've (partially) implemented this in Clang under the flag
`-gsimple-template-names` due to some really large debug info issues with
(especially eigen and tensorflow) expression templates (I saw template names as
long as 50k characters leading to exceeding the 32 bit limit in .debug_str.dwo
sections in dwp files (and gold dwp didn't check for overflow, so this caused
silent corruption)).

There certainly are some issues with it - my approach didn't simplify all names
- certain names aren't easy to roundtrip from the DIE descriptions of the
template parameters (lambdas are a great/difficult example, for instance - the
lambda type DIEs don't have anything about the lambda mangling number, etc, and
maybe should - so even in non-template cases the lambdas could be matched up
between two TUs (lambdas in inline functions are the same type even in
different translation units & should be treated as such))

So there's a bunch of work that'd probably need to be done on template DIE
accuracy/completeness before this feature could be adopted wholesale without
any exemptions, but for the size benefits (especially in expression template
heavy code) I've found it to be worthwhile & we've done some work to flesh out
support for this in lldb as well as identify maybe a couple of gdb bugs related
to this.

I've tried to poke dwarf-discuss about the lambda issue in particular (
http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/2022-August/007117.html
) but no one seems interested in discussing it. So maybe it's something
GCC/Clang/GDB/LLDB folks should discuss more directly together.

Also some recent discussion with Simon Marchi on the gdb list:
https://sourceware.org/pipermail/gdb/2023-January/050496.html

[Bug c++/107741] Missed member variable name in mangling of externally visible lambdas used in inline initialization of static members

2022-11-17 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107741

--- Comment #1 from David Blaikie  ---
Oh, some context - discovered while investigating a related clang bug:
https://github.com/llvm/llvm-project/issues/58819 - so don't check clang for an
example of what's right here, it has different bugs, though I've sent a fix for
that for review.

[Bug c++/107741] New: Missed member variable name in mangling of externally visible lambdas used in inline initialization of static members

2022-11-17 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107741

Bug ID: 107741
   Summary: Missed member variable name in mangling of externally
visible lambdas used in inline initialization of
static members
   Product: gcc
   Version: 13.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dblaikie at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/7514cTh5o
```
struct A {
static constexpr auto x = [] {
return 1;
};
};
template 
struct B {
static constexpr auto x = [] {
return 1;
};
};
template 
struct C {
static int x;
};
void side_effect();
template 
int C::x = (side_effect(), [] { return 1; }());
template int C::x;
void f() {
A::x();
B::x();
}
```
GCC produces these manglings:
```
A::{lambda()#1}::operator()() const
_ZNK1AUlvE_clEv

B::{lambda()#3}::operator()() const
_ZNK1BIiEUlvE1_clEv

C::x::{lambda()#1}::operator()() const
_ZNK1CIiE1xMUlvE_clEv
```

I believe in the first two cases, the member variable scope ("::x") is missing.

Oh, and it looks like the lambda numbering is off - B's lambda is 1 within its
scope (either the type or the member) - so I guess that needs to be fixed
too/scoping the numbering to within the member along with the mangling having
that scoping.

[Bug c/89549] [10/11/12/13 Regression] -Wmisleading-indentation is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers

2022-10-10 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89549

--- Comment #26 from David Blaikie  ---
FWIW I'm not sure it's a pragma I'd want, but it might be sufficient (put the
pragma at the start of very long/autogenerated files) - I'd have thought what
some folks (myself/LLVM included, I think) is a version of the warning that is
"best effort" and otherwise quiet.

"Tell me when you know I have misleading indentation, otherwise say nothing" -
which is how most warnings work, basically - they all have false negatives.

[Bug debug/60833] Inheritance via typedef skips the typedef

2022-10-04 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60833

--- Comment #3 from David Blaikie  ---
FWIW, bug on the GDB side seems to have been fixed (
https://sourceware.org/bugzilla/show_bug.cgi?id=16841 ) - might be nice to fix
the GCC side too. (though, admittedly, I don't know that this extra debug info
provides much value at the moment - I think GDB mostly looks straight through
typedefs)

[Bug c/89549] [10/11/12/13 Regression] -Wmisleading-indentation is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers

2022-09-08 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89549

David Blaikie  changed:

   What|Removed |Added

 CC||dblaikie at gmail dot com

--- Comment #23 from David Blaikie  ---
FWIW, the inability to disable this note has caused Clang to disable the
warning due to the noise. ( https://reviews.llvm.org/D132914 )

It'd be nice to have a way to enable the warning as "best effort" - knowing
that some files are too long to get checking.

(but also - it'd be nice if the warning were implemented in such a way that it
could scale up to indefinitely long files - it seems like that should be
possible to have a scalable implementation of the warning? (at least a version
that's linear in the number of lines in the file/or the number of lines in long
nested scopes?))

[Bug c++/87729] Please include -Woverloaded-virtual in -Wall

2022-06-24 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87729

David Blaikie  changed:

   What|Removed |Added

 CC||dblaikie at gmail dot com

--- Comment #7 from David Blaikie  ---
FWIW, I implemented (or at least tuned) overloaded-virtual in Clang - it
doesn't quite match GCC's behavior. (specifically it doesn't warn on two
overloads within the same class - it specifically warns on the case where a
user might've mismatched what was intended to be an override but instead became
an overload).

At least that's my recollection.

[Bug libstdc++/101227] Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer

2021-06-27 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101227

David Blaikie  changed:

   What|Removed |Added

 CC||dblaikie at gmail dot com

--- Comment #2 from David Blaikie  ---
My guess, libstdc++'s std::optional uses is_default_constructible
unconditionally in some way, instantiating the template while the type
parameter is incomplete (because the nested class is incomplete until the
enclosing class is complete?).

Essentially something like this:

https://godbolt.org/z/6eohMofdb

[Bug c/82134] warn_unused_result triggers on empty structs even when they are used

2021-05-15 Thread dblaikie at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134

David Blaikie  changed:

   What|Removed |Added

 CC||dblaikie at gmail dot com

--- Comment #6 from David Blaikie  ---
For what it's worth, this is being actively worked around in gmock here:
https://github.com/google/googletest/blob/662fe38e44900c007eccb65a5d2ea19df7bd520e/googlemock/include/gmock/gmock-more-actions.h#L295