public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/2] __bos and flex arrays
@ 2022-12-21 22:25 Siddhesh Poyarekar
  2022-12-21 22:25 ` [PATCH 1/2] testsuite: Run __bos tests to completion Siddhesh Poyarekar
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Siddhesh Poyarekar @ 2022-12-21 22:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub

Hi,

The first patch in the series is just a minor test cleanup that I did to
make sure all tests in a test case run (instead of aborting at first
failure) and print the ones that failed.  The second patch is the actual
fix.

The patch intends to make __bos/__bdos do the right thing with structs
containing flex arrays, either directly or within nested structs and
unions.  This should improve minimum object size estimation in some
cases and also bail out more consistently so that flex arrays don't
cause false positives in fortification.

I've tested this with a bootstrap on x86_64 and also with
--with-build-config=bootstrap-ubsan to make sure that there are no new
failures due to this change.

Siddhesh Poyarekar (2):
  testsuite: Run __bos tests to completion
  tree-object-size: More consistent behaviour with flex arrays

 .../g++.dg/ext/builtin-object-size1.C         | 267 ++++++++--------
 .../g++.dg/ext/builtin-object-size2.C         | 267 ++++++++--------
 .../gcc.dg/builtin-dynamic-object-size-0.c    |  14 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 263 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-12.c |  12 +-
 gcc/testsuite/gcc.dg/builtin-object-size-13.c |  17 +-
 gcc/testsuite/gcc.dg/builtin-object-size-15.c |  11 +-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 287 +++++++++---------
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 263 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  | 267 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-6.c  | 267 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-7.c  |  52 ++--
 gcc/testsuite/gcc.dg/builtin-object-size-8.c  |  17 +-
 .../gcc.dg/builtin-object-size-common.h       |  12 +
 .../gcc.dg/builtin-object-size-flex-common.h  |  90 ++++++
 ...n-object-size-flex-nested-struct-nonzero.c |   6 +
 ...ltin-object-size-flex-nested-struct-zero.c |   6 +
 .../builtin-object-size-flex-nested-struct.c  |  22 ++
 ...in-object-size-flex-nested-union-nonzero.c |   6 +
 ...iltin-object-size-flex-nested-union-zero.c |   6 +
 .../builtin-object-size-flex-nested-union.c   |  28 ++
 .../gcc.dg/builtin-object-size-flex-nonzero.c |   6 +
 .../gcc.dg/builtin-object-size-flex-zero.c    |   6 +
 .../gcc.dg/builtin-object-size-flex.c         |  18 ++
 gcc/testsuite/gcc.dg/pr101836.c               |  11 +-
 gcc/testsuite/gcc.dg/strict-flex-array-3.c    |  11 +-
 gcc/tree-object-size.cc                       | 150 ++++-----
 27 files changed, 1275 insertions(+), 1107 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-common.h
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex.c

-- 
2.38.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/2] testsuite: Run __bos tests to completion
  2022-12-21 22:25 [PATCH 0/2] __bos and flex arrays Siddhesh Poyarekar
@ 2022-12-21 22:25 ` Siddhesh Poyarekar
  2023-01-31 12:33   ` Jakub Jelinek
  2022-12-21 22:25 ` [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays Siddhesh Poyarekar
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Siddhesh Poyarekar @ 2022-12-21 22:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub

Instead of failing on first error, run all __builtin_object_size and
__builtin_dynamic_object_size tests to completion and then provide a
summary of which tests failed.

gcc/testsuite/ChangeLog:

	* gcc.dg/builtin-dynamic-object-size-0.c: Move FAIL and nfail
	into...
	* gcc.dg/builtin-object-size-common.h: ... new file.
	* g++.dg/ext/builtin-object-size1.C: Include
	builtin-object-size-common.h.  Replace all abort with FAIL.
	(main): Call DONE.
	* g++.dg/ext/builtin-object-size2.C: Likewise.
	* gcc.dg/builtin-object-size-1.c: Likewise.
	* gcc.dg/builtin-object-size-12.c: Likewise.
	* gcc.dg/builtin-object-size-13.c: Likewise.
	* gcc.dg/builtin-object-size-15.c: Likewise.
	* gcc.dg/builtin-object-size-2.c: Likewise.
	* gcc.dg/builtin-object-size-3.c: Likewise.
	* gcc.dg/builtin-object-size-4.c: Likewise.
	* gcc.dg/builtin-object-size-6.c: Likewise.
	* gcc.dg/builtin-object-size-7.c: Likewise.
	* gcc.dg/builtin-object-size-8.c: Likewise.
	* gcc.dg/pr101836.c: Likewise.
	* gcc.dg/strict-flex-array-3.c: Likewise.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
 .../g++.dg/ext/builtin-object-size1.C         | 257 ++++++++--------
 .../g++.dg/ext/builtin-object-size2.C         | 257 ++++++++--------
 .../gcc.dg/builtin-dynamic-object-size-0.c    |  14 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 263 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-12.c |  12 +-
 gcc/testsuite/gcc.dg/builtin-object-size-13.c |  13 +-
 gcc/testsuite/gcc.dg/builtin-object-size-15.c |  11 +-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 287 +++++++++---------
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 263 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  | 267 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-6.c  | 257 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-7.c  |  52 ++--
 gcc/testsuite/gcc.dg/builtin-object-size-8.c  |  13 +-
 .../gcc.dg/builtin-object-size-common.h       |  12 +
 gcc/testsuite/gcc.dg/pr101836.c               |  11 +-
 gcc/testsuite/gcc.dg/strict-flex-array-3.c    |  11 +-
 16 files changed, 1010 insertions(+), 990 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-common.h

diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
index 8590a0bbebd..165b415683b 100644
--- a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
+++ b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
@@ -1,8 +1,9 @@
 // { dg-do run }
 // { dg-options "-O2" }
 
+#include "../../gcc.dg/builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
-extern "C" void abort ();
 extern "C" void exit (int);
 extern "C" void *malloc (size_t);
 extern "C" void free (void *);
@@ -20,105 +21,105 @@ test1 (A *p)
 {
   char *c;
   if (__builtin_object_size (&p->a, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -129,105 +130,105 @@ test2 (void)
   size_t s = 2 * sizeof (A);
   A *p = (A *) malloc (2 * sizeof (A));
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -239,48 +240,48 @@ test3 (void)
   size_t s;
   A *p = (A *) malloc (4);
   if (__builtin_object_size (&p->a, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 0)
-    abort ();
+    FAIL ();
   free (p);
   s = __builtin_offsetof (A, c) + 4;
   p = (A *) malloc (s);
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 4)
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -294,17 +295,17 @@ __attribute__ ((noinline))
 test4 (struct B *q, int i)
 {
   if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
 }
 
 struct C
@@ -318,13 +319,13 @@ __attribute__ ((noinline))
 test5 (struct C *c)
 {
   if (__builtin_object_size (&c->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 3) != 1)
-    abort ();
+    FAIL ();
 }
 
 struct D
@@ -342,13 +343,13 @@ __attribute__ ((noinline))
 test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
 }
 
 struct E
@@ -366,21 +367,21 @@ __attribute__ ((noinline))
 test7 (struct E *e)
 {
   if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 union F
@@ -398,13 +399,13 @@ __attribute__ ((noinline))
 test8 (union F *f)
 {
   if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 int
@@ -431,5 +432,5 @@ main (void)
   union F f, *fp = &f;
   __asm ("" : "+r" (fp));
   test8 (fp);
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
index d79b1b83310..c5dbd96193c 100644
--- a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
+++ b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
@@ -1,8 +1,9 @@
 // { dg-do run }
 // { dg-options "-O2" }
 
+#include "../../gcc.dg/builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
-extern "C" void abort ();
 extern "C" void exit (int);
 extern "C" void *malloc (size_t);
 extern "C" void free (void *);
@@ -23,105 +24,105 @@ test1 (A *p)
 {
   char *c;
   if (__builtin_object_size (&p->a, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -132,105 +133,105 @@ test2 (void)
   size_t s = 2 * sizeof (A);
   A *p = (A *) malloc (2 * sizeof (A));
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -242,48 +243,48 @@ test3 (void)
   size_t s;
   A *p = (A *) malloc (4);
   if (__builtin_object_size (&p->a, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 0)
-    abort ();
+    FAIL ();
   free (p);
   s = __builtin_offsetof (A, c) + 4;
   p = (A *) malloc (s);
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 4)
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -297,17 +298,17 @@ __attribute__ ((noinline))
 test4 (struct B *q, int i)
 {
   if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
 }
 
 struct C
@@ -321,13 +322,13 @@ __attribute__ ((noinline))
 test5 (struct C *c)
 {
   if (__builtin_object_size (&c->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 3) != 1)
-    abort ();
+    FAIL ();
 }
 
 struct D
@@ -345,13 +346,13 @@ __attribute__ ((noinline))
 test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
 }
 
 struct E
@@ -369,21 +370,21 @@ __attribute__ ((noinline))
 test7 (struct E *e)
 {
   if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 union F
@@ -401,13 +402,13 @@ __attribute__ ((noinline))
 test8 (union F *f)
 {
   if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 int
@@ -434,5 +435,5 @@ main (void)
   union F f, *fp = &f;
   __asm ("" : "+r" (fp));
   test8 (fp);
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index f9047a037d9..cf1ea009788 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -1,6 +1,8 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
 #define abort __builtin_abort
 
@@ -539,13 +541,6 @@ test_pr105736 (struct TV4 *a)
   return &a->v[0];
 }
 
-unsigned nfails = 0;
-
-#define FAIL() ({ \
-  __builtin_printf ("Failure at line: %d\n", __LINE__);			      \
-  nfails++;								      \
-})
-
 int
 main (int argc, char **argv)
 {
@@ -707,8 +702,5 @@ main (int argc, char **argv)
   if (test_strndup_min (str, 4) != 1)
     FAIL ();
 
-  if (nfails > 0)
-    __builtin_abort ();
-
-  return 0;
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-1.c b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
index c6e5b4c29f8..851194c30b5 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-1.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
@@ -2,8 +2,9 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
 extern void exit (int);
 extern void *malloc (size_t);
 extern void *calloc (size_t, size_t);
@@ -39,22 +40,22 @@ test1 (void *q, int x)
     r = &a.c[1];
   if (__builtin_object_size (p, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 0)
       != sizeof (a) - __builtin_offsetof (struct A, c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 0
 	  ? sizeof (a) - __builtin_offsetof (struct A, a) - 9
 	  : sizeof (a) - __builtin_offsetof (struct A, c) - 1))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 9)
-    abort ();
+    FAIL ();
 #endif
   if (x < 6)
     r = &w[2].a[1];
@@ -62,23 +63,23 @@ test1 (void *q, int x)
     r = &a.a[6];
   if (__builtin_object_size (&y, 0)
       != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 0)
       != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 0)
       != sizeof (a) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 6
 	  ? 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1
 	  : sizeof (a) - __builtin_offsetof (struct A, a) - 6))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0)
       != 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -86,14 +87,14 @@ test1 (void *q, int x)
     r = calloc (2, 16);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 20 ? 30 : 2 * 16))
-    abort ();
+    FAIL ();
 #else
   /* We may duplicate this test onto the two exit paths.  On one path
      the size will be 32, the other it will be 30.  If we don't duplicate
      this test, then the size will be 32.  */
   if (__builtin_object_size (r, 0) != 2 * 16
       && __builtin_object_size (r, 0) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -101,10 +102,10 @@ test1 (void *q, int x)
     r = calloc (2, 14);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 20 ? 30 : 2 * 14))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 30)
     r = malloc (sizeof (a));
@@ -112,102 +113,102 @@ test1 (void *q, int x)
     r = &a.a[3];
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 30 ? sizeof (a) - 4 : sizeof (a) - 7))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != sizeof (a) - 4)
-    abort ();
+    FAIL ();
 #endif
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 0) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 0) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 0) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 0) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 0) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 0) != x + 5)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (zerol, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 0) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 0) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 0) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 0) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 0) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 0) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 0) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 0) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
 }
 
 size_t l1 = 1;
@@ -254,7 +255,7 @@ test2 (void)
   res = 20;
 #endif
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
     {
@@ -282,29 +283,29 @@ test2 (void)
         res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
     }
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
 #else
   res = 15;
 #endif
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
   r += 8;
 #ifdef __builtin_object_size
   res -= 8;
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
   if (res >= 6)
     {
       if (__builtin_object_size (r + 6, 0) != res - 6)
-        abort ();
+        FAIL ();
     }
   else if (__builtin_object_size (r + 6, 0) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 6, 0) != 1)
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[18];
   for (i = 0; i < 4; ++i)
@@ -335,13 +336,13 @@ test2 (void)
   if (res >= 12)
     {
       if (__builtin_object_size (r + 12, 0) != res - 12)
-        abort ();
+        FAIL ();
     }
   else if (__builtin_object_size (r + 12, 0) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r + 12, 0) != 4)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -357,103 +358,103 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 0) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 0) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 0) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 0) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 0) != sizeof (x) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 0)
       != sizeof (x) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 0)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 0)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 0)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 0)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 0)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 0)
       != sizeof (x) - __builtin_offsetof (struct B, c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 0)
       != sizeof (x) - __builtin_offsetof (struct B, d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 0)
       != sizeof (x) - __builtin_offsetof (struct B, e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 0)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 0)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 0)
       != sizeof (x) - __builtin_offsetof (struct B, f)
 	 - sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 0) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 0) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 0) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 0) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -470,7 +471,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 0) != (size_t) -1)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -487,7 +488,7 @@ test5 (size_t x)
     p = p + 4;
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0) != sizeof (buf) - 8 - 4 * x)
-    abort ();
+    FAIL ();
 #else
   /* My understanding of ISO C99 6.5.6 is that a conforming
      program will not end up with p equal to &buf[0]
@@ -497,7 +498,7 @@ test5 (size_t x)
      bytes from p until end of the object is 56, otherwise
      it would be 64 (or conservative (size_t) -1 == unknown).  */
   if (__builtin_object_size (p, 0) != sizeof (buf) - 8)
-    abort ();
+    FAIL ();
 #endif
   memset (p, ' ', sizeof (buf) - 8 - 4 * 4);
 }
@@ -514,10 +515,10 @@ test6 (size_t x)
     p = p + 4;
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0) != sizeof (t) - 8 - 4 * x)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 0) != sizeof (t) - 8)
-    abort ();
+    FAIL ();
 #endif
   memset (p, ' ', sizeof (t) - 8 - 4 * 4);
 }
@@ -531,13 +532,13 @@ test7 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 63, 0) != sizeof (t) - 64 - 63)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 0) != sizeof (t) - 64 - 64)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 256, 0) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -548,17 +549,17 @@ test8 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 0) != sizeof (t) - 10 + 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 0) != sizeof (t) - 10)
-    abort ();
+    FAIL ();
   /* GCC only handles additions, not subtractions.  */
   q = q - 8;
   if (__builtin_object_size (q, 0) != (size_t) -1
       && __builtin_object_size (q, 0) != sizeof (t) - 10 + 8)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 0) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -575,10 +576,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 0) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 0) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -586,10 +587,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 0) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -599,10 +600,10 @@ test9 (unsigned cond)
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0)
       != sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 0) != sizeof (y))
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -620,10 +621,10 @@ test10 (void)
 	{
 #ifdef __builtin_object_size
 	  if (__builtin_object_size (p - 3, 0) != sizeof (buf) - i + 3)
-	    abort ();
+	    FAIL ();
 #else
 	  if (__builtin_object_size (p - 3, 0) != sizeof (buf))
-	    abort ();
+	    FAIL ();
 #endif
 	  break;
 	}
@@ -641,19 +642,19 @@ test11 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 0) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 0) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 0) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -662,19 +663,19 @@ test11 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 0) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 0) != 33)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 0) != 64)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -684,39 +685,39 @@ test11 (void)
 #else
   if (__builtin_object_size (res, 0) != (size_t) -1)
 #endif
-    abort ();
+    FAIL ();
   free (res);
   free (ptr2);
 
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 0) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 0) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 0) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 0) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 0) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 0) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -736,5 +737,5 @@ main (void)
   test9 (1);
   test10 ();
   test11 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-12.c b/gcc/testsuite/gcc.dg/builtin-object-size-12.c
index b21eb0071b3..e29dd17d611 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-12.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-12.c
@@ -1,7 +1,8 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-extern void abort (void);
+#include "builtin-object-size-common.h"
+
 struct S {
     int len;
     char s[0];
@@ -10,10 +11,11 @@ int main()
 {
   char buf[sizeof (struct S) + 32];
   if (__builtin_object_size (((struct S *)&buf[0])->s, 1) != 32)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (((struct S *)&buf[1])->s, 1) != 31)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (((struct S *)&buf[64])->s, 0) != 0)
-    abort ();
-  return 0;
+    FAIL ();
+
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-13.c b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
index 80a6280e3f9..c7d58c941d4 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-13.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
@@ -1,10 +1,11 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
 extern void *malloc (size_t);
 extern void free (void *);
-extern void abort (void);
 
 union A
 {
@@ -56,13 +57,13 @@ struct H
 
 #define T(X, S0, S1) \
   if (__builtin_object_size (X, 0) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 1) != (S1))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 2) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 3) != (S1))	\
-    abort ()
+    FAIL ()
 #define TS(X, S0) T(&X, S0, sizeof (X))
 #define TA(X, S0, S1) \
   T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1)
@@ -347,5 +348,5 @@ main (void)
   free (h2);
   free (h1);
 
-  return 0;
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-15.c b/gcc/testsuite/gcc.dg/builtin-object-size-15.c
index 97018572bf8..7ee8ac095e7 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-15.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-15.c
@@ -1,7 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-extern void abort (void);
+#include "builtin-object-size-common.h"
 
 int
 main ()
@@ -9,12 +9,12 @@ main ()
   struct A { char buf1[9]; char buf2[1]; } a;
 
   if (__builtin_object_size (a.buf1 + (0 + 4), 1) != 5)
-    abort ();
+    FAIL ();
   char *p = a.buf1;
   p += 1;
   p += 3;
   if (__builtin_object_size (p, 1) != 5)
-    abort ();
+    FAIL ();
   p = (char *) &a;
   char *q = p + 1;
   char *r = q + 3;
@@ -22,6 +22,7 @@ main ()
   if (r != (char *) &a + 4)
     t = (char *) &a + 1;
   if (__builtin_object_size (t, 1) != 6)
-    abort ();
-  return 0;
+    FAIL ();
+
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-2.c b/gcc/testsuite/gcc.dg/builtin-object-size-2.c
index 639a83cfd39..d801b23392b 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-2.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-2.c
@@ -2,8 +2,9 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
 extern void exit (int);
 extern void *malloc (size_t);
 extern void *calloc (size_t, size_t);
@@ -40,39 +41,39 @@ test1 (void *q, int x)
   else
     r = &a.c[1];
   if (__builtin_object_size (p, 1) != sizeof (a.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 1)
       != sizeof (a.c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (x < 0
       ? __builtin_object_size (r, 1) != sizeof (a.a) - 9
       : __builtin_object_size (r, 1) != sizeof (a.c) - 1)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a.c) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 6)
     r = &w[2].a[1];
   else
     r = &a.a[6];
   if (__builtin_object_size (&y, 1) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 1) != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 1) != sizeof (a.b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (x < 6
       ? __builtin_object_size (r, 1) != sizeof (a.a) - 1
       : __builtin_object_size (r, 1) != sizeof (a.a) - 6)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -80,14 +81,14 @@ test1 (void *q, int x)
     r = calloc (2, 16);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 20 ? 30 : 2 * 16))
-    abort ();
+    FAIL ();
 #else
   /* We may duplicate this test onto the two exit paths.  On one path
      the size will be 32, the other it will be 30.  If we don't duplicate
      this test, then the size will be 32.  */
   if (__builtin_object_size (r, 1) != 2 * 16
       && __builtin_object_size (r, 1) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -95,10 +96,10 @@ test1 (void *q, int x)
     r = calloc (2, 14);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 20 ? 30 : 2 * 14))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 30)
     r = malloc (sizeof (a));
@@ -106,132 +107,132 @@ test1 (void *q, int x)
     r = &a.a[3];
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 30 ? sizeof (a) - 4 : sizeof (a) - 7))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a) - 4)
-    abort ();
+    FAIL ();
 #endif
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 1) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 1) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 1) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc + 10, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc->a, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&(extc + 10)->b, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5].c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 1) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 1) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 1) != x + 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 1) != (x + 10) * sizeof (struct A))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 1) != x * sizeof (struct A))
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 1) != (x + 5) * sizeof (struct A))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 1) != (size_t) -1)
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (&vara[0].a, 1) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[10].a[0], 1) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].a[4], 1) != sizeof (vara[0].a) - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].b, 1) != sizeof (vara[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[7].c[7], 1) != sizeof (vara[0].c) - 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 1) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 1) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 1) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 1) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 1) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 1) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 1) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 1) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
 }
 
 size_t l1 = 1;
@@ -277,10 +278,10 @@ test2 (void)
 	dyn_res = sizeof (a.buf1) - 9;
     }
   if (__builtin_object_size (r, 1) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (buf3))
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
@@ -309,10 +310,10 @@ test2 (void)
         dyn_res = sizeof (a.buf1) - 9;
     }
   if (__builtin_object_size (r, 1) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (buf3) - 5)
-    abort ();
+    FAIL ();
 #endif
   r += 8;
 #ifdef __builtin_object_size
@@ -320,23 +321,23 @@ test2 (void)
     {
       dyn_res -= 8;
       if (__builtin_object_size (r, 1) != dyn_res)
-	abort ();
+	FAIL ();
 
       if (dyn_res >= 6)
 	{
 	  if (__builtin_object_size (r + 6, 1) != dyn_res - 6)
-	    abort ();
+	    FAIL ();
 	}
       else if (__builtin_object_size (r + 6, 1) != 0)
-	abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r, 1) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (buf3) - 13)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 6, 1) != sizeof (buf3) - 19)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -352,78 +353,78 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 1) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 1) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 1) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 1) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 1) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 1) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 1) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 1) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 1) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 1) != sizeof (x.a[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 1) != sizeof (x.a[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 1) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 1) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 1) != sizeof (x.a[1].c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 1) != sizeof (x.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 1) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 1) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 1) != sizeof (x.b.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 1) != sizeof (x.b.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 1) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 1) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 1) != sizeof (x.b.c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 1) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 1) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 1) != sizeof (x.c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 1) != sizeof (x.d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 1) != sizeof (x.e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 1) != sizeof (x.f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 1) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 1) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 1) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 1) != sizeof (z))
-      abort ();
+      FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 1) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 1) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -440,7 +441,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 1) != (size_t) -1)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -457,10 +458,10 @@ test5 (size_t x)
     p = p + 4;
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 1) != sizeof (t.buf) - 8 - 4 * x)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 1) != sizeof (t.buf) - 8)
-    abort ();
+    FAIL ();
 #endif
   memset (p, ' ', sizeof (t.buf) - 8 - 4 * 4);
 }
@@ -474,11 +475,11 @@ test6 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 0, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 1) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -489,18 +490,18 @@ test7 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 1) != sizeof (t.buf2))
-    abort ();
+    FAIL ();
   q = &t.buf[10];
   if (__builtin_object_size (q, 1) != 0)
-    abort ();
+    FAIL ();
   q = &t.buf[11];
   if (__builtin_object_size (q, 1) != 0)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 1) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -517,10 +518,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 1) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 1) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -528,10 +529,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 1) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 1) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -540,10 +541,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 1) != sizeof (y.c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 1) != sizeof (y.c))
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -555,19 +556,19 @@ test9 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 1) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 1) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 1) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -576,19 +577,19 @@ test9 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 1) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 1) != 33)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 1) != 64)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -598,7 +599,7 @@ test9 (void)
 #else
   if (__builtin_object_size (res, 1) != (size_t) -1)
 #endif
-    abort ();
+    FAIL ();
 
   free (res);
   free (ptr2);
@@ -606,32 +607,32 @@ test9 (void)
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 1) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 1) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 1) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 1) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 1) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 1) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -649,5 +650,5 @@ main (void)
   test7 ();
   test8 (1);
   test9 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-3.c b/gcc/testsuite/gcc.dg/builtin-object-size-3.c
index ff4f1747334..ad0f981adaa 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-3.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-3.c
@@ -2,8 +2,9 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
 extern void exit (int);
 extern void *malloc (size_t);
 extern void *calloc (size_t, size_t);
@@ -39,22 +40,22 @@ test1 (void *q, int x)
     r = &a.c[1];
   if (__builtin_object_size (p, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 2)
       != sizeof (a) - __builtin_offsetof (struct A, c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 2) != 0)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2)
       != (x < 0
 	  ? sizeof (a) - __builtin_offsetof (struct A, a) - 9
 	  : sizeof (a) - __builtin_offsetof (struct A, c) - 1))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, c) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 6)
     r = &w[2].a[1];
@@ -62,23 +63,23 @@ test1 (void *q, int x)
     r = &a.a[6];
   if (__builtin_object_size (&y, 2)
       != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 2)
       != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 2)
       != sizeof (a) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2)
       != (x < 6
 	  ? 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1
 	  : sizeof (a) - __builtin_offsetof (struct A, a) - 6))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 6)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -86,10 +87,10 @@ test1 (void *q, int x)
     r = calloc (2, 16);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != (x < 20 ? 30 : 2 * 16))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -97,10 +98,10 @@ test1 (void *q, int x)
     r = calloc (2, 14);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != (x < 20 ? 30 : 2 * 14))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 2 * 14)
-    abort ();
+    FAIL ();
 #endif
   if (x < 30)
     r = malloc (sizeof (a));
@@ -110,104 +111,104 @@ test1 (void *q, int x)
   size_t objsz = (x < 30 ? sizeof (a)
                   : sizeof (a) - __builtin_offsetof (struct A, a) - 3);
   if (__builtin_object_size (r, 2) != objsz)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != objsz)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != objsz - 4)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3 - 4)
-    abort ();
+    FAIL ();
 #endif
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 2) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 2) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 2) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 2) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 2) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 2) != x + 5)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 2) != 0)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (zerol, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 2) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 2) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 2) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 2) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 2) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 2) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 2) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 2) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
 }
 
 size_t l1 = 1;
@@ -253,10 +254,10 @@ test2 (void)
 	dyn_res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
     }
   if (__builtin_object_size (r, 2) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 3)
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
@@ -271,7 +272,7 @@ test2 (void)
 	r = &a.buf1[9];
     }
   if (__builtin_object_size (r, 2) != 0)
-    abort ();
+    FAIL ();
   r = &buf3[2];
   for (i = 0; i < 4; ++i)
     {
@@ -299,28 +300,28 @@ test2 (void)
 	dyn_res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 4;
     }
   if (__builtin_object_size (r, 2) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 15)
-    abort ();
+    FAIL ();
 #endif
   r += 8;
 #ifdef __builtin_object_size
   dyn_res -= 8;
   if (__builtin_object_size (r, 2) != dyn_res)
-    abort ();
+    FAIL ();
   if (dyn_res >= 6)
     {
       if (__builtin_object_size (r + 6, 2) != dyn_res - 6)
-	abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r + 6, 2) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 6, 2) != 1)
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[18];
   for (i = 0; i < 4; ++i)
@@ -351,13 +352,13 @@ test2 (void)
   if (dyn_res >= 12)
     {
       if (__builtin_object_size (r + 12, 2) != dyn_res - 12)
-	abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r + 12, 2) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r + 12, 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -373,103 +374,103 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 2) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 2) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 2) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 2) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 2) != sizeof (x) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 2)
       != sizeof (x) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 2)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 2)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 2)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 2)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 2)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 2)
       != sizeof (x) - __builtin_offsetof (struct B, c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 2)
       != sizeof (x) - __builtin_offsetof (struct B, d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 2)
       != sizeof (x) - __builtin_offsetof (struct B, e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 2)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 2)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 2)
       != sizeof (x) - __builtin_offsetof (struct B, f)
 	 - sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 2) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 2) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 2) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 2) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -486,7 +487,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 2) != 0)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -506,7 +507,7 @@ test5 (size_t x)
 #else
   if (__builtin_object_size (p, 2) != 0)
 #endif
-    abort ();
+    FAIL ();
   memset (p, ' ', sizeof (buf) - 8 - 4 * 4);
 }
 
@@ -525,7 +526,7 @@ test6 (size_t x)
 #else
   if (__builtin_object_size (p, 2) != 0)
 #endif
-    abort ();
+    FAIL ();
   memset (p, ' ', sizeof (t) - 8 - 4 * 4);
 }
 
@@ -538,13 +539,13 @@ test7 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 63, 2) != sizeof (t) - 64 - 63)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 2) != sizeof (t) - 64 - 64)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 256, 2) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -555,17 +556,17 @@ test8 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 2) != sizeof (t) - 10 + 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 2) != sizeof (t) - 10)
-    abort ();
+    FAIL ();
   /* GCC only handles additions, not subtractions.  */
   q = q - 8;
   if (__builtin_object_size (q, 2) != 0
       && __builtin_object_size (q, 2) != sizeof (t) - 10 + 8)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 2) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -582,10 +583,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 2) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -593,10 +594,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 2) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -606,10 +607,10 @@ test9 (unsigned cond)
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 2)
       != sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -627,10 +628,10 @@ test10 (void)
 	{
 #ifdef __builtin_object_size
 	  if (__builtin_object_size (p - 3, 2) != sizeof (buf) - i + 3)
-	    abort ();
+	    FAIL ();
 #else
 	  if (__builtin_object_size (p - 3, 2) != 0)
-	    abort ();
+	    FAIL ();
 #endif
 	  break;
 	}
@@ -647,19 +648,19 @@ test11 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 2) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 2) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 2) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -668,19 +669,19 @@ test11 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -691,7 +692,7 @@ test11 (void)
 #else
   if (__builtin_object_size (res, 2) != 1)
 #endif
-    abort ();
+    FAIL ();
 
   free (res);
   free (ptr2);
@@ -699,32 +700,32 @@ test11 (void)
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 2) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 2) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 2) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -744,5 +745,5 @@ main (void)
   test9 (1);
   test10 ();
   test11 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-4.c b/gcc/testsuite/gcc.dg/builtin-object-size-4.c
index 4c007c364b7..34385d3cc9f 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-4.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-4.c
@@ -2,8 +2,9 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
 extern void exit (int);
 extern void *malloc (size_t);
 extern void *calloc (size_t, size_t);
@@ -40,36 +41,36 @@ test1 (void *q, int x)
   else
     r = &a.c[1];
   if (__builtin_object_size (p, 3) != sizeof (a.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 3)
       != sizeof (a.c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 3) != 0)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3)
       != (x < 0 ? sizeof (a.a) - 9 : sizeof (a.c) - 1))
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 9)
 #endif
-    abort ();
+    FAIL ();
   if (x < 6)
     r = &w[2].a[1];
   else
     r = &a.a[6];
   if (__builtin_object_size (&y, 3) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 3) != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 3) != sizeof (a.b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3)
       != (x < 6 ? sizeof (w[2].a) - 1 : sizeof (a.a) - 6))
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 6)
 #endif
-    abort ();
+    FAIL ();
   if (x < 20)
     r = malloc (30);
   else
@@ -79,7 +80,7 @@ test1 (void *q, int x)
 #else
   if (__builtin_object_size (r, 3) != 30)
 #endif
-    abort ();
+    FAIL ();
   if (x < 20)
     r = malloc (30);
   else
@@ -89,7 +90,7 @@ test1 (void *q, int x)
 #else
   if (__builtin_object_size (r, 3) != 2 * 14)
 #endif
-    abort ();
+    FAIL ();
   if (x < 30)
     r = malloc (sizeof (a));
   else
@@ -100,125 +101,125 @@ test1 (void *q, int x)
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 3)
 #endif
-    abort ();
+    FAIL ();
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3) != objsz)
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 3)
 #endif
-    abort ();
+    FAIL ();
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3) != objsz - 4)
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 3 - 4)
 #endif
-    abort ();
+    FAIL ();
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 3) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 3) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 3) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc + 10, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc->a, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&(extc + 10)->b, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5].c[3], 3) != 0)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 3) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 3) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 3) != x + 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 3) != (x + 10) * sizeof (struct A))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 3) != x * sizeof (struct A))
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 3) != (x + 5) * sizeof (struct A))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 3) != 0)
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 3) != 0)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (&vara[0].a, 3) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[10].a[0], 3) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].a[4], 3) != sizeof (vara[0].a) - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].b, 3) != sizeof (vara[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[7].c[7], 3) != sizeof (vara[0].c) - 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 3) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 3) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 3) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 3) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 3) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 3) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 3) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 3) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
   /* Prevent DSE from removing calls that prevent bad combining of
      addresses and offsets.  */
   asm volatile ("" : : "g" (&a));
@@ -253,7 +254,7 @@ test2 (void)
 	r = &a.buf1[9];
     }
   if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 9)
-    abort ();
+    FAIL ();
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
     {
@@ -267,7 +268,7 @@ test2 (void)
 	r = &a.buf1[9];
     }
   if (__builtin_object_size (r, 3) != 0)
-    abort ();
+    FAIL ();
   r = &buf3[1];
   for (i = 0; i < 4; ++i)
     {
@@ -295,22 +296,22 @@ test2 (void)
         dyn_res = sizeof (a.buf1) - 2;
     }
   if (__builtin_object_size (r, 3) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 6)
-    abort ();
+    FAIL ();
 #endif
   r += 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3) != dyn_res - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 1, 3) != dyn_res - 3)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 6 - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 1, 3) != sizeof (a.buf1) - 6 - 3)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -326,78 +327,78 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 3) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 3) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 3) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 3) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 3) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 3) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 3) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 3) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 3) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 3) != sizeof (x.a[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 3) != sizeof (x.a[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 3) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 3) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 3) != sizeof (x.a[1].c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 3) != sizeof (x.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 3) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 3) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 3) != sizeof (x.b.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 3) != sizeof (x.b.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 3) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 3) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 3) != sizeof (x.b.c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 3) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 3) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 3) != sizeof (x.c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 3) != sizeof (x.d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 3) != sizeof (x.e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 3) != sizeof (x.f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 3) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 3) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 3) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 3) != sizeof (z))
-      abort ();
+      FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 3) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 3) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -414,7 +415,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 3) != 0)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -434,7 +435,7 @@ test5 (size_t x)
 #else
   if (__builtin_object_size (p, 3) != 0)
 #endif
-    abort ();
+    FAIL ();
   memset (p, ' ', sizeof (t.buf) - 8 - 4 * 4);
 }
 
@@ -447,11 +448,11 @@ test6 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 0, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -462,18 +463,18 @@ test7 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 3) != sizeof (t.buf2))
-    abort ();
+    FAIL ();
   q = &t.buf[10];
   if (__builtin_object_size (q, 3) != 0)
-    abort ();
+    FAIL ();
   q = &t.buf[11];
   if (__builtin_object_size (q, 3) != 0)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -490,10 +491,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 3) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 3) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -501,10 +502,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 3) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -513,10 +514,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 3) != sizeof (y.c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -528,19 +529,19 @@ test9 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 3) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 3) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 3) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -549,19 +550,19 @@ test9 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -571,7 +572,7 @@ test9 (void)
 #else
   if (__builtin_object_size (res, 3) != 1)
 #endif
-    abort ();
+    FAIL ();
 
   free (res);
   free (ptr2);
@@ -579,32 +580,32 @@ test9 (void)
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 3) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 3) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 3) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -622,5 +623,5 @@ main (void)
   test7 ();
   test8 (1);
   test9 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-6.c b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
index c6887b854ac..4ce05184143 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-6.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
@@ -1,8 +1,9 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
 extern void exit (int);
 extern void *malloc (size_t);
 extern void free (void *);
@@ -20,105 +21,105 @@ test1 (struct A *p)
 {
   char *c;
   if (__builtin_object_size (&p->a, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -129,105 +130,105 @@ test2 (void)
   size_t s = 2 * sizeof (struct A);
   struct A *p = malloc (2 * sizeof (struct A));
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -239,48 +240,48 @@ test3 (void)
   size_t s;
   struct A *p = malloc (4);
   if (__builtin_object_size (&p->a, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 0)
-    abort ();
+    FAIL ();
   free (p);
   s = __builtin_offsetof (struct A, c) + 4;
   p = malloc (s);
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 4)
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -294,17 +295,17 @@ __attribute__ ((noinline))
 test4 (struct B *q, int i)
 {
   if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
 }
 
 struct C
@@ -318,13 +319,13 @@ __attribute__ ((noinline))
 test5 (struct C *c)
 {
   if (__builtin_object_size (&c->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 3) != 1)
-    abort ();
+    FAIL ();
 }
 
 struct D
@@ -342,13 +343,13 @@ __attribute__ ((noinline))
 test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
 }
 
 struct E
@@ -366,21 +367,21 @@ __attribute__ ((noinline))
 test7 (struct E *e)
 {
   if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 union F
@@ -398,13 +399,13 @@ __attribute__ ((noinline))
 test8 (union F *f)
 {
   if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 int
@@ -431,5 +432,5 @@ main (void)
   union F f, *fp = &f;
   __asm ("" : "+r" (fp));
   test8 (fp);
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-7.c b/gcc/testsuite/gcc.dg/builtin-object-size-7.c
index 41742b974ef..15d7cfade8f 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-7.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-7.c
@@ -1,6 +1,8 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
 extern void *malloc (size_t);
 extern void abort (void);
@@ -20,52 +22,52 @@ main (void)
   struct A *a = malloc (s);
   struct A *b = malloc (o + 212);
   if (__builtin_object_size (a->buf, 0) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (a->buf, 1) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (a->buf, 2) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (a->buf, 3) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 0) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 1) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 2) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 3) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 0) != s - o - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 1) != sizeof (a->buf) - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 2) != s - o - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 3) != sizeof (a->buf) - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 0) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 1) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 2) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 3) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 0) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 1) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 2) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 3) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 0) != 212 - 28)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 1) != 212 - 28)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 2) != 212 - 28)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 3) != 212 - 28)
-    abort ();
-  return 0;
+    FAIL ();
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-8.c b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
index f2d88f9d591..f67902e29f0 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-8.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
@@ -1,10 +1,11 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
 extern void *malloc (size_t);
 extern void free (void *);
-extern void abort (void);
 
 union A
 {
@@ -56,13 +57,13 @@ struct H
 
 #define T(X, S0, S1) \
   if (__builtin_object_size (X, 0) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 1) != (S1))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 2) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 3) != (S1))	\
-    abort ()
+    FAIL ()
 #define TS(X, S0) T(&X, S0, sizeof (X))
 #define TA(X, S0, S1) \
   T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1)
@@ -196,5 +197,5 @@ main (void)
   free (h2);
   free (h1);
 
-  return 0;
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-common.h b/gcc/testsuite/gcc.dg/builtin-object-size-common.h
new file mode 100644
index 00000000000..ca3b65c7ab5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-common.h
@@ -0,0 +1,12 @@
+unsigned nfails = 0;
+
+#define FAIL() ({ \
+  __builtin_printf ("Failure at line: %d\n", __LINE__);			      \
+  nfails++;								      \
+})
+
+#define DONE() ({ \
+  if (nfails > 0)							      \
+    __builtin_abort ();							      \
+  return 0;								      \
+})
diff --git a/gcc/testsuite/gcc.dg/pr101836.c b/gcc/testsuite/gcc.dg/pr101836.c
index efad02cfe89..87495236be4 100644
--- a/gcc/testsuite/gcc.dg/pr101836.c
+++ b/gcc/testsuite/gcc.dg/pr101836.c
@@ -4,16 +4,17 @@
 /* { dg-do run } */
 /* { dg-options "-O2 -fstrict-flex-arrays" } */
 
-#include <stdio.h>
+#include "builtin-object-size-common.h"
+typedef __SIZE_TYPE__ size_t;
 
 #define expect(p, _v) do { \
     size_t v = _v; \
     if (p == v) \
-        printf("ok:  %s == %zd\n", #p, p); \
+        __builtin_printf("ok:  %s == %zd\n", #p, p); \
     else \
 	{  \
-          printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
-	  __builtin_abort (); \
+          __builtin_printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
+	  FAIL (); \
 	} \
 } while (0);
 
@@ -56,5 +57,5 @@ int main(int argc, char *argv[])
 {
     stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]);
 
-    return 0;
+    DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/strict-flex-array-3.c b/gcc/testsuite/gcc.dg/strict-flex-array-3.c
index 602f99dc79a..2592e3fa8e7 100644
--- a/gcc/testsuite/gcc.dg/strict-flex-array-3.c
+++ b/gcc/testsuite/gcc.dg/strict-flex-array-3.c
@@ -4,16 +4,17 @@
 /* { dg-do run } */
 /* { dg-options "-O2 -fstrict-flex-arrays=0" } */
 
-#include <stdio.h>
+#include "builtin-object-size-common.h"
 
+typedef __SIZE_TYPE__ size_t;
 #define expect(p, _v) do { \
     size_t v = _v; \
     if (p == v) \
-        printf("ok:  %s == %zd\n", #p, p); \
+        __builtin_printf ("ok:  %s == %zd\n", #p, p); \
     else \
 	{  \
-          printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
-	  __builtin_abort (); \
+          __builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
+	  FAIL (); \
 	} \
 } while (0);
 
@@ -56,5 +57,5 @@ int main(int argc, char *argv[])
 {
     stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]);
 
-    return 0;
+    DONE ();
 }
-- 
2.38.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays
  2022-12-21 22:25 [PATCH 0/2] __bos and flex arrays Siddhesh Poyarekar
  2022-12-21 22:25 ` [PATCH 1/2] testsuite: Run __bos tests to completion Siddhesh Poyarekar
@ 2022-12-21 22:25 ` Siddhesh Poyarekar
  2023-01-26 16:20   ` Qing Zhao
  2023-01-31 12:46   ` Jakub Jelinek
  2023-01-03 14:30 ` [ping][PATCH 0/2] __bos and " Siddhesh Poyarekar
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Siddhesh Poyarekar @ 2022-12-21 22:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub

The tree object size pass tries to fail when it detects a flex array in
the struct, but it ends up doing the right thing only when the flex
array is in the outermost struct.  For nested cases (such as arrays
nested in a union or an inner struct), it ends up taking whatever value
the flex array is declared with, using zero for the standard flex array,
i.e. [].

Rework subobject size computation to make it more consistent across the
board, honoring -fstrict-flex-arrays.  With this change, any array at
the end of the struct will end up causing __bos to use the allocated
value of the outer object, bailing out in the maximum case when it can't
find it.  In the minimum case, it will return the subscript value or the
allocated value of the outer object, whichever is larger.

gcc/ChangeLog:

	PR tree-optimization/107952
	* tree-object-size.cc (size_from_objects): New function.
	(addr_object_size): Call it.  Fully rely on
	array_ref_flexible_size_p call to determine flex array.

gcc/testsuite/ChangeLog:

	PR tree-optimization/107952
	* g++.dg/ext/builtin-object-size1.C (test1, test6, test7,
	test8): Adjust expected result for object size type 3 and 1.
	* g++.dg/ext/builtin-object-size2.C (test1, test6, test7,
	test8): Likewise.
	* gcc.dg/builtin-object-size-13.c (main): Likewise.
	* gcc.dg/builtin-object-size-6.c (test1, test6, test7, test8):
	Likewise.
	* gcc.dg/builtin-object-size-8.c (main): Likewise.
	* gcc.dg/builtin-object-size-flex-common.h: Common code for new
	tests.
	* gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c: New
	test.
	* gcc.dg/builtin-object-size-flex-nested-struct-zero.c: New
	test.
	* gcc.dg/builtin-object-size-flex-nested-struct.c: New test.
	* gcc.dg/builtin-object-size-flex-nested-union-nonzero.c: New
	test.
	* gcc.dg/builtin-object-size-flex-nested-union-zero.c: New test.
	* gcc.dg/builtin-object-size-flex-nested-union.c: New test.
	* gcc.dg/builtin-object-size-flex-nonzero.c: New test.
	* gcc.dg/builtin-object-size-flex-zero.c: New test.
	* gcc.dg/builtin-object-size-flex.c: New test.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
 .../g++.dg/ext/builtin-object-size1.C         |  10 +-
 .../g++.dg/ext/builtin-object-size2.C         |  10 +-
 gcc/testsuite/gcc.dg/builtin-object-size-13.c |   4 +-
 gcc/testsuite/gcc.dg/builtin-object-size-6.c  |  10 +-
 gcc/testsuite/gcc.dg/builtin-object-size-8.c  |   4 +-
 .../gcc.dg/builtin-object-size-flex-common.h  |  90 +++++++++++
 ...n-object-size-flex-nested-struct-nonzero.c |   6 +
 ...ltin-object-size-flex-nested-struct-zero.c |   6 +
 .../builtin-object-size-flex-nested-struct.c  |  22 +++
 ...in-object-size-flex-nested-union-nonzero.c |   6 +
 ...iltin-object-size-flex-nested-union-zero.c |   6 +
 .../builtin-object-size-flex-nested-union.c   |  28 ++++
 .../gcc.dg/builtin-object-size-flex-nonzero.c |   6 +
 .../gcc.dg/builtin-object-size-flex-zero.c    |   6 +
 .../gcc.dg/builtin-object-size-flex.c         |  18 +++
 gcc/tree-object-size.cc                       | 150 ++++++------------
 16 files changed, 265 insertions(+), 117 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex.c

diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
index 165b415683b..5b863637123 100644
--- a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
+++ b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
@@ -103,7 +103,7 @@ test1 (A *p)
     FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
     FAIL ();
-  if (__builtin_object_size (&p->c, 3) != 0)
+  if (__builtin_object_size (&p->c, 3) != 10)
     FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
@@ -118,7 +118,7 @@ test1 (A *p)
   if (__builtin_object_size (c, 3) != sizeof (p->b))
     FAIL ();
   c = (char *) &p->c;
-  if (__builtin_object_size (c, 3) != 0)
+  if (__builtin_object_size (c, 3) != 10)
     FAIL ();
 }
 
@@ -344,7 +344,7 @@ test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
     FAIL ();
-  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
+  if (__builtin_object_size (&d->j.a[3], 1) != (size_t) -1)
     FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
     FAIL ();
@@ -380,7 +380,7 @@ test7 (struct E *e)
     FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
     FAIL ();
-  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
+  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))
     FAIL ();
 }
 
@@ -404,7 +404,7 @@ test8 (union F *f)
     FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
     FAIL ();
-  if (__builtin_object_size (&f->d.c[3], 3) != 0)
+  if (__builtin_object_size (&f->d.c[3], 3) != sizeof (f->d.c) - 3)
     FAIL ();
 }
 
diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
index c5dbd96193c..665dad886d4 100644
--- a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
+++ b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
@@ -106,7 +106,7 @@ test1 (A *p)
     FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
     FAIL ();
-  if (__builtin_object_size (&p->c, 3) != 0)
+  if (__builtin_object_size (&p->c, 3) != 10)
     FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
@@ -121,7 +121,7 @@ test1 (A *p)
   if (__builtin_object_size (c, 3) != sizeof (p->b))
     FAIL ();
   c = (char *) &p->c;
-  if (__builtin_object_size (c, 3) != 0)
+  if (__builtin_object_size (c, 3) != 10)
     FAIL ();
 }
 
@@ -347,7 +347,7 @@ test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
     FAIL ();
-  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
+  if (__builtin_object_size (&d->j.a[3], 1) != (size_t) -1)
     FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
     FAIL ();
@@ -383,7 +383,7 @@ test7 (struct E *e)
     FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
     FAIL ();
-  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
+  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))
     FAIL ();
 }
 
@@ -407,7 +407,7 @@ test8 (union F *f)
     FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
     FAIL ();
-  if (__builtin_object_size (&f->d.c[3], 3) != 0)
+  if (__builtin_object_size (&f->d.c[3], 3) != sizeof (f->d.c) - 3)
     FAIL ();
 }
 
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-13.c b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
index c7d58c941d4..6429dcaf426 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-13.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
@@ -332,9 +332,9 @@ main (void)
   o2 = __builtin_offsetof (struct H, h2.e1.c2);
   h1 = malloc (s);
   h2 = malloc (o2 + 212);
-  TA (h1->h2.e1.c2.a2, s - o2, sizeof (h1->h2.e1.c2.a2));
+  TA (h1->h2.e1.c2.a2, s - o2, s - o2);
   s = o2 + 212;
-  TA (h2->h2.e1.c2.a2, s - o2, sizeof (h2->h2.e1.c2.a2));
+  TA (h2->h2.e1.c2.a2, s - o2, s - o2);
   free (h2);
   free (h1);
   s = sizeof (struct H);
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-6.c b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
index 4ce05184143..1ae608d456b 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-6.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
@@ -103,7 +103,7 @@ test1 (struct A *p)
     FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
     FAIL ();
-  if (__builtin_object_size (&p->c, 3) != 0)
+  if (__builtin_object_size (&p->c, 3) != 10)
     FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
@@ -118,7 +118,7 @@ test1 (struct A *p)
   if (__builtin_object_size (c, 3) != sizeof (p->b))
     FAIL ();
   c = (char *) &p->c;
-  if (__builtin_object_size (c, 3) != 0)
+  if (__builtin_object_size (c, 3) != 10)
     FAIL ();
 }
 
@@ -344,7 +344,7 @@ test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
     FAIL ();
-  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
+  if (__builtin_object_size (&d->j.a[3], 1) != -1)
     FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
     FAIL ();
@@ -380,7 +380,7 @@ test7 (struct E *e)
     FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
     FAIL ();
-  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
+  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))
     FAIL ();
 }
 
@@ -404,7 +404,7 @@ test8 (union F *f)
     FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
     FAIL ();
-  if (__builtin_object_size (&f->d.c[3], 3) != 0)
+  if (__builtin_object_size (&f->d.c[3], 3) != 7)
     FAIL ();
 }
 
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-8.c b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
index f67902e29f0..184769f1bd8 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-8.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
@@ -186,13 +186,13 @@ main (void)
   TS (h1->h1, s);
   TS (h1->h2.e1.c1, s - o);
   TS (h1->h2.e1.c2.a1, s - o2);
-  TA (h1->h2.e1.c2.a2, s - o2, sizeof (h1->h2.e1.c2.a2));
+  TA (h1->h2.e1.c2.a2, s - o2, s - o2);
   TF (h1->h2.e2, s - o);
   s = o2 + 212;
   TS (h2->h1, s);
   TS (h2->h2.e1.c1, s - o);
   TS (h2->h2.e1.c2.a1, s - o2);
-  TA (h2->h2.e1.c2.a2, s - o2, sizeof (h2->h2.e1.c2.a2));
+  TA (h2->h2.e1.c2.a2, s - o2, s - o2);
   TF (h2->h2.e2, s - o);
   free (h2);
   free (h1);
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h b/gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
new file mode 100644
index 00000000000..b8b68da762d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
@@ -0,0 +1,90 @@
+#include "builtin-object-size-common.h"
+
+typedef __SIZE_TYPE__ size_t;
+
+void
+__attribute__ ((noinline))
+test_flexarray_allocate (const char *name)
+{
+  size_t n = sizeof (flex_t);
+
+  if (name != (void *) 0)
+    n += __builtin_strlen (name) + 1;
+
+  flex_t *p = __builtin_malloc (n);
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 0)
+      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 1)
+      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 2)
+      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 3)
+      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+
+  __builtin_free (p);
+}
+
+void
+__attribute__ ((noinline))
+__attribute__ ((access (read_only, 1, 2)))
+test_flexarray_access (flex_t *p, size_t sz)
+{
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 0)
+      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 1)
+      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 2)
+      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 3)
+      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
+    FAIL ();
+}
+
+void
+__attribute__ ((noinline))
+test_flexarray_none (flex_t *p)
+{
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 0) != -1)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 1) != -1)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 2) != 0)
+    FAIL ();
+
+  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 3) != SIZEOF_FLEX_ARRAY)
+    FAIL ();
+}
+
+int
+main (int argc, char **argv)
+{
+  const char *str = "qwertyuiopasdfgghjklzxcvbnm";
+
+  test_flexarray_allocate (str);
+
+  const size_t sz = 1024;
+  flex_t *p = __builtin_malloc (sz * sizeof (*p));
+
+  test_flexarray_access (p, sz);
+
+  test_flexarray_none (p);
+  __builtin_free (p);
+
+  DONE ();
+}
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
new file mode 100644
index 00000000000..c50cd89a817
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#define SIZEOF_FLEX_ARRAY 4
+
+#include "builtin-object-size-flex-nested-struct.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
new file mode 100644
index 00000000000..554aece0b46
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#define SIZEOF_FLEX_ARRAY 0
+
+#include "builtin-object-size-flex-nested-struct.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
new file mode 100644
index 00000000000..1adeac16ac4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
@@ -0,0 +1,22 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#ifndef SIZEOF_FLEX_ARRAY
+# define SIZEOF_FLEX_ARRAY_DECL
+# define SIZEOF_FLEX_ARRAY 0
+#else
+# define SIZEOF_FLEX_ARRAY_DECL SIZEOF_FLEX_ARRAY
+#endif
+
+typedef struct {
+  unsigned pad;
+  struct {
+    unsigned pad;
+    char data[SIZEOF_FLEX_ARRAY_DECL];
+  } s;
+} flex_t;
+
+#define FLEX_ARRAY(p) p->s.data
+#define SIZE_OF_FLEX sizeof (unsigned) + sizeof (unsigned)
+
+#include "builtin-object-size-flex-common.h"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
new file mode 100644
index 00000000000..58e387c8db6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#define SIZEOF_FLEX_ARRAY 4
+
+#include "builtin-object-size-flex-nested-union.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
new file mode 100644
index 00000000000..ec6429a5a9b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#define SIZEOF_FLEX_ARRAY 0
+
+#include "builtin-object-size-flex-nested-union.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
new file mode 100644
index 00000000000..8326131c890
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#ifndef SIZEOF_FLEX_ARRAY
+# define SIZEOF_FLEX_ARRAY_DECL
+# define SIZEOF_FLEX_ARRAY 0
+#else
+# define SIZEOF_FLEX_ARRAY_DECL SIZEOF_FLEX_ARRAY
+#endif
+
+typedef struct {
+  unsigned pad;
+  union {
+      struct {
+	unsigned pad;
+	char data[SIZEOF_FLEX_ARRAY_DECL];
+      } s1;
+      struct {
+	unsigned pad;
+	char data[SIZEOF_FLEX_ARRAY_DECL];
+      } s2;
+  } u;
+} flex_t;
+
+#define FLEX_ARRAY(p) p->u.s1.data
+#define SIZE_OF_FLEX sizeof (unsigned) + sizeof (unsigned)
+
+#include "builtin-object-size-flex-common.h"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
new file mode 100644
index 00000000000..693d2e98758
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#define SIZEOF_FLEX_ARRAY 4
+
+#include "builtin-object-size-flex.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
new file mode 100644
index 00000000000..f38d0e01d4b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#define SIZEOF_FLEX_ARRAY 0
+
+#include "builtin-object-size-flex.c"
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex.c
new file mode 100644
index 00000000000..34aba8942d6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex.c
@@ -0,0 +1,18 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#ifndef SIZEOF_FLEX_ARRAY
+# define SIZEOF_FLEX_ARRAY_DECL
+# define SIZEOF_FLEX_ARRAY 0
+#else
+# define SIZEOF_FLEX_ARRAY_DECL SIZEOF_FLEX_ARRAY
+#endif
+
+typedef struct {
+  unsigned pad;
+  char data[SIZEOF_FLEX_ARRAY_DECL];
+} flex_t;
+
+#define FLEX_ARRAY(p) p->data
+
+#include "builtin-object-size-flex-common.h"
diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
index d9f25397c71..98ee3c2b527 100644
--- a/gcc/tree-object-size.cc
+++ b/gcc/tree-object-size.cc
@@ -499,6 +499,19 @@ decl_init_size (tree decl, bool min)
   return size;
 }
 
+/* Return the size of SUBOBJ that is within VAR where the latter has VAR_SIZE
+   size.  */
+
+static tree
+size_from_objects (const_tree subobj, const_tree var, tree var_size,
+		   int object_size_type)
+{
+  tree bytes = compute_object_offset (subobj, var);
+
+  return (bytes != error_mark_node ? size_for_offset (var_size, bytes)
+	  : size_unknown (object_size_type));
+}
+
 /* Compute __builtin_object_size for PTR, which is a ADDR_EXPR.
    OBJECT_SIZE_TYPE is the second argument from __builtin_object_size.
    If unknown, return size_unknown (object_size_type).  */
@@ -589,105 +602,52 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
 	{
 	  var = TREE_OPERAND (ptr, 0);
 
+	  /* Get the immediate containing subobject.  Skip over conversions
+	     because we don't need them.  */
 	  while (var != pt_var
-		 && TREE_CODE (var) != BIT_FIELD_REF
-		 && TREE_CODE (var) != COMPONENT_REF
-		 && TREE_CODE (var) != ARRAY_REF
-		 && TREE_CODE (var) != ARRAY_RANGE_REF
-		 && TREE_CODE (var) != REALPART_EXPR
-		 && TREE_CODE (var) != IMAGPART_EXPR)
+		 && (!handled_component_p (var)
+		     || TREE_CODE (var) == VIEW_CONVERT_EXPR))
 	    var = TREE_OPERAND (var, 0);
 	  if (var != pt_var && TREE_CODE (var) == ARRAY_REF)
 	    var = TREE_OPERAND (var, 0);
+
+	  /* If the subobject size cannot be easily inferred or is smaller than
+	     the whole size, just use the whole size.  */
 	  if (! TYPE_SIZE_UNIT (TREE_TYPE (var))
 	      || ! tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (var)))
 	      || (pt_var_size && TREE_CODE (pt_var_size) == INTEGER_CST
 		  && tree_int_cst_lt (pt_var_size,
 				      TYPE_SIZE_UNIT (TREE_TYPE (var)))))
 	    var = pt_var;
-	  else if (var != pt_var && TREE_CODE (pt_var) == MEM_REF)
-	    {
-	      tree v = var;
-	      /* For &X->fld, compute object size if fld isn't a flexible array
-		 member.  */
-	      bool is_flexible_array_mem_ref = false;
-	      while (v && v != pt_var)
-		switch (TREE_CODE (v))
-		  {
-		  case ARRAY_REF:
-		    if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_OPERAND (v, 0))))
-		      {
-			tree domain
-			  = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (v, 0)));
-			if (domain && TYPE_MAX_VALUE (domain))
-			  {
-			    v = NULL_TREE;
-			    break;
-			  }
-		      }
-		    v = TREE_OPERAND (v, 0);
-		    break;
-		  case REALPART_EXPR:
-		  case IMAGPART_EXPR:
-		    v = NULL_TREE;
-		    break;
-		  case COMPONENT_REF:
-		    if (TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE)
-		      {
-			v = NULL_TREE;
-			break;
-		      }
-		    is_flexible_array_mem_ref = array_ref_flexible_size_p (v);
-		    while (v != pt_var && TREE_CODE (v) == COMPONENT_REF)
-		      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
-			  != UNION_TYPE
-			  && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
-			  != QUAL_UNION_TYPE)
-			break;
-		      else
-			v = TREE_OPERAND (v, 0);
-		    if (TREE_CODE (v) == COMPONENT_REF
-			&& TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
-			   == RECORD_TYPE)
-		      {
-			/* compute object size only if v is not a
-			   flexible array member.  */
-			if (!is_flexible_array_mem_ref)
-			  {
-			    v = NULL_TREE;
-			    break;
-			  }
-			v = TREE_OPERAND (v, 0);
-		      }
-		    while (v != pt_var && TREE_CODE (v) == COMPONENT_REF)
-		      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
-			  != UNION_TYPE
-			  && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
-			  != QUAL_UNION_TYPE)
-			break;
-		      else
-			v = TREE_OPERAND (v, 0);
-		    if (v != pt_var)
-		      v = NULL_TREE;
-		    else
-		      v = pt_var;
-		    break;
-		  default:
-		    v = pt_var;
-		    break;
-		  }
-	      if (v == pt_var)
-		var = pt_var;
-	    }
 	}
       else
 	var = pt_var;
 
+      bool is_flexible_array_mem_ref = false;
+      /* Find out if this is a flexible array.  This will change
+	 according to -fstrict-flex-arrays.  */
+      if (var != pt_var && TREE_CODE (pt_var) == MEM_REF)
+	is_flexible_array_mem_ref = array_ref_flexible_size_p (var);
+
+      /* We cannot get a maximum estimate for a flex array without the
+	 whole object size.  */
+      if (is_flexible_array_mem_ref && !pt_var_size
+	  && !(object_size_type & OST_MINIMUM))
+	return false;
+
       if (var != pt_var)
 	{
-	  var_size = TYPE_SIZE_UNIT (TREE_TYPE (var));
-	  if (!TREE_CONSTANT (var_size))
-	    var_size = get_or_create_ssa_default_def (cfun, var_size);
+	  /* For flexible arrays, we prefer the size based on the whole object
+	     if it is available.  */
+	  if (is_flexible_array_mem_ref && pt_var_size)
+	    var_size = size_from_objects (var, pt_var, pt_var_size,
+					  object_size_type);
+	  else
+	    {
+	      var_size = TYPE_SIZE_UNIT (TREE_TYPE (var));
+	      if (!TREE_CONSTANT (var_size))
+		var_size = get_or_create_ssa_default_def (cfun, var_size);
+	    }
 	  if (!var_size)
 	    return false;
 	}
@@ -695,23 +655,17 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
 	return false;
       else
 	var_size = pt_var_size;
-      bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var);
-      if (bytes != error_mark_node)
+
+      bytes = size_from_objects (TREE_OPERAND (ptr, 0), var, var_size,
+				 object_size_type);
+
+      if (var != pt_var && pt_var_size && TREE_CODE (pt_var) == MEM_REF
+	  && !is_flexible_array_mem_ref)
 	{
-	  bytes = size_for_offset (var_size, bytes);
-	  if (var != pt_var && pt_var_size && TREE_CODE (pt_var) == MEM_REF)
-	    {
-	      tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0),
-						   pt_var);
-	      if (bytes2 != error_mark_node)
-		{
-		  bytes2 = size_for_offset (pt_var_size, bytes2);
-		  bytes = size_binop (MIN_EXPR, bytes, bytes2);
-		}
-	    }
+	  tree bytes2 = size_from_objects (TREE_OPERAND (ptr, 0), pt_var,
+					   pt_var_size, object_size_type);
+	  bytes = size_binop (MIN_EXPR, bytes, bytes2);
 	}
-      else
-	bytes = size_unknown (object_size_type);
 
       wholebytes
 	= object_size_type & OST_SUBOBJECT ? var_size : pt_var_wholesize;
-- 
2.38.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ping][PATCH 0/2] __bos and flex arrays
  2022-12-21 22:25 [PATCH 0/2] __bos and flex arrays Siddhesh Poyarekar
  2022-12-21 22:25 ` [PATCH 1/2] testsuite: Run __bos tests to completion Siddhesh Poyarekar
  2022-12-21 22:25 ` [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays Siddhesh Poyarekar
@ 2023-01-03 14:30 ` Siddhesh Poyarekar
  2023-01-11 13:14 ` [ping2][PATCH " Siddhesh Poyarekar
  2023-01-20 19:38 ` [ping3][PATCH " Siddhesh Poyarekar
  4 siblings, 0 replies; 13+ messages in thread
From: Siddhesh Poyarekar @ 2023-01-03 14:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub

Ping!

On 2022-12-21 17:25, Siddhesh Poyarekar wrote:
> Hi,
> 
> The first patch in the series is just a minor test cleanup that I did to
> make sure all tests in a test case run (instead of aborting at first
> failure) and print the ones that failed.  The second patch is the actual
> fix.
> 
> The patch intends to make __bos/__bdos do the right thing with structs
> containing flex arrays, either directly or within nested structs and
> unions.  This should improve minimum object size estimation in some
> cases and also bail out more consistently so that flex arrays don't
> cause false positives in fortification.
> 
> I've tested this with a bootstrap on x86_64 and also with
> --with-build-config=bootstrap-ubsan to make sure that there are no new
> failures due to this change.
> 
> Siddhesh Poyarekar (2):
>    testsuite: Run __bos tests to completion
>    tree-object-size: More consistent behaviour with flex arrays
> 
>   .../g++.dg/ext/builtin-object-size1.C         | 267 ++++++++--------
>   .../g++.dg/ext/builtin-object-size2.C         | 267 ++++++++--------
>   .../gcc.dg/builtin-dynamic-object-size-0.c    |  14 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 263 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-12.c |  12 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-13.c |  17 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-15.c |  11 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 287 +++++++++---------
>   gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 263 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-4.c  | 267 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-6.c  | 267 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-7.c  |  52 ++--
>   gcc/testsuite/gcc.dg/builtin-object-size-8.c  |  17 +-
>   .../gcc.dg/builtin-object-size-common.h       |  12 +
>   .../gcc.dg/builtin-object-size-flex-common.h  |  90 ++++++
>   ...n-object-size-flex-nested-struct-nonzero.c |   6 +
>   ...ltin-object-size-flex-nested-struct-zero.c |   6 +
>   .../builtin-object-size-flex-nested-struct.c  |  22 ++
>   ...in-object-size-flex-nested-union-nonzero.c |   6 +
>   ...iltin-object-size-flex-nested-union-zero.c |   6 +
>   .../builtin-object-size-flex-nested-union.c   |  28 ++
>   .../gcc.dg/builtin-object-size-flex-nonzero.c |   6 +
>   .../gcc.dg/builtin-object-size-flex-zero.c    |   6 +
>   .../gcc.dg/builtin-object-size-flex.c         |  18 ++
>   gcc/testsuite/gcc.dg/pr101836.c               |  11 +-
>   gcc/testsuite/gcc.dg/strict-flex-array-3.c    |  11 +-
>   gcc/tree-object-size.cc                       | 150 ++++-----
>   27 files changed, 1275 insertions(+), 1107 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-common.h
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex.c
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ping2][PATCH 0/2] __bos and flex arrays
  2022-12-21 22:25 [PATCH 0/2] __bos and flex arrays Siddhesh Poyarekar
                   ` (2 preceding siblings ...)
  2023-01-03 14:30 ` [ping][PATCH 0/2] __bos and " Siddhesh Poyarekar
@ 2023-01-11 13:14 ` Siddhesh Poyarekar
  2023-01-20 19:38 ` [ping3][PATCH " Siddhesh Poyarekar
  4 siblings, 0 replies; 13+ messages in thread
From: Siddhesh Poyarekar @ 2023-01-11 13:14 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub

Ping!

On 2022-12-21 17:25, Siddhesh Poyarekar wrote:
> Hi,
> 
> The first patch in the series is just a minor test cleanup that I did to
> make sure all tests in a test case run (instead of aborting at first
> failure) and print the ones that failed.  The second patch is the actual
> fix.
> 
> The patch intends to make __bos/__bdos do the right thing with structs
> containing flex arrays, either directly or within nested structs and
> unions.  This should improve minimum object size estimation in some
> cases and also bail out more consistently so that flex arrays don't
> cause false positives in fortification.
> 
> I've tested this with a bootstrap on x86_64 and also with
> --with-build-config=bootstrap-ubsan to make sure that there are no new
> failures due to this change.
> 
> Siddhesh Poyarekar (2):
>    testsuite: Run __bos tests to completion
>    tree-object-size: More consistent behaviour with flex arrays
> 
>   .../g++.dg/ext/builtin-object-size1.C         | 267 ++++++++--------
>   .../g++.dg/ext/builtin-object-size2.C         | 267 ++++++++--------
>   .../gcc.dg/builtin-dynamic-object-size-0.c    |  14 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 263 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-12.c |  12 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-13.c |  17 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-15.c |  11 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 287 +++++++++---------
>   gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 263 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-4.c  | 267 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-6.c  | 267 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-7.c  |  52 ++--
>   gcc/testsuite/gcc.dg/builtin-object-size-8.c  |  17 +-
>   .../gcc.dg/builtin-object-size-common.h       |  12 +
>   .../gcc.dg/builtin-object-size-flex-common.h  |  90 ++++++
>   ...n-object-size-flex-nested-struct-nonzero.c |   6 +
>   ...ltin-object-size-flex-nested-struct-zero.c |   6 +
>   .../builtin-object-size-flex-nested-struct.c  |  22 ++
>   ...in-object-size-flex-nested-union-nonzero.c |   6 +
>   ...iltin-object-size-flex-nested-union-zero.c |   6 +
>   .../builtin-object-size-flex-nested-union.c   |  28 ++
>   .../gcc.dg/builtin-object-size-flex-nonzero.c |   6 +
>   .../gcc.dg/builtin-object-size-flex-zero.c    |   6 +
>   .../gcc.dg/builtin-object-size-flex.c         |  18 ++
>   gcc/testsuite/gcc.dg/pr101836.c               |  11 +-
>   gcc/testsuite/gcc.dg/strict-flex-array-3.c    |  11 +-
>   gcc/tree-object-size.cc                       | 150 ++++-----
>   27 files changed, 1275 insertions(+), 1107 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-common.h
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex.c
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ping3][PATCH 0/2] __bos and flex arrays
  2022-12-21 22:25 [PATCH 0/2] __bos and flex arrays Siddhesh Poyarekar
                   ` (3 preceding siblings ...)
  2023-01-11 13:14 ` [ping2][PATCH " Siddhesh Poyarekar
@ 2023-01-20 19:38 ` Siddhesh Poyarekar
  4 siblings, 0 replies; 13+ messages in thread
From: Siddhesh Poyarekar @ 2023-01-20 19:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub

ping!

On 2022-12-21 17:25, Siddhesh Poyarekar wrote:
> Hi,
> 
> The first patch in the series is just a minor test cleanup that I did to
> make sure all tests in a test case run (instead of aborting at first
> failure) and print the ones that failed.  The second patch is the actual
> fix.
> 
> The patch intends to make __bos/__bdos do the right thing with structs
> containing flex arrays, either directly or within nested structs and
> unions.  This should improve minimum object size estimation in some
> cases and also bail out more consistently so that flex arrays don't
> cause false positives in fortification.
> 
> I've tested this with a bootstrap on x86_64 and also with
> --with-build-config=bootstrap-ubsan to make sure that there are no new
> failures due to this change.
> 
> Siddhesh Poyarekar (2):
>    testsuite: Run __bos tests to completion
>    tree-object-size: More consistent behaviour with flex arrays
> 
>   .../g++.dg/ext/builtin-object-size1.C         | 267 ++++++++--------
>   .../g++.dg/ext/builtin-object-size2.C         | 267 ++++++++--------
>   .../gcc.dg/builtin-dynamic-object-size-0.c    |  14 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 263 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-12.c |  12 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-13.c |  17 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-15.c |  11 +-
>   gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 287 +++++++++---------
>   gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 263 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-4.c  | 267 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-6.c  | 267 ++++++++--------
>   gcc/testsuite/gcc.dg/builtin-object-size-7.c  |  52 ++--
>   gcc/testsuite/gcc.dg/builtin-object-size-8.c  |  17 +-
>   .../gcc.dg/builtin-object-size-common.h       |  12 +
>   .../gcc.dg/builtin-object-size-flex-common.h  |  90 ++++++
>   ...n-object-size-flex-nested-struct-nonzero.c |   6 +
>   ...ltin-object-size-flex-nested-struct-zero.c |   6 +
>   .../builtin-object-size-flex-nested-struct.c  |  22 ++
>   ...in-object-size-flex-nested-union-nonzero.c |   6 +
>   ...iltin-object-size-flex-nested-union-zero.c |   6 +
>   .../builtin-object-size-flex-nested-union.c   |  28 ++
>   .../gcc.dg/builtin-object-size-flex-nonzero.c |   6 +
>   .../gcc.dg/builtin-object-size-flex-zero.c    |   6 +
>   .../gcc.dg/builtin-object-size-flex.c         |  18 ++
>   gcc/testsuite/gcc.dg/pr101836.c               |  11 +-
>   gcc/testsuite/gcc.dg/strict-flex-array-3.c    |  11 +-
>   gcc/tree-object-size.cc                       | 150 ++++-----
>   27 files changed, 1275 insertions(+), 1107 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-common.h
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
>   create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex.c
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays
  2022-12-21 22:25 ` [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays Siddhesh Poyarekar
@ 2023-01-26 16:20   ` Qing Zhao
  2023-01-26 17:16     ` Siddhesh Poyarekar
  2023-01-31 12:46   ` Jakub Jelinek
  1 sibling, 1 reply; 13+ messages in thread
From: Qing Zhao @ 2023-01-26 16:20 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: gcc Patches, Jakub Jelinek, kees Cook

Hi, Siddhesh,

Thanks a lot for this patch, after -fstrict-flex-array functionality has been added into GCC,
 I think that making the tree-object-size to have consistent behavior with flex arrays is a 
valuable and natural work that need to be added.

I also like the comments you added into tree-object-size.cc, making the code much easier to be understood.

Minor comments below:

> On Dec 21, 2022, at 5:25 PM, Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
> 
> The tree object size pass tries to fail when it detects a flex array in
> the struct, but it ends up doing the right thing only when the flex
> array is in the outermost struct.  For nested cases (such as arrays
> nested in a union or an inner struct), it ends up taking whatever value
> the flex array is declared with, using zero for the standard flex array,
> i.e. [].
> 
> Rework subobject size computation to make it more consistent across the
> board, honoring -fstrict-flex-arrays.  With this change, any array at
> the end of the struct will end up causing __bos to use the allocated
> value of the outer object, bailing out in the maximum case when it can't
> find it.  In the minimum case, it will return the subscript value or the
> allocated value of the outer object, whichever is larger.

I see from the changes in the testing case, there are the following major changes for the existing behavior (can be show with the testing case)


****For non-nested structures:

struct A
{
  char a[10];
  int b;
  char c[10];
};

1.  The Minimum size of the reference to the subobject that is a trailing array of a structure is changed from “0” to “sizeof the subobject"
> -  if (__builtin_object_size (&p->c, 3) != 0)
+  if (__builtin_object_size (&p->c, 3) != 10)

****For nested structures:

struct D
{
  int i;
  struct D1
  {
    char b;
    char a[10];
  } j;
};

2.   The Maximum size of the reference to the subobject that is a trailing array of the inner structure is changed from “sizeof the subobject” to “-1"
> -  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
> +  if (__builtin_object_size (&d->j.a[3], 1) != (size_t) -1)

.
3.  The Minimum size of the reference to the subobject that is a trailing array of the inner structure is changed from “0” to “sizeof the subobject"
-  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
> +  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))


I think that all the above changes are good. My only concern is, for the change of the Minimum size of the reference to the subobject that is a trailing array (the above case 1 and 3), will there be any negtive impact on the existing application that use it?

> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/107952
> 	* tree-object-size.cc (size_from_objects): New function.
> 	(addr_object_size): Call it.  Fully rely on
> 	array_ref_flexible_size_p call to determine flex array.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/107952
> 	* g++.dg/ext/builtin-object-size1.C (test1, test6, test7,
> 	test8): Adjust expected result for object size type 3 and 1.
> 	* g++.dg/ext/builtin-object-size2.C (test1, test6, test7,
> 	test8): Likewise.
> 	* gcc.dg/builtin-object-size-13.c (main): Likewise.
> 	* gcc.dg/builtin-object-size-6.c (test1, test6, test7, test8):
> 	Likewise.
> 	* gcc.dg/builtin-object-size-8.c (main): Likewise.
> 	* gcc.dg/builtin-object-size-flex-common.h: Common code for new
> 	tests.
> 	* gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c: New
> 	test.
> 	* gcc.dg/builtin-object-size-flex-nested-struct-zero.c: New
> 	test.
> 	* gcc.dg/builtin-object-size-flex-nested-struct.c: New test.
> 	* gcc.dg/builtin-object-size-flex-nested-union-nonzero.c: New
> 	test.
> 	* gcc.dg/builtin-object-size-flex-nested-union-zero.c: New test.
> 	* gcc.dg/builtin-object-size-flex-nested-union.c: New test.
> 	* gcc.dg/builtin-object-size-flex-nonzero.c: New test.
> 	* gcc.dg/builtin-object-size-flex-zero.c: New test.
> 	* gcc.dg/builtin-object-size-flex.c: New test.
> 
> Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
> ---
> .../g++.dg/ext/builtin-object-size1.C         |  10 +-
> .../g++.dg/ext/builtin-object-size2.C         |  10 +-
> gcc/testsuite/gcc.dg/builtin-object-size-13.c |   4 +-
> gcc/testsuite/gcc.dg/builtin-object-size-6.c  |  10 +-
> gcc/testsuite/gcc.dg/builtin-object-size-8.c  |   4 +-
> .../gcc.dg/builtin-object-size-flex-common.h  |  90 +++++++++++
> ...n-object-size-flex-nested-struct-nonzero.c |   6 +
> ...ltin-object-size-flex-nested-struct-zero.c |   6 +
> .../builtin-object-size-flex-nested-struct.c  |  22 +++
> ...in-object-size-flex-nested-union-nonzero.c |   6 +
> ...iltin-object-size-flex-nested-union-zero.c |   6 +
> .../builtin-object-size-flex-nested-union.c   |  28 ++++
> .../gcc.dg/builtin-object-size-flex-nonzero.c |   6 +
> .../gcc.dg/builtin-object-size-flex-zero.c    |   6 +
> .../gcc.dg/builtin-object-size-flex.c         |  18 +++
> gcc/tree-object-size.cc                       | 150 ++++++------------
> 16 files changed, 265 insertions(+), 117 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-flex.c
> 
> diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
> index 165b415683b..5b863637123 100644
> --- a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
> +++ b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
> @@ -103,7 +103,7 @@ test1 (A *p)
>     FAIL ();
>   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
>     FAIL ();
> -  if (__builtin_object_size (&p->c, 3) != 0)
> +  if (__builtin_object_size (&p->c, 3) != 10)
>     FAIL ();
>   c = p->a;
>   if (__builtin_object_size (c, 3) != sizeof (p->a))
> @@ -118,7 +118,7 @@ test1 (A *p)
>   if (__builtin_object_size (c, 3) != sizeof (p->b))
>     FAIL ();
>   c = (char *) &p->c;
> -  if (__builtin_object_size (c, 3) != 0)
> +  if (__builtin_object_size (c, 3) != 10)
>     FAIL ();
> }
> 
> @@ -344,7 +344,7 @@ test6 (struct D *d)
> {
>   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
>     FAIL ();
> -  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
> +  if (__builtin_object_size (&d->j.a[3], 1) != (size_t) -1)
>     FAIL ();
>   if (__builtin_object_size (&d->j.a[3], 2) != 0)
>     FAIL ();
> @@ -380,7 +380,7 @@ test7 (struct E *e)
>     FAIL ();
>   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
>     FAIL ();
> -  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
> +  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))
>     FAIL ();
> }
> 
> @@ -404,7 +404,7 @@ test8 (union F *f)
>     FAIL ();
>   if (__builtin_object_size (&f->d.c[3], 2) != 0)
>     FAIL ();
> -  if (__builtin_object_size (&f->d.c[3], 3) != 0)
> +  if (__builtin_object_size (&f->d.c[3], 3) != sizeof (f->d.c) - 3)
>     FAIL ();
> }
> 
> diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
> index c5dbd96193c..665dad886d4 100644
> --- a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
> +++ b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
> @@ -106,7 +106,7 @@ test1 (A *p)
>     FAIL ();
>   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
>     FAIL ();
> -  if (__builtin_object_size (&p->c, 3) != 0)
> +  if (__builtin_object_size (&p->c, 3) != 10)
>     FAIL ();
>   c = p->a;
>   if (__builtin_object_size (c, 3) != sizeof (p->a))
> @@ -121,7 +121,7 @@ test1 (A *p)
>   if (__builtin_object_size (c, 3) != sizeof (p->b))
>     FAIL ();
>   c = (char *) &p->c;
> -  if (__builtin_object_size (c, 3) != 0)
> +  if (__builtin_object_size (c, 3) != 10)
>     FAIL ();
> }
> 
> @@ -347,7 +347,7 @@ test6 (struct D *d)
> {
>   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
>     FAIL ();
> -  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
> +  if (__builtin_object_size (&d->j.a[3], 1) != (size_t) -1)
>     FAIL ();
>   if (__builtin_object_size (&d->j.a[3], 2) != 0)
>     FAIL ();
> @@ -383,7 +383,7 @@ test7 (struct E *e)
>     FAIL ();
>   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
>     FAIL ();
> -  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
> +  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))
>     FAIL ();
> }
> 
> @@ -407,7 +407,7 @@ test8 (union F *f)
>     FAIL ();
>   if (__builtin_object_size (&f->d.c[3], 2) != 0)
>     FAIL ();
> -  if (__builtin_object_size (&f->d.c[3], 3) != 0)
> +  if (__builtin_object_size (&f->d.c[3], 3) != sizeof (f->d.c) - 3)
>     FAIL ();
> }
> 
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-13.c b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
> index c7d58c941d4..6429dcaf426 100644
> --- a/gcc/testsuite/gcc.dg/builtin-object-size-13.c
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
> @@ -332,9 +332,9 @@ main (void)
>   o2 = __builtin_offsetof (struct H, h2.e1.c2);
>   h1 = malloc (s);
>   h2 = malloc (o2 + 212);
> -  TA (h1->h2.e1.c2.a2, s - o2, sizeof (h1->h2.e1.c2.a2));
> +  TA (h1->h2.e1.c2.a2, s - o2, s - o2);
>   s = o2 + 212;
> -  TA (h2->h2.e1.c2.a2, s - o2, sizeof (h2->h2.e1.c2.a2));
> +  TA (h2->h2.e1.c2.a2, s - o2, s - o2);
>   free (h2);
>   free (h1);
>   s = sizeof (struct H);
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-6.c b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
> index 4ce05184143..1ae608d456b 100644
> --- a/gcc/testsuite/gcc.dg/builtin-object-size-6.c
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
> @@ -103,7 +103,7 @@ test1 (struct A *p)
>     FAIL ();
>   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
>     FAIL ();
> -  if (__builtin_object_size (&p->c, 3) != 0)
> +  if (__builtin_object_size (&p->c, 3) != 10)
>     FAIL ();
>   c = p->a;
>   if (__builtin_object_size (c, 3) != sizeof (p->a))
> @@ -118,7 +118,7 @@ test1 (struct A *p)
>   if (__builtin_object_size (c, 3) != sizeof (p->b))
>     FAIL ();
>   c = (char *) &p->c;
> -  if (__builtin_object_size (c, 3) != 0)
> +  if (__builtin_object_size (c, 3) != 10)
>     FAIL ();
> }
> 
> @@ -344,7 +344,7 @@ test6 (struct D *d)
> {
>   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
>     FAIL ();
> -  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
> +  if (__builtin_object_size (&d->j.a[3], 1) != -1)
>     FAIL ();
>   if (__builtin_object_size (&d->j.a[3], 2) != 0)
>     FAIL ();
> @@ -380,7 +380,7 @@ test7 (struct E *e)
>     FAIL ();
>   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
>     FAIL ();
> -  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
> +  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))
>     FAIL ();
> }
> 
> @@ -404,7 +404,7 @@ test8 (union F *f)
>     FAIL ();
>   if (__builtin_object_size (&f->d.c[3], 2) != 0)
>     FAIL ();
> -  if (__builtin_object_size (&f->d.c[3], 3) != 0)
> +  if (__builtin_object_size (&f->d.c[3], 3) != 7)
>     FAIL ();
> }
> 
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-8.c b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
> index f67902e29f0..184769f1bd8 100644
> --- a/gcc/testsuite/gcc.dg/builtin-object-size-8.c
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
> @@ -186,13 +186,13 @@ main (void)
>   TS (h1->h1, s);
>   TS (h1->h2.e1.c1, s - o);
>   TS (h1->h2.e1.c2.a1, s - o2);
> -  TA (h1->h2.e1.c2.a2, s - o2, sizeof (h1->h2.e1.c2.a2));
> +  TA (h1->h2.e1.c2.a2, s - o2, s - o2);
>   TF (h1->h2.e2, s - o);
>   s = o2 + 212;
>   TS (h2->h1, s);
>   TS (h2->h2.e1.c1, s - o);
>   TS (h2->h2.e1.c2.a1, s - o2);
> -  TA (h2->h2.e1.c2.a2, s - o2, sizeof (h2->h2.e1.c2.a2));
> +  TA (h2->h2.e1.c2.a2, s - o2, s - o2);
>   TF (h2->h2.e2, s - o);
>   free (h2);
>   free (h1);
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h b/gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
> new file mode 100644
> index 00000000000..b8b68da762d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-common.h
> @@ -0,0 +1,90 @@
> +#include "builtin-object-size-common.h"
> +
> +typedef __SIZE_TYPE__ size_t;
> +
> +void
> +__attribute__ ((noinline))
> +test_flexarray_allocate (const char *name)
> +{
> +  size_t n = sizeof (flex_t);
> +
> +  if (name != (void *) 0)
> +    n += __builtin_strlen (name) + 1;
> +
> +  flex_t *p = __builtin_malloc (n);
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 0)
> +      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 1)
> +      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 2)
> +      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 3)
> +      != n - sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +
> +  __builtin_free (p);
> +}
> +
> +void
> +__attribute__ ((noinline))
> +__attribute__ ((access (read_only, 1, 2)))
> +test_flexarray_access (flex_t *p, size_t sz)
> +{
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 0)
> +      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 1)
> +      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 2)
> +      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 3)
> +      != (sz - 1) * sizeof (*p) + SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +}
> +
> +void
> +__attribute__ ((noinline))
> +test_flexarray_none (flex_t *p)
> +{
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 0) != -1)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 1) != -1)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 2) != 0)
> +    FAIL ();
> +
> +  if (__builtin_dynamic_object_size (FLEX_ARRAY (p), 3) != SIZEOF_FLEX_ARRAY)
> +    FAIL ();
> +}
> +
> +int
> +main (int argc, char **argv)
> +{
> +  const char *str = "qwertyuiopasdfgghjklzxcvbnm";
> +
> +  test_flexarray_allocate (str);
> +
> +  const size_t sz = 1024;
> +  flex_t *p = __builtin_malloc (sz * sizeof (*p));
> +
> +  test_flexarray_access (p, sz);
> +
> +  test_flexarray_none (p);
> +  __builtin_free (p);
> +
> +  DONE ();
> +}
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
> new file mode 100644
> index 00000000000..c50cd89a817
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-nonzero.c
> @@ -0,0 +1,6 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#define SIZEOF_FLEX_ARRAY 4
> +
> +#include "builtin-object-size-flex-nested-struct.c"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
> new file mode 100644
> index 00000000000..554aece0b46
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct-zero.c
> @@ -0,0 +1,6 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#define SIZEOF_FLEX_ARRAY 0
> +
> +#include "builtin-object-size-flex-nested-struct.c"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
> new file mode 100644
> index 00000000000..1adeac16ac4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-struct.c
> @@ -0,0 +1,22 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#ifndef SIZEOF_FLEX_ARRAY
> +# define SIZEOF_FLEX_ARRAY_DECL
> +# define SIZEOF_FLEX_ARRAY 0
> +#else
> +# define SIZEOF_FLEX_ARRAY_DECL SIZEOF_FLEX_ARRAY
> +#endif
> +
> +typedef struct {
> +  unsigned pad;
> +  struct {
> +    unsigned pad;
> +    char data[SIZEOF_FLEX_ARRAY_DECL];
> +  } s;
> +} flex_t;
> +
> +#define FLEX_ARRAY(p) p->s.data
> +#define SIZE_OF_FLEX sizeof (unsigned) + sizeof (unsigned)
> +
> +#include "builtin-object-size-flex-common.h"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
> new file mode 100644
> index 00000000000..58e387c8db6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-nonzero.c
> @@ -0,0 +1,6 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#define SIZEOF_FLEX_ARRAY 4
> +
> +#include "builtin-object-size-flex-nested-union.c"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
> new file mode 100644
> index 00000000000..ec6429a5a9b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union-zero.c
> @@ -0,0 +1,6 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#define SIZEOF_FLEX_ARRAY 0
> +
> +#include "builtin-object-size-flex-nested-union.c"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
> new file mode 100644
> index 00000000000..8326131c890
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nested-union.c
> @@ -0,0 +1,28 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#ifndef SIZEOF_FLEX_ARRAY
> +# define SIZEOF_FLEX_ARRAY_DECL
> +# define SIZEOF_FLEX_ARRAY 0
> +#else
> +# define SIZEOF_FLEX_ARRAY_DECL SIZEOF_FLEX_ARRAY
> +#endif
> +
> +typedef struct {
> +  unsigned pad;
> +  union {
> +      struct {
> +	unsigned pad;
> +	char data[SIZEOF_FLEX_ARRAY_DECL];
> +      } s1;
> +      struct {
> +	unsigned pad;
> +	char data[SIZEOF_FLEX_ARRAY_DECL];
> +      } s2;
> +  } u;
> +} flex_t;
> +
> +#define FLEX_ARRAY(p) p->u.s1.data
> +#define SIZE_OF_FLEX sizeof (unsigned) + sizeof (unsigned)
> +
> +#include "builtin-object-size-flex-common.h"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
> new file mode 100644
> index 00000000000..693d2e98758
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-nonzero.c
> @@ -0,0 +1,6 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#define SIZEOF_FLEX_ARRAY 4
> +
> +#include "builtin-object-size-flex.c"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
> new file mode 100644
> index 00000000000..f38d0e01d4b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex-zero.c
> @@ -0,0 +1,6 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#define SIZEOF_FLEX_ARRAY 0
> +
> +#include "builtin-object-size-flex.c"
> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-flex.c b/gcc/testsuite/gcc.dg/builtin-object-size-flex.c
> new file mode 100644
> index 00000000000..34aba8942d6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-flex.c
> @@ -0,0 +1,18 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +#ifndef SIZEOF_FLEX_ARRAY
> +# define SIZEOF_FLEX_ARRAY_DECL
> +# define SIZEOF_FLEX_ARRAY 0
> +#else
> +# define SIZEOF_FLEX_ARRAY_DECL SIZEOF_FLEX_ARRAY
> +#endif
> +
> +typedef struct {
> +  unsigned pad;
> +  char data[SIZEOF_FLEX_ARRAY_DECL];
> +} flex_t;
> +
> +#define FLEX_ARRAY(p) p->data
> +
> +#include "builtin-object-size-flex-common.h"
> diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
> index d9f25397c71..98ee3c2b527 100644
> --- a/gcc/tree-object-size.cc
> +++ b/gcc/tree-object-size.cc
> @@ -499,6 +499,19 @@ decl_init_size (tree decl, bool min)
>   return size;
> }
> 
> +/* Return the size of SUBOBJ that is within VAR where the latter has VAR_SIZE
> +   size.  */
> +
> +static tree
> +size_from_objects (const_tree subobj, const_tree var, tree var_size,
> +		   int object_size_type)
> +{
> +  tree bytes = compute_object_offset (subobj, var);
> +
> +  return (bytes != error_mark_node ? size_for_offset (var_size, bytes)
> +	  : size_unknown (object_size_type));
> +}
> +
> /* Compute __builtin_object_size for PTR, which is a ADDR_EXPR.
>    OBJECT_SIZE_TYPE is the second argument from __builtin_object_size.
>    If unknown, return size_unknown (object_size_type).  */
> @@ -589,105 +602,52 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
> 	{
> 	  var = TREE_OPERAND (ptr, 0);
> 
> +	  /* Get the immediate containing subobject.  Skip over conversions
> +	     because we don't need them.  */
> 	  while (var != pt_var
> -		 && TREE_CODE (var) != BIT_FIELD_REF
> -		 && TREE_CODE (var) != COMPONENT_REF
> -		 && TREE_CODE (var) != ARRAY_REF
> -		 && TREE_CODE (var) != ARRAY_RANGE_REF
> -		 && TREE_CODE (var) != REALPART_EXPR
> -		 && TREE_CODE (var) != IMAGPART_EXPR)
> +		 && (!handled_component_p (var)
> +		     || TREE_CODE (var) == VIEW_CONVERT_EXPR))
> 	    var = TREE_OPERAND (var, 0);
> 	  if (var != pt_var && TREE_CODE (var) == ARRAY_REF)
> 	    var = TREE_OPERAND (var, 0);
> +
> +	  /* If the subobject size cannot be easily inferred or is smaller than
> +	     the whole size, just use the whole size.  */

Should the above comment be:

+	  /* If the subobject size cannot be easily inferred or is larger than
+	     the whole size, just use the whole size.  */

> 	  if (! TYPE_SIZE_UNIT (TREE_TYPE (var))
> 	      || ! tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (var)))
> 	      || (pt_var_size && TREE_CODE (pt_var_size) == INTEGER_CST
> 		  && tree_int_cst_lt (pt_var_size,
> 				      TYPE_SIZE_UNIT (TREE_TYPE (var)))))
> 	    var = pt_var;


thanks.

Qing
> -	  else if (var != pt_var && TREE_CODE (pt_var) == MEM_REF)
> -	    {
> -	      tree v = var;
> -	      /* For &X->fld, compute object size if fld isn't a flexible array
> -		 member.  */
> -	      bool is_flexible_array_mem_ref = false;
> -	      while (v && v != pt_var)
> -		switch (TREE_CODE (v))
> -		  {
> -		  case ARRAY_REF:
> -		    if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_OPERAND (v, 0))))
> -		      {
> -			tree domain
> -			  = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (v, 0)));
> -			if (domain && TYPE_MAX_VALUE (domain))
> -			  {
> -			    v = NULL_TREE;
> -			    break;
> -			  }
> -		      }
> -		    v = TREE_OPERAND (v, 0);
> -		    break;
> -		  case REALPART_EXPR:
> -		  case IMAGPART_EXPR:
> -		    v = NULL_TREE;
> -		    break;
> -		  case COMPONENT_REF:
> -		    if (TREE_CODE (TREE_TYPE (v)) != ARRAY_TYPE)
> -		      {
> -			v = NULL_TREE;
> -			break;
> -		      }
> -		    is_flexible_array_mem_ref = array_ref_flexible_size_p (v);
> -		    while (v != pt_var && TREE_CODE (v) == COMPONENT_REF)
> -		      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
> -			  != UNION_TYPE
> -			  && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
> -			  != QUAL_UNION_TYPE)
> -			break;
> -		      else
> -			v = TREE_OPERAND (v, 0);
> -		    if (TREE_CODE (v) == COMPONENT_REF
> -			&& TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
> -			   == RECORD_TYPE)
> -		      {
> -			/* compute object size only if v is not a
> -			   flexible array member.  */
> -			if (!is_flexible_array_mem_ref)
> -			  {
> -			    v = NULL_TREE;
> -			    break;
> -			  }
> -			v = TREE_OPERAND (v, 0);
> -		      }
> -		    while (v != pt_var && TREE_CODE (v) == COMPONENT_REF)
> -		      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
> -			  != UNION_TYPE
> -			  && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
> -			  != QUAL_UNION_TYPE)
> -			break;
> -		      else
> -			v = TREE_OPERAND (v, 0);
> -		    if (v != pt_var)
> -		      v = NULL_TREE;
> -		    else
> -		      v = pt_var;
> -		    break;
> -		  default:
> -		    v = pt_var;
> -		    break;
> -		  }
> -	      if (v == pt_var)
> -		var = pt_var;
> -	    }
> 	}
>       else
> 	var = pt_var;
> 
> +      bool is_flexible_array_mem_ref = false;
> +      /* Find out if this is a flexible array.  This will change
> +	 according to -fstrict-flex-arrays.  */
> +      if (var != pt_var && TREE_CODE (pt_var) == MEM_REF)
> +	is_flexible_array_mem_ref = array_ref_flexible_size_p (var);
> +
> +      /* We cannot get a maximum estimate for a flex array without the
> +	 whole object size.  */
> +      if (is_flexible_array_mem_ref && !pt_var_size
> +	  && !(object_size_type & OST_MINIMUM))
> +	return false;
> +
>       if (var != pt_var)
> 	{
> -	  var_size = TYPE_SIZE_UNIT (TREE_TYPE (var));
> -	  if (!TREE_CONSTANT (var_size))
> -	    var_size = get_or_create_ssa_default_def (cfun, var_size);
> +	  /* For flexible arrays, we prefer the size based on the whole object
> +	     if it is available.  */
> +	  if (is_flexible_array_mem_ref && pt_var_size)
> +	    var_size = size_from_objects (var, pt_var, pt_var_size,
> +					  object_size_type);
> +	  else
> +	    {
> +	      var_size = TYPE_SIZE_UNIT (TREE_TYPE (var));
> +	      if (!TREE_CONSTANT (var_size))
> +		var_size = get_or_create_ssa_default_def (cfun, var_size);
> +	    }
> 	  if (!var_size)
> 	    return false;
> 	}
> @@ -695,23 +655,17 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
> 	return false;
>       else
> 	var_size = pt_var_size;
> -      bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var);
> -      if (bytes != error_mark_node)
> +
> +      bytes = size_from_objects (TREE_OPERAND (ptr, 0), var, var_size,
> +				 object_size_type);
> +
> +      if (var != pt_var && pt_var_size && TREE_CODE (pt_var) == MEM_REF
> +	  && !is_flexible_array_mem_ref)
> 	{
> -	  bytes = size_for_offset (var_size, bytes);
> -	  if (var != pt_var && pt_var_size && TREE_CODE (pt_var) == MEM_REF)
> -	    {
> -	      tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0),
> -						   pt_var);
> -	      if (bytes2 != error_mark_node)
> -		{
> -		  bytes2 = size_for_offset (pt_var_size, bytes2);
> -		  bytes = size_binop (MIN_EXPR, bytes, bytes2);
> -		}
> -	    }
> +	  tree bytes2 = size_from_objects (TREE_OPERAND (ptr, 0), pt_var,
> +					   pt_var_size, object_size_type);
> +	  bytes = size_binop (MIN_EXPR, bytes, bytes2);
> 	}
> -      else
> -	bytes = size_unknown (object_size_type);
> 
>       wholebytes
> 	= object_size_type & OST_SUBOBJECT ? var_size : pt_var_wholesize;
> -- 
> 2.38.1
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays
  2023-01-26 16:20   ` Qing Zhao
@ 2023-01-26 17:16     ` Siddhesh Poyarekar
  2023-01-26 17:42       ` Qing Zhao
  0 siblings, 1 reply; 13+ messages in thread
From: Siddhesh Poyarekar @ 2023-01-26 17:16 UTC (permalink / raw)
  To: Qing Zhao; +Cc: gcc Patches, Jakub Jelinek, kees Cook

On 2023-01-26 11:20, Qing Zhao wrote:
> Hi, Siddhesh,
> 
> Thanks a lot for this patch, after -fstrict-flex-array functionality has been added into GCC,
>   I think that making the tree-object-size to have consistent behavior with flex arrays is a
> valuable and natural work that need to be added.
> 
> I also like the comments you added into tree-object-size.cc, making the code much easier to be understood.
> 
> Minor comments below:
> 
>> On Dec 21, 2022, at 5:25 PM, Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
>>
>> The tree object size pass tries to fail when it detects a flex array in
>> the struct, but it ends up doing the right thing only when the flex
>> array is in the outermost struct.  For nested cases (such as arrays
>> nested in a union or an inner struct), it ends up taking whatever value
>> the flex array is declared with, using zero for the standard flex array,
>> i.e. [].
>>
>> Rework subobject size computation to make it more consistent across the
>> board, honoring -fstrict-flex-arrays.  With this change, any array at
>> the end of the struct will end up causing __bos to use the allocated
>> value of the outer object, bailing out in the maximum case when it can't
>> find it.  In the minimum case, it will return the subscript value or the
>> allocated value of the outer object, whichever is larger.
> 
> I see from the changes in the testing case, there are the following major changes for the existing behavior (can be show with the testing case)
> 
> 
> ****For non-nested structures:
> 
> struct A
> {
>    char a[10];
>    int b;
>    char c[10];
> };
> 
> 1.  The Minimum size of the reference to the subobject that is a trailing array of a structure is changed from “0” to “sizeof the subobject"
>> -  if (__builtin_object_size (&p->c, 3) != 0)
> +  if (__builtin_object_size (&p->c, 3) != 10)
> 
> ****For nested structures:
> 
> struct D
> {
>    int i;
>    struct D1
>    {
>      char b;
>      char a[10];
>    } j;
> };
> 
> 2.   The Maximum size of the reference to the subobject that is a trailing array of the inner structure is changed from “sizeof the subobject” to “-1"
>> -  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
>> +  if (__builtin_object_size (&d->j.a[3], 1) != (size_t) -1)
> 
> .
> 3.  The Minimum size of the reference to the subobject that is a trailing array of the inner structure is changed from “0” to “sizeof the subobject"
> -  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
>> +  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))

All of the above is correct, thanks for the high level review!

> 
> I think that all the above changes are good. My only concern is, for the change of the Minimum size of the reference to the subobject that is a trailing array (the above case 1 and 3), will there be any negtive impact on the existing application that use it?

I doubt it, because the 0 return value for minimum object size is 
essentially a failure to determine minimum object size, i.e. a special 
value.  This change can be interpreted as succeeding to get the minimum 
object size in more cases.

Likewise for the maximum object size change, the change can be 
interpreted as failing to get the maximum object size in more cases. 
Does that sound reasonable?

>> +	  /* If the subobject size cannot be easily inferred or is smaller than
>> +	     the whole size, just use the whole size.  */
> 
> Should the above comment be:
> 
> +	  /* If the subobject size cannot be easily inferred or is larger than
> +	     the whole size, just use the whole size.  */
> 
>> 	  if (! TYPE_SIZE_UNIT (TREE_TYPE (var))
>> 	      || ! tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (var)))
>> 	      || (pt_var_size && TREE_CODE (pt_var_size) == INTEGER_CST
>> 		  && tree_int_cst_lt (pt_var_size,
>> 				      TYPE_SIZE_UNIT (TREE_TYPE (var)))))
>> 	    var = pt_var;
> 

Oops, yes indeed, fixed in my copy.

Thanks,
Sid

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays
  2023-01-26 17:16     ` Siddhesh Poyarekar
@ 2023-01-26 17:42       ` Qing Zhao
  0 siblings, 0 replies; 13+ messages in thread
From: Qing Zhao @ 2023-01-26 17:42 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: gcc Patches, Jakub Jelinek, kees Cook



> On Jan 26, 2023, at 12:16 PM, Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
> 
> On 2023-01-26 11:20, Qing Zhao wrote:
>> Hi, Siddhesh,
>> Thanks a lot for this patch, after -fstrict-flex-array functionality has been added into GCC,
>>  I think that making the tree-object-size to have consistent behavior with flex arrays is a
>> valuable and natural work that need to be added.
>> I also like the comments you added into tree-object-size.cc, making the code much easier to be understood.
>> Minor comments below:
>>> On Dec 21, 2022, at 5:25 PM, Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
>>> 
>>> The tree object size pass tries to fail when it detects a flex array in
>>> the struct, but it ends up doing the right thing only when the flex
>>> array is in the outermost struct.  For nested cases (such as arrays
>>> nested in a union or an inner struct), it ends up taking whatever value
>>> the flex array is declared with, using zero for the standard flex array,
>>> i.e. [].
>>> 
>>> Rework subobject size computation to make it more consistent across the
>>> board, honoring -fstrict-flex-arrays.  With this change, any array at
>>> the end of the struct will end up causing __bos to use the allocated
>>> value of the outer object, bailing out in the maximum case when it can't
>>> find it.  In the minimum case, it will return the subscript value or the
>>> allocated value of the outer object, whichever is larger.
>> I see from the changes in the testing case, there are the following major changes for the existing behavior (can be show with the testing case)
>> ****For non-nested structures:
>> struct A
>> {
>>   char a[10];
>>   int b;
>>   char c[10];
>> };
>> 1.  The Minimum size of the reference to the subobject that is a trailing array of a structure is changed from “0” to “sizeof the subobject"
>>> -  if (__builtin_object_size (&p->c, 3) != 0)
>> +  if (__builtin_object_size (&p->c, 3) != 10)
>> ****For nested structures:
>> struct D
>> {
>>   int i;
>>   struct D1
>>   {
>>     char b;
>>     char a[10];
>>   } j;
>> };
>> 2.   The Maximum size of the reference to the subobject that is a trailing array of the inner structure is changed from “sizeof the subobject” to “-1"
>>> -  if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
>>> +  if (__builtin_object_size (&d->j.a[3], 1) != (size_t) -1)
>> .
>> 3.  The Minimum size of the reference to the subobject that is a trailing array of the inner structure is changed from “0” to “sizeof the subobject"
>> -  if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
>>> +  if (__builtin_object_size ((char *) &e->j[0], 3) != sizeof (e->j))
> 
> All of the above is correct, thanks for the high level review!
> 
>> I think that all the above changes are good. My only concern is, for the change of the Minimum size of the reference to the subobject that is a trailing array (the above case 1 and 3), will there be any negtive impact on the existing application that use it?
> 
> I doubt it, because the 0 return value for minimum object size is essentially a failure to determine minimum object size, i.e. a special value.  This change can be interpreted as succeeding to get the minimum object size in more cases.
> 
> Likewise for the maximum object size change, the change can be interpreted as failing to get the maximum object size in more cases. Does that sound reasonable?

Yes, make sense to me.

Thanks.

Qing
> 
>>> +	  /* If the subobject size cannot be easily inferred or is smaller than
>>> +	     the whole size, just use the whole size.  */
>> Should the above comment be:
>> +	  /* If the subobject size cannot be easily inferred or is larger than
>> +	     the whole size, just use the whole size.  */
>>> 	  if (! TYPE_SIZE_UNIT (TREE_TYPE (var))
>>> 	      || ! tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (var)))
>>> 	      || (pt_var_size && TREE_CODE (pt_var_size) == INTEGER_CST
>>> 		  && tree_int_cst_lt (pt_var_size,
>>> 				      TYPE_SIZE_UNIT (TREE_TYPE (var)))))
>>> 	    var = pt_var;
> 
> Oops, yes indeed, fixed in my copy.
> 
> Thanks,
> Sid


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] testsuite: Run __bos tests to completion
  2022-12-21 22:25 ` [PATCH 1/2] testsuite: Run __bos tests to completion Siddhesh Poyarekar
@ 2023-01-31 12:33   ` Jakub Jelinek
  2023-02-01 16:46     ` [committed v2] " Siddhesh Poyarekar
  0 siblings, 1 reply; 13+ messages in thread
From: Jakub Jelinek @ 2023-01-31 12:33 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: gcc-patches

On Wed, Dec 21, 2022 at 05:25:53PM -0500, Siddhesh Poyarekar wrote:
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/builtin-dynamic-object-size-0.c: Move FAIL and nfail
> 	into...
> 	* gcc.dg/builtin-object-size-common.h: ... new file.
> 	* g++.dg/ext/builtin-object-size1.C: Include
> 	builtin-object-size-common.h.  Replace all abort with FAIL.
> 	(main): Call DONE.
> 	* g++.dg/ext/builtin-object-size2.C: Likewise.
> 	* gcc.dg/builtin-object-size-1.c: Likewise.
> 	* gcc.dg/builtin-object-size-12.c: Likewise.
> 	* gcc.dg/builtin-object-size-13.c: Likewise.
> 	* gcc.dg/builtin-object-size-15.c: Likewise.
> 	* gcc.dg/builtin-object-size-2.c: Likewise.
> 	* gcc.dg/builtin-object-size-3.c: Likewise.
> 	* gcc.dg/builtin-object-size-4.c: Likewise.
> 	* gcc.dg/builtin-object-size-6.c: Likewise.
> 	* gcc.dg/builtin-object-size-7.c: Likewise.
> 	* gcc.dg/builtin-object-size-8.c: Likewise.
> 	* gcc.dg/pr101836.c: Likewise.
> 	* gcc.dg/strict-flex-array-3.c: Likewise.
> --- a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
> +++ b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
> @@ -1,8 +1,9 @@
>  // { dg-do run }
>  // { dg-options "-O2" }
>  
> +#include "../../gcc.dg/builtin-object-size-common.h"
> +
>  typedef __SIZE_TYPE__ size_t;
> -extern "C" void abort ();
>  extern "C" void exit (int);
>  extern "C" void *malloc (size_t);
>  extern "C" void free (void *);

I'd then wonder if size_t shouldn't be typedefed and perhaps
even exit/malloc/free etc. shouldn't be prototyped in
builtin-object-size-common.h too (of course, with extern "C"
conditionalized on __cplusplus).

>        if (__builtin_object_size (r + 6, 0) != res - 6)
> -        abort ();
> +        FAIL ();

There should be a tab, not 8 spaces.

> @@ -335,13 +336,13 @@ test2 (void)
>    if (res >= 12)
>      {
>        if (__builtin_object_size (r + 12, 0) != res - 12)
> -        abort ();
> +        FAIL ();

Ditto.
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-common.h
> @@ -0,0 +1,12 @@
> +unsigned nfails = 0;
> +
> +#define FAIL() ({ \
> +  __builtin_printf ("Failure at line: %d\n", __LINE__);			      \
> +  nfails++;								      \
> +})
> +
> +#define DONE() ({ \
> +  if (nfails > 0)							      \
> +    __builtin_abort ();							      \
> +  return 0;								      \
> +})

Why the statement expressions?  do { and } while (0) would work too...
> -          printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
> -	  __builtin_abort (); \
> +          __builtin_printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
> +	  FAIL (); \

The above has rightly indented FAIL, but the line before that uses
10 spaces rather than tab + 2 spaces.

Otherwise LGTM.

	Jakub


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays
  2022-12-21 22:25 ` [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays Siddhesh Poyarekar
  2023-01-26 16:20   ` Qing Zhao
@ 2023-01-31 12:46   ` Jakub Jelinek
  2023-01-31 13:01     ` Siddhesh Poyarekar
  1 sibling, 1 reply; 13+ messages in thread
From: Jakub Jelinek @ 2023-01-31 12:46 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: gcc-patches

On Wed, Dec 21, 2022 at 05:25:54PM -0500, Siddhesh Poyarekar wrote:
> The tree object size pass tries to fail when it detects a flex array in
> the struct, but it ends up doing the right thing only when the flex
> array is in the outermost struct.  For nested cases (such as arrays
> nested in a union or an inner struct), it ends up taking whatever value
> the flex array is declared with, using zero for the standard flex array,
> i.e. [].
> 
> Rework subobject size computation to make it more consistent across the
> board, honoring -fstrict-flex-arrays.  With this change, any array at
> the end of the struct will end up causing __bos to use the allocated
> value of the outer object, bailing out in the maximum case when it can't
> find it.  In the minimum case, it will return the subscript value or the
> allocated value of the outer object, whichever is larger.

I think it is way too late in the GCC 13 cycle to change behavior here
except for when -fstrict-flex-arrays is used.
Plus, am not really convinced it is a good idea to change the behavior
here except for the new options, programs in the wild took 2+ years
to acommodate for what we GCC requiring and am not sure they'd be willing
to be adjusted again.

> gcc/ChangeLog:
> 
> 	PR tree-optimization/107952
> 	* tree-object-size.cc (size_from_objects): New function.
> 	(addr_object_size): Call it.  Fully rely on
> 	array_ref_flexible_size_p call to determine flex array.

	Jakub


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays
  2023-01-31 12:46   ` Jakub Jelinek
@ 2023-01-31 13:01     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 13+ messages in thread
From: Siddhesh Poyarekar @ 2023-01-31 13:01 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 2023-01-31 07:46, Jakub Jelinek wrote:
> On Wed, Dec 21, 2022 at 05:25:54PM -0500, Siddhesh Poyarekar wrote:
>> The tree object size pass tries to fail when it detects a flex array in
>> the struct, but it ends up doing the right thing only when the flex
>> array is in the outermost struct.  For nested cases (such as arrays
>> nested in a union or an inner struct), it ends up taking whatever value
>> the flex array is declared with, using zero for the standard flex array,
>> i.e. [].
>>
>> Rework subobject size computation to make it more consistent across the
>> board, honoring -fstrict-flex-arrays.  With this change, any array at
>> the end of the struct will end up causing __bos to use the allocated
>> value of the outer object, bailing out in the maximum case when it can't
>> find it.  In the minimum case, it will return the subscript value or the
>> allocated value of the outer object, whichever is larger.
> 
> I think it is way too late in the GCC 13 cycle to change behavior here
> except for when -fstrict-flex-arrays is used.

I agree.

> Plus, am not really convinced it is a good idea to change the behavior
> here except for the new options, programs in the wild took 2+ years
> to acommodate for what we GCC requiring and am not sure they'd be willing
> to be adjusted again.

The behaviour change basically does two things: better minimum object 
size estimates and more conservative object size estimates for trailing 
arrays.  ISTM that this should in fact reduce breakages due to flex 
arrays, although one could argue that protection gets reduced for 
trailing arrays without -fstrict-flex-arrays.  It wouldn't cause 
non-mitigation behaviour changes though, would it?

We don't need to rush this of course, we could consider this for gcc 14 
given that we're well into stage 4.

Thanks,
Sid

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [committed v2] testsuite: Run __bos tests to completion
  2023-01-31 12:33   ` Jakub Jelinek
@ 2023-02-01 16:46     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 13+ messages in thread
From: Siddhesh Poyarekar @ 2023-02-01 16:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub

Instead of failing on first error, run all __builtin_object_size and
__builtin_dynamic_object_size tests to completion and then provide a
summary of which tests failed.

gcc/testsuite/ChangeLog:

	* gcc.dg/builtin-dynamic-object-size-0.c: Move FAIL and nfail
	into...
	* gcc.dg/builtin-object-size-common.h: ... new file.
	* g++.dg/ext/builtin-object-size1.C: Include
	builtin-object-size-common.h.  Replace all abort with FAIL.
	(main): Call DONE.
	* g++.dg/ext/builtin-object-size2.C: Likewise.
	* gcc.dg/builtin-object-size-1.c: Likewise.
	* gcc.dg/builtin-object-size-12.c: Likewise.
	* gcc.dg/builtin-object-size-13.c: Likewise.
	* gcc.dg/builtin-object-size-15.c: Likewise.
	* gcc.dg/builtin-object-size-2.c: Likewise.
	* gcc.dg/builtin-object-size-3.c: Likewise.
	* gcc.dg/builtin-object-size-4.c: Likewise.
	* gcc.dg/builtin-object-size-6.c: Likewise.
	* gcc.dg/builtin-object-size-7.c: Likewise.
	* gcc.dg/builtin-object-size-8.c: Likewise.
	* gcc.dg/pr101836.c: Likewise.
	* gcc.dg/strict-flex-array-3.c: Likewise.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
 .../g++.dg/ext/builtin-object-size1.C         | 260 ++++++++-------
 .../g++.dg/ext/builtin-object-size2.C         | 260 ++++++++-------
 .../gcc.dg/builtin-dynamic-object-size-0.c    |  14 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 297 ++++++++---------
 gcc/testsuite/gcc.dg/builtin-object-size-12.c |  12 +-
 gcc/testsuite/gcc.dg/builtin-object-size-13.c |  15 +-
 gcc/testsuite/gcc.dg/builtin-object-size-15.c |  11 +-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 305 +++++++++---------
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 275 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  | 285 ++++++++--------
 gcc/testsuite/gcc.dg/builtin-object-size-6.c  | 260 ++++++++-------
 gcc/testsuite/gcc.dg/builtin-object-size-7.c  |  54 ++--
 gcc/testsuite/gcc.dg/builtin-object-size-8.c  |  15 +-
 .../gcc.dg/builtin-object-size-common.h       |  32 ++
 gcc/testsuite/gcc.dg/pr101836.c               |  10 +-
 gcc/testsuite/gcc.dg/strict-flex-array-3.c    |  10 +-
 16 files changed, 1039 insertions(+), 1076 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-common.h

diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
index 8590a0bbebd..ebbeced1942 100644
--- a/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
+++ b/gcc/testsuite/g++.dg/ext/builtin-object-size1.C
@@ -1,11 +1,7 @@
 // { dg-do run }
 // { dg-options "-O2" }
 
-typedef __SIZE_TYPE__ size_t;
-extern "C" void abort ();
-extern "C" void exit (int);
-extern "C" void *malloc (size_t);
-extern "C" void free (void *);
+#include "../../gcc.dg/builtin-object-size-common.h"
 
 struct A
 {
@@ -20,105 +16,105 @@ test1 (A *p)
 {
   char *c;
   if (__builtin_object_size (&p->a, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -129,105 +125,105 @@ test2 (void)
   size_t s = 2 * sizeof (A);
   A *p = (A *) malloc (2 * sizeof (A));
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -239,48 +235,48 @@ test3 (void)
   size_t s;
   A *p = (A *) malloc (4);
   if (__builtin_object_size (&p->a, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 0)
-    abort ();
+    FAIL ();
   free (p);
   s = __builtin_offsetof (A, c) + 4;
   p = (A *) malloc (s);
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 4)
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -294,17 +290,17 @@ __attribute__ ((noinline))
 test4 (struct B *q, int i)
 {
   if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
 }
 
 struct C
@@ -318,13 +314,13 @@ __attribute__ ((noinline))
 test5 (struct C *c)
 {
   if (__builtin_object_size (&c->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 3) != 1)
-    abort ();
+    FAIL ();
 }
 
 struct D
@@ -342,13 +338,13 @@ __attribute__ ((noinline))
 test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
 }
 
 struct E
@@ -366,21 +362,21 @@ __attribute__ ((noinline))
 test7 (struct E *e)
 {
   if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 union F
@@ -398,13 +394,13 @@ __attribute__ ((noinline))
 test8 (union F *f)
 {
   if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 int
@@ -431,5 +427,5 @@ main (void)
   union F f, *fp = &f;
   __asm ("" : "+r" (fp));
   test8 (fp);
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
index d79b1b83310..7a8f4e62733 100644
--- a/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
+++ b/gcc/testsuite/g++.dg/ext/builtin-object-size2.C
@@ -1,11 +1,7 @@
 // { dg-do run }
 // { dg-options "-O2" }
 
-typedef __SIZE_TYPE__ size_t;
-extern "C" void abort ();
-extern "C" void exit (int);
-extern "C" void *malloc (size_t);
-extern "C" void free (void *);
+#include "../../gcc.dg/builtin-object-size-common.h"
 
 typedef struct A
 {
@@ -23,105 +19,105 @@ test1 (A *p)
 {
   char *c;
   if (__builtin_object_size (&p->a, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -132,105 +128,105 @@ test2 (void)
   size_t s = 2 * sizeof (A);
   A *p = (A *) malloc (2 * sizeof (A));
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != s - __builtin_offsetof (A, c))
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -242,48 +238,48 @@ test3 (void)
   size_t s;
   A *p = (A *) malloc (4);
   if (__builtin_object_size (&p->a, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 0)
-    abort ();
+    FAIL ();
   free (p);
   s = __builtin_offsetof (A, c) + 4;
   p = (A *) malloc (s);
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 4)
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -297,17 +293,17 @@ __attribute__ ((noinline))
 test4 (struct B *q, int i)
 {
   if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
 }
 
 struct C
@@ -321,13 +317,13 @@ __attribute__ ((noinline))
 test5 (struct C *c)
 {
   if (__builtin_object_size (&c->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 3) != 1)
-    abort ();
+    FAIL ();
 }
 
 struct D
@@ -345,13 +341,13 @@ __attribute__ ((noinline))
 test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
 }
 
 struct E
@@ -369,21 +365,21 @@ __attribute__ ((noinline))
 test7 (struct E *e)
 {
   if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 union F
@@ -401,13 +397,13 @@ __attribute__ ((noinline))
 test8 (union F *f)
 {
   if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 int
@@ -434,5 +430,5 @@ main (void)
   union F f, *fp = &f;
   __asm ("" : "+r" (fp));
   test8 (fp);
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index 76079d8702e..6da04202ffe 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -1,6 +1,8 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
+#include "builtin-object-size-common.h"
+
 typedef __SIZE_TYPE__ size_t;
 #define abort __builtin_abort
 
@@ -604,13 +606,6 @@ test_pr105736 (struct TV4 *a)
   return &a->v[0];
 }
 
-unsigned nfails = 0;
-
-#define FAIL() ({ \
-  __builtin_printf ("Failure at line: %d\n", __LINE__);			      \
-  nfails++;								      \
-})
-
 int
 main (int argc, char **argv)
 {
@@ -790,8 +785,5 @@ main (int argc, char **argv)
   if (test_strndup_min (str, 4) != 1)
     FAIL ();
 
-  if (nfails > 0)
-    __builtin_abort ();
-
-  return 0;
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-1.c b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
index c6e5b4c29f8..db325801f93 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-1.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
@@ -2,18 +2,7 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
 
 struct A
 {
@@ -39,22 +28,22 @@ test1 (void *q, int x)
     r = &a.c[1];
   if (__builtin_object_size (p, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 0)
       != sizeof (a) - __builtin_offsetof (struct A, c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 0
 	  ? sizeof (a) - __builtin_offsetof (struct A, a) - 9
 	  : sizeof (a) - __builtin_offsetof (struct A, c) - 1))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 9)
-    abort ();
+    FAIL ();
 #endif
   if (x < 6)
     r = &w[2].a[1];
@@ -62,23 +51,23 @@ test1 (void *q, int x)
     r = &a.a[6];
   if (__builtin_object_size (&y, 0)
       != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 0)
       != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 0)
       != sizeof (a) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 6
 	  ? 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1
 	  : sizeof (a) - __builtin_offsetof (struct A, a) - 6))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0)
       != 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -86,14 +75,14 @@ test1 (void *q, int x)
     r = calloc (2, 16);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 20 ? 30 : 2 * 16))
-    abort ();
+    FAIL ();
 #else
   /* We may duplicate this test onto the two exit paths.  On one path
      the size will be 32, the other it will be 30.  If we don't duplicate
      this test, then the size will be 32.  */
   if (__builtin_object_size (r, 0) != 2 * 16
       && __builtin_object_size (r, 0) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -101,10 +90,10 @@ test1 (void *q, int x)
     r = calloc (2, 14);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 20 ? 30 : 2 * 14))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 30)
     r = malloc (sizeof (a));
@@ -112,102 +101,102 @@ test1 (void *q, int x)
     r = &a.a[3];
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 30 ? sizeof (a) - 4 : sizeof (a) - 7))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != sizeof (a) - 4)
-    abort ();
+    FAIL ();
 #endif
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 0)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 0) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 0) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 0) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 0) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 0) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 0) != x + 5)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (zerol, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 0) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 0) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 0) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 0) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 0) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 0) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 0) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 0) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
 }
 
 size_t l1 = 1;
@@ -242,19 +231,19 @@ test2 (void)
   for (i = 0; i < 4; ++i)
     {
       if (i == l1 - 1)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 1;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 1;
       else if (i == l1)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
       else if (i == l1 + 1)
-        res = sizeof (buf3) - 5;
+	res = sizeof (buf3) - 5;
       else if (i == l1 + 2)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
     }
 #else
   res = 20;
 #endif
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
     {
@@ -273,38 +262,38 @@ test2 (void)
   for (i = 0; i < 4; ++i)
     {
       if (i == l1 - 1)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 7;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 7;
       else if (i == l1)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
       else if (i == l1 + 1)
-        res = sizeof (buf3) - 5;
+	res = sizeof (buf3) - 5;
       else if (i == l1 + 2)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
     }
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
 #else
   res = 15;
 #endif
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
   r += 8;
 #ifdef __builtin_object_size
   res -= 8;
   if (__builtin_object_size (r, 0) != res)
-    abort ();
+    FAIL ();
   if (res >= 6)
     {
       if (__builtin_object_size (r + 6, 0) != res - 6)
-        abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r + 6, 0) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 0) != 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 6, 0) != 1)
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[18];
   for (i = 0; i < 4; ++i)
@@ -324,24 +313,24 @@ test2 (void)
   for (i = 0; i < 4; ++i)
     {
       if (i == l1 - 1)
-          res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
+	  res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
       else if (i == l1)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 9;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 9;
       else if (i == l1 + 1)
-        res = sizeof (buf3) - 5;
+	res = sizeof (buf3) - 5;
       else if (i == l1 + 2)
-        res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 4;
+	res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 4;
     }
   if (res >= 12)
     {
       if (__builtin_object_size (r + 12, 0) != res - 12)
-        abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r + 12, 0) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r + 12, 0) != 4)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -357,103 +346,103 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 0) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 0) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 0) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 0) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 0) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 0) != sizeof (x) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 0)
       != sizeof (x) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 0)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 0)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 0)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 0)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 0)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 0)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 0)
       != sizeof (x) - __builtin_offsetof (struct B, c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 0)
       != sizeof (x) - __builtin_offsetof (struct B, d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 0)
       != sizeof (x) - __builtin_offsetof (struct B, e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 0)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 0)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 0)
       != sizeof (x) - __builtin_offsetof (struct B, f)
 	 - sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 0) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 0) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 0) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 0) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -470,7 +459,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 0) != (size_t) -1)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -487,7 +476,7 @@ test5 (size_t x)
     p = p + 4;
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0) != sizeof (buf) - 8 - 4 * x)
-    abort ();
+    FAIL ();
 #else
   /* My understanding of ISO C99 6.5.6 is that a conforming
      program will not end up with p equal to &buf[0]
@@ -497,7 +486,7 @@ test5 (size_t x)
      bytes from p until end of the object is 56, otherwise
      it would be 64 (or conservative (size_t) -1 == unknown).  */
   if (__builtin_object_size (p, 0) != sizeof (buf) - 8)
-    abort ();
+    FAIL ();
 #endif
   memset (p, ' ', sizeof (buf) - 8 - 4 * 4);
 }
@@ -514,10 +503,10 @@ test6 (size_t x)
     p = p + 4;
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0) != sizeof (t) - 8 - 4 * x)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 0) != sizeof (t) - 8)
-    abort ();
+    FAIL ();
 #endif
   memset (p, ' ', sizeof (t) - 8 - 4 * 4);
 }
@@ -531,13 +520,13 @@ test7 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 63, 0) != sizeof (t) - 64 - 63)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 0) != sizeof (t) - 64 - 64)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 256, 0) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -548,17 +537,17 @@ test8 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 0) != sizeof (t) - 10 + 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 0) != sizeof (t) - 10)
-    abort ();
+    FAIL ();
   /* GCC only handles additions, not subtractions.  */
   q = q - 8;
   if (__builtin_object_size (q, 0) != (size_t) -1
       && __builtin_object_size (q, 0) != sizeof (t) - 10 + 8)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 0) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -575,10 +564,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 0) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 0) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -586,10 +575,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 0) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -599,10 +588,10 @@ test9 (unsigned cond)
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 0)
       != sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 0) != sizeof (y))
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -620,10 +609,10 @@ test10 (void)
 	{
 #ifdef __builtin_object_size
 	  if (__builtin_object_size (p - 3, 0) != sizeof (buf) - i + 3)
-	    abort ();
+	    FAIL ();
 #else
 	  if (__builtin_object_size (p - 3, 0) != sizeof (buf))
-	    abort ();
+	    FAIL ();
 #endif
 	  break;
 	}
@@ -641,19 +630,19 @@ test11 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 0) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 0) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 0) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -662,19 +651,19 @@ test11 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 0) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 0) != 33)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 0) != 64)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -684,39 +673,39 @@ test11 (void)
 #else
   if (__builtin_object_size (res, 0) != (size_t) -1)
 #endif
-    abort ();
+    FAIL ();
   free (res);
   free (ptr2);
 
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 0) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 0) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 0) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 0) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 0) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 0) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -736,5 +725,5 @@ main (void)
   test9 (1);
   test10 ();
   test11 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-12.c b/gcc/testsuite/gcc.dg/builtin-object-size-12.c
index b21eb0071b3..e29dd17d611 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-12.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-12.c
@@ -1,7 +1,8 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-extern void abort (void);
+#include "builtin-object-size-common.h"
+
 struct S {
     int len;
     char s[0];
@@ -10,10 +11,11 @@ int main()
 {
   char buf[sizeof (struct S) + 32];
   if (__builtin_object_size (((struct S *)&buf[0])->s, 1) != 32)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (((struct S *)&buf[1])->s, 1) != 31)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (((struct S *)&buf[64])->s, 0) != 0)
-    abort ();
-  return 0;
+    FAIL ();
+
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-13.c b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
index 80a6280e3f9..7b6264d7486 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-13.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-13.c
@@ -1,10 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void *malloc (size_t);
-extern void free (void *);
-extern void abort (void);
+#include "builtin-object-size-common.h"
 
 union A
 {
@@ -56,13 +53,13 @@ struct H
 
 #define T(X, S0, S1) \
   if (__builtin_object_size (X, 0) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 1) != (S1))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 2) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 3) != (S1))	\
-    abort ()
+    FAIL ()
 #define TS(X, S0) T(&X, S0, sizeof (X))
 #define TA(X, S0, S1) \
   T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1)
@@ -347,5 +344,5 @@ main (void)
   free (h2);
   free (h1);
 
-  return 0;
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-15.c b/gcc/testsuite/gcc.dg/builtin-object-size-15.c
index 97018572bf8..7ee8ac095e7 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-15.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-15.c
@@ -1,7 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-extern void abort (void);
+#include "builtin-object-size-common.h"
 
 int
 main ()
@@ -9,12 +9,12 @@ main ()
   struct A { char buf1[9]; char buf2[1]; } a;
 
   if (__builtin_object_size (a.buf1 + (0 + 4), 1) != 5)
-    abort ();
+    FAIL ();
   char *p = a.buf1;
   p += 1;
   p += 3;
   if (__builtin_object_size (p, 1) != 5)
-    abort ();
+    FAIL ();
   p = (char *) &a;
   char *q = p + 1;
   char *r = q + 3;
@@ -22,6 +22,7 @@ main ()
   if (r != (char *) &a + 4)
     t = (char *) &a + 1;
   if (__builtin_object_size (t, 1) != 6)
-    abort ();
-  return 0;
+    FAIL ();
+
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-2.c b/gcc/testsuite/gcc.dg/builtin-object-size-2.c
index 639a83cfd39..4c71b1f6a37 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-2.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-2.c
@@ -2,18 +2,7 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
 
 struct A
 {
@@ -40,39 +29,39 @@ test1 (void *q, int x)
   else
     r = &a.c[1];
   if (__builtin_object_size (p, 1) != sizeof (a.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 1)
       != sizeof (a.c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (x < 0
       ? __builtin_object_size (r, 1) != sizeof (a.a) - 9
       : __builtin_object_size (r, 1) != sizeof (a.c) - 1)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a.c) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 6)
     r = &w[2].a[1];
   else
     r = &a.a[6];
   if (__builtin_object_size (&y, 1) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 1) != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 1) != sizeof (a.b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (x < 6
       ? __builtin_object_size (r, 1) != sizeof (a.a) - 1
       : __builtin_object_size (r, 1) != sizeof (a.a) - 6)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -80,14 +69,14 @@ test1 (void *q, int x)
     r = calloc (2, 16);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 20 ? 30 : 2 * 16))
-    abort ();
+    FAIL ();
 #else
   /* We may duplicate this test onto the two exit paths.  On one path
      the size will be 32, the other it will be 30.  If we don't duplicate
      this test, then the size will be 32.  */
   if (__builtin_object_size (r, 1) != 2 * 16
       && __builtin_object_size (r, 1) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -95,10 +84,10 @@ test1 (void *q, int x)
     r = calloc (2, 14);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 20 ? 30 : 2 * 14))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 30)
     r = malloc (sizeof (a));
@@ -106,132 +95,132 @@ test1 (void *q, int x)
     r = &a.a[3];
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 1) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a))
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 0)
       != (x < 30 ? sizeof (a) - 4 : sizeof (a) - 7))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (a) - 4)
-    abort ();
+    FAIL ();
 #endif
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 1) != sizeof (a.a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 1) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 1) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 1) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc + 10, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc->a, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&(extc + 10)->b, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5].c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 1) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 1) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 1) != x + 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 1) != (x + 10) * sizeof (struct A))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 1) != x * sizeof (struct A))
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 1) != (x + 5) * sizeof (struct A))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 1) != (size_t) -1)
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (&vara[0].a, 1) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[10].a[0], 1) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].a[4], 1) != sizeof (vara[0].a) - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].b, 1) != sizeof (vara[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[7].c[7], 1) != sizeof (vara[0].c) - 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 1) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 1) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 1) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 1) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 1) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 1) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 1) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 1) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
 }
 
 size_t l1 = 1;
@@ -277,10 +266,10 @@ test2 (void)
 	dyn_res = sizeof (a.buf1) - 9;
     }
   if (__builtin_object_size (r, 1) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (buf3))
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
@@ -300,19 +289,19 @@ test2 (void)
   for (i = 0; i < 4; ++i)
     {
       if (i == l1 - 1)
-        dyn_res = sizeof (a.buf1) - 7;
+	dyn_res = sizeof (a.buf1) - 7;
       else if (i == l1)
-        dyn_res = sizeof (a.buf2) - 7;
+	dyn_res = sizeof (a.buf2) - 7;
       else if (i == l1 + 1)
-        dyn_res = sizeof (buf3) - 5;
+	dyn_res = sizeof (buf3) - 5;
       else if (i == l1 + 2)
-        dyn_res = sizeof (a.buf1) - 9;
+	dyn_res = sizeof (a.buf1) - 9;
     }
   if (__builtin_object_size (r, 1) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (buf3) - 5)
-    abort ();
+    FAIL ();
 #endif
   r += 8;
 #ifdef __builtin_object_size
@@ -320,23 +309,23 @@ test2 (void)
     {
       dyn_res -= 8;
       if (__builtin_object_size (r, 1) != dyn_res)
-	abort ();
+	FAIL ();
 
       if (dyn_res >= 6)
 	{
 	  if (__builtin_object_size (r + 6, 1) != dyn_res - 6)
-	    abort ();
+	    FAIL ();
 	}
       else if (__builtin_object_size (r + 6, 1) != 0)
-	abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r, 1) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 1) != sizeof (buf3) - 13)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 6, 1) != sizeof (buf3) - 19)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -352,78 +341,78 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 1) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 1) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 1) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 1) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 1) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 1) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 1) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 1) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 1) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 1) != sizeof (x.a[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 1) != sizeof (x.a[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 1) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 1) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 1) != sizeof (x.a[1].c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 1) != sizeof (x.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 1) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 1) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 1) != sizeof (x.b.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 1) != sizeof (x.b.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 1) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 1) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 1) != sizeof (x.b.c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 1) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 1) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 1) != sizeof (x.c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 1) != sizeof (x.d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 1) != sizeof (x.e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 1) != sizeof (x.f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 1) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 1) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 1) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 1) != sizeof (z))
-      abort ();
+      FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 1) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 1) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -440,7 +429,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 1) != (size_t) -1)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -457,10 +446,10 @@ test5 (size_t x)
     p = p + 4;
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 1) != sizeof (t.buf) - 8 - 4 * x)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 1) != sizeof (t.buf) - 8)
-    abort ();
+    FAIL ();
 #endif
   memset (p, ' ', sizeof (t.buf) - 8 - 4 * 4);
 }
@@ -474,11 +463,11 @@ test6 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 0, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 1) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -489,18 +478,18 @@ test7 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 1) != sizeof (t.buf2))
-    abort ();
+    FAIL ();
   q = &t.buf[10];
   if (__builtin_object_size (q, 1) != 0)
-    abort ();
+    FAIL ();
   q = &t.buf[11];
   if (__builtin_object_size (q, 1) != 0)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 1) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -517,10 +506,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 1) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 1) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -528,10 +517,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 1) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 1) != 10)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -540,10 +529,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 1) != sizeof (y.c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 1) != sizeof (y.c))
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -555,19 +544,19 @@ test9 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 1) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 1) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 1) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -576,19 +565,19 @@ test9 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 1) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 1) != 33)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 1) != 64)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -598,7 +587,7 @@ test9 (void)
 #else
   if (__builtin_object_size (res, 1) != (size_t) -1)
 #endif
-    abort ();
+    FAIL ();
 
   free (res);
   free (ptr2);
@@ -606,32 +595,32 @@ test9 (void)
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 1) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 1) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 1) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 1) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 1) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 1) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -649,5 +638,5 @@ main (void)
   test7 ();
   test8 (1);
   test9 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-3.c b/gcc/testsuite/gcc.dg/builtin-object-size-3.c
index ff4f1747334..3d907ef4814 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-3.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-3.c
@@ -2,18 +2,7 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
 
 struct A
 {
@@ -39,22 +28,22 @@ test1 (void *q, int x)
     r = &a.c[1];
   if (__builtin_object_size (p, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 2)
       != sizeof (a) - __builtin_offsetof (struct A, c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 2) != 0)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2)
       != (x < 0
 	  ? sizeof (a) - __builtin_offsetof (struct A, a) - 9
 	  : sizeof (a) - __builtin_offsetof (struct A, c) - 1))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, c) - 1)
-    abort ();
+    FAIL ();
 #endif
   if (x < 6)
     r = &w[2].a[1];
@@ -62,23 +51,23 @@ test1 (void *q, int x)
     r = &a.a[6];
   if (__builtin_object_size (&y, 2)
       != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 2)
       != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 2)
       != sizeof (a) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2)
       != (x < 6
 	  ? 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1
 	  : sizeof (a) - __builtin_offsetof (struct A, a) - 6))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 6)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -86,10 +75,10 @@ test1 (void *q, int x)
     r = calloc (2, 16);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != (x < 20 ? 30 : 2 * 16))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 30)
-    abort ();
+    FAIL ();
 #endif
   if (x < 20)
     r = malloc (30);
@@ -97,10 +86,10 @@ test1 (void *q, int x)
     r = calloc (2, 14);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != (x < 20 ? 30 : 2 * 14))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 2 * 14)
-    abort ();
+    FAIL ();
 #endif
   if (x < 30)
     r = malloc (sizeof (a));
@@ -108,106 +97,106 @@ test1 (void *q, int x)
     r = &a.a[3];
 #ifdef __builtin_object_size
   size_t objsz = (x < 30 ? sizeof (a)
-                  : sizeof (a) - __builtin_offsetof (struct A, a) - 3);
+		  : sizeof (a) - __builtin_offsetof (struct A, a) - 3);
   if (__builtin_object_size (r, 2) != objsz)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != objsz)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
-    abort ();
+    FAIL ();
 #endif
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 2) != objsz - 4)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 3 - 4)
-    abort ();
+    FAIL ();
 #endif
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 2)
       != sizeof (a) - __builtin_offsetof (struct A, a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 2) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 2) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 2) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 2) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 2) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 2) != x + 5)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 2) != 0)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (zerol, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 2) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 2) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 2) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 2) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 2) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 2) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 2) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 2) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
 }
 
 size_t l1 = 1;
@@ -253,10 +242,10 @@ test2 (void)
 	dyn_res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
     }
   if (__builtin_object_size (r, 2) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 3)
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
@@ -271,7 +260,7 @@ test2 (void)
 	r = &a.buf1[9];
     }
   if (__builtin_object_size (r, 2) != 0)
-    abort ();
+    FAIL ();
   r = &buf3[2];
   for (i = 0; i < 4; ++i)
     {
@@ -299,28 +288,28 @@ test2 (void)
 	dyn_res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 4;
     }
   if (__builtin_object_size (r, 2) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 15)
-    abort ();
+    FAIL ();
 #endif
   r += 8;
 #ifdef __builtin_object_size
   dyn_res -= 8;
   if (__builtin_object_size (r, 2) != dyn_res)
-    abort ();
+    FAIL ();
   if (dyn_res >= 6)
     {
       if (__builtin_object_size (r + 6, 2) != dyn_res - 6)
-	abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r + 6, 2) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 2) != 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 6, 2) != 1)
-    abort ();
+    FAIL ();
 #endif
   r = &buf3[18];
   for (i = 0; i < 4; ++i)
@@ -351,13 +340,13 @@ test2 (void)
   if (dyn_res >= 12)
     {
       if (__builtin_object_size (r + 12, 2) != dyn_res - 12)
-	abort ();
+	FAIL ();
     }
   else if (__builtin_object_size (r + 12, 2) != 0)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r + 12, 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -373,103 +362,103 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 2) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 2) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 2) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 2) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 2) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 2) != sizeof (x) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 2)
       != sizeof (x) - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 2)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 2)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 2)
       != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 2)
       != sizeof (x) - __builtin_offsetof (struct B, b)
 	 - __builtin_offsetof (struct A, c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 2)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 2)
       != sizeof (x) - __builtin_offsetof (struct B, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 2)
       != sizeof (x) - __builtin_offsetof (struct B, c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 2)
       != sizeof (x) - __builtin_offsetof (struct B, d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 2)
       != sizeof (x) - __builtin_offsetof (struct B, e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 2)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 2)
       != sizeof (x) - __builtin_offsetof (struct B, f))
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 2)
       != sizeof (x) - __builtin_offsetof (struct B, f)
 	 - sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 2) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 2) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 2) != sizeof (z))
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 2) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -486,7 +475,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 2) != 0)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -506,7 +495,7 @@ test5 (size_t x)
 #else
   if (__builtin_object_size (p, 2) != 0)
 #endif
-    abort ();
+    FAIL ();
   memset (p, ' ', sizeof (buf) - 8 - 4 * 4);
 }
 
@@ -525,7 +514,7 @@ test6 (size_t x)
 #else
   if (__builtin_object_size (p, 2) != 0)
 #endif
-    abort ();
+    FAIL ();
   memset (p, ' ', sizeof (t) - 8 - 4 * 4);
 }
 
@@ -538,13 +527,13 @@ test7 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 63, 2) != sizeof (t) - 64 - 63)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 2) != sizeof (t) - 64 - 64)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 256, 2) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -555,17 +544,17 @@ test8 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 2) != sizeof (t) - 10 + 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 2) != sizeof (t) - 10)
-    abort ();
+    FAIL ();
   /* GCC only handles additions, not subtractions.  */
   q = q - 8;
   if (__builtin_object_size (q, 2) != 0
       && __builtin_object_size (q, 2) != sizeof (t) - 10 + 8)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 2) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -582,10 +571,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 2) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -593,10 +582,10 @@ test9 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 2) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -606,10 +595,10 @@ test9 (unsigned cond)
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 2)
       != sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 2) != 0)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -627,10 +616,10 @@ test10 (void)
 	{
 #ifdef __builtin_object_size
 	  if (__builtin_object_size (p - 3, 2) != sizeof (buf) - i + 3)
-	    abort ();
+	    FAIL ();
 #else
 	  if (__builtin_object_size (p - 3, 2) != 0)
-	    abort ();
+	    FAIL ();
 #endif
 	  break;
 	}
@@ -647,19 +636,19 @@ test11 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 2) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 2) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 2) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -668,19 +657,19 @@ test11 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -691,7 +680,7 @@ test11 (void)
 #else
   if (__builtin_object_size (res, 2) != 1)
 #endif
-    abort ();
+    FAIL ();
 
   free (res);
   free (ptr2);
@@ -699,32 +688,32 @@ test11 (void)
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 2) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 2) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 2) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 2) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -744,5 +733,5 @@ main (void)
   test9 (1);
   test10 ();
   test11 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-4.c b/gcc/testsuite/gcc.dg/builtin-object-size-4.c
index 4c007c364b7..c9af07499a4 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-4.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-4.c
@@ -2,18 +2,7 @@
 /* { dg-options "-O2 -Wno-stringop-overread" } */
 /* { dg-require-effective-target alloca } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
 
 struct A
 {
@@ -40,36 +29,36 @@ test1 (void *q, int x)
   else
     r = &a.c[1];
   if (__builtin_object_size (p, 3) != sizeof (a.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a.c[9], 3)
       != sizeof (a.c) - 9)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 3) != 0)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3)
       != (x < 0 ? sizeof (a.a) - 9 : sizeof (a.c) - 1))
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 9)
 #endif
-    abort ();
+    FAIL ();
   if (x < 6)
     r = &w[2].a[1];
   else
     r = &a.a[6];
   if (__builtin_object_size (&y, 3) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (w, 3) != sizeof (w))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&y.b, 3) != sizeof (a.b))
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3)
       != (x < 6 ? sizeof (w[2].a) - 1 : sizeof (a.a) - 6))
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 6)
 #endif
-    abort ();
+    FAIL ();
   if (x < 20)
     r = malloc (30);
   else
@@ -79,7 +68,7 @@ test1 (void *q, int x)
 #else
   if (__builtin_object_size (r, 3) != 30)
 #endif
-    abort ();
+    FAIL ();
   if (x < 20)
     r = malloc (30);
   else
@@ -89,7 +78,7 @@ test1 (void *q, int x)
 #else
   if (__builtin_object_size (r, 3) != 2 * 14)
 #endif
-    abort ();
+    FAIL ();
   if (x < 30)
     r = malloc (sizeof (a));
   else
@@ -100,125 +89,125 @@ test1 (void *q, int x)
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 3)
 #endif
-    abort ();
+    FAIL ();
   r = memcpy (r, "a", 2);
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3) != objsz)
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 3)
 #endif
-    abort ();
+    FAIL ();
   r = memcpy (r + 2, "b", 2) + 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3) != objsz - 4)
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 3 - 4)
 #endif
-    abort ();
+    FAIL ();
   r = &a.a[4];
   r = memset (r, 'a', 2);
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 4)
-    abort ();
+    FAIL ();
   r = memset (r + 2, 'b', 2) + 2;
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 8)
-    abort ();
+    FAIL ();
   r = &a.a[1];
   r = strcpy (r, "ab");
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 1)
-    abort ();
+    FAIL ();
   r = strcpy (r + 2, "cd") + 2;
   if (__builtin_object_size (r, 3) != sizeof (a.a) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (exta + 10, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&exta[5], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb, 3) != sizeof (extb))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extb + 10, 3) != sizeof (extb) - 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extb[5], 3) != sizeof (extb) - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (extc + 10, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc->a, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&(extc + 10)->b, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&extc[5].c[3], 3) != 0)
-    abort ();
+    FAIL ();
 #ifdef __builtin_object_size
   if (__builtin_object_size (var, 3) != x + 10)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 3) != x)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 3) != x + 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 3) != (x + 10) * sizeof (struct A))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 3) != x * sizeof (struct A))
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 3) != (x + 5) * sizeof (struct A))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (var, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (var + 10, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&var[5], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (vara + 10, 3) != 0)
-    abort ();    
+    FAIL ();    
   if (__builtin_object_size (&vara[5], 3) != 0)
-    abort ();
+    FAIL ();
 #endif
   if (__builtin_object_size (&vara[0].a, 3) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[10].a[0], 3) != sizeof (vara[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].a[4], 3) != sizeof (vara[0].a) - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[5].b, 3) != sizeof (vara[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&vara[7].c[7], 3) != sizeof (vara[0].c) - 7)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (zerol[0].a, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].a[0], 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&zerol[0].b, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcdefg", 3) != sizeof ("abcdefg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg", 3) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg", 3) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[0], 3) != sizeof ("abcd\0efg"))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&"abcd\0efg"[4], 3) != sizeof ("abcd\0efg") - 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ("abcd\0efg" + 5, 3) != sizeof ("abcd\0efg") - 5)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (L"abcdefg", 3) != sizeof (L"abcdefg"))
-    abort ();
+    FAIL ();
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 3) != sizeof (L"abcd\0efg") - 2)
-    abort ();
+    FAIL ();
   /* Prevent DSE from removing calls that prevent bad combining of
      addresses and offsets.  */
   asm volatile ("" : : "g" (&a));
@@ -253,7 +242,7 @@ test2 (void)
 	r = &a.buf1[9];
     }
   if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 9)
-    abort ();
+    FAIL ();
   r = &buf3[20];
   for (i = 0; i < 4; ++i)
     {
@@ -267,7 +256,7 @@ test2 (void)
 	r = &a.buf1[9];
     }
   if (__builtin_object_size (r, 3) != 0)
-    abort ();
+    FAIL ();
   r = &buf3[1];
   for (i = 0; i < 4; ++i)
     {
@@ -286,31 +275,31 @@ test2 (void)
   for (i = 0; i < 4; ++i)
     {
       if (i == l1 - 1)
-        dyn_res = sizeof (a.buf1) - 6;
+	dyn_res = sizeof (a.buf1) - 6;
       else if (i == l1)
-        dyn_res = sizeof (a.buf2) - 4;
+	dyn_res = sizeof (a.buf2) - 4;
       else if (i == l1 + 1)
-        dyn_res = sizeof (buf3) - 5;
+	dyn_res = sizeof (buf3) - 5;
       else if (i == l1 + 2)
-        dyn_res = sizeof (a.buf1) - 2;
+	dyn_res = sizeof (a.buf1) - 2;
     }
   if (__builtin_object_size (r, 3) != dyn_res)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 6)
-    abort ();
+    FAIL ();
 #endif
   r += 2;
 #ifdef __builtin_object_size
   if (__builtin_object_size (r, 3) != dyn_res - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 1, 3) != dyn_res - 3)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 6 - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (r + 1, 3) != sizeof (a.buf1) - 6 - 3)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -326,78 +315,78 @@ test3 (void)
   double *dp;
 
   if (__builtin_object_size (buf4, 3) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4, 3) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[0], 3) != sizeof (buf4))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&buf4[1], 3) != sizeof (buf4) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x, 3) != sizeof (x))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a, 3) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0], 3) != sizeof (x.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a, 3) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[0], 3) != sizeof (x.a[0].a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].a[3], 3) != sizeof (x.a[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[0].b, 3) != sizeof (x.a[0].b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c, 3) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[0], 3) != sizeof (x.a[1].c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.a[1].c[3], 3) != sizeof (x.a[1].c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b, 3) != sizeof (x.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a, 3) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[0], 3) != sizeof (x.b.a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.a[3], 3) != sizeof (x.b.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.b, 3) != sizeof (x.b.b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c, 3) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[0], 3) != sizeof (x.b.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.b.c[3], 3) != sizeof (x.b.c) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c, 3) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[0], 3) != sizeof (x.c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.c[1], 3) != sizeof (x.c) - 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.d, 3) != sizeof (x.d))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.e, 3) != sizeof (x.e))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&x.f, 3) != sizeof (x.f))
-    abort ();
+    FAIL ();
   dp = &__real__ x.f;
   if (__builtin_object_size (dp, 3) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ x.f;
   if (__builtin_object_size (dp, 3) != sizeof (x.f) / 2)
-    abort ();
+    FAIL ();
   dp = &y;
   if (__builtin_object_size (dp, 3) != sizeof (y))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&z, 3) != sizeof (z))
-      abort ();
+      FAIL ();
   dp = &__real__ z;
   if (__builtin_object_size (dp, 3) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
   dp = &__imag__ z;
   if (__builtin_object_size (dp, 3) != sizeof (z) / 2)
-    abort ();
+    FAIL ();
 }
 
 struct S { unsigned int a; };
@@ -414,7 +403,7 @@ test4 (char *x, int y)
       p = (struct A *) x;
       x = (char *) &p[1];
       if (__builtin_object_size (p, 3) != 0)
-	abort ();
+	FAIL ();
     }
   return x;
 }
@@ -434,7 +423,7 @@ test5 (size_t x)
 #else
   if (__builtin_object_size (p, 3) != 0)
 #endif
-    abort ();
+    FAIL ();
   memset (p, ' ', sizeof (t.buf) - 8 - 4 * 4);
 }
 
@@ -447,11 +436,11 @@ test6 (void)
   char *p = &buf[64], *q = &t.buf[64];
 
   if (__builtin_object_size (p + 64, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 0, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q + 64, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -462,18 +451,18 @@ test7 (void)
   char *p = &t.buf2[-4];
   char *q = &t.buf2[0];
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (q, 3) != sizeof (t.buf2))
-    abort ();
+    FAIL ();
   q = &t.buf[10];
   if (__builtin_object_size (q, 3) != 0)
-    abort ();
+    FAIL ();
   q = &t.buf[11];
   if (__builtin_object_size (q, 3) != 0)
-    abort ();
+    FAIL ();
   p = &t.buf[-4];
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -490,10 +479,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (&p[-4], 3) != (cond ? 6 : 10))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (&p[-4], 3) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   for (unsigned i = cond; i > 0; i--)
@@ -501,10 +490,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 3) != ((cond ? 2 : 6) + cond))
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
 #endif
 
   p = &y.c[8];
@@ -513,10 +502,10 @@ test8 (unsigned cond)
 
 #ifdef __builtin_object_size
   if (__builtin_object_size (p, 3) != sizeof (y.c) - 8 + cond)
-    abort ();
+    FAIL ();
 #else
   if (__builtin_object_size (p, 3) != 0)
-    abort ();
+    FAIL ();
 #endif
 }
 
@@ -528,19 +517,19 @@ test9 (void)
   const char *ptr = "abcdefghijklmnopqrstuvwxyz";
   char *res = strndup (ptr, 21);
   if (__builtin_object_size (res, 3) != 22)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr, 32);
   if (__builtin_object_size (res, 3) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strdup (ptr);
   if (__builtin_object_size (res, 3) != 27)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -549,19 +538,19 @@ test9 (void)
 
   res = strndup (ptr2, 21);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 32);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
   res = strndup (ptr2, 128);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
 
   free (res);
 
@@ -571,7 +560,7 @@ test9 (void)
 #else
   if (__builtin_object_size (res, 3) != 1)
 #endif
-    abort ();
+    FAIL ();
 
   free (res);
   free (ptr2);
@@ -579,32 +568,32 @@ test9 (void)
   ptr = "abcd\0efghijklmnopqrstuvwxyz";
   res = strdup (ptr);
   if (__builtin_object_size (res, 3) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 24);
   if (__builtin_object_size (res, 3) != 5)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (ptr, 2);
   if (__builtin_object_size (res, 3) != 3)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strdup (&ptr[4]);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 4);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
   free (res);
 
   res = strndup (&ptr[4], 1);
   if (__builtin_object_size (res, 3) != 1)
-    abort ();
+    FAIL ();
   free (res);
 }
 
@@ -622,5 +611,5 @@ main (void)
   test7 ();
   test8 (1);
   test9 ();
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-6.c b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
index c6887b854ac..b456b321db0 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-6.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-6.c
@@ -1,11 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void free (void *);
+#include "builtin-object-size-common.h"
 
 struct A
 {
@@ -20,105 +16,105 @@ test1 (struct A *p)
 {
   char *c;
   if (__builtin_object_size (&p->a, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != 0)
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 void
@@ -129,105 +125,105 @@ test2 (void)
   size_t s = 2 * sizeof (struct A);
   struct A *p = malloc (2 * sizeof (struct A));
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 0) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 0) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 0) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 1) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 2) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 2) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 2) != s)
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 2) != s - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 2) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   c = p->a;
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[0];
   if (__builtin_object_size (c, 3) != sizeof (p->a))
-    abort ();
+    FAIL ();
   c = &p->a[3];
   if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   c = (char *) &p->b;
   if (__builtin_object_size (c, 3) != sizeof (p->b))
-    abort ();
+    FAIL ();
   c = (char *) &p->c;
   if (__builtin_object_size (c, 3) != s - __builtin_offsetof (struct A, c))
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -239,48 +235,48 @@ test3 (void)
   size_t s;
   struct A *p = malloc (4);
   if (__builtin_object_size (&p->a, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 0)
-    abort ();
+    FAIL ();
   free (p);
   s = __builtin_offsetof (struct A, c) + 4;
   p = malloc (s);
   if (__builtin_object_size (&p->a, 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 0) != s)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 0) != s - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (struct A, b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 0) != 4)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&p->c, 1) != 4)
-    abort ();
+    FAIL ();
   free (p);
 }
 
@@ -294,17 +290,17 @@ __attribute__ ((noinline))
 test4 (struct B *q, int i)
 {
   if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
-    abort ();
+    FAIL ();
 }
 
 struct C
@@ -318,13 +314,13 @@ __attribute__ ((noinline))
 test5 (struct C *c)
 {
   if (__builtin_object_size (&c->b, 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 1) != 1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&c->b, 3) != 1)
-    abort ();
+    FAIL ();
 }
 
 struct D
@@ -342,13 +338,13 @@ __attribute__ ((noinline))
 test6 (struct D *d)
 {
   if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
-    abort ();
+    FAIL ();
 }
 
 struct E
@@ -366,21 +362,21 @@ __attribute__ ((noinline))
 test7 (struct E *e)
 {
   if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 union F
@@ -398,13 +394,13 @@ __attribute__ ((noinline))
 test8 (union F *f)
 {
   if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 2) != 0)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&f->d.c[3], 3) != 0)
-    abort ();
+    FAIL ();
 }
 
 int
@@ -431,5 +427,5 @@ main (void)
   union F f, *fp = &f;
   __asm ("" : "+r" (fp));
   test8 (fp);
-  exit (0);
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-7.c b/gcc/testsuite/gcc.dg/builtin-object-size-7.c
index 41742b974ef..0d11c429876 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-7.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-7.c
@@ -1,9 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void *malloc (size_t);
-extern void abort (void);
+#include "builtin-object-size-common.h"
 
 struct A
 {
@@ -20,52 +18,52 @@ main (void)
   struct A *a = malloc (s);
   struct A *b = malloc (o + 212);
   if (__builtin_object_size (a->buf, 0) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (a->buf, 1) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (a->buf, 2) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (a->buf, 3) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 0) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 1) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 2) != s - o)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[0], 3) != sizeof (a->buf))
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 0) != s - o - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 1) != sizeof (a->buf) - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 2) != s - o - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&a->buf[6], 3) != sizeof (a->buf) - 6)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 0) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 1) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 2) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (b->buf, 3) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 0) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 1) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 2) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[0], 3) != 212)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 0) != 212 - 28)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 1) != 212 - 28)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 2) != 212 - 28)
-    abort ();
+    FAIL ();
   if (__builtin_object_size (&b->buf[28], 3) != 212 - 28)
-    abort ();
-  return 0;
+    FAIL ();
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-8.c b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
index f2d88f9d591..294e5242633 100644
--- a/gcc/testsuite/gcc.dg/builtin-object-size-8.c
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-8.c
@@ -1,10 +1,7 @@
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 
-typedef __SIZE_TYPE__ size_t;
-extern void *malloc (size_t);
-extern void free (void *);
-extern void abort (void);
+#include "builtin-object-size-common.h"
 
 union A
 {
@@ -56,13 +53,13 @@ struct H
 
 #define T(X, S0, S1) \
   if (__builtin_object_size (X, 0) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 1) != (S1))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 2) != (S0))	\
-    abort ();					\
+    FAIL ();					\
   if (__builtin_object_size (X, 3) != (S1))	\
-    abort ()
+    FAIL ()
 #define TS(X, S0) T(&X, S0, sizeof (X))
 #define TA(X, S0, S1) \
   T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1)
@@ -196,5 +193,5 @@ main (void)
   free (h2);
   free (h1);
 
-  return 0;
+  DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-common.h b/gcc/testsuite/gcc.dg/builtin-object-size-common.h
new file mode 100644
index 00000000000..66ff7cdd953
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-common.h
@@ -0,0 +1,32 @@
+typedef __SIZE_TYPE__ size_t;
+#ifdef __cplusplus
+extern "C" {
+#endif
+  extern void exit (int);
+  extern void *malloc (size_t);
+  extern void free (void *);
+  extern void *calloc (size_t, size_t);
+  extern void *alloca (size_t);
+  extern void *memcpy (void *, const void *, size_t);
+  extern void *memset (void *, int, size_t);
+  extern char *strcpy (char *, const char *);
+  extern char *strdup (const char *);
+  extern char *strndup (const char *, size_t);
+#ifdef __cplusplus
+}
+#endif
+
+unsigned nfails = 0;
+
+#define FAIL() \
+  do { \
+    __builtin_printf ("Failure at line: %d\n", __LINE__);		      \
+    nfails++;								      \
+  } while (0)
+
+#define DONE() \
+  do {									      \
+    if (nfails > 0)							      \
+      __builtin_abort ();						      \
+    return 0;								      \
+  } while (0)
diff --git a/gcc/testsuite/gcc.dg/pr101836.c b/gcc/testsuite/gcc.dg/pr101836.c
index efad02cfe89..096196d9b7f 100644
--- a/gcc/testsuite/gcc.dg/pr101836.c
+++ b/gcc/testsuite/gcc.dg/pr101836.c
@@ -4,16 +4,16 @@
 /* { dg-do run } */
 /* { dg-options "-O2 -fstrict-flex-arrays" } */
 
-#include <stdio.h>
+#include "builtin-object-size-common.h"
 
 #define expect(p, _v) do { \
     size_t v = _v; \
     if (p == v) \
-        printf("ok:  %s == %zd\n", #p, p); \
+	__builtin_printf("ok:  %s == %zd\n", #p, p); \
     else \
 	{  \
-          printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
-	  __builtin_abort (); \
+	  __builtin_printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
+	  FAIL (); \
 	} \
 } while (0);
 
@@ -56,5 +56,5 @@ int main(int argc, char *argv[])
 {
     stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]);
 
-    return 0;
+    DONE ();
 }
diff --git a/gcc/testsuite/gcc.dg/strict-flex-array-3.c b/gcc/testsuite/gcc.dg/strict-flex-array-3.c
index 602f99dc79a..f74ed96c751 100644
--- a/gcc/testsuite/gcc.dg/strict-flex-array-3.c
+++ b/gcc/testsuite/gcc.dg/strict-flex-array-3.c
@@ -4,16 +4,16 @@
 /* { dg-do run } */
 /* { dg-options "-O2 -fstrict-flex-arrays=0" } */
 
-#include <stdio.h>
+#include "builtin-object-size-common.h"
 
 #define expect(p, _v) do { \
     size_t v = _v; \
     if (p == v) \
-        printf("ok:  %s == %zd\n", #p, p); \
+	__builtin_printf ("ok:  %s == %zd\n", #p, p); \
     else \
 	{  \
-          printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
-	  __builtin_abort (); \
+	  __builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
+	  FAIL (); \
 	} \
 } while (0);
 
@@ -56,5 +56,5 @@ int main(int argc, char *argv[])
 {
     stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]);
 
-    return 0;
+    DONE ();
 }
-- 
2.38.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-02-01 16:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 22:25 [PATCH 0/2] __bos and flex arrays Siddhesh Poyarekar
2022-12-21 22:25 ` [PATCH 1/2] testsuite: Run __bos tests to completion Siddhesh Poyarekar
2023-01-31 12:33   ` Jakub Jelinek
2023-02-01 16:46     ` [committed v2] " Siddhesh Poyarekar
2022-12-21 22:25 ` [PATCH 2/2] tree-object-size: More consistent behaviour with flex arrays Siddhesh Poyarekar
2023-01-26 16:20   ` Qing Zhao
2023-01-26 17:16     ` Siddhesh Poyarekar
2023-01-26 17:42       ` Qing Zhao
2023-01-31 12:46   ` Jakub Jelinek
2023-01-31 13:01     ` Siddhesh Poyarekar
2023-01-03 14:30 ` [ping][PATCH 0/2] __bos and " Siddhesh Poyarekar
2023-01-11 13:14 ` [ping2][PATCH " Siddhesh Poyarekar
2023-01-20 19:38 ` [ping3][PATCH " Siddhesh Poyarekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).