]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add missing return in gori_compute::logical_combine
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 25 Sep 2023 18:48:53 +0000 (20:48 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Tue, 26 Sep 2023 19:02:29 +0000 (21:02 +0200)
The varying case currently falls through to the 1/true case.

gcc/
* gimple-range-gori.cc (gori_compute::logical_combine): Add missing
return statement in the varying case.

gcc/testsuite/
* gnat.dg/opt102.adb:New test.
* gnat.dg/opt102_pkg.adb, gnat.dg/opt102_pkg.ads: New helper.

gcc/gimple-range-gori.cc
gcc/testsuite/gnat.dg/opt102.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt102_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt102_pkg.ads [new file with mode: 0644]

index 772ccb88d5518445635263c08ef55f7a68b15b8c..263360862fe816bf66bf3e2fd4d87d4e0a90cbba 100644 (file)
@@ -880,6 +880,7 @@ gori_compute::logical_combine (irange &r, enum tree_code code,
        res = false;
       if (idx)
        tracer.trailer (idx, "logical_combine", res, NULL_TREE, r);
+      return res;
     }
 
   switch (code)
diff --git a/gcc/testsuite/gnat.dg/opt102.adb b/gcc/testsuite/gnat.dg/opt102.adb
new file mode 100644 (file)
index 0000000..2b5bec5
--- /dev/null
@@ -0,0 +1,10 @@
+-- { dg-do run }
+-- { dg-options "-O2 -gnata" }
+
+with Opt102_Pkg; use Opt102_Pkg;
+
+procedure Opt102 is
+  I, F : aliased Integer;
+begin
+  I := Get (Two, F'Access, null);
+end;
diff --git a/gcc/testsuite/gnat.dg/opt102_pkg.adb b/gcc/testsuite/gnat.dg/opt102_pkg.adb
new file mode 100644 (file)
index 0000000..09c338d
--- /dev/null
@@ -0,0 +1,12 @@
+package body Opt102_Pkg is
+
+  function Get (E : Enum; F, M : access Integer) return Integer is
+  begin
+    case E is
+      when One   => return 0;
+      when Two   => return F.all;
+      when Three => return M.all;
+    end case;
+  end;
+
+end Opt102_Pkg;
diff --git a/gcc/testsuite/gnat.dg/opt102_pkg.ads b/gcc/testsuite/gnat.dg/opt102_pkg.ads
new file mode 100644 (file)
index 0000000..7afc3fe
--- /dev/null
@@ -0,0 +1,10 @@
+package Opt102_Pkg is
+
+  type Enum is (One, Two, Three);
+
+  function Get (E : Enum; F, M : access Integer) return Integer
+    with Pre => (E = One) = (F = null and M = null) and
+                (E = Two) = (F /= null) and
+                (E = Three) = (M /= null);
+
+end Opt102_Pkg;