Bug 115967 - ubsan: shift exponent 64 is too large for 64-bit type HOST_WIDE_INT in ext-dce.cc on line 600 since r15-1901-g98914f9eba5f19
Summary: ubsan: shift exponent 64 is too large for 64-bit type HOST_WIDE_INT in ext-dc...
Status: RESOLVED DUPLICATE of bug 115876
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: ubsan
  Show dependency treegraph
 
Reported: 2024-07-17 11:48 UTC by Martin Jambor
Modified: 2024-07-17 14:45 UTC (History)
1 user (show)

See Also:
Host: x86_64-linux
Target: x86_64-linux
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Jambor 2024-07-17 11:48:22 UTC
Undefined behavior sanitizer reports a failure when running Fortran
testcase gfortran.dg/ieee/large_1.f90 at -O2 and higher:

  /home/mjambor/gcc/mine/src/gcc/ext-dce.cc:600:15: runtime error: shift exponent 64 is too large for 64-bit type 'long unsigned int'
  /home/mjambor/gcc/mine/src/gcc/ext-dce.cc:404:23: runtime error: left shift of negative value -1
  FAIL: gfortran.dg/ieee/large_1.f90   -O2  (test for excess errors)

The failure is present since the introduction of the source file
ext-dce.cc with commit r15-1901-g98914f9eba5f19 (Jeff Law:
[to-be-committed][RISC-V][V3] DCE analysis for extension elimination)

One way to reproduce the issue is to bootstrap GCC with Fortran
enabled and with --with-build-config=bootstrap-ubsan and then run the
test case as usual.

It is however much easier to (on an x86_64-linux at least) simply
apply the following patch and then run
  make -k check-gfortran RUNTESTFLAGS="ieee.exp=large_1.f90"

--- a/gcc/ext-dce.cc
+++ b/gcc/ext-dce.cc
@@ -597,6 +597,7 @@ ext_dce_process_uses (rtx_insn *insn, rtx obj, bitmap live_tmp)
                      bit = subreg_lsb (y).to_constant ();
                      if (dst_mask)
                        {
+                         gcc_assert (bit < 64);
                          dst_mask <<= bit;
                          if (!dst_mask)
                            dst_mask = -0x100000000ULL;
Comment 1 Andrew Pinski 2024-07-17 14:45:09 UTC
Already recorded as PR 115876 .

*** This bug has been marked as a duplicate of bug 115876 ***