This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix PR 18314


An old-style definition of a built-in function needs to suppress the
built-in declaration, since we cannot validate the argument list
against the built-in prototype.

Bootstrapped sparc-sun-solaris2.8, applied mainline and branch.

zw

        * c-decl.c (diagnose_mismatched_decls): Also discard a
        built-in if we encounter an old-style definition with the
        same name.
testsuite:
        * gcc.dg/builtins-30.c: New testcase.

===================================================================
Index: c-decl.c
--- c-decl.c	21 Jan 2004 10:35:01 -0000	1.470.4.1
+++ c-decl.c	23 Jan 2004 04:46:00 -0000
@@ -1029,11 +1029,15 @@ diagnose_mismatched_decls (tree newdecl,
      extern-inline definition supersedes the extern-inline definition.  */
   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
     {
-      if (DECL_BUILT_IN (olddecl) && !TREE_PUBLIC (newdecl))
+      /* If you declare a built-in function name as static, or
+	 define the built-in with an old-style definition (so we
+	 can't validate the argument list) the built-in definition is
+	 overridden, but optionally warn this was a bad choice of name.  */
+      if (DECL_BUILT_IN (olddecl)
+	  && (!TREE_PUBLIC (newdecl)
+	      || (DECL_INITIAL (newdecl)
+		  && !TYPE_ARG_TYPES (TREE_TYPE (newdecl)))))
 	{
-	  /* If you declare a built-in function name as static, the
-	     built-in definition is overridden,
-	     but optionally warn this was a bad choice of name.  */
 	  if (warn_shadow)
 	    warning ("%Jshadowing built-in function '%D'", newdecl, newdecl);
 	  /* Discard the old built-in function.  */
===================================================================
Index: testsuite/gcc.dg/builtins-30.c
--- testsuite/gcc.dg/builtins-30.c	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/builtins-30.c	23 Jan 2004 04:46:02 -0000
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wshadow" } */
+
+extern double strtod (const char *, char **);
+#define UNUSED __attribute__ ((unused))
+
+/* A built-in function may be overridden by an old-style definition
+   specifying too few arguments... */
+double nan ()
+{
+  return strtod ("nan", 0);  /* { dg-warning "shadowing built-in" } */
+}
+
+/* the right number, but the wrong type, arguments... */
+float nanf (foo)
+     int foo UNUSED;
+{
+  return strtod ("nan", 0);  /* { dg-warning "shadowing built-in" } */
+}
+
+/* or too many arguments.  */
+long double nanl (foo, bar)
+     const char *foo UNUSED;
+     int bar UNUSED;
+{
+  return strtod ("nan", 0);  /* { dg-warning "shadowing built-in" } */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]