stdckdint.h _BitInt test

Message ID ZNUEskNR0ezRW2Js@tucnak
State Accepted
Headers
Series stdckdint.h _BitInt test |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Jakub Jelinek Aug. 10, 2023, 3:39 p.m. UTC
  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.


	Jakub
  

Comments

Joseph Myers Aug. 10, 2023, 10:31 p.m. UTC | #1
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.)
  

Patch

--- 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" } */
+}