Bug 15642 - NAN Is Not a Constant Because __APPLE_CC__ is Not Defined (OK in Apple 3.3.0)
Summary: NAN Is Not a Constant Because __APPLE_CC__ is Not Defined (OK in Apple 3.3.0)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 4.2.0
Assignee: Andrew Pinski
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-25 01:01 UTC by Flash Sheridan
Modified: 2006-01-19 17:18 UTC (History)
2 users (show)

See Also:
Host:
Target: *-*-darwin[0-7]
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-16 02:02:17


Attachments
Pre-processed source, specifying full path to math.h (1.27 KB, application/x-gzip)
2004-05-25 01:04 UTC, Flash Sheridan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Flash Sheridan 2004-05-25 01:01:35 UTC
The following code give "error: initializer element is not constant" with gcc 3.4.0 in C99 mode on 
OSX 10.3.3.  It compiled as expected with gcc 3.3 from Apple's X-Code 1.2.  Section 7.12[5] of the C99 
spec says that NAN expands to a constant expression.

#include <math.h>
	const volatile static float arg2_float_23 = NAN;

    Similar results when I hard-coded the path to the 3.4.0 version of math.h; session below, and I'll 
attach the preprocessed file, which did indeed fail to define NAN as a constant.
    The problem seems to be that __APPLE_CC__ is no longer defined in 3.4.0 (though __APPLE__ still is); 
but the math.h with 3.4.0 (built from the gnu sources) still depends on it:

#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)
#define NAN		__builtin_nanf("0x7fc00000") /* Constant expression, can be used as initializer. */
#else
#define NAN		__nan( )
#endif

    Adding "-D__APPLE_CC__=1642" to the command line worked around the problem.

    Here are the diffs between the predefined macros in the two versions; the other ones look fairly 
innocuous, except perhaps for __GXX_ABI_VERSION, which I don't understand.

3d2
< #define __APPLE_CC__ 1640
10a10,11
> #define __DBL_HAS_INFINITY__ 1
> #define __DBL_HAS_QUIET_NAN__ 1
24a26,27
> #define __FLT_HAS_INFINITY__ 1
> #define __FLT_HAS_QUIET_NAN__ 1
33c36
< #define __GNUC_MINOR__ 3
---
> #define __GNUC_MINOR__ 4
36c39
< #define __GXX_ABI_VERSION 102
---
> #define __GXX_ABI_VERSION 1002
40a44,45
> #define __LDBL_HAS_INFINITY__ 1
> #define __LDBL_HAS_QUIET_NAN__ 1
63c68
< #define __VERSION__ "3.3 20030304 (Apple Computer, Inc. build 1640)"
---
> #define __VERSION__ "3.4.0"


- - -


 /usr/local/gcc34/bin/gcc -std=c99 -pedantic -lmx -funsigned-char -v -save-temps  -c ../c/noerror/
bugfiles/gcc_bugfiles/warn/NAN_not_const-full-path.c
Reading specs from /usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/specs
Configured with: configure --prefix=/usr/local/gcc34
Thread model: posix
gcc version 3.4.0
 /usr/local/gcc34/libexec/gcc/powerpc-apple-darwin7.3.0/3.4.0/cc1 -E -quiet -v -D__DYNAMIC__ ../
c/noerror/bugfiles/gcc_bugfiles/warn/NAN_not_const-full-path.c -fPIC -std=c99 -pedantic 
-funsigned-char -o NAN_not_const-full-path.i
ignoring nonexistent directory "/usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/../../../../
powerpc-apple-darwin7.3.0/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/gcc34/include
 /usr/local/gcc34/lib/gcc/powerpc-apple-darwin7.3.0/3.4.0/include
 /usr/include
End of search list.
 /usr/local/gcc34/libexec/gcc/powerpc-apple-darwin7.3.0/3.4.0/cc1 -fpreprocessed NAN_not_const-
full-path.i -fPIC -quiet -dumpbase NAN_not_const-full-path.c -auxbase NAN_not_const-full-path 
-pedantic -std=c99 -version -funsigned-char -o NAN_not_const-full-path.s
GNU C version 3.4.0 (powerpc-apple-darwin7.3.0)
        compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
../c/noerror/bugfiles/gcc_bugfiles/warn/NAN_not_const-full-path.c:2: error: initializer element is not 
constant
Comment 1 Flash Sheridan 2004-05-25 01:04:02 UTC
Created attachment 6375 [details]
Pre-processed source, specifying full path to math.h
Comment 2 Andrew Pinski 2004-05-25 01:19:01 UTC
Confirmed, please report this to Apple also as this is a bug in Apple's headers, we can fixincludes them.
Comment 3 Andrew Pinski 2004-05-25 01:47:41 UTC
We can replace the check for __APPLE_CC__ with a check for __GNUC__, and __GNUC_MINOR__.
Comment 4 Flash Sheridan 2004-05-25 02:03:24 UTC
Apple bug #3666675:
<https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa/6/wo/MPeQbCnDgtJADiIQLAsBN0/
7.27>
Comment 5 Andrew Pinski 2004-05-28 00:16:30 UTC
I think I have a fixincl fix but I cannot test it until I build autogen which it fails for me.
Here is the inclhack.def part which I created:
/*
 * Fixup Darwin's broken check for __builtin_nanf.
 */ 
    
fix = {
   hackname = broken_nan;
    files    = "architecture/ppc/math.h";
    files    = "architecture/i386/math.h";
    select   = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)"
     
    c_fix     = format; 
    c_fxi_arg = "#if defined(__GNUC__) && ((__GNUC__ > 4)||((__GNUC__ > 3) && (__GNUC_MINOR__ >= 
3)))"
    
    test_text = "#if defined(__APPLE_CC__) && (__APPLE_CC__ >= 1345)"
}; 
Comment 6 Andrew Pinski 2005-05-27 00:00:25 UTC
I should try this patch soon again now I can regenerate fixincludes.
Comment 7 Andrew Pinski 2005-07-26 03:26:55 UTC
I will take of this soon.
Comment 8 Andrew Pinski 2005-07-26 23:54:18 UTC
Hmm, this no longer works because we fixinclude architecture/ppc/math.h a different way now.
I can no longer fix this.
Comment 9 Andrew Pinski 2005-07-27 00:01:42 UTC
This is also radar 4194286 now because I was tried of this not being fixed.
Comment 10 Andrew Pinski 2005-08-09 18:12:31 UTC
I have a fix which I am about to submit.
Comment 11 Andrew Pinski 2006-01-19 17:18:36 UTC
Subject: Bug 15642

Author: pinskia
Date: Thu Jan 19 17:18:29 2006
New Revision: 109973

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109973
Log:
2006-01-19  Andrew Pinski  <pinskia@physics.uc.edu>

        PR target/15642
        * inclhack.def (AAB_darwin7_9_long_double_funcs [replace]): Define
        __APPLE_CC_ as 1345.
        (broken_nan): New.
        * fixincl.x: Regenerate.


Modified:
    trunk/fixincludes/ChangeLog
    trunk/fixincludes/fixincl.x
    trunk/fixincludes/inclhack.def

Comment 12 Andrew Pinski 2006-01-19 17:18:54 UTC
Fixed in 4.2.0.