public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97553] New: [missed optimization] constexprness not noticed when UBsan enabled
@ 2020-10-23 16:27 eyalroz at technion dot ac.il
  2020-10-23 16:34 ` [Bug c++/97553] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: eyalroz at technion dot ac.il @ 2020-10-23 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97553
           Summary: [missed optimization] constexprness not noticed when
                    UBsan enabled
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eyalroz at technion dot ac.il
  Target Milestone: ---

(GodBolt example: https://godbolt.org/z/Kvan5c)

Consider the following code:

  #include <string_view>

  constexpr std::string_view f() { return "hello"; }

  static constexpr std::string_view g() {
      auto x { f() };
      return x.substr(1, 3);
  } 

  int foo() { return g().length(); }

if you compile it with flags `--std=c++17 -O3`, it results in a pleasant:

  foo():
          mov     eax, 3
          ret

but if you also enabled undefined-behavior sanitization, i.e. `--std=c++17
-fsanitize=undefined -O3`, then you get a much longer program with UB-related
instrumentation - which is never used.

I'm not sure if it's because some optimizations are disabled with UBsan, in
which case this might be a "misfeature", or whether they're enabled but the
optimization is just missed.

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

end of thread, other threads:[~2023-04-26 13:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 16:27 [Bug c++/97553] New: [missed optimization] constexprness not noticed when UBsan enabled eyalroz at technion dot ac.il
2020-10-23 16:34 ` [Bug c++/97553] " jakub at gcc dot gnu.org
2020-10-26 16:50 ` mpolacek at gcc dot gnu.org
2020-10-26 19:40 ` eyalroz at technion dot ac.il
2020-10-26 19:45 ` jakub at gcc dot gnu.org
2020-10-26 20:46 ` eyalroz at technion dot ac.il
2023-02-17 20:21 ` cvs-commit at gcc dot gnu.org
2023-03-02 19:05 ` cvs-commit at gcc dot gnu.org
2023-04-26 13:18 ` ppalka at gcc dot gnu.org

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).