aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/format
diff options
context:
space:
mode:
authorKaveh Ghazi <ghazi@gcc.gnu.org>2004-09-05 02:50:09 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2004-09-05 02:50:09 +0000
commit3d091dac56f97cc79cc2e9a31796219fba99764c (patch)
tree616590e443b211fdf7309d929fce3872a4ff3f15 /gcc/testsuite/gcc.dg/format
parentecd466457ce9203bec0241815528533fcbee81ea (diff)
downloadgcc-3d091dac56f97cc79cc2e9a31796219fba99764c.zip
gcc-3d091dac56f97cc79cc2e9a31796219fba99764c.tar.gz
gcc-3d091dac56f97cc79cc2e9a31796219fba99764c.tar.bz2
builtin-attrs.def (ATTR_SENTINEL, [...]): New.
gcc: * builtin-attrs.def (ATTR_SENTINEL, ATTR_SENTINEL_NOTHROW_LIST): New. * builtins.def (BUILT_IN_EXECL, BUILT_IN_EXECLP): Add `sentinel' attribute. * c-common.c (handle_sentinel_attribute, check_function_sentinel): New functions. (c_common_attribute_table): Add `sentinel' attribute. (check_function_arguments): Handle `sentinel' attribute. * doc/extend.texi: Document `sentinel' attribute. gcc/testsuite: * gcc.dg/format/sentinel-1.c: New test. include: * ansidecl.h (ATTRIBUTE_SENTINEL): Define. * libiberty.h (concat, reconcat, concat_length, concat_copy, concat_copy2): Use ATTRIBUTE_SENTINEL. From-SVN: r87096
Diffstat (limited to 'gcc/testsuite/gcc.dg/format')
-rw-r--r--gcc/testsuite/gcc.dg/format/sentinel-1.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/format/sentinel-1.c b/gcc/testsuite/gcc.dg/format/sentinel-1.c
new file mode 100644
index 0000000..e1e127dc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/sentinel-1.c
@@ -0,0 +1,37 @@
+/* Test for attribute sentinel. */
+/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
+/* { dg-do compile } */
+/* { dg-options "-Wformat" } */
+
+#include <stddef.h> /* For NULL, which must be (ptr)0. */
+
+extern int execl (const char *, const char *, ...);
+extern int execlp (const char *, const char *, ...);
+
+#define ATTR __attribute__ ((__sentinel__))
+
+extern int a ATTR; /* { dg-warning "applies to function types" "sentinel" } */
+
+extern void foo1 (const char *, ...) ATTR;
+extern void foo2 (...) ATTR; /* { dg-error "ISO C requires|named arguments" "sentinel" } */
+extern void foo3 () ATTR; /* { dg-warning "named arguments" "sentinel" } */
+extern void foo4 (const char *, int) ATTR; /* { dg-warning "variadic functions" "sentinel" } */
+
+extern void bar(void)
+{
+ foo1 (); /* { dg-error "missing sentinel|too few arguments" "sentinel" } */
+ foo1 ("a"); /* { dg-warning "missing sentinel" "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);
+
+ execl ("/bin/ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
+ execl ("/bin/ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
+ execl ("/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);
+}