diff gcc/testsuite/gcc.dg/nonnull-4.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/nonnull-4.c	Fri Oct 27 22:46:09 2017 +0900
@@ -0,0 +1,79 @@
+/* PR c/78673 - sprintf missing attribute nonnull on destination argument
+   Test to verify that calls to user-defined functions declared with
+   the "nonnull" function attribute are diagnosed.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wnonnull" } */
+
+#define N(...) __attribute__ ((nonnull (__VA_ARGS__)))
+
+void N (1) f1_1 (void*);
+
+void N (1)       f2_1 (void*, void*);
+void N (1) N (2) f2_1_2 (void*, void*);
+
+void N (1) N (3) f3_1_3 (void*, void*, void*);
+
+void N (1, 2) N (4) g4_1_2_4 (void*, void*, void*, void*);
+void N (1, 3) N (4) g4_1_3_4 (void*, void*, void*, void*);
+void N (2, 3, 4)    g4_2_3_4 (void*, void*, void*, void*);
+
+void N () g4_all (void*, void*, void*, void*);
+
+void N (1, 3, 5, 7, 11, 13)
+g16_1_3_5_7_11_13 (void*, void*, void*, void*,
+		   void*, void*, void*, void*,
+		   void*, void*, void*, void*,
+		   void*, void*, void*, void*);
+
+void* null (void) { return 0; }
+
+void test (void)
+{
+  void *p0 = null ();
+  void *px = &px;
+
+  f1_1 (p0);   /* { dg-warning "argument 1 null where non-null expected " } */
+  f1_1 (px);
+
+  f2_1 (p0, px);  /* { dg-warning "argument 1 null" } */
+  f2_1 (px, p0);
+  f2_1 (p0, p0);  /* { dg-warning "argument 1 null" } */
+
+  f2_1_2 (p0, px);  /* { dg-warning "argument 1 null" } */
+  f2_1_2 (px, p0);  /* { dg-warning "argument 2 null" } */
+  f2_1_2 (p0, p0);  /* { dg-warning "argument 1 null" } */
+  /* { dg-warning "argument 2 null" "argument 2" { target *-*-* } .-1 } */
+
+  f3_1_3 (p0, px, px);  /* { dg-warning "argument 1 null" } */
+  f3_1_3 (px, p0, px);
+  f3_1_3 (px, px, p0);  /* { dg-warning "argument 3 null" } */
+  f3_1_3 (p0, p0, px);  /* { dg-warning "argument 1 null" } */
+  f3_1_3 (px, p0, p0);  /* { dg-warning "argument 3 null" } */
+  f3_1_3 (p0, p0, p0);  /* { dg-warning "argument 1 null" } */
+  /* { dg-warning "argument 3 null" "argument 3" { target *-*-* } .-1 } */
+
+  g4_1_2_4 (p0, px, px, px);  /* { dg-warning "argument 1 null" } */
+  g4_1_2_4 (px, p0, px, px);  /* { dg-warning "argument 2 null" } */
+  g4_1_2_4 (px, px, p0, px);
+  g4_1_2_4 (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
+
+  g4_1_3_4 (p0, px, px, px);  /* { dg-warning "argument 1 null" } */
+  g4_1_3_4 (px, p0, px, px);
+  g4_1_3_4 (px, px, p0, px);  /* { dg-warning "argument 3 null" } */
+  g4_1_3_4 (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
+
+  g4_2_3_4 (p0, px, px, px);
+  g4_2_3_4 (px, p0, px, px);  /* { dg-warning "argument 2 null" } */
+  g4_2_3_4 (px, px, p0, px);  /* { dg-warning "argument 3 null" } */
+  g4_2_3_4 (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
+
+  g4_all (p0, px, px, px);  /* { dg-warning "argument 1 null" } */
+  g4_all (px, p0, px, px);  /* { dg-warning "argument 2 null" } */
+  g4_all (px, px, p0, px);  /* { dg-warning "argument 3 null" } */
+  g4_all (px, px, px, p0);  /* { dg-warning "argument 4 null" } */
+
+  g16_1_3_5_7_11_13 (px, px, px, px, px, px, px, px,
+		     px, px, px, px, px, px, px, px);
+
+  g16_1_3_5_7_11_13 (px, p0, px, p0, px, p0, px, p0, p0, p0, px, p0, p0, p0, p0, p0);   /* { dg-warning "argument 13 null" } */
+}