Skip to content

Commit 2558784

Browse files
committed
Fixed missing mask for shifts in constants (still in v6.1.6)
1 parent 98a275c commit 2558784

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Version 6.1.6
22
- Added ability to double quote to include quotes in literal BASIC strings
33
- Allowed BASIC string constants to initialize other consts
44
- Fixed a problem with declaring new types that are arrays of objects
5+
- Fixed a bug with calculating bits in BASIC direction() and output()
56
- Implemented flush() for FATFS files (thanks to Ada)
67
- Improved some error messages
78
- In C++ output, treat unknown types in prints as generic

expr.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,17 @@ ReplaceExprWithVariable(const char *prefix, AST *expr, AST **inits)
490490
return exprvar;
491491
}
492492

493+
/* mask off a bit number */
494+
static AST *
495+
BitNumber(AST *x)
496+
{
497+
if (curfunc && IsSpinLang(curfunc->language)) return x;
498+
if (!IsConstExpr(x)) return x;
499+
500+
// make sure we don't turn 1<<n into a big 64 bit number
501+
return AstOperator('&', x, AstInteger(31));
502+
}
503+
493504
/*
494505
* special case an assignment like outa[2..1] ^= -1
495506
*/
@@ -506,7 +517,7 @@ RangeXor(AST *dst, AST *src)
506517

507518
AstReportAs(dst, &saveinfo);
508519
if (dst->right->right == NULL) {
509-
loexpr = FoldIfConst(dst->right->left);
520+
loexpr = FoldIfConst(BitNumber(dst->right->left));
510521
nbits = AstInteger(1);
511522
/* special case: if src is -1 or 0
512523
* then we don't have to construct a mask,
@@ -529,8 +540,8 @@ RangeXor(AST *dst, AST *src)
529540
}
530541
}
531542
} else {
532-
hiexpr = FoldIfConst(dst->right->left);
533-
loexpr = FoldIfConst(dst->right->right);
543+
hiexpr = FoldIfConst(BitNumber(dst->right->left));
544+
loexpr = FoldIfConst(BitNumber(dst->right->right));
534545
//nbits = (hi - lo + 1);
535546
nbits = AstOperator('+',
536547
AstOperator(K_ABS, NULL,
@@ -578,11 +589,11 @@ RangeBitSet(AST *dst, uint32_t mask, int bitset)
578589

579590
AstReportAs(dst, &saveinfo);
580591
if (dst->right->right == NULL) {
581-
loexpr = dst->right->left;
592+
loexpr = BitNumber(dst->right->left);
582593
} else {
583594
AST *hiexpr;
584-
loexpr = dst->right->right;
585-
hiexpr = dst->right->left;
595+
loexpr = BitNumber(dst->right->right);
596+
hiexpr = BitNumber(dst->right->left);
586597
loexpr = AstOperator(K_LIMITMAX, loexpr, hiexpr);
587598
loexpr = FoldIfConst(loexpr);
588599
}

0 commit comments

Comments
 (0)