public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32099]  New: a constant value is said to be not constant
@ 2007-05-26 18:15 andrei dot kouznetsov at gmail dot com
  2007-05-26 18:27 ` [Bug c/32099] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andrei dot kouznetsov at gmail dot com @ 2007-05-26 18:15 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1360 bytes --]

when I'm trying to compile the program
============================
#include <math.h>

static double s = sin(0.0);

int main(){
        return 0;
}
============================
with gcc t.c, the compiler produces the warnings

t.c:3: warning: initializer element is not constant
t.c:3: warning: (near initialization for ‘s’)
t.c:3: warning: ‘s’ defined but not used

I'm worried about the first warning, since sin(0) is constant

gcc -v generates:
=======================================
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)


-- 
           Summary: a constant value is said to be not constant
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: andrei dot kouznetsov at gmail dot com


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


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

* [Bug c/32099] a constant value is said to be not constant
  2007-05-26 18:15 [Bug c/32099] New: a constant value is said to be not constant andrei dot kouznetsov at gmail dot com
@ 2007-05-26 18:27 ` pinskia at gcc dot gnu dot org
  2007-05-26 18:47 ` andrei dot kouznetsov at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-26 18:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-05-26 18:26 -------
No, sin(0) is not constant in C.  C has specific rules about constant
expression.  You can use __builtin_sin(0) to always get the constant folding.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c/32099] a constant value is said to be not constant
  2007-05-26 18:15 [Bug c/32099] New: a constant value is said to be not constant andrei dot kouznetsov at gmail dot com
  2007-05-26 18:27 ` [Bug c/32099] " pinskia at gcc dot gnu dot org
@ 2007-05-26 18:47 ` andrei dot kouznetsov at gmail dot com
  2007-05-28 12:54 ` manu at gcc dot gnu dot org
  2007-06-10  3:23 ` [Bug middle-end/32099] not constant folding sin pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: andrei dot kouznetsov at gmail dot com @ 2007-05-26 18:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from andrei dot kouznetsov at gmail dot com  2007-05-26 18:47 -------
Ok, but __builtin_sin(M_PI) is not constant again


-- 


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


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

* [Bug c/32099] a constant value is said to be not constant
  2007-05-26 18:15 [Bug c/32099] New: a constant value is said to be not constant andrei dot kouznetsov at gmail dot com
  2007-05-26 18:27 ` [Bug c/32099] " pinskia at gcc dot gnu dot org
  2007-05-26 18:47 ` andrei dot kouznetsov at gmail dot com
@ 2007-05-28 12:54 ` manu at gcc dot gnu dot org
  2007-06-10  3:23 ` [Bug middle-end/32099] not constant folding sin pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-05-28 12:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2007-05-28 12:54 -------
Worse, with __builtin_sin(M_PI), I get an error:

test.c:2: error: initializer element is not constant

Maybe this is fixed now in GCC 4.3 by using MPFR.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


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

* [Bug middle-end/32099] not constant folding sin
  2007-05-26 18:15 [Bug c/32099] New: a constant value is said to be not constant andrei dot kouznetsov at gmail dot com
                   ` (2 preceding siblings ...)
  2007-05-28 12:54 ` manu at gcc dot gnu dot org
@ 2007-06-10  3:23 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-10  3:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-06-10 03:23 -------
This is an extension that GCC allows some constant folding with some functions.

So this is just a missed optimization of not constant folding sin.

And yes this is fixed in 4.3.0 by the use of MPFR.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|c                           |middle-end
           Keywords|                            |missed-optimization
         Resolution|                            |FIXED
            Summary|a constant value is said to |not constant folding sin
                   |be not constant             |
   Target Milestone|---                         |4.3.0


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


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

end of thread, other threads:[~2007-06-10  3:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-26 18:15 [Bug c/32099] New: a constant value is said to be not constant andrei dot kouznetsov at gmail dot com
2007-05-26 18:27 ` [Bug c/32099] " pinskia at gcc dot gnu dot org
2007-05-26 18:47 ` andrei dot kouznetsov at gmail dot com
2007-05-28 12:54 ` manu at gcc dot gnu dot org
2007-06-10  3:23 ` [Bug middle-end/32099] not constant folding sin pinskia at gcc dot gnu dot 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).