c2lang / c2compiler

the c2 programming language
c2lang.org
Apache License 2.0
703 stars 49 forks source link

[FIX] LiteralAnalyser: Missing shift operations causes compiler crash. #34

Closed lerno closed 6 years ago

lerno commented 6 years ago

Added code for handling shr/shl operators in LiteralAnalyser. The previous default made them return a 1 bit result :(

Added warnings for lhs < 0, rhs < 0, and shift where shift was wider than lhs bit width. Should probably add warning for lhs overflow too. But that requires a discussion. Added tests, one to reproduce the problem, three for the warnings.

I also added a missing include for when C2Parser has debug on.

Minor refactoring: since getting lhs/rhs was common, I extracted those values into locals.