https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90578
Bug ID: 90578 Summary: Wrong code with LSHIFT and optimization Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: dominiq at lps dot ens.fr Target Milestone: --- While experimenting with pr90577, I have found that the run-time output for the following reduced test program test_rshift_lshift implicit none integer :: i(15), j, n i = (/ -huge(i), -huge(i)/2, -129, -128, -127, -2, -1, 0, & 1, 2, 127, 128, 129, huge(i)/2, huge(i) /) print *, lshift(i(1),-30) print *, lshift(i(1),-29) if (lshift(i(1),-30) /= 4) STOP 1 end program test_rshift_lshift depends on the optimization level: % gfc lrshift_1_red.f90 % ./a.out 4 8 % gfc lrshift_1_red.f90 -O % ./a.out 2 4 STOP 1 but gfc lrshift_1_red.f90 -fauto-inc-dec -fbranch-count-reg -fcombine-stack-adjustments -fcompare-elim -fcprop-registers -fdce -fdefer-pop -fdse -fforward-propagate -fguess-branch-probability -fif-conversion -fif-conversion2 -finline-functions-called-once -fipa-profile -fipa-pure-const -fipa-reference -fipa-reference-addressable -fmerge-constants -fmove-loop-invariants -fomit-frame-pointer -freorder-blocks -fshrink-wrap -fshrink-wrap-separate -fsplit-wide-types -fssa-backprop -fssa-phiopt -ftree-bit-ccp -ftree-ccp -ftree-ch -ftree-coalesce-vars -ftree-copy-prop -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-forwprop -ftree-fre -ftree-phiprop -ftree-pta -ftree-scev-cprop -ftree-sink -ftree-slsr -ftree-sra -ftree-ter -funit-at-a-time gives also 4 8 I see this behavior from at least 4.8 up to trunk (10.0).