public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104081] New: Variable optimized out despite -Og
@ 2022-01-18  8:32 matthias at urlichs dot de
  2022-01-18  8:34 ` [Bug c++/104081] " matthias at urlichs dot de
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: matthias at urlichs dot de @ 2022-01-18  8:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081

            Bug ID: 104081
           Summary: Variable optimized out despite -Og
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matthias at urlichs dot de
  Target Milestone: ---

I expect the optimizer, when confronted with "-Og", to keep my variables
debuggable.

(I also expect (of me) to not make terminally stupid mistakes like the one
exhibited here, but that's a different problem …)

// "data" is a std::string_view
(gdb) l
19                      if(data.length() == 0)
20                              throw_invalid("empty",data);
21              }
22              for (const auto& c : data) {
23                      if ('0' < c || '9' > c)
24                              throw_invalid("not a number",data);
25                      val = val*10 + c-'0';
26              }
27              if(neg)
28                      val = -val;
(gdb) p data
$1 = <optimized out>
(gdb) p c
$2 = <optimized out>
(gdb) q

Options: g++-12 -march=native -Og -g -xc++ -std=c++17 …

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/104081] Variable optimized out despite -Og
  2022-01-18  8:32 [Bug c++/104081] New: Variable optimized out despite -Og matthias at urlichs dot de
@ 2022-01-18  8:34 ` matthias at urlichs dot de
  2022-01-18  8:37 ` [Bug middle-end/104081] " pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: matthias at urlichs dot de @ 2022-01-18  8:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081

--- Comment #1 from Matthias Urlichs <matthias at urlichs dot de> ---
current line is 24, after "throw_invalid" has called abort()

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/104081] Variable optimized out despite -Og
  2022-01-18  8:32 [Bug c++/104081] New: Variable optimized out despite -Og matthias at urlichs dot de
  2022-01-18  8:34 ` [Bug c++/104081] " matthias at urlichs dot de
@ 2022-01-18  8:37 ` pinskia at gcc dot gnu.org
  2022-01-18  8:51 ` matthias at urlichs dot de
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-18  8:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you attach the original source?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/104081] Variable optimized out despite -Og
  2022-01-18  8:32 [Bug c++/104081] New: Variable optimized out despite -Og matthias at urlichs dot de
  2022-01-18  8:34 ` [Bug c++/104081] " matthias at urlichs dot de
  2022-01-18  8:37 ` [Bug middle-end/104081] " pinskia at gcc dot gnu.org
@ 2022-01-18  8:51 ` matthias at urlichs dot de
  2022-01-18  9:46 ` rguenth at gcc dot gnu.org
  2022-01-18 10:13 ` matthias at urlichs dot de
  4 siblings, 0 replies; 6+ messages in thread
From: matthias at urlichs dot de @ 2022-01-18  8:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081

--- Comment #3 from Matthias Urlichs <matthias at urlichs dot de> ---
Sure.

gcc -Og -g -std=c++17 -lstdc++ /tmp/test.cpp


#include <string_view>
#include <string>

void throw_invalid(const char *a, std::string_view b) {
    (void)a; (void)b;
    throw;
}

int64_t str_atoi(std::string_view data)
{
    const std::string_view odata = data;

    int64_t val = 0;
    bool neg;

    if(data.length() == 0)
        throw_invalid("empty",odata);
    neg = data.front() == '-';
    if(neg) {
        data.remove_prefix(1);
        if(data.length() == 0)
            throw_invalid("empty",data);
    }
    for (const auto& c : data) {
        if (c < '0' || '9' < c)
            throw_invalid("not a number",odata);
        val = val*10 + c-'0';
    }
    if(neg)
        val = -val;
    return val;
}

int main() {
    volatile int x =  str_atoi("nope");
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/104081] Variable optimized out despite -Og
  2022-01-18  8:32 [Bug c++/104081] New: Variable optimized out despite -Og matthias at urlichs dot de
                   ` (2 preceding siblings ...)
  2022-01-18  8:51 ` matthias at urlichs dot de
@ 2022-01-18  9:46 ` rguenth at gcc dot gnu.org
  2022-01-18 10:13 ` matthias at urlichs dot de
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-18  9:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
when I break at line 24 the data is still there but it's lost when unwinding
frames from the SIGABRT:

(gdb) bt
#0  0x00007ffff70cc18b in raise () from /lib64/libc.so.6
#1  0x00007ffff70cd585 in abort () from /lib64/libc.so.6
#2  0x00007ffff7a66016 in ?? () from /usr/lib64/libstdc++.so.6
#3  0x00007ffff7a718dc in ?? () from /usr/lib64/libstdc++.so.6
#4  0x00007ffff7a71947 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5  0x00007ffff7a71c3d in __cxa_rethrow () from /usr/lib64/libstdc++.so.6
#6  0x000000000040055f in throw_invalid (a=a@entry=0x4006aa "not a number", 
    b=...) at t.C:6
#7  0x00000000004005f8 in str_atoi (data=...) at t.C:26
#8  0x0000000000400610 in main () at /usr/include/c++/11/bits/char_traits.h:371

is that what you mean?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/104081] Variable optimized out despite -Og
  2022-01-18  8:32 [Bug c++/104081] New: Variable optimized out despite -Og matthias at urlichs dot de
                   ` (3 preceding siblings ...)
  2022-01-18  9:46 ` rguenth at gcc dot gnu.org
@ 2022-01-18 10:13 ` matthias at urlichs dot de
  4 siblings, 0 replies; 6+ messages in thread
From: matthias at urlichs dot de @ 2022-01-18 10:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081

--- Comment #5 from Matthias Urlichs <matthias at urlichs dot de> ---
> when I break at line 24 the data is still there but it's lost 
> when unwinding frames from the SIGABRT:

Yes, that's exactly the problem.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-18 10:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18  8:32 [Bug c++/104081] New: Variable optimized out despite -Og matthias at urlichs dot de
2022-01-18  8:34 ` [Bug c++/104081] " matthias at urlichs dot de
2022-01-18  8:37 ` [Bug middle-end/104081] " pinskia at gcc dot gnu.org
2022-01-18  8:51 ` matthias at urlichs dot de
2022-01-18  9:46 ` rguenth at gcc dot gnu.org
2022-01-18 10:13 ` matthias at urlichs dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).