From: Eric Botcazou Date: Mon, 25 Sep 2023 18:48:53 +0000 (+0200) Subject: Add missing return in gori_compute::logical_combine X-Git-Tag: releases/gcc-12.4.0~673 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=381eb600cf29c77f9fbbadbaf9cc1515ef060aa7;p=thirdparty%2Fgcc.git Add missing return in gori_compute::logical_combine 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. --- diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 772ccb88d551..263360862fe8 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -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 index 000000000000..2b5bec54c3d6 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt102.adb @@ -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 index 000000000000..09c338d0517f --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt102_pkg.adb @@ -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 index 000000000000..7afc3fe6ac79 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt102_pkg.ads @@ -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;