re PR c/16666 (dremf type conflict)
authorJoseph Myers <joseph@codesourcery.com>
Sat, 30 Oct 2004 08:50:31 +0000 (09:50 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sat, 30 Oct 2004 08:50:31 +0000 (09:50 +0100)
PR c/16666
* c-decl.c (start_function): Don't check for DECL_BUILT_IN when
determining whether to copy parameter types from a previous
prototype declaration.

testsuite:
* gcc.dg/dremf-type-compat-1.c, gcc.dg/dremf-type-compat-2.c,
gcc.dg/dremf-type-compat-3.c, gcc.dg/dremf-type-compat-4.c,
gcc.dg/old-style-prom-1.c, gcc.dg/old-style-prom-2.c,
gcc.dg/old-style-prom-3.c: New tests.

From-SVN: r89883

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/dremf-type-compat-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/dremf-type-compat-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/dremf-type-compat-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/dremf-type-compat-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/old-style-prom-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/old-style-prom-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/old-style-prom-3.c [new file with mode: 0644]

index 2dd6438805cf62b7f9639bc39e351f58377e5f69..e255638479b12e3867ebfc8cecad9642d692bbbc 100644 (file)
@@ -1,3 +1,10 @@
+2004-10-30  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/16666
+       * c-decl.c (start_function): Don't check for DECL_BUILT_IN when
+       determining whether to copy parameter types from a previous
+       prototype declaration.
+
 2004-10-29  Roger Sayle  <roger@eyesopen.com>
 
        PR rtl-optimization/17581
index 08f790982431a6a1ba5a9f3edaea7f45f9ef4578..839b5f3b2ab8f3ff5635d5fdf0b9c784d6e8db76 100644 (file)
@@ -5698,11 +5698,9 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
   DECL_INITIAL (decl1) = error_mark_node;
 
   /* If this definition isn't a prototype and we had a prototype declaration
-     before, copy the arg type info from that prototype.
-     But not if what we had before was a builtin function.  */
+     before, copy the arg type info from that prototype.  */
   old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
   if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
-      && !DECL_BUILT_IN (old_decl)
       && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
                    TREE_TYPE (TREE_TYPE (old_decl)))
       && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
index 804e51b56dd6b2213f1c32b8e1a481404c712ea2..7ccc30d9bf5042eede540ecf396ef2c1101fa2a3 100644 (file)
@@ -1,3 +1,11 @@
+2004-10-30  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/16666
+       * gcc.dg/dremf-type-compat-1.c, gcc.dg/dremf-type-compat-2.c,
+       gcc.dg/dremf-type-compat-3.c, gcc.dg/dremf-type-compat-4.c,
+       gcc.dg/old-style-prom-1.c, gcc.dg/old-style-prom-2.c,
+       gcc.dg/old-style-prom-3.c: New tests.
+
 2004-10-30  Danny Smith  <dannysmith@users.sourceforge.net>
 
        * gcc.dg/bf-ms-attrib.c: Add protototype for abort.
diff --git a/gcc/testsuite/gcc.dg/dremf-type-compat-1.c b/gcc/testsuite/gcc.dg/dremf-type-compat-1.c
new file mode 100644 (file)
index 0000000..79c55ef
--- /dev/null
@@ -0,0 +1,16 @@
+/* Test for bogus diagnostics for dremf definition.  Although this
+   definition is formally incorrect in ISO C, a GNU extension permits
+   a prototype followed by unpromoted types in a function definition,
+   so it should be permitted when the function is built in.  Bug
+   16666.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+float dremf (float, float);
+
+float
+dremf (x, y)
+     float x, y;
+{
+  return x + y;
+}
diff --git a/gcc/testsuite/gcc.dg/dremf-type-compat-2.c b/gcc/testsuite/gcc.dg/dremf-type-compat-2.c
new file mode 100644 (file)
index 0000000..101da65
--- /dev/null
@@ -0,0 +1,18 @@
+/* Test for bogus diagnostics for dremf definition.  Although this
+   definition is formally incorrect in ISO C, a GNU extension permits
+   a prototype followed by unpromoted types in a function definition,
+   so it should be permitted when the function is built in.  Bug
+   16666.  Test with -pedantic, where the problem should still be
+   diagnosed.  */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+float dremf (float, float); /* { dg-warning "warning: prototype declaration" } */
+
+float
+dremf (x, y)
+     float x;
+     float y;
+{ /* { dg-warning "warning: promoted argument '.' doesn't match prototype" } */
+  return x + y;
+}
diff --git a/gcc/testsuite/gcc.dg/dremf-type-compat-3.c b/gcc/testsuite/gcc.dg/dremf-type-compat-3.c
new file mode 100644 (file)
index 0000000..ff0f509
--- /dev/null
@@ -0,0 +1,18 @@
+/* Test for bogus diagnostics for dremf definition.  Although this
+   definition is formally incorrect in ISO C, a GNU extension permits
+   a prototype followed by unpromoted types in a function definition,
+   so it should be permitted when the function is built in.  Bug
+   16666.  Test with -pedantic-errors, where the problem should still
+   be diagnosed.  */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+float dremf (float, float); /* { dg-error "error: prototype declaration" } */
+
+float
+dremf (x, y)
+     float x;
+     float y;
+{ /* { dg-error "error: promoted argument '.' doesn't match prototype" } */
+  return x + y;
+}
diff --git a/gcc/testsuite/gcc.dg/dremf-type-compat-4.c b/gcc/testsuite/gcc.dg/dremf-type-compat-4.c
new file mode 100644 (file)
index 0000000..6355fad
--- /dev/null
@@ -0,0 +1,13 @@
+/* Test for bogus diagnostics for dremf definition, as in bug 16666.
+   The GNU extension permitting a prototype to override the promotion
+   of old-style parameter declarations should only apply when the
+   prototype is visible, not for a built-in prototype.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+float
+dremf(x, y)
+     float x, y; /* { dg-warning "warning: conflicting types for built-in function 'dremf'" } */
+{
+  return x + y;
+}
diff --git a/gcc/testsuite/gcc.dg/old-style-prom-1.c b/gcc/testsuite/gcc.dg/old-style-prom-1.c
new file mode 100644 (file)
index 0000000..165ff98
--- /dev/null
@@ -0,0 +1,13 @@
+/* Test for prototype followed by old-style definition, as in
+   dremf-type-compat-1.c but with a non-built-in function.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+float f (float, float);
+
+float
+f (x, y)
+     float x, y;
+{
+  return x + y;
+}
diff --git a/gcc/testsuite/gcc.dg/old-style-prom-2.c b/gcc/testsuite/gcc.dg/old-style-prom-2.c
new file mode 100644 (file)
index 0000000..5f4d877
--- /dev/null
@@ -0,0 +1,14 @@
+/* Test for prototype followed by old-style definition, as in
+   dremf-type-compat-2.c but with a non-built-in function.  */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+float f (float, float); /* { dg-warning "warning: prototype declaration" } */
+
+float
+f (x, y)
+     float x;
+     float y;
+{ /* { dg-warning "warning: promoted argument '.' doesn't match prototype" } */
+  return x + y;
+}
diff --git a/gcc/testsuite/gcc.dg/old-style-prom-3.c b/gcc/testsuite/gcc.dg/old-style-prom-3.c
new file mode 100644 (file)
index 0000000..19bbc8c
--- /dev/null
@@ -0,0 +1,14 @@
+/* Test for prototype followed by old-style definition, as in
+   dremf-type-compat-3.c but with a non-built-in function.  */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+float f (float, float); /* { dg-error "error: prototype declaration" } */
+
+float
+f (x, y)
+     float x;
+     float y;
+{ /* { dg-error "error: promoted argument '.' doesn't match prototype" } */
+  return x + y;
+}