Skip to content

Commit

Permalink
Value: no longer use 0 as criterion for signed integer determination …
Browse files Browse the repository at this point in the history
…when execute intcast.

This change matches the behavior of gcc/clang
  • Loading branch information
Organ1sm committed Jul 9, 2024
1 parent 26d8718 commit a97148d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/aro/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ pub fn intCast(v: *Value, dest_ty: Type, comp: *Compilation) !IntCastChangeKind
const big = v.toBigInt(&space, comp);
const value_bits = big.bitCountTwosComp();

// if big is negative or zero, then is signed.
const src_signed = (!big.positive or big.eqlZero());
// if big is negative, then is signed.
const src_signed = !big.positive;
const sign_change = src_signed != dest_signed;

const limbs = try comp.gpa.alloc(
Expand All @@ -264,10 +264,9 @@ pub fn intCast(v: *Value, dest_ty: Type, comp: *Compilation) !IntCastChangeKind
var result_bigint = BigIntMutable{ .limbs = limbs, .positive = undefined, .len = undefined };
result_bigint.truncate(big, dest_ty.signedness(comp), dest_bits);

const truncation_occurred = value_bits > dest_bits;

v.* = try intern(comp, .{ .int = .{ .big_int = result_bigint.toConst() } });

const truncation_occurred = value_bits > dest_bits;
if (truncation_occurred) {
return .truncated;
} else if (sign_change) {
Expand Down

0 comments on commit a97148d

Please sign in to comment.