aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2005-06-26 21:54:24 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2005-06-26 21:54:24 +0000
commit10a22b110764c1c665fa2ff5f29607bdeb8f79ba (patch)
tree41908d1e14fb3ba4c882eacbba3fca4d4f164007
parent82e5a12a581ea11e83cbd94d368e3297abda8fe2 (diff)
downloadgcc-10a22b110764c1c665fa2ff5f29607bdeb8f79ba.zip
gcc-10a22b110764c1c665fa2ff5f29607bdeb8f79ba.tar.gz
gcc-10a22b110764c1c665fa2ff5f29607bdeb8f79ba.tar.bz2
re PR c/21911 (named parameter mistakenly identified as sentinel)
PR c/21911 * c-common.c (check_function_sentinel): Pass in named argument list, skip over named arguments before looking for a sentinel. (check_function_arguments): Pass in named argument list. * c-common.h (check_function_arguments): Likewise. * c-typeck.c (build_function_call): Likewise. cp: * call.c (build_over_call): Pass in named argument list to `check_function_arguments'. * typeck.c (build_function_call): Likewise. testsuite: PR c/21911 * gcc.dg/format/sentinel-1.c: Update. Fix execl* calls. From-SVN: r101341
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/c-common.c19
-rw-r--r--gcc/c-common.h2
-rw-r--r--gcc/c-typeck.c3
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/cp/typeck.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/format/sentinel-1.c39
9 files changed, 62 insertions, 26 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c63f5fc..1ed245e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,14 @@
2005-06-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+ PR c/21911
+ * c-common.c (check_function_sentinel): Pass in named argument
+ list, skip over named arguments before looking for a sentinel.
+ (check_function_arguments): Pass in named argument list.
+ * c-common.h (check_function_arguments): Likewise.
+ * c-typeck.c (build_function_call): Likewise.
+
+2005-06-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
* genautomata.c (decl_mode_check_failed,
regexp_mode_check_failed): Add noreturn attribute.
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 6b753dc..24280ae 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -5143,14 +5143,21 @@ check_function_nonnull (tree attrs, tree params)
from the end) is a (pointer)0. */
static void
-check_function_sentinel (tree attrs, tree params)
+check_function_sentinel (tree attrs, tree params, tree typelist)
{
tree attr = lookup_attribute ("sentinel", attrs);
if (attr)
{
- if (!params)
- warning (0, "missing sentinel in function call");
+ /* Skip over the named arguments. */
+ while (typelist && params)
+ {
+ typelist = TREE_CHAIN (typelist);
+ params = TREE_CHAIN (params);
+ }
+
+ if (typelist || !params)
+ warning (0, "not enough variable arguments to fit a sentinel");
else
{
tree sentinel, end;
@@ -5172,7 +5179,7 @@ check_function_sentinel (tree attrs, tree params)
}
if (pos > 0)
{
- warning (0, "not enough arguments to fit a sentinel");
+ warning (0, "not enough variable arguments to fit a sentinel");
return;
}
@@ -5386,7 +5393,7 @@ handle_sentinel_attribute (tree *node, tree name, tree args,
/* Check for valid arguments being passed to a function. */
void
-check_function_arguments (tree attrs, tree params)
+check_function_arguments (tree attrs, tree params, tree typelist)
{
/* Check for null being passed in a pointer argument that must be
non-null. We also need to do this if format checking is enabled. */
@@ -5399,7 +5406,7 @@ check_function_arguments (tree attrs, tree params)
if (warn_format)
{
check_function_format (attrs, params);
- check_function_sentinel (attrs, params);
+ check_function_sentinel (attrs, params, typelist);
}
}
diff --git a/gcc/c-common.h b/gcc/c-common.h
index 7fcd386..d3839b7 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -626,7 +626,7 @@ extern void finish_fname_decls (void);
extern const char *fname_as_string (int);
extern tree fname_decl (unsigned, tree);
-extern void check_function_arguments (tree, tree);
+extern void check_function_arguments (tree, tree, tree);
extern void check_function_arguments_recurse (void (*)
(void *, tree,
unsigned HOST_WIDE_INT),
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 483beb8..7f32b65 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2067,7 +2067,8 @@ build_function_call (tree function, tree params)
/* Check that the arguments to the function are valid. */
- check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params);
+ check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params,
+ TYPE_ARG_TYPES (fntype));
result = build3 (CALL_EXPR, TREE_TYPE (fntype),
function, coerced_params, NULL_TREE);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 198167e..217a244 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2005-06-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+ * call.c (build_over_call): Pass in named argument list to
+ `check_function_arguments'.
+ * typeck.c (build_function_call): Likewise.
+
+2005-06-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
* cp-tree.h (lang_check_failed): Add noreturn attribute.
2005-06-25 Kelley Cook <kcook@gcc.gnu.org>
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 25aa0c2..d3cd467 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4790,7 +4790,7 @@ build_over_call (struct z_candidate *cand, int flags)
converted_args = nreverse (converted_args);
check_function_arguments (TYPE_ATTRIBUTES (TREE_TYPE (fn)),
- converted_args);
+ converted_args, TYPE_ARG_TYPES (TREE_TYPE (fn)));
/* Avoid actually calling copy constructors and copy assignment operators,
if possible. */
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 4ac78cf..edf1519 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2498,7 +2498,8 @@ build_function_call (tree function, tree params)
/* Check for errors in format strings and inappropriately
null parameters. */
- check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params);
+ check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params,
+ TYPE_ARG_TYPES (fntype));
return build_cxx_call (function, coerced_params);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c95184c..fa0a562 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-06-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ PR c/21911
+ * gcc.dg/format/sentinel-1.c: Update. Fix execl* calls.
+
2005-06-26 Jakub Jelinek <jakub@redhat.com>
PR middle-end/17965
diff --git a/gcc/testsuite/gcc.dg/format/sentinel-1.c b/gcc/testsuite/gcc.dg/format/sentinel-1.c
index 12915b7..1dc0908 100644
--- a/gcc/testsuite/gcc.dg/format/sentinel-1.c
+++ b/gcc/testsuite/gcc.dg/format/sentinel-1.c
@@ -27,40 +27,47 @@ extern void foo10 (const char *, ...) __attribute__ ((__sentinel__(1,3))); /* {
extern void bar(void)
{
- foo1 (); /* { dg-error "missing sentinel|too few arguments" "sentinel" } */
- foo1 ("a"); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo1 (); /* { dg-error "not enough|too few arguments" "sentinel" } */
+ foo1 (NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo1 ("a"); /* { dg-warning "not enough" "sentinel" } */
foo1 ("a", 1); /* { dg-warning "missing sentinel" "sentinel" } */
foo1 ("a", 0); /* { dg-warning "missing sentinel" "sentinel" } */
foo1 ("a", (void*)1); /* { dg-warning "missing sentinel" "sentinel" } */
foo1 ("a", NULL, 1); /* { dg-warning "missing sentinel" "sentinel" } */
foo1 ("a", NULL);
+ foo5 (NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo5 (NULL, 1); /* { dg-warning "not enough" "sentinel" } */
+ foo5 ("a", NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo5 ("a", NULL, 1);
foo5 ("a", 1, 2, 3, NULL); /* { dg-warning "missing sentinel" "sentinel" } */
foo5 ("a", 1, 2, NULL, 3);
foo5 ("a", 1, NULL, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
foo5 ("a", NULL, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
foo5 ("a", 0, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
- foo6 ("a", 1, NULL); /* { dg-warning "not enough arguments" "sentinel" } */
- foo6 ("a", 1, NULL, 2); /* { dg-warning "not enough arguments" "sentinel" } */
- foo6 ("a", 1, NULL, 2, 3); /* { dg-warning "not enough arguments" "sentinel" } */
- foo6 ("a", NULL, 1, 2, 3); /* { dg-warning "not enough arguments" "sentinel" } */
- foo6 ("a", NULL, 1, 2, 3, 4); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo6 ("a", 1, NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", 1, NULL, 2); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", 1, NULL, 2, 3); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", NULL, 1, 2, 3); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", NULL, 1, 2, 3, 4); /* { dg-warning "not enough" "sentinel" } */
+ foo6 (NULL, 1, 2, 3, 4, 5); /* { dg-warning "not enough" "sentinel" } */
foo6 ("a", NULL, 1, 2, 3, 4, 5);
+ foo6 ("a", 0, NULL, 1, 2, 3, 4, 5);
foo6 ("a", 0, 1, 2, 3, 4, 5); /* { dg-warning "missing sentinel" "sentinel" } */
foo6 ("a", NULL, 1, 2, 3, 4, 5, 6); /* { dg-warning "missing sentinel" "sentinel" } */
foo7 ("a", 1, 2, 3, NULL);
- execl ("/bin/ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
- execl ("/bin/ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
- execl ("/bin/ls", "-aFC", NULL);
+ execl ("/bin/ls", "/bin/ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
+ execl ("/bin/ls", "/bin/ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
+ execl ("/bin/ls", "/bin/ls", "-aFC", NULL);
- execlp ("ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
- execlp ("ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
- execlp ("ls", "-aFC", NULL);
+ execlp ("ls", "ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
+ execlp ("ls", "ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
+ execlp ("ls", "ls", "-aFC", NULL);
- execle ("ls", "-aFC", ".", envp); /* { dg-warning "missing sentinel" "sentinel" } */
- execle ("ls", "-aFC", ".", 0, envp); /* { dg-warning "missing sentinel" "sentinel" } */
- execle ("ls", "-aFC", ".", NULL, envp);
+ execle ("ls", "ls", "-aFC", ".", envp); /* { dg-warning "missing sentinel" "sentinel" } */
+ execle ("ls", "ls", "-aFC", ".", 0, envp); /* { dg-warning "missing sentinel" "sentinel" } */
+ execle ("ls", "ls", "-aFC", ".", NULL, envp);
}