aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jsifier.js6
-rw-r--r--tests/runner.py30
2 files changed, 33 insertions, 3 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index edf8c6fa..806ea577 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -752,7 +752,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
return makeOne(0);
});
- function makeSignOp(value, type, op) {
+ function makeSignOp(value, type, op) { // TODO: If value isNumber, do this at compile time
if (!value) return value;
if (!GUARD_SIGNS) return value;
if (type in Runtime.INT_TYPES) {
@@ -778,10 +778,10 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
item['ident'+i] = null; // just so it exists for purposes of reading ident2 etc. later on, and no exception is thrown
}
}
- if (op[0] == 'u' || op[0] == 'z' || (variant && variant[0] == 'u')) { // z for zext, see below
+ if (op in set('udiv', 'urem', 'uitofp', 'zext', 'lshr') || (variant && variant[0] == 'u')) {
ident1 = makeSignOp(ident1, type, 'un');
ident2 = makeSignOp(ident2, type, 'un');
- } else if (op[0] == 's' || (variant && variant[0] == 's')) {
+ } else if (op in set('sdiv', 'srem', 'sitofp', 'sext', 'ashr') || (variant && variant[0] == 's')) {
ident1 = makeSignOp(ident1, type, 're');
ident2 = makeSignOp(ident2, type, 're');
}
diff --git a/tests/runner.py b/tests/runner.py
index 09e53251..1c2e6f1c 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -315,6 +315,36 @@ if 'benchmark' not in sys.argv:
'''
self.do_test(src, '*5,23,10,19,121,1,37,1,0*\n0:-1,1:134217727,2:4194303,3:131071,4:4095,5:127,6:3,7:0,8:0*\n*56,09*\n*246,296*\n*21*')
+ def test_sintvars(self):
+ src = '''
+ #include <stdio.h>
+ struct S {
+ char *match_start;
+ char *strstart;
+ };
+ int main()
+ {
+ struct S _s;
+ struct S *s = &_s;
+ unsigned short int sh;
+
+ s->match_start = (char*)32522;
+ s->strstart = (char*)(32780);
+ printf("*%d,%d,%d*\\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start));
+ sh = s->strstart - s->match_start;
+ printf("*%d,%d*\\n", sh, sh>>7);
+
+ s->match_start = (char*)32999;
+ s->strstart = (char*)(32780);
+ printf("*%d,%d,%d*\\n", (int)s->strstart, (int)s->match_start, (int)(s->strstart - s->match_start));
+ sh = s->strstart - s->match_start;
+ printf("*%d,%d*\\n", sh, sh>>7);
+ }
+ '''
+ output = '*32780,32522,258*\n*258,2*\n*32780,32999,-219*\n*65317,510*'
+ global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 0 # We should not need overflow correction to get this right
+ self.do_test(src, output, force_c=True)
+
def test_unsigned(self):
src = '''
#include <stdio.h>