target/30484 - testcase for exploration
Checks
Commit Message
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
new file mode 100644
@@ -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;
+}