c2compiler icon indicating copy to clipboard operation
c2compiler copied to clipboard

Incorrect cast behaviour in LiteralAnalyser

Open lerno opened this issue 7 years ago • 2 comments

  1. cast(3) => will cast the expression to a 31 bit integer.
  2. cast(2147483648) => 0
  3. cast(2147483647) => -1
  4. cast(1073741823) = 1073741823
  5. cast(1073741824) = -1073741824

The cast is using getIntegerWidth to set the resulting width, causing this issue.

lerno avatar Oct 27 '18 20:10 lerno

Which syntax do you use exactly then? Because currently cast needs a generics-like argument, like: cast<u32>(2147483648)

bvdberg avatar Oct 30 '18 08:10 bvdberg

It's in the implicit casts in the LiteralAnalyser when mixing uXX with iXX values.

lerno avatar Oct 30 '18 09:10 lerno