public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53875] New: calls to const functions are eliminated at -O0
@ 2012-07-06 14:09 James.H.McKim at nasa dot gov
  2012-07-09  8:42 ` [Bug c++/53875] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: James.H.McKim at nasa dot gov @ 2012-07-06 14:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53875

             Bug #: 53875
           Summary: calls to const functions are eliminated at -O0
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: James.H.McKim@nasa.gov


Compiler version 4.6.3.
System: ubuntu 12.1

When source containing a call to a const function is compiled, that function's
invocation is always (regardless of -O level) eliminated if the returned result
is discarded. That action is an optimization, and when no optimization is
specified, having it happen is surprising.

If the compiler is intended to always eliminate, it would be helpful if there
was a diagnostic indicating the elimination. For instance, instead of the
warning "statement has no effect", maybe "statement has no effect,
eliminating".


The code was compiled with the command:

g++ -O0 -S -o t1b.lst t1b.cxx


The example code (t1b.cxx):

extern int pthread_self (void) __attribute__ ((__const__));

int main() {

  // Demonstrate the compiler doesn't emit this call.
  pthread_self();

  // A workaround.
  // volatile int x = pthread_self();

  return 0;
}


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

end of thread, other threads:[~2021-11-29 11:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
2012-07-09  8:42 ` [Bug c++/53875] " rguenth at gcc dot gnu.org
2021-07-22 18:47 ` [Bug middle-end/53875] " pinskia at gcc dot gnu.org
2021-11-29  2:53 ` pinskia at gcc dot gnu.org
2021-11-29  2:56 ` pinskia at gcc dot gnu.org
2021-11-29  3:00 ` pinskia at gcc dot gnu.org
2021-11-29 11:31 ` roger at nextmovesoftware dot com

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