public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] stdckdint.h _BitInt test
@ 2023-08-10 15:39 Jakub Jelinek
  2023-08-10 22:31 ` Joseph Myers
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2023-08-10 15:39 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

Hi!

The following patch (on top of the stdckdint.h patch and _BitInt patch
series) adds a test for _BitInt diagnostics of ckd_{add,sub,mul} macros.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-08-10  Jakub Jelinek  <jakub@redhat.com>

	* gcc.dg/stdckdint-3.c: New test.

--- gcc/testsuite/gcc.dg/stdckdint-3.c.jj	2023-08-10 13:02:10.520431079 +0200
+++ gcc/testsuite/gcc.dg/stdckdint-3.c	2023-08-10 13:03:41.352129959 +0200
@@ -0,0 +1,21 @@
+/* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>.  */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c2x" } */
+
+#include <stdckdint.h>
+
+int
+main ()
+{
+  _BitInt(32) a;
+  int b;
+  ckd_add (&a, 1, 1);		/* { dg-error "types used in ckd_add should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_sub (&a, 1, 1);		/* { dg-error "types used in ckd_sub should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_mul (&a, 1, 1);		/* { dg-error "types used in ckd_mul should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_add (&b, 1wb, 1);		/* { dg-error "types used in ckd_add should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_sub (&b, 1wb, 1);		/* { dg-error "types used in ckd_sub should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_mul (&b, 1wb, 1);		/* { dg-error "types used in ckd_mul should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_add (&b, 1, 1wb);		/* { dg-error "types used in ckd_add should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_sub (&b, 1, 1wb);		/* { dg-error "types used in ckd_sub should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+  ckd_mul (&b, 1, 1wb);		/* { dg-error "types used in ckd_mul should be integral other than plain char, bool, bit-precise integer or enumerated type" } */
+}

	Jakub


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

* Re: [PATCH] stdckdint.h _BitInt test
  2023-08-10 15:39 [PATCH] stdckdint.h _BitInt test Jakub Jelinek
@ 2023-08-10 22:31 ` Joseph Myers
  2023-08-11  8:09   ` [PATCH] c, v3: Add stdckdint.h header for C23 Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Joseph Myers @ 2023-08-10 22:31 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Thu, 10 Aug 2023, Jakub Jelinek via Gcc-patches wrote:

> Hi!
> 
> The following patch (on top of the stdckdint.h patch and _BitInt patch
> series) adds a test for _BitInt diagnostics of ckd_{add,sub,mul} macros.

I remain unconvinced that diagnosing use with types where it's clear what 
the right semantics for the operation are is a good idea (given, in the 
_BitInt case, that you've already implemented the built-in functions for 
_BitInt types).  (Diagnosing for bool results *is* a good idea, since it's 
not clear what the semantics should be.  Likewise for enums with fixed 
underlying type bool, whether or not it's diagnosed for other enums.)

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* [PATCH] c, v3: Add stdckdint.h header for C23
  2023-08-10 22:31 ` Joseph Myers
@ 2023-08-11  8:09   ` Jakub Jelinek
  2023-08-11 13:25     ` Joseph Myers
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2023-08-11  8:09 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc-patches

On Thu, Aug 10, 2023 at 10:31:12PM +0000, Joseph Myers wrote:
> > The following patch (on top of the stdckdint.h patch and _BitInt patch
> > series) adds a test for _BitInt diagnostics of ckd_{add,sub,mul} macros.
> 
> I remain unconvinced that diagnosing use with types where it's clear what 
> the right semantics for the operation are is a good idea (given, in the 
> _BitInt case, that you've already implemented the built-in functions for 
> _BitInt types).  (Diagnosing for bool results *is* a good idea, since it's 
> not clear what the semantics should be.  Likewise for enums with fixed 
> underlying type bool, whether or not it's diagnosed for other enums.)

Ok, here is an updated patch without that diagnostics.
All that is diagnosed is when result is bool or enum (any kind).  Even for
enums without bool underlying type, a question is what exactly it would
mean, whether checking result fits into the range of the underlying type,
or range between smallest and largest enumerator, or signed/unsigned range
with minimum precision to represent smallest/largest enumerator, or only
where the result would fall into some enumerator, so I think punting on
those as we do for years for __builtin_*_overflow is ok.

2023-08-11  Jakub Jelinek  <jakub@redhat.com>

	* Makefile.in (USER_H): Add stdckdint.h.
	* ginclude/stdckdint.h: New file.

	* gcc.dg/stdckdint-1.c: New test.
	* gcc.dg/stdckdint-2.c: New test.

--- gcc/Makefile.in.jj	2023-08-10 17:23:55.502325592 +0200
+++ gcc/Makefile.in	2023-08-11 09:37:35.968944530 +0200
@@ -469,6 +469,7 @@ USER_H = $(srcdir)/ginclude/float.h \
 	 $(srcdir)/ginclude/stdnoreturn.h \
 	 $(srcdir)/ginclude/stdalign.h \
 	 $(srcdir)/ginclude/stdatomic.h \
+	 $(srcdir)/ginclude/stdckdint.h \
 	 $(EXTRA_HEADERS)
 
 USER_H_INC_NEXT_PRE = @user_headers_inc_next_pre@
--- gcc/ginclude/stdckdint.h.jj	2023-08-11 09:37:35.968944530 +0200
+++ gcc/ginclude/stdckdint.h	2023-08-11 09:39:50.383054196 +0200
@@ -0,0 +1,40 @@
+/* Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* ISO C23: 7.20 Checked Integer Arithmetic <stdckdint.h>.  */
+
+#ifndef _STDCKDINT_H
+#define _STDCKDINT_H
+
+#define __STDC_VERSION_STDCKDINT_H__ 202311L
+
+#define ckd_add(r, a, b) ((_Bool) __builtin_add_overflow (a, b, r))
+#define ckd_sub(r, a, b) ((_Bool) __builtin_sub_overflow (a, b, r))
+#define ckd_mul(r, a, b) ((_Bool) __builtin_mul_overflow (a, b, r))
+
+/* Allow for the C library to add its part to the header.  */
+#if !defined (_LIBC_STDCKDINT_H) && __has_include_next (<stdckdint.h>)
+# include_next <stdckdint.h>
+#endif
+
+#endif /* stdckdint.h */
--- gcc/testsuite/gcc.dg/stdckdint-1.c.jj	2023-08-11 09:37:35.968944530 +0200
+++ gcc/testsuite/gcc.dg/stdckdint-1.c	2023-08-11 09:37:35.968944530 +0200
@@ -0,0 +1,61 @@
+/* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x" } */
+
+#include <stdckdint.h>
+
+#if __STDC_VERSION_STDCKDINT_H__ != 202311L
+# error __STDC_VERSION_STDCKDINT_H__ not defined to 202311L
+#endif
+
+extern void abort (void);
+
+int
+main ()
+{
+  unsigned int a;
+  if (ckd_add (&a, 1, 2) || a != 3)
+    abort ();
+  if (ckd_add (&a, ~2U, 2) || a != ~0U)
+    abort ();
+  if (!ckd_add (&a, ~2U, 4) || a != 1)
+    abort ();
+  if (ckd_sub (&a, 42, 2) || a != 40)
+    abort ();
+  if (!ckd_sub (&a, 11, ~0ULL) || a != 12)
+    abort ();
+  if (ckd_mul (&a, 42, 16U) || a != 672)
+    abort ();
+  if (ckd_mul (&a, ~0UL, 0) || a != 0)
+    abort ();
+  if (ckd_mul (&a, 1, ~0U) || a != ~0U)
+    abort ();
+  if (ckd_mul (&a, ~0UL, 1) != (~0UL > ~0U) || a != ~0U)
+    abort ();
+  static_assert (_Generic (ckd_add (&a, 1, 1), bool: 1, default: 0));
+  static_assert (_Generic (ckd_sub (&a, 1, 1), bool: 1, default: 0));
+  static_assert (_Generic (ckd_mul (&a, 1, 1), bool: 1, default: 0));
+  signed char b;
+  if (ckd_add (&b, 8, 12) || b != 20)
+    abort ();
+  if (ckd_sub (&b, 8UL, 12ULL) || b != -4)
+    abort ();
+  if (ckd_mul (&b, 2, 3) || b != 6)
+    abort ();
+  unsigned char c;
+  if (ckd_add (&c, 8, 12) || c != 20)
+    abort ();
+  if (ckd_sub (&c, 8UL, 12ULL) != (-4ULL > (unsigned char) -4U)
+      || c != (unsigned char) -4U)
+    abort ();
+  if (ckd_mul (&c, 2, 3) || c != 6)
+    abort ();
+  long long d;
+  if (ckd_add (&d, ~0U, ~0U) != (~0U + 1ULL < ~0U)
+      || d != (long long) (2 * (unsigned long long) ~0U))
+    abort ();
+  if (ckd_sub (&d, 0, 0) || d != 0)
+    abort ();
+  if (ckd_mul (&d, 16, 1) || d != 16)
+    abort ();
+}
--- gcc/testsuite/gcc.dg/stdckdint-2.c.jj	2023-08-11 09:37:35.968944530 +0200
+++ gcc/testsuite/gcc.dg/stdckdint-2.c	2023-08-11 09:56:58.536595283 +0200
@@ -0,0 +1,47 @@
+/* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+#include <stdckdint.h>
+
+int
+main ()
+{
+  char a;
+  bool b;
+  enum E { E1, E2 } c = E1;
+  int d;
+  ckd_add (&a, 1, 1);
+  ckd_sub (&a, 1, 1);
+  ckd_mul (&a, 1, 1);
+  ckd_add (&b, 1, 1);		/* { dg-error "has pointer to boolean type" } */
+  ckd_sub (&b, 1, 1);		/* { dg-error "has pointer to boolean type" } */
+  ckd_mul (&b, 1, 1);		/* { dg-error "has pointer to boolean type" } */
+  ckd_add (&c, 1, 1);		/* { dg-error "has pointer to enumerated type" } */
+  ckd_sub (&c, 1, 1);		/* { dg-error "has pointer to enumerated type" } */
+  ckd_mul (&c, 1, 1);		/* { dg-error "has pointer to enumerated type" } */
+  ckd_add (&d, (char) 1, 1);
+  ckd_sub (&d, (char) 1, 1);
+  ckd_mul (&d, (char) 1, 1);
+  ckd_add (&d, false, 1);
+  ckd_sub (&d, false, 1);
+  ckd_mul (&d, false, 1);
+  ckd_add (&d, true, 1);
+  ckd_sub (&d, true, 1);
+  ckd_mul (&d, true, 1);
+  ckd_add (&d, c, 1);
+  ckd_sub (&d, c, 1);
+  ckd_mul (&d, c, 1);
+  ckd_add (&d, 1, (char) 1);
+  ckd_sub (&d, 1, (char) 1);
+  ckd_mul (&d, 1, (char) 1);
+  ckd_add (&d, 1, false);
+  ckd_sub (&d, 1, false);
+  ckd_mul (&d, 1, false);
+  ckd_add (&d, 1, true);
+  ckd_sub (&d, 1, true);
+  ckd_mul (&d, 1, true);
+  ckd_add (&d, 1, c);
+  ckd_sub (&d, 1, c);
+  ckd_mul (&d, 1, c);
+}


	Jakub


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

* Re: [PATCH] c, v3: Add stdckdint.h header for C23
  2023-08-11  8:09   ` [PATCH] c, v3: Add stdckdint.h header for C23 Jakub Jelinek
@ 2023-08-11 13:25     ` Joseph Myers
  2023-08-11 17:31       ` [PATCH] c, v4: " Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Joseph Myers @ 2023-08-11 13:25 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Fri, 11 Aug 2023, Jakub Jelinek wrote:

> All that is diagnosed is when result is bool or enum (any kind).  Even for

I'd suggest tests that other nonsense cases are diagnosed, such as 
floating-point or pointer arguments or results (hopefully such cases are 
already diagnosed and just need tests).

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* [PATCH] c, v4: Add stdckdint.h header for C23
  2023-08-11 13:25     ` Joseph Myers
@ 2023-08-11 17:31       ` Jakub Jelinek
  2023-08-11 21:50         ` Joseph Myers
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2023-08-11 17:31 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc-patches

On Fri, Aug 11, 2023 at 01:25:38PM +0000, Joseph Myers wrote:
> On Fri, 11 Aug 2023, Jakub Jelinek wrote:
> 
> > All that is diagnosed is when result is bool or enum (any kind).  Even for
> 
> I'd suggest tests that other nonsense cases are diagnosed, such as 
> floating-point or pointer arguments or results (hopefully such cases are 
> already diagnosed and just need tests).

So like this then?

2023-08-11  Jakub Jelinek  <jakub@redhat.com>

	* Makefile.in (USER_H): Add stdckdint.h.
	* ginclude/stdckdint.h: New file.

	* gcc.dg/stdckdint-1.c: New test.
	* gcc.dg/stdckdint-2.c: New test.

--- gcc/Makefile.in.jj	2023-08-11 10:15:49.669691051 +0200
+++ gcc/Makefile.in	2023-08-11 18:48:52.829964582 +0200
@@ -469,6 +469,7 @@ USER_H = $(srcdir)/ginclude/float.h \
 	 $(srcdir)/ginclude/stdnoreturn.h \
 	 $(srcdir)/ginclude/stdalign.h \
 	 $(srcdir)/ginclude/stdatomic.h \
+	 $(srcdir)/ginclude/stdckdint.h \
 	 $(EXTRA_HEADERS)
 
 USER_H_INC_NEXT_PRE = @user_headers_inc_next_pre@
--- gcc/ginclude/stdckdint.h.jj	2023-08-11 18:48:52.829964582 +0200
+++ gcc/ginclude/stdckdint.h	2023-08-11 18:48:52.829964582 +0200
@@ -0,0 +1,40 @@
+/* Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* ISO C23: 7.20 Checked Integer Arithmetic <stdckdint.h>.  */
+
+#ifndef _STDCKDINT_H
+#define _STDCKDINT_H
+
+#define __STDC_VERSION_STDCKDINT_H__ 202311L
+
+#define ckd_add(r, a, b) ((_Bool) __builtin_add_overflow (a, b, r))
+#define ckd_sub(r, a, b) ((_Bool) __builtin_sub_overflow (a, b, r))
+#define ckd_mul(r, a, b) ((_Bool) __builtin_mul_overflow (a, b, r))
+
+/* Allow for the C library to add its part to the header.  */
+#if !defined (_LIBC_STDCKDINT_H) && __has_include_next (<stdckdint.h>)
+# include_next <stdckdint.h>
+#endif
+
+#endif /* stdckdint.h */
--- gcc/testsuite/gcc.dg/stdckdint-1.c.jj	2023-08-11 18:48:52.829964582 +0200
+++ gcc/testsuite/gcc.dg/stdckdint-1.c	2023-08-11 18:48:52.829964582 +0200
@@ -0,0 +1,61 @@
+/* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x" } */
+
+#include <stdckdint.h>
+
+#if __STDC_VERSION_STDCKDINT_H__ != 202311L
+# error __STDC_VERSION_STDCKDINT_H__ not defined to 202311L
+#endif
+
+extern void abort (void);
+
+int
+main ()
+{
+  unsigned int a;
+  if (ckd_add (&a, 1, 2) || a != 3)
+    abort ();
+  if (ckd_add (&a, ~2U, 2) || a != ~0U)
+    abort ();
+  if (!ckd_add (&a, ~2U, 4) || a != 1)
+    abort ();
+  if (ckd_sub (&a, 42, 2) || a != 40)
+    abort ();
+  if (!ckd_sub (&a, 11, ~0ULL) || a != 12)
+    abort ();
+  if (ckd_mul (&a, 42, 16U) || a != 672)
+    abort ();
+  if (ckd_mul (&a, ~0UL, 0) || a != 0)
+    abort ();
+  if (ckd_mul (&a, 1, ~0U) || a != ~0U)
+    abort ();
+  if (ckd_mul (&a, ~0UL, 1) != (~0UL > ~0U) || a != ~0U)
+    abort ();
+  static_assert (_Generic (ckd_add (&a, 1, 1), bool: 1, default: 0));
+  static_assert (_Generic (ckd_sub (&a, 1, 1), bool: 1, default: 0));
+  static_assert (_Generic (ckd_mul (&a, 1, 1), bool: 1, default: 0));
+  signed char b;
+  if (ckd_add (&b, 8, 12) || b != 20)
+    abort ();
+  if (ckd_sub (&b, 8UL, 12ULL) || b != -4)
+    abort ();
+  if (ckd_mul (&b, 2, 3) || b != 6)
+    abort ();
+  unsigned char c;
+  if (ckd_add (&c, 8, 12) || c != 20)
+    abort ();
+  if (ckd_sub (&c, 8UL, 12ULL) != (-4ULL > (unsigned char) -4U)
+      || c != (unsigned char) -4U)
+    abort ();
+  if (ckd_mul (&c, 2, 3) || c != 6)
+    abort ();
+  long long d;
+  if (ckd_add (&d, ~0U, ~0U) != (~0U + 1ULL < ~0U)
+      || d != (long long) (2 * (unsigned long long) ~0U))
+    abort ();
+  if (ckd_sub (&d, 0, 0) || d != 0)
+    abort ();
+  if (ckd_mul (&d, 16, 1) || d != 16)
+    abort ();
+}
--- gcc/testsuite/gcc.dg/stdckdint-2.c.jj	2023-08-11 18:48:52.829964582 +0200
+++ gcc/testsuite/gcc.dg/stdckdint-2.c	2023-08-11 19:28:50.081643961 +0200
@@ -0,0 +1,87 @@
+/* Test C23 Checked Integer Arithmetic macros in <stdckdint.h>.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+#include <stdckdint.h>
+
+int
+main ()
+{
+  char a;
+  bool b;
+  enum E { E1, E2 } c = E1;
+  int d;
+  int *e;
+  float f;
+  double g;
+  long double h;
+  ckd_add (&a, 1, 1);
+  ckd_sub (&a, 1, 1);
+  ckd_mul (&a, 1, 1);
+  ckd_add (&b, 1, 1);		/* { dg-error "has pointer to boolean type" } */
+  ckd_sub (&b, 1, 1);		/* { dg-error "has pointer to boolean type" } */
+  ckd_mul (&b, 1, 1);		/* { dg-error "has pointer to boolean type" } */
+  ckd_add (&c, 1, 1);		/* { dg-error "has pointer to enumerated type" } */
+  ckd_sub (&c, 1, 1);		/* { dg-error "has pointer to enumerated type" } */
+  ckd_mul (&c, 1, 1);		/* { dg-error "has pointer to enumerated type" } */
+  ckd_add (&d, (char) 1, 1);
+  ckd_sub (&d, (char) 1, 1);
+  ckd_mul (&d, (char) 1, 1);
+  ckd_add (&d, false, 1);
+  ckd_sub (&d, false, 1);
+  ckd_mul (&d, false, 1);
+  ckd_add (&d, true, 1);
+  ckd_sub (&d, true, 1);
+  ckd_mul (&d, true, 1);
+  ckd_add (&d, c, 1);
+  ckd_sub (&d, c, 1);
+  ckd_mul (&d, c, 1);
+  ckd_add (&d, 1, (char) 1);
+  ckd_sub (&d, 1, (char) 1);
+  ckd_mul (&d, 1, (char) 1);
+  ckd_add (&d, 1, false);
+  ckd_sub (&d, 1, false);
+  ckd_mul (&d, 1, false);
+  ckd_add (&d, 1, true);
+  ckd_sub (&d, 1, true);
+  ckd_mul (&d, 1, true);
+  ckd_add (&d, 1, c);
+  ckd_sub (&d, 1, c);
+  ckd_mul (&d, 1, c);
+  ckd_add (&e, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_sub (&e, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_mul (&e, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_add (&f, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_sub (&f, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_mul (&f, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_add (&g, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_sub (&g, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_mul (&g, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_add (&h, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_sub (&h, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_mul (&h, 1, 1);		/* { dg-error "does not have pointer to integral type" } */
+  ckd_add (&d, 1.0f, 1);	/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, 1.0f, 1);	/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, 1.0f, 1);	/* { dg-error "does not have integral type" } */
+  ckd_add (&d, 1.0, 1);		/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, 1.0, 1);		/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, 1.0, 1);		/* { dg-error "does not have integral type" } */
+  ckd_add (&d, 1.0L, 1);	/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, 1.0L, 1);	/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, 1.0L, 1);	/* { dg-error "does not have integral type" } */
+  ckd_add (&d, 1, 1.0f);	/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, 1, 1.0f);	/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, 1, 1.0f);	/* { dg-error "does not have integral type" } */
+  ckd_add (&d, 1, 1.0);		/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, 1, 1.0);		/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, 1, 1.0);		/* { dg-error "does not have integral type" } */
+  ckd_add (&d, 1, 1.0L);	/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, 1, 1.0L);	/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, 1, 1.0L);	/* { dg-error "does not have integral type" } */
+  ckd_add (&d, (int *) 0, 1);	/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, (int *) 0, 1);	/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, (int *) 0, 1);	/* { dg-error "does not have integral type" } */
+  ckd_add (&d, 1, (int *) 0);	/* { dg-error "does not have integral type" } */
+  ckd_sub (&d, 1, (int *) 0);	/* { dg-error "does not have integral type" } */
+  ckd_mul (&d, 1, (int *) 0);	/* { dg-error "does not have integral type" } */
+}


	Jakub


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

* Re: [PATCH] c, v4: Add stdckdint.h header for C23
  2023-08-11 17:31       ` [PATCH] c, v4: " Jakub Jelinek
@ 2023-08-11 21:50         ` Joseph Myers
  0 siblings, 0 replies; 6+ messages in thread
From: Joseph Myers @ 2023-08-11 21:50 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Fri, 11 Aug 2023, Jakub Jelinek via Gcc-patches wrote:

> On Fri, Aug 11, 2023 at 01:25:38PM +0000, Joseph Myers wrote:
> > On Fri, 11 Aug 2023, Jakub Jelinek wrote:
> > 
> > > All that is diagnosed is when result is bool or enum (any kind).  Even for
> > 
> > I'd suggest tests that other nonsense cases are diagnosed, such as 
> > floating-point or pointer arguments or results (hopefully such cases are 
> > already diagnosed and just need tests).
> 
> So like this then?

I think it should also test the diagnostic for when *result is 
const-qualified.  OK with that change.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

end of thread, other threads:[~2023-08-11 21:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-10 15:39 [PATCH] stdckdint.h _BitInt test Jakub Jelinek
2023-08-10 22:31 ` Joseph Myers
2023-08-11  8:09   ` [PATCH] c, v3: Add stdckdint.h header for C23 Jakub Jelinek
2023-08-11 13:25     ` Joseph Myers
2023-08-11 17:31       ` [PATCH] c, v4: " Jakub Jelinek
2023-08-11 21:50         ` Joseph Myers

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).