HaxeFoundation / HaxeFoundation/haxe

[CPP] Int/Int32 inconsistent results for shift left operations

Open
#10,943 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Using left shift operation give different results when the static analyser is on or off
For example: ( https://try.haxe.org/#BAA31234)
```haxe
var x:Int = 1<<32;
trace("Int(x): " + x);
var n:Int = 1;
var m:Int = n << 32;
trace("Int(m): " + m);
var x:Int32 = 1<<32;
trace("Int32(x): " + x);
var n:Int32 = 1;
var m:Int32 = n << 32;
trace("Int32(m): " + m);
```
If the static analyzer is on, the code ```var x:Int = 1<<32;``` will be optimized to 0 ( for javascript) and if off , to 1.
For Int32 it will return 0 ( for all targets) which is also wrong

Contributor guide

Open the contributing guide

Research direction

Reproduce the linked try.haxe.org example with the static analyzer enabled and disabled, comparing left shifts for Int and Int32 on JavaScript and other targets. Trace how literal and variable shifts are handled in the compiler and verify that the resulting values are consistent and correct across analyzer modes and targets.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.