Add optmization testcase for incorrect optimization in Ada
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 4 Feb 2022 16:41:55 +0000 (17:41 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 4 Feb 2022 16:44:44 +0000 (17:44 +0100)
gcc/testsuite/
PR tree-optimization/104356
* gnat.dg/opt97.adb: New test.

gcc/testsuite/gnat.dg/opt97.adb [new file with mode: 0644]

diff --git a/gcc/testsuite/gnat.dg/opt97.adb b/gcc/testsuite/gnat.dg/opt97.adb
new file mode 100644 (file)
index 0000000..1bf6a75
--- /dev/null
@@ -0,0 +1,25 @@
+-- { dg-do compile }
+-- { dg-options "-O2 -fdump-tree-optimized" }
+
+with System.Unsigned_Types; use System.Unsigned_Types;
+
+function Opt97 (X, Y : Unsigned) return Unsigned is
+
+  pragma Suppress (All_Checks);
+
+  Z : Unsigned;
+
+begin
+  if X >= 2 then
+    return 0;
+  end if;
+
+  Z := Y;
+  if X = 1 then
+    Z := Y + 4;
+  end if;
+
+  return Z / X;
+end;
+
+-- { dg-final { scan-tree-dump "/" "optimized" } }