| 1 |
/* Test for the bad usage of "nonnull" function attribute parms. */ |
| 2 |
/* */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-Wnonnull-compare" } */ |
| 5 |
|
| 6 |
#include <stddef.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
void foo(void *bar) __attribute__((nonnull(1))); |
| 10 |
|
| 11 |
void foo(void *bar) { if (!bar) abort(); } /* { dg-warning "'nonnull' argument" "bar compared to NULL" } */ |
| 12 |
|
| 13 |
extern int func (char *, char *, char *, char *) __attribute__((nonnull)); |
| 14 |
|
| 15 |
int |
| 16 |
func (char *cp1, char *cp2, char *cp3, char *cp4) |
| 17 |
{ |
| 18 |
if (cp1) /* { dg-warning "'nonnull' argument" "cp1 compared to NULL" } */ |
| 19 |
return 1; |
| 20 |
|
| 21 |
if (cp2 == NULL) /* { dg-warning "'nonnull' argument" "cp2 compared to NULL" } */ |
| 22 |
return 2; |
| 23 |
|
| 24 |
if (NULL != cp3) /* { dg-warning "'nonnull' argument" "cp3 compared to NULL" } */ |
| 25 |
return 3; |
| 26 |
|
| 27 |
return cp4 != 0 ? 0 : 1; /* { dg-warning "'nonnull' argument" "cp4 compared to NULL" } */ |
| 28 |
} |
| 29 |
|
| 30 |
__attribute__((nonnull (1))) int |
| 31 |
func2 (char *cp) |
| 32 |
{ |
| 33 |
return (cp != NULL) ? 1 : 0; /* { dg-warning "'nonnull' argument" "cp compared to NULL" } */ |
| 34 |
} |