Bug 38943 - Optimization removes trapping instruction
Summary: Optimization removes trapping instruction
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-23 08:55 UTC by Uroš Bizjak
Modified: 2022-10-01 23:58 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2021-12-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2009-01-23 08:55:15 UTC
Following test:

--cut here--
#define _GNU_SOURCE
#include <fenv.h>
#include <signal.h>
#include <stdlib.h>

static void foo (int sig)
{
  exit (0);
}

float __attribute__((noinline)) test (float x) { return 2.0f / x; };
  
int main()
{
  signal (SIGFPE, foo);

  feclearexcept (FE_ALL_EXCEPT);
  feenableexcept (FE_INEXACT);

  test (3.0f);

  abort ();
}
--cut here--

aborts when compiled with optimizations, since the call to a procedure with a trapping insn is removed.

$ gcc -O2 -fnon-call-exceptions -ftrapping-math -lm sf.c
$ ./a.out
Aborted

$ gcc -lm sf.c
$ ./a.out
$ [...works OK...]

A wild guess is to blame tree optimizers, since in 123t.optimized we already have the call removed:

main ()
{
<bb 2>:
  signal (8, foo);
  feclearexcept (61);
  feenableexcept (32);
  abort ();

}
Comment 1 Richard Biener 2009-01-23 09:21:17 UTC
FENV access is not implemented.
Comment 2 Andrew Pinski 2021-12-24 04:48:59 UTC
I think the test is invalid as you can still remove trapping math if the result is not used; even with FENV access implemented.