From 8b023e7ccce7cdf79ae316169ae4a71e25957867 Mon Sep 17 00:00:00 2001 From: dj Date: Wed, 6 Nov 2013 23:33:33 +0000 Subject: [PATCH] * c-decl.c (locate_old_decl): If a previous conflicting decl is both explicit and builtin, print the location of the explicit one. * gcc.dg/mismatch-decl-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@204491 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c/ChangeLog | 5 +++++ gcc/c/c-decl.c | 3 ++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/mismatch-decl-1.c | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/mismatch-decl-1.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 9a9eed39de5..cc335e454b5 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2013-11-06 DJ Delorie + + * c-decl.c (locate_old_decl): If a previous conflicting decl is + both explicit and builtin, print the location of the explicit one. + 2013-11-05 Tobias Burnus * c-parser.c (c_parser_omp_for, c_parser_omp_parallel, diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 2833fdba486..23f05163a62 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -1634,7 +1634,8 @@ validate_proto_after_old_defn (tree newdecl, tree newtype, tree oldtype) static void locate_old_decl (tree decl) { - if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl)) + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl) + && !C_DECL_DECLARED_BUILTIN (decl)) ; else if (DECL_INITIAL (decl)) inform (input_location, "previous definition of %q+D was here", decl); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ce0c26c7e45..b857d00f851 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-11-06 DJ Delorie + + * gcc.dg/mismatch-decl-1.c: New test. + 2013-11-06 Joseph Myers * gcc.dg/torture/float128-cmp-invalid.c, diff --git a/gcc/testsuite/gcc.dg/mismatch-decl-1.c b/gcc/testsuite/gcc.dg/mismatch-decl-1.c new file mode 100644 index 00000000000..da4db0a57f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/mismatch-decl-1.c @@ -0,0 +1,22 @@ +/* This test assumes -fbuiltin and not -fansi to get "index" and "memchr" builtin DECLs. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +/* The bug this is testing is that if a new decl conflicts with an + explicit decl, you don't get the "changes type of builtin" message, + but if there was *also* a builtin, you *also* don't get the + "previous declaration was here" message, leaving you with no clue + where the previous declaration came from. */ + +extern char foo(int,int); /* { dg-message "previous declaration of 'foo' was here" } */ +extern char *index(const char *,int); /* { dg-message "previous declaration of 'index' was here" } */ + +/* This changes the type of "index", which is both a builtin and an + explicit decl. */ +int index; /* { dg-error "redeclared as different kind of symbol" } */ + +/* This changes the type of "memchr", which is only a builtin. */ +int memchr; /* { dg-warning "built-in function 'memchr' declared as non-function" } */ + +/* This changes the type of "foo", which is only an explicit decl. */ +int foo; /* { dg-error "redeclared as different kind of symbol" } */ -- 2.11.4.GIT