Project

General

Profile

Actions

Emulator Issues #8089

open

Some signed shifts should be unsigned

Added by flacs over 9 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.

Actions #1

Updated by tueidj about 9 years ago

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

Actions #2

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

Actions #3

Updated by tueidj about 9 years ago

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

Actions #4

Updated by flacs about 9 years ago

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

Actions

Also available in: Atom PDF