diff mbox series

Add another new testcase

Message ID 20230510180006.1340377-1-apinski@marvell.com
State New
Headers show
Series Add another new testcase | expand

Commit Message

Andrew Pinski May 10, 2023, 6 p.m. UTC
While working on improving min/max detection, this
code (which is reduced from worse_state in ipa-pure-const.cc)
was being miscompiled. Since there was no testcase in the
testsuite yet for this, this patch adds one.

Committed as obvious after testing the testcase via:
make check-gcc RUNTESTFLAGS="execute.exp=20230510-1.c"

gcc/testsuite/ChangeLog:

	* gcc.c-torture/execute/20230510-1.c: New test.
---
 .../gcc.c-torture/execute/20230510-1.c        | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/20230510-1.c
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.c-torture/execute/20230510-1.c b/gcc/testsuite/gcc.c-torture/execute/20230510-1.c
new file mode 100644
index 00000000000..ec9c9e6eae4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20230510-1.c
@@ -0,0 +1,34 @@ 
+/* This code shows up in worse_state in ipa-pure-const.cc:
+   *looping = MAX (*looping, looping2);
+   was miscompiling it as just `return 1` though instead of
+   `MAX_EXPR<*a, b>` (which should be transformed into `*a | b`
+   note MAX_EXPR<bool, bool> is really `bool | bool` so we
+   use that to compare against here.
+ */
+#define bool _Bool
+bool __attribute__((noipa)) f(bool *a, bool b)
+{
+  bool t = *a;
+  if (t <= b)
+    return b;
+  return t;
+}
+bool __attribute__((noipa)) f1(bool *a, bool b)
+{
+  return *a | b;
+}
+
+int main()
+{
+  int i = 0;
+  int j = 0;
+
+  for (i = 0; i <= 1; i++)
+    for (j = 0; j <= 1; j++)
+      {
+        bool a = i;
+        if (f(&a, j) != f1(&a, j))
+          __builtin_abort();
+      }
+  return 0;
+}