diff options
author | David Malcolm <dmalcolm@redhat.com> | 2020-01-23 17:46:12 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2020-01-23 20:47:34 -0500 |
commit | a0b935ac66bc9804b0864151e5f1bfde5ac1ddeb (patch) | |
tree | 162e8a14cf0e4b482bf62521ec94e7179393820d | |
parent | 472dc648ce3e7661762931d584d239611ddca964 (diff) | |
download | gcc-a0b935ac66bc9804b0864151e5f1bfde5ac1ddeb.zip gcc-a0b935ac66bc9804b0864151e5f1bfde5ac1ddeb.tar.gz gcc-a0b935ac66bc9804b0864151e5f1bfde5ac1ddeb.tar.bz2 |
analyzer: avoid relying on system <assert.h> in testsuite (PR 93367)
PR analyzer/93367 reports a testsuite failure in abort.c on
hppa64-hp-hpux11.11 when detecting if the analyzer "knows" that the
condition holds after the assert.
The root cause is that the assertion failure function in that
configuration's <assert.h> is not marked with
__attribute__ ((__noreturn__)).
This patch reworks the test to avoid <assert.h> in favor of a custom
implementation of assert, so that the test demonstrates the idea without
relying on properties of <assert.h>.
gcc/testsuite/ChangeLog:
PR analyzer/93367
* gcc.dg/analyzer/abort.c: Remove include of <assert.h>.
Replace use of assert with a custom assertion implementation.
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/analyzer/abort.c | 18 |
2 files changed, 19 insertions, 5 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 85e2fbb..df547bc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-01-23 David Malcolm <dmalcolm@redhat.com> + + PR analyzer/93367 + * gcc.dg/analyzer/abort.c: Remove include of <assert.h>. + Replace use of assert with a custom assertion implementation. + 2020-01-23 Jakub Jelinek <jakub@redhat.com> PR inline-asm/93027 diff --git a/gcc/testsuite/gcc.dg/analyzer/abort.c b/gcc/testsuite/gcc.dg/analyzer/abort.c index ea1756e..9497ae3 100644 --- a/gcc/testsuite/gcc.dg/analyzer/abort.c +++ b/gcc/testsuite/gcc.dg/analyzer/abort.c @@ -1,4 +1,3 @@ -#include <assert.h> #include <stdio.h> #include <stdlib.h> #include "analyzer-decls.h" @@ -62,11 +61,20 @@ void test_4 (void *ptr) /**************************************************************************/ +/* Verify that we discover conditions from assertions if the assert macro + isn't disabled, and that it has its failure-handler labelled with + __attribute__ ((__noreturn__)). + This attribute isn't present for all implementations of <assert.h>, so + we have to test the idea using our own assert macro. */ + +extern void my_assert_fail (const char *expr, const char *file, int line) + __attribute__ ((__noreturn__)); + +#define MY_ASSERT(EXPR) \ + do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) + void test_5 (int i) { - assert (i < 10); - - /* We have not defined NDEBUG, so this will call __assert_fail if - i >= 10, which is labelled with __attribute__ ((__noreturn__)). */ + MY_ASSERT (i < 10); __analyzer_eval (i < 10); /* { dg-warning "TRUE" } */ } |