Actions
Emulator Issues #8089
openSome signed shifts should be unsigned
Status:
Accepted
Priority:
Normal
Assignee:
-
% Done:
0%
Operating system:
N/A
Issue type:
Bug
Milestone:
Regression:
No
Relates to usability:
No
Relates to performance:
No
Easy:
Yes
Relates to maintainability:
No
Regression start:
Fixed in:
Description
Dolphin uses signed shifts (1 << x) at least some of which should be unsigned (1u << x). I'm not sure signed shifts are ever useful, maybe the linter should get a rule for this.
Updated by tueidj about 9 years ago
Why is this relevant? Sign has no affect on the result of left shifts.
Updated by flacs about 9 years ago
@tueidj: Sorry, I should have explained this better. Consider code like this (assuming int is 32 bits wide):
uint64_t foo = 1 << 31;
uint64_t bar = 1u << 31;
printf("%016lx\n%016lx\n", foo, bar);
ffffffff80000000
0000000080000000
Updated by tueidj about 9 years ago
So it's a type promotion issue rather than a shift issue.
Updated by flacs about 9 years ago
Turns out, Clang has a warning for this: -Wshift-sign-overflow
Actions