Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shift operators for variables #527

Closed
wants to merge 24 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift click to select a range
98e737d
Support bitshifting in variables
axic Apr 29, 2016
b14976d
Properly support SAR - Use SDIV for signed input
axic Apr 29, 2016
dfad184
Add tests for shift operations
axic Apr 29, 2016
1998ec8
Only use << and >> as shift operators and throw on >>>
axic Jun 7, 2016
5e6b625
Perform variable cleanup before shift
axic Aug 2, 2016
d39df5b
Throw exception when shifting with a negative right value
axic Aug 2, 2016
f53225a
Promote appendShiftOperatorCode as a top level method
axic Sep 6, 2016
c97ca4b
Include LValue and RValue in shift operators (check only for negative…
axic Sep 6, 2016
44970a9
Pass proper types to shiftOperatorCode
axic Oct 20, 2016
6cd41b8
Shift RValue can be a RationalNumber
axic Oct 21, 2016
d132252
Enable type conversion for shifts
axic Oct 21, 2016
4efdbf7
Add changelog entry
axic Oct 25, 2016
3fd8d13
Optimise negative right shift value detection
axic Nov 5, 2016
f7ee2e4
Simplify sign detection
axic Nov 5, 2016
4fc9a1a
Do not allow shifts for addresses
axic Nov 6, 2016
8011274
Add shift cleanup test
axic Nov 16, 2016
1f85c7f
test: add tests for cleanup before shifts
pirapira Nov 22, 2016
e1fbdf1
test: no overflow exception for unsigined shifts
pirapira Nov 22, 2016
30dafec
test: signed shifts should not throw on overflows either
pirapira Nov 22, 2016
63c90fd
Ensure the rightType is valid for shifts
axic Nov 28, 2016
f52b626
Ensure the left type is an integer for shifts
axic Nov 28, 2016
ccbdff0
Keep the left type for shifts
axic Nov 28, 2016
5f318cd
Disable the >>> operator before codegen
axic Nov 28, 2016
9b20fce
test: add a test case about cleaning up higher order bits before a shift
pirapira Dec 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Keep the left type for shifts
  • Loading branch information
axic committed Nov 28, 2016
commit ccbdff048f00d7f7af24ed384e7bed3257515987
2 changes: 1 addition & 1 deletion libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 348,7 @@ TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointe
if (Token::isCompareOp(_operator))
return commonType;
if (Token::isShiftOp(_operator) && !isAddress()) // && !_other->isAddress())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @pirapira suggested further below, this should not return the common type of the operands but rather the type of the left operand.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chriseth Should we check here for the other side to be an address?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to do this whole thing even before line 342. The following should be possible (please add a test):

uint x = 70;
int8 y = 2;
x << y;

x and y do not have a common type, and so currently, it would fail in line 345.

Yes, we should perform some more checks for the other side. I would say rational number is fine as long as it is an integer. Fixed point is fine, but we have to perform an integer check at run-time. Integer is fine as long as it is not an address.

return commonType;
return shared_from_this();
if (Token::isBooleanOp(_operator))
return TypePointer();
if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType))
Expand Down