Bug 103323 - Front end simplifies sin although no header included
Summary: Front end simplifies sin although no header included
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-18 20:29 UTC by Thomas Koenig
Modified: 2021-11-18 21:20 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2021-11-18 20:29:12 UTC
$ cat a.c
double 
sin(double x) {
  return x/2 + x;
}

double
foo(double x) {
  return 1 - sin(-x);
}
$ gcc -S -fdump-tree-original a.c 
$ cat a.c.005t.original 

;; Function sin (null)
;; enabled by -tree-original


{
  return x / 2.0e+0 + x;
}


;; Function foo (null)
;; enabled by -tree-original


{
  return sin (x) + 1.0e+0;
}

$ gcc -v
Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/ig25/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Ziel: x86_64-pc-linux-gnu
Konfiguriert mit: ../trunk/configure --prefix=/home/ig25 --enable-languages=c,c++,fortran --enable-maintainer-mode
Thread-Modell: posix
Unterstützte LTO-Kompressionsalgorithmen: zlib
gcc-Version 12.0.0 20211116 (experimental) [master revision e87559d202d:f4e6da6e8ac:36ec54aac7da134441c83248e14825381b8d6f17] (GCC) 

The sin(x) in the tree dump should be sin(-x).
Comment 1 Andrew Pinski 2021-11-18 20:39:01 UTC
sin is a reserved symbol in c, you need to use -fno-builtins if you don't want the optimization.
Comment 2 Thomas Koenig 2021-11-18 21:20:39 UTC
(In reply to Andrew Pinski from comment #1)
> sin is a reserved symbol in c, you need to use -fno-builtins if you don't
> want the optimization.

Ah, correct.

I also see that PR 51437 has the request for a warning.