This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR c/5503
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 13 Feb 2002 23:34:56 +0100
- Subject: [PATCH] Fix PR c/5503
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This PR was about no errors/warnings when fputs (and bzero/bcmp too) were
used with wrong number of arguments or incompatible arguments.
The problem is that gcc defines the above builtins with BT_FN_VOID_VAR resp.
BT_FN_INT_VAR, so that TYPE_ARG_TYPES is NULL and thus it agrees with any
prototypes provided the return type matches.
But once we saw the prototype, we know what the arguments should be, so the
resulting function type needs to be given those arguments.
Ok to commit?
2002-02-13 Jakub Jelinek <jakub@redhat.com>
PR c/5503:
* c-decl.c (duplicate_decls): If builtin type has TYPE_ARG_TYPES NULL,
use arguments from newtype.
* gcc.dg/noncompile/20020213-1.c: New test.
--- gcc/testsuite/gcc.dg/noncompile/20020213-1.c.jj Wed Feb 13 23:24:34 2002
+++ gcc/testsuite/gcc.dg/noncompile/20020213-1.c Wed Feb 13 23:24:17 2002
@@ -0,0 +1,31 @@
+/* PR c/5503
+ Test whether argument checking is done for fputs, bzero and bcmp. */
+typedef struct { int i; } FILE;
+typedef __SIZE_TYPE__ size_t;
+int fputs (const char *, FILE *);
+void bzero (void *, size_t);
+int bcmp (const void *, const void *, size_t);
+
+char buf[32];
+FILE *f;
+
+int main ()
+{
+ fputs ("foo"); /* { dg-error "too few" } */
+ fputs ("foo", "bar", "baz"); /* { dg-error "too many" } */
+ fputs (21, 43);
+ bzero (buf); /* { dg-error "too few" } */
+ bzero (21); /* { dg-error "too few" } */
+ bcmp (buf, buf + 16); /* { dg-error "too few" } */
+ bcmp (21); /* { dg-error "too few" } */
+ fputs ("foo", f);
+ bzero (buf, 32);
+ bcmp (buf, buf + 16, 16);
+ return 0;
+}
+
+/* { dg-warning "passing arg 2 of" "2nd incompatible" { target *-*-* } 15 } */
+/* { dg-warning "passing arg 1 of" "1st incompatible" { target *-*-* } 16 } */
+/* { dg-warning "passing arg 2 of" "2nd incompatible" { target *-*-* } 16 } */
+/* { dg-warning "passing arg 1 of" "1st incompatible" { target *-*-* } 18 } */
+/* { dg-warning "passing arg 1 of" "1st incompatible" { target *-*-* } 20 } */
--- gcc/c-decl.c.jj Thu Feb 7 12:23:09 2002
+++ gcc/c-decl.c Wed Feb 13 23:02:20 2002
@@ -1548,6 +1548,22 @@ duplicate_decls (newdecl, olddecl, diffe
if (! different_binding_level)
TREE_TYPE (olddecl) = oldtype;
}
+ else if (TYPE_ARG_TYPES (oldtype) == NULL
+ && TYPE_ARG_TYPES (newtype) != NULL)
+ {
+ /* For bcmp, bzero, fputs the builtin type has arguments not
+ specified. Use the ones from the prototype so that type checking
+ is done for them. */
+ tree trytype
+ = build_function_type (TREE_TYPE (oldtype),
+ TYPE_ARG_TYPES (newtype));
+ trytype = build_type_attribute_variant (trytype,
+ TYPE_ATTRIBUTES (oldtype));
+
+ oldtype = trytype;
+ if (! different_binding_level)
+ TREE_TYPE (olddecl) = oldtype;
+ }
if (!types_match)
{
/* If types don't match for a built-in, throw away the built-in. */
Jakub