OSDN Git Service

Document compatibility with earlier ProPolice implementation.
[pf3gnuchains/gcc-fork.git] / gcc / c-cppbuiltin.c
index 84bd6f5..9020e0b 100644 (file)
@@ -1,5 +1,5 @@
 /* Define builtin-in macros for the C family front ends.
-   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -15,14 +15,15 @@ for more details.
 
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "version.h"
 #include "flags.h"
 #include "real.h"
 #include "c-common.h"
@@ -31,6 +32,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "except.h"            /* For USING_SJLJ_EXCEPTIONS.  */
 #include "toplev.h"
 #include "tm_p.h"              /* Target prototypes.  */
+#include "target.h"
 
 #ifndef TARGET_OS_CPP_BUILTINS
 # define TARGET_OS_CPP_BUILTINS()
@@ -52,6 +54,7 @@ static void builtin_define_with_int_value (const char *, HOST_WIDE_INT);
 static void builtin_define_with_hex_fp_value (const char *, tree,
                                              int, const char *,
                                              const char *);
+static void builtin_define_stdint_macros (void);
 static void builtin_define_type_max (const char *, tree, int);
 static void builtin_define_type_precision (const char *, tree);
 static void builtin_define_float_constants (const char *, const char *,
@@ -216,7 +219,12 @@ builtin_define_float_constants (const char *name_prefix, const char *fp_suffix,
   /* The difference between 1 and the least value greater than 1 that is
      representable in the given floating point type, b**(1-p).  */
   sprintf (name, "__%s_EPSILON__", name_prefix);
-  sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b);
+  if (fmt->pnan < fmt->p)
+    /* This is an IBM extended double format, so 1.0 + any double is
+       representable precisely.  */
+      sprintf (buf, "0x1p%d", (fmt->emin - fmt->p) * fmt->log2_b);
+    else      
+      sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b);
   builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
 
   /* For C++ std::numeric_limits<T>::denorm_min.  The minimum denormalized
@@ -256,10 +264,9 @@ define__GNUC__ (void)
      ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?  */
   const char *q, *v = version_string;
 
-  while (*v && ! ISDIGIT (*v))
+  while (*v && !ISDIGIT (*v))
     v++;
-  if (!*v || (v > version_string && v[-1] != '-'))
-    abort ();
+  gcc_assert (*v && (v <= version_string || v[-1] == '-'));
 
   q = v;
   while (ISDIGIT (*v))
@@ -268,8 +275,8 @@ define__GNUC__ (void)
   if (c_dialect_cxx ())
     builtin_define_with_value_n ("__GNUG__", q, v - q);
 
-  if (*v != '.' || !ISDIGIT (v[1]))
-    abort ();
+  gcc_assert (*v == '.' && ISDIGIT (v[1]));
+  
   q = ++v;
   while (ISDIGIT (*v))
     v++;
@@ -277,8 +284,7 @@ define__GNUC__ (void)
 
   if (*v == '.')
     {
-      if (!ISDIGIT (v[1]))
-       abort ();
+      gcc_assert (ISDIGIT (v[1]));
       q = ++v;
       while (ISDIGIT (*v))
        v++;
@@ -287,8 +293,24 @@ define__GNUC__ (void)
   else
     builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", "0", 1);
 
-  if (*v && *v != ' ' && *v != '-')
-    abort ();
+  gcc_assert (!*v || *v == ' ' || *v == '-');
+}
+
+/* Define macros used by <stdint.h>.  Currently only defines limits
+   for intmax_t, used by the testsuite.  */
+static void
+builtin_define_stdint_macros (void)
+{
+  int intmax_long;
+  if (intmax_type_node == long_long_integer_type_node)
+    intmax_long = 2;
+  else if (intmax_type_node == long_integer_type_node)
+    intmax_long = 1;
+  else if (intmax_type_node == integer_type_node)
+    intmax_long = 0;
+  else
+    gcc_unreachable ();
+  builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node, intmax_long);
 }
 
 /* Hook that registers front end and target-specific built-ins.  */
@@ -306,7 +328,7 @@ c_cpp_builtins (cpp_reader *pfile)
 
   if (c_dialect_cxx ())
     {
-      if (SUPPORTS_ONE_ONLY)
+      if (flag_weak && SUPPORTS_ONE_ONLY) 
        cpp_define (pfile, "__GXX_WEAK__=1");
       else
        cpp_define (pfile, "__GXX_WEAK__=0");
@@ -330,7 +352,7 @@ c_cpp_builtins (cpp_reader *pfile)
        different from system to system.  */
     builtin_define_with_int_value ("__GXX_ABI_VERSION", 999999);
   else if (flag_abi_version == 1)
-    /* Due to an historical accident, this version had the value
+    /* Due to a historical accident, this version had the value
        "102".  */
     builtin_define_with_int_value ("__GXX_ABI_VERSION", 102);
   else
@@ -352,6 +374,9 @@ c_cpp_builtins (cpp_reader *pfile)
 
   builtin_define_type_precision ("__CHAR_BIT__", char_type_node);
 
+  /* stdint.h (eventually) and the testsuite need to know these.  */
+  builtin_define_stdint_macros ();
+
   /* float.h needs to know these.  */
 
   builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
@@ -408,6 +433,21 @@ c_cpp_builtins (cpp_reader *pfile)
   if (c_dialect_objc () && flag_next_runtime)
     cpp_define (pfile, "__NEXT_RUNTIME__");
 
+  /* Show the availability of some target pragmas.  */
+  if (flag_mudflap || targetm.handle_pragma_redefine_extname)
+    cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME");
+
+  if (targetm.handle_pragma_extern_prefix)
+    cpp_define (pfile, "__PRAGMA_EXTERN_PREFIX");
+
+  /* Make the choice of the stack protector runtime visible to source code.
+     The macro names and values here were chosen for compatibility with an
+     earlier implementation, i.e. ProPolice.  */
+  if (flag_stack_protect == 2)
+    cpp_define (pfile, "__SSP_ALL__=2");
+  else if (flag_stack_protect == 1)
+    cpp_define (pfile, "__SSP__=1");
+
   /* A straightforward target hook doesn't work, because of problems
      linking that hook's body when part of non-C front ends.  */
 # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
@@ -417,6 +457,15 @@ c_cpp_builtins (cpp_reader *pfile)
   TARGET_CPU_CPP_BUILTINS ();
   TARGET_OS_CPP_BUILTINS ();
   TARGET_OBJFMT_CPP_BUILTINS ();
+
+  /* Support the __declspec keyword by turning them into attributes.
+     Note that the current way we do this may result in a collision
+     with predefined attributes later on.  This can be solved by using
+     one attribute, say __declspec__, and passing args to it.  The
+     problem with that approach is that args are not accumulated: each
+     new appearance would clobber any existing args.  */
+  if (TARGET_DECLSPEC)
+    builtin_define ("__declspec(x)=__attribute__((x))");
 }
 
 /* Pass an object-like macro.  If it doesn't lie in the user's
@@ -578,7 +627,7 @@ builtin_define_type_max (const char *macro, tree type, int is_long)
     case 32:   idx = 4; break;
     case 64:   idx = 6; break;
     case 128:  idx = 8; break;
-    default:    abort ();
+    default:    gcc_unreachable ();
     }
 
   value = values[idx + TYPE_UNSIGNED (type)];