diff mbox

[testsuite,committed] : Fix wrong sizeof(int)==4 assumption (yet another time)

Message ID 4EE0B379.5000604@gjlay.de
State New
Headers show

Commit Message

Georg-Johann Lay Dec. 8, 2011, 12:54 p.m. UTC
I allowed me to apply the following change:

http://gcc.gnu.org/viewcvs?view=revision&revision=182109

Assumptions like sizeof(int)==4 or sizeof(void*)==4 are the most frequent cause
for annoying false FAILing C test cases.

Besides that: Why are there new test cases in gcc.c-torture?

As far as I remember that place is deprecated and the preferred place for new C
tests like this is gcc.dg?

Johann

Comments

Jakub Jelinek Dec. 8, 2011, 1:04 p.m. UTC | #1
On Thu, Dec 08, 2011 at 01:54:17PM +0100, Georg-Johann Lay wrote:
The test should be using
typedef __INT16_TYPE__ int16_t;
typedef __INT32_TYPE__ int32_t;
instead of what you are proposing.

> Index: gcc.c-torture/execute/20111208-1.c
> ===================================================================
> --- gcc.c-torture/execute/20111208-1.c  (revision 182106)
> +++ gcc.c-torture/execute/20111208-1.c  (working copy)
> @@ -10,8 +10,26 @@ extern void *memcpy (void *__restrict __
>  extern size_t strlen (__const char *__s)
>       __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__
> ((__nonnull__ (1)));
> 
> +#if __SIZEOF_SHORT__ == 2
>  typedef short int int16_t;
> +#elif __SIZEOF_INT__ == 2
> +typedef int int16_t;
> +#elif __SIZEOF_LONG__ == 2
> +typedef long int16_t;
> +#else
> +#error Fix this
> +#endif
> +
> +
> +#if __SIZEOF_INT__ == 4
>  typedef int int32_t;
> +#elif __SIZEOF_LONG__ == 4
> +typedef long int32_t;
> +#elif __SIZEOF_SHORT__ == 4
> +typedef short int32_t;
> +#else
> +#error Fix this
> +#endif
> 
>  extern void abort (void);

	Jakub
Georg-Johann Lay Dec. 8, 2011, 1:59 p.m. UTC | #2
Jakub Jelinek wrote:
> On Thu, Dec 08, 2011 at 01:54:17PM +0100, Georg-Johann Lay wrote:
> The test should be using
> typedef __INT16_TYPE__ int16_t;
> typedef __INT32_TYPE__ int32_t;
> instead of what you are proposing.

Ah, thanks for the hint! Looks way better now.

Johann
Eric Botcazou Dec. 8, 2011, 9:27 p.m. UTC | #3
> I allowed me to apply the following change:
>
> http://gcc.gnu.org/viewcvs?view=revision&revision=182109

Then you need to do the same on the 4.6 branch.

> Besides that: Why are there new test cases in gcc.c-torture?
>
> As far as I remember that place is deprecated and the preferred place for
> new C tests like this is gcc.dg?

What makes you think so?
diff mbox

Patch

Index: gcc.c-torture/execute/20111208-1.c
===================================================================
--- gcc.c-torture/execute/20111208-1.c  (revision 182106)
+++ gcc.c-torture/execute/20111208-1.c  (working copy)
@@ -10,8 +10,26 @@  extern void *memcpy (void *__restrict __
 extern size_t strlen (__const char *__s)
      __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__
((__nonnull__ (1)));

+#if __SIZEOF_SHORT__ == 2
 typedef short int int16_t;
+#elif __SIZEOF_INT__ == 2
+typedef int int16_t;
+#elif __SIZEOF_LONG__ == 2
+typedef long int16_t;
+#else
+#error Fix this
+#endif
+
+
+#if __SIZEOF_INT__ == 4
 typedef int int32_t;
+#elif __SIZEOF_LONG__ == 4
+typedef long int32_t;
+#elif __SIZEOF_SHORT__ == 4
+typedef short int32_t;
+#else
+#error Fix this
+#endif

 extern void abort (void);