Project

General

Profile

Emulator Issues #8089

Some signed shifts should be unsigned

Added by flacs over 5 years ago.

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.

History

#1 Updated by tueidj over 5 years ago

Why is this relevant? Sign has no affect on the result of left shifts.

#2 Updated by flacs over 5 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

#3 Updated by tueidj over 5 years ago

So it's a type promotion issue rather than a shift issue.

#4 Updated by flacs over 5 years ago

Turns out, Clang has a warning for this: -Wshift-sign-overflow

Also available in: Atom PDF