target/30484 - testcase for exploration

Message ID 20230919124241.8368713458@imap2.suse-dmz.suse.de
State Accepted
Headers
Series target/30484 - testcase for exploration |

Checks

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

Commit Message

Richard Biener Sept. 19, 2023, 12:42 p.m. UTC
  The following adds a testcase for the unfixed PR, skipped on the
known affected target.  The intent is to discover targets that
suffer from the same issue or whose sdiv do not wrap as expected
with -fwrapv.

Tested on x86_64-unknown-linux-gnu.

OK?  Jeff, do you want to put this on your tester first (do they
perform runtime simulator testing?)

	PR target/30484
	* gcc.dg/torture/pr30484.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr30484.c | 33 ++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr30484.c
  

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr30484.c b/gcc/testsuite/gcc.dg/torture/pr30484.c
new file mode 100644
index 00000000000..22ea23bd27a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr30484.c
@@ -0,0 +1,33 @@ 
+/* { dg-do run } */
+/* { dg-skip-if "PR30484" { x86_64-*-* i?86-*-* } } */
+/* { dg-additional-options "-fwrapv" } */
+
+#define CHECK(TYPE, UTYPE) \
+TYPE __attribute__((noipa)) \
+div ## TYPE (TYPE a, TYPE b) \
+{ \
+  return a / b; \
+} \
+TYPE __attribute__((noipa)) \
+neg ## TYPE (TYPE a) \
+{ \
+  return -a; \
+} \
+void __attribute__((noipa)) \
+test ## TYPE () \
+{ \
+  TYPE min = (TYPE)((UTYPE)1 << (sizeof(TYPE)*8-1)); \
+  if (div ## TYPE (min, -1) != min  \
+      || neg ## TYPE (min) != min) \
+    __builtin_abort (); \
+}
+
+CHECK(int, unsigned)
+CHECK(long, unsigned long)
+
+int main()
+{
+  testlong ();
+  testint ();
+  return 0;
+}