Previous submission/discussion here:
https://gcc.gnu.org/ml/gcc-patches/2018-11/msg02151.html
For msp430-elf with the large memory model (-mlarge), __{,U}INTPTR_TYPE__,
__PTRDIFF_TYPE__ and __SIZE_TYPE__ are __int20.
If a test using these macros is compiled with -pedantic-errors, and -std=* or
-ansi, then GCC emits an error:
ISO C does not support __int20 types
The macros expand to __int20 after pre-processing, so to prevent the errors
__extension__ needs to be added before their usage in the testsuite.
I should clarify that using size_t/ptrdiff_t does not cause any ISO C errors,
even though __int20 is the underlying type. It is only when the builtin macros
for these types are used does the error occur.
Successfully regtested x86_64-pc-linux-gnu and msp430-elf/-mlarge.
Ok for trunk?
>From b940f79fa7c2a76fdda75dae7baf2bd48c72e9fa Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <[email protected]>
Date: Mon, 31 Dec 2018 11:36:09 +0000
Subject: [PATCH] [ping][TESTSUITE] Fix ISO C errors in tests when ptr_t/size_t
are not ISO C compatible
2018-12-31 Jozef Lawrynowicz <[email protected]>
Fix ISO C errors in tests when ptr_t/size_t are not ISO C compatible
gcc/testsuite/ChangeLog:
* gcc.dg/addr_builtin-1.c: Add __extension__ before usage of
__SIZE_TYPE__ and __UINTPTR_TYPE__.
* gcc.dg/vla-11.c: Likewise.
* gcc.dg/c11-static-assert-3.c: Add __extension__ before usage of
__SIZE_TYPE__.
* gcc.dg/c11-uni-string-1.c: Likewise.
* gcc.dg/c99-const-expr-10.c: Likewise.
* gcc.dg/c99-const-expr-9.c: Likewise.
* gcc.dg/c99-init-1.c: Likewise.
* gcc.dg/pr52549.c: Likewise.
* gcc.dg/pr71558.c: Likewise.
* gcc.dg/pr77587.c: Likewise.
* gcc.dg/pr79223.c: Likewise.
* gcc.dg/vla-9.c: Likewise.
* gcc.dg/c99-const-expr-6.c: Add __extension__ before usage of
__INTPTR_TYPE__.
* gcc.dg/c99-stdint-5.c: Likewise.
* gcc.dg/c99-stdint-6.c: Likewise.
* gcc.dg/pr61240.c: Add __extension__ before usage of __PTRDIFF_TYPE__.
---
gcc/testsuite/gcc.dg/addr_builtin-1.c | 6 +++---
gcc/testsuite/gcc.dg/c11-static-assert-3.c | 2 +-
gcc/testsuite/gcc.dg/c11-uni-string-1.c | 2 +-
gcc/testsuite/gcc.dg/c99-const-expr-10.c | 14 +++++++-------
gcc/testsuite/gcc.dg/c99-const-expr-6.c | 4 ++--
gcc/testsuite/gcc.dg/c99-const-expr-9.c | 2 +-
gcc/testsuite/gcc.dg/c99-init-1.c | 2 +-
gcc/testsuite/gcc.dg/c99-stdint-5.c | 4 ++--
gcc/testsuite/gcc.dg/c99-stdint-6.c | 4 ++--
gcc/testsuite/gcc.dg/pr52549.c | 3 ++-
gcc/testsuite/gcc.dg/pr61240.c | 2 +-
gcc/testsuite/gcc.dg/pr71558.c | 8 +++++---
gcc/testsuite/gcc.dg/pr77587.c | 2 +-
gcc/testsuite/gcc.dg/pr79223.c | 2 +-
gcc/testsuite/gcc.dg/vla-11.c | 4 ++--
gcc/testsuite/gcc.dg/vla-9.c | 4 +++-
16 files changed, 35 insertions(+), 30 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/addr_builtin-1.c b/gcc/testsuite/gcc.dg/addr_builtin-1.c
index 4a0888a..d7ad785 100644
--- a/gcc/testsuite/gcc.dg/addr_builtin-1.c
+++ b/gcc/testsuite/gcc.dg/addr_builtin-1.c
@@ -2,7 +2,7 @@
{ dg-do compile } */
typedef void (F)(void);
-typedef __UINTPTR_TYPE__ uintptr_t;
+__extension__ typedef __UINTPTR_TYPE__ uintptr_t;
/* Utility function to test passing built-in functions as an ordinary
argument and via the ellipsis. */
@@ -122,7 +122,7 @@ static F* test_taking_address_of_gcc_builtin (void)
of a user-declared function that's also a GCC built-in. */
extern int abs (int);
-extern __SIZE_TYPE__ strlen (const char*);
+__extension__ extern __SIZE_TYPE__ strlen (const char*);
/* Taking the address of a builtin with a library "fallback" must be
allowed, either using the __builtin_xxx form or the xxx form, when
@@ -147,7 +147,7 @@ void test_taking_address_of_library_builtin (int i)
}
{
- typedef __SIZE_TYPE__ size_t;
+ __extension__ typedef __SIZE_TYPE__ size_t;
typedef size_t F (const char*);
/* Compute the address of libc's strlen using the implicitly
diff --git a/gcc/testsuite/gcc.dg/c11-static-assert-3.c b/gcc/testsuite/gcc.dg/c11-static-assert-3.c
index 9799b97..25a9346 100644
--- a/gcc/testsuite/gcc.dg/c11-static-assert-3.c
+++ b/gcc/testsuite/gcc.dg/c11-static-assert-3.c
@@ -5,7 +5,7 @@
_Static_assert (__INT_MAX__ * 2, "overflow"); /* { dg-warning "integer overflow in expression" } */
/* { dg-error "overflow in constant expression" "error" { target *-*-* } .-1 } */
-_Static_assert ((void *)(__SIZE_TYPE__)16, "non-integer"); /* { dg-error "not an integer" } */
+_Static_assert (__extension__ (void *)(__SIZE_TYPE__)16, "non-integer"); /* { dg-error "not an integer" } */
_Static_assert (1.0, "non-integer"); /* { dg-error "not an integer" } */
diff --git a/gcc/testsuite/gcc.dg/c11-uni-string-1.c b/gcc/testsuite/gcc.dg/c11-uni-string-1.c
index 9f86bea..6ace5e0 100644
--- a/gcc/testsuite/gcc.dg/c11-uni-string-1.c
+++ b/gcc/testsuite/gcc.dg/c11-uni-string-1.c
@@ -8,7 +8,7 @@
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
-typedef __SIZE_TYPE__ size_t;
+__extension__ typedef __SIZE_TYPE__ size_t;
extern void abort (void);
extern void exit (int);
diff --git a/gcc/testsuite/gcc.dg/c99-const-expr-10.c b/gcc/testsuite/gcc.dg/c99-const-expr-10.c
index 2aca610..0a81953 100644
--- a/gcc/testsuite/gcc.dg/c99-const-expr-10.c
+++ b/gcc/testsuite/gcc.dg/c99-const-expr-10.c
@@ -4,25 +4,25 @@
/* Origin: Joseph Myers <[email protected]> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
-
-void *p = (__SIZE_TYPE__)(void *)0; /* { dg-error "without a cast" } */
-struct s { void *a; } q = { (__SIZE_TYPE__)(void *)0 }; /* { dg-error "without a cast|near initialization" } */
+__extension__ typedef __SIZE_TYPE__ size_t;
+void *p = (size_t)(void *)0; /* { dg-error "without a cast" } */
+struct s { void *a; } q = { (size_t)(void *)0 }; /* { dg-error "without a cast|near initialization" } */
void *
f (void)
{
void *r;
- r = (__SIZE_TYPE__)(void *)0; /* { dg-error "without a cast" } */
- return (__SIZE_TYPE__)(void *)0; /* { dg-error "without a cast" } */
+ r = (size_t)(void *)0; /* { dg-error "without a cast" } */
+ return (size_t)(void *)0; /* { dg-error "without a cast" } */
}
void g (void *); /* { dg-message "but argument is of type" } */
void
h (void)
{
- g ((__SIZE_TYPE__)(void *)0); /* { dg-error "without a cast" } */
+ g ((size_t)(void *)0); /* { dg-error "without a cast" } */
}
void g2 (int, void *); /* { dg-message "but argument is of type" } */
void
h2 (void)
{
- g2 (0, (__SIZE_TYPE__)(void *)0); /* { dg-error "without a cast" } */
+ g2 (0, (size_t)(void *)0); /* { dg-error "without a cast" } */
}
diff --git a/gcc/testsuite/gcc.dg/c99-const-expr-6.c b/gcc/testsuite/gcc.dg/c99-const-expr-6.c
index ca60243..ecb048b 100644
--- a/gcc/testsuite/gcc.dg/c99-const-expr-6.c
+++ b/gcc/testsuite/gcc.dg/c99-const-expr-6.c
@@ -8,7 +8,7 @@
int n = 0, p[n * 0 + 1]; /* { dg-error "variabl" } */
/* PR 31871. */
-extern int c[1 + ((__INTPTR_TYPE__) (void *) 0)]; /* { dg-error "variab" } */
+extern int c[1 + (__extension__ (__INTPTR_TYPE__) (void *) 0)]; /* { dg-error "variab" } */
/* Implicit conversions from floating-point constants are not OK,
although explicit ones are. */
@@ -32,7 +32,7 @@ struct s {
};
enum e {
- E = (1 + ((__INTPTR_TYPE__) (void *) 0)), /* { dg-error "constant" } */
+ E = (1 + (__extension__ (__INTPTR_TYPE__) (void *) 0)), /* { dg-error "constant" } */
E2 = 0
};
diff --git a/gcc/testsuite/gcc.dg/c99-const-expr-9.c b/gcc/testsuite/gcc.dg/c99-const-expr-9.c
index 11e0b2c..371e105 100644
--- a/gcc/testsuite/gcc.dg/c99-const-expr-9.c
+++ b/gcc/testsuite/gcc.dg/c99-const-expr-9.c
@@ -14,7 +14,7 @@ struct t {
int b[2];
};
-#define old_offsetof(TYPE, MEMBER) ((__SIZE_TYPE__)(__UINTPTR_TYPE__) &((TYPE *)0)->MEMBER)
+#define old_offsetof(TYPE, MEMBER) (__extension__ (__SIZE_TYPE__)(__UINTPTR_TYPE__) &((TYPE *)0)->MEMBER)
enum e {
E1 = old_offsetof (struct s, a), /* { dg-error "constant" } */
diff --git a/gcc/testsuite/gcc.dg/c99-init-1.c b/gcc/testsuite/gcc.dg/c99-init-1.c
index 95803c2..cefcfef 100644
--- a/gcc/testsuite/gcc.dg/c99-init-1.c
+++ b/gcc/testsuite/gcc.dg/c99-init-1.c
@@ -3,7 +3,7 @@
/* { dg-do run } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
-typedef __SIZE_TYPE__ size_t;
+__extension__ typedef __SIZE_TYPE__ size_t;
typedef __WCHAR_TYPE__ wchar_t;
extern int memcmp (const void *, const void *, size_t);
extern void abort (void);
diff --git a/gcc/testsuite/gcc.dg/c99-stdint-5.c b/gcc/testsuite/gcc.dg/c99-stdint-5.c
index 6051323..97cd6f7 100644
--- a/gcc/testsuite/gcc.dg/c99-stdint-5.c
+++ b/gcc/testsuite/gcc.dg/c99-stdint-5.c
@@ -57,10 +57,10 @@ check_types (void)
CHECK_TYPES(__UINT_FAST32_TYPE__, uint_fast32_t);
CHECK_TYPES(__UINT_FAST64_TYPE__, uint_fast64_t);
#ifdef __INTPTR_TYPE__
- CHECK_TYPES(__INTPTR_TYPE__, intptr_t);
+ CHECK_TYPES(__extension__ __INTPTR_TYPE__, intptr_t);
#endif
#ifdef __UINTPTR_TYPE__
- CHECK_TYPES(__UINTPTR_TYPE__, uintptr_t);
+ CHECK_TYPES(__extension__ __UINTPTR_TYPE__, uintptr_t);
#endif
CHECK_TYPES(__INTMAX_TYPE__, intmax_t);
CHECK_TYPES(__UINTMAX_TYPE__, uintmax_t);
diff --git a/gcc/testsuite/gcc.dg/c99-stdint-6.c b/gcc/testsuite/gcc.dg/c99-stdint-6.c
index 60ac31f..1075828 100644
--- a/gcc/testsuite/gcc.dg/c99-stdint-6.c
+++ b/gcc/testsuite/gcc.dg/c99-stdint-6.c
@@ -60,10 +60,10 @@ check_types (void)
CHECK_TYPES(__UINT_FAST64_TYPE__, uint_fast64_t);
#endif
#ifdef __INTPTR_TYPE__
- CHECK_TYPES(__INTPTR_TYPE__, intptr_t);
+ CHECK_TYPES(__extension__ __INTPTR_TYPE__, intptr_t);
#endif
#ifdef __UINTPTR_TYPE__
- CHECK_TYPES(__UINTPTR_TYPE__, uintptr_t);
+ CHECK_TYPES(__extension__ __UINTPTR_TYPE__, uintptr_t);
#endif
#ifndef NO_MAX_TYPES
CHECK_TYPES(__INTMAX_TYPE__, intmax_t);
diff --git a/gcc/testsuite/gcc.dg/pr52549.c b/gcc/testsuite/gcc.dg/pr52549.c
index 4d0a3e0..faf4e5d 100644
--- a/gcc/testsuite/gcc.dg/pr52549.c
+++ b/gcc/testsuite/gcc.dg/pr52549.c
@@ -1,7 +1,8 @@
/* { dg-do compile } */
#ifdef __SIZE_TYPE__
-_mark (__SIZE_TYPE__ obj, int i, char *a)
+__extension__ typedef __SIZE_TYPE__ size_t;
+_mark (size_t obj, int i, char *a)
{
(char *)&(((long *)(obj)) [i]) - a;
}
diff --git a/gcc/testsuite/gcc.dg/pr61240.c b/gcc/testsuite/gcc.dg/pr61240.c
index 6332918..8bbb347 100644
--- a/gcc/testsuite/gcc.dg/pr61240.c
+++ b/gcc/testsuite/gcc.dg/pr61240.c
@@ -1,7 +1,7 @@
/* PR c/61240 */
/* { dg-do compile } */
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
+__extension__ typedef __PTRDIFF_TYPE__ ptrdiff_t;
ptrdiff_t
foo (ptrdiff_t a[4])
diff --git a/gcc/testsuite/gcc.dg/pr71558.c b/gcc/testsuite/gcc.dg/pr71558.c
index 33a648e..ada830b 100644
--- a/gcc/testsuite/gcc.dg/pr71558.c
+++ b/gcc/testsuite/gcc.dg/pr71558.c
@@ -3,15 +3,17 @@
/* strcpy must not be pure, but make sure we don't ICE even when
it is declared incorrectly. */
char *strcpy (char *, const char *) __attribute__ ((__pure__));
-__SIZE_TYPE__ strlen (const char *);
-void *malloc (__SIZE_TYPE__);
+__extension__ typedef __SIZE_TYPE__ size_t;
+
+size_t strlen (const char *);
+void *malloc (size_t);
char a[20];
char *
foo (void)
{
- __SIZE_TYPE__ b = strlen (a);
+ size_t b = strlen (a);
char *c = malloc (b);
return strcpy (c, a);
}
diff --git a/gcc/testsuite/gcc.dg/pr77587.c b/gcc/testsuite/gcc.dg/pr77587.c
index 8f5afef..c4a6ebf 100644
--- a/gcc/testsuite/gcc.dg/pr77587.c
+++ b/gcc/testsuite/gcc.dg/pr77587.c
@@ -10,6 +10,6 @@ bar (long x, long y, long z)
struct __attribute__((aligned (16))) S { long a, b, c, d; } s;
char *p = (char *) &s;
__asm ("" : "+r" (p));
- if (((__UINTPTR_TYPE__) p) & 15)
+ if ((__extension__ (__UINTPTR_TYPE__) p) & 15)
__builtin_abort ();
}
diff --git a/gcc/testsuite/gcc.dg/pr79223.c b/gcc/testsuite/gcc.dg/pr79223.c
index ef0dd1b..f043fc4 100644
--- a/gcc/testsuite/gcc.dg/pr79223.c
+++ b/gcc/testsuite/gcc.dg/pr79223.c
@@ -2,7 +2,7 @@
{ dg-do compile }
{ dg-additional-options "-O2 -Wall -Wno-array-bounds -std=gnu99" } */
-typedef __SIZE_TYPE__ size_t;
+__extension__ typedef __SIZE_TYPE__ size_t;
extern void* memcpy (void*, const void*, size_t);
extern void* mempcpy (void*, const void*, size_t);
diff --git a/gcc/testsuite/gcc.dg/vla-11.c b/gcc/testsuite/gcc.dg/vla-11.c
index 1504853..e2d5488 100644
--- a/gcc/testsuite/gcc.dg/vla-11.c
+++ b/gcc/testsuite/gcc.dg/vla-11.c
@@ -5,8 +5,8 @@
/* Origin: Joseph Myers <[email protected]> */
/* { dg-do compile } */
/* { dg-options "-std=c99 -pedantic-errors" } */
-
+__extension__ typedef __SIZE_TYPE__ size_t;
void foo11a(int x[sizeof(int *(*)[*])]); /* { dg-warning "not in a declaration" } */
-void foo11b(__SIZE_TYPE__ x, int y[(__UINTPTR_TYPE__)(int (*)[*])x]); /* { dg-warning "not in a declaration" } */
+void foo11b(size_t x, int y[__extension__ (__UINTPTR_TYPE__)(int (*)[*])x]); /* { dg-warning "not in a declaration" } */
void foo11c(struct s { int (*x)[*]; } *y); /* { dg-error "a member of a structure or union cannot have a variably modified type" "variably modified" } */
/* { dg-warning "'struct s' declared inside parameter list" "struct decl" { target *-*-* } .-1 } */
diff --git a/gcc/testsuite/gcc.dg/vla-9.c b/gcc/testsuite/gcc.dg/vla-9.c
index 506a1a2..44a232b 100644
--- a/gcc/testsuite/gcc.dg/vla-9.c
+++ b/gcc/testsuite/gcc.dg/vla-9.c
@@ -2,7 +2,9 @@
/* { dg-options "-std=c99 -pedantic-errors -W -Wall" } */
/* PR c/28280 */
-void f(__SIZE_TYPE__ d)
+__extension__ typedef __SIZE_TYPE__ size_t;
+
+void f(size_t d)
{
typedef int t[d];
t *g = (__typeof (g)) d;
--
2.7.4