aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/nonnull-14.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/nonnull-14.c')
-rw-r--r--gcc/testsuite/gcc.dg/nonnull-14.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/nonnull-14.c b/gcc/testsuite/gcc.dg/nonnull-14.c
new file mode 100644
index 0000000..6194dd0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/nonnull-14.c
@@ -0,0 +1,23 @@
+/* Test for the "nonnull" function attribute on builtins. Use the
+ "__builtin_" style below so we don't need prototypes. */
+/* { dg-do compile } */
+/* { dg-options "-Wnonnull" } */
+
+#include <stddef.h>
+
+void
+foo (void *p, char *s)
+{
+ __builtin_fwrite (s, 0, 0, NULL); /* { dg-warning "null" "null pointer check" } */
+ __builtin_fwrite (s, 0, 2, NULL); /* { dg-warning "null" "null pointer check" } */
+ __builtin_fwrite (s, 1, 0, NULL); /* { dg-warning "null" "null pointer check" } */
+ __builtin_fwrite (NULL, 16, 0, p);
+ __builtin_fwrite (NULL, 0, 12, p);
+ __builtin_fwrite (NULL, 2, 3, p); /* { dg-warning "null" "null pointer check" } */
+ __builtin_fwrite_unlocked (s, 0, 0, NULL); /* { dg-warning "null" "null pointer check" } */
+ __builtin_fwrite_unlocked (s, 0, 2, NULL); /* { dg-warning "null" "null pointer check" } */
+ __builtin_fwrite_unlocked (s, 1, 0, NULL); /* { dg-warning "null" "null pointer check" } */
+ __builtin_fwrite_unlocked (NULL, 16, 0, p);
+ __builtin_fwrite_unlocked (NULL, 0, 12, p);
+ __builtin_fwrite_unlocked (NULL, 2, 3, p); /* { dg-warning "null" "null pointer check" } */
+}