For C++98 -fsanitize=undefined didn't warn in case of left shifts of negative values. Now that trunk switched to C++14 a number of new warnings popped up: gcc/config/rs6000/rs6000.c:5398:36: runtime error: left shift of negative value -12301 gcc/config/rs6000/rs6000.md:3126:17: runtime error: left shift of negative value -1 gcc/dce.c:287:16: runtime error: ../../gcc/gcc/haifa-sched.c:1442:26:left shift of negative value -1 gcc/expmed.c:3002:15: runtime error: left shift of negative value -1 gcc/haifa-sched.c:1164:24: runtime error: left shift of negative value -1 gcc/haifa-sched.c:1442:26: runtime error: left shift of negative value -1 gcc/hwint.h:250:19: runtime error: left shift of negative value -1000013824 gcc/real.c:2861:25: runtime error: left shift of negative value -63 gcc/sched-deps.c:112:20: runtime error: left shift of negative value -1 gcc/sreal.c:231:20: runtime error: left shift of negative value -1092263868 libcpp/files.c:683:30: runtime error: left shift of negative value -1 libiberty/regex.c:6970:11: runtime error: left shift of negative value -1 libiberty/regex.c:7165:4: runtime error: left shift of negative value -1
gcc/haifa-sched.c:1164:24 gcc/haifa-sched.c:1442:26 gcc/sched-deps.c:112:20 are caused by the following macro definition in gcc/sched-int.h:243: #define UNKNOWN_DEP_COST (-1<<19)
The warnings in regex.c are already described in issue 64920
(In reply to Mikhail Maltsev from comment #1) > gcc/haifa-sched.c:1164:24 > gcc/haifa-sched.c:1442:26 > gcc/sched-deps.c:112:20 > > are caused by the following macro definition in gcc/sched-int.h:243: > #define UNKNOWN_DEP_COST (-1<<19) I fixed this one with #define UNKNOWN_DEP_COST (-1u<<19)
Using #define UNKNOWN_DEP_COST (-1u<<19) is dangerous in case UNKNOWN_DEP_COST is later assigned to a long. Do not do this please.
I am traveling now so I cannot double check your hint. What do you suggest?
If you really want to fix it, (-(1 << 19)) is the best. The real fix would be to lobby the C/C++ committees so that left shift of a negative value is unspecified behavior rather than undefined.
I believe UNKNOWN_DEP_COST stuff has been fixed in the meantime. The question is about the others, but it has been so long that the locations are all useless.
Created attachment 37079 [details] Convert to unsigned before shifting (In reply to Jakub Jelinek from comment #7) > The question is about the others, but it has been so long that the > locations are all useless. I have just checked. The only problems that still remain are in libiberty/regex.c. The uploaded patch fixes this problem. I plan to submit it for review after running a few more regression tests.
Author: nickc Date: Mon Dec 21 08:23:35 2015 New Revision: 231873 URL: https://gcc.gnu.org/viewcvs?rev=231873&root=gcc&view=rev Log: PR 66827 * regex.c (EXTRACT_NUMBER): Cast sign byte to unsigned before left shifting. Modified: trunk/libiberty/ChangeLog trunk/libiberty/regex.c
Fixed.