aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-05-25 15:00:11 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-05-25 15:00:11 -0700
commitd3efb7dcb71f0d9d6df09fee687fa1dbd0bde9bf (patch)
tree19be204e6a786b13d7a1136302e457deca36404e
parente1b8b28863ee7fea3117d0d10d7ab0a679dfb8ca (diff)
allow 2 and 3 in SAFE_HEAP and CHECK_* options. 2 is only these, 3 is all but these
-rw-r--r--src/compiler.js8
-rw-r--r--src/parseTools.js24
-rw-r--r--src/settings.js11
-rw-r--r--tests/runner.py46
4 files changed, 71 insertions, 18 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 46d6b5cf..bdfdbba8 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -27,16 +27,16 @@ for (setting in settings) {
}
var CONSTANTS = { 'QUANTUM_SIZE': QUANTUM_SIZE };
-if (CORRECT_SIGNS === 2) {
+if (CORRECT_SIGNS >= 2) {
CORRECT_SIGNS_LINES = set(CORRECT_SIGNS_LINES); // for fast checking
}
-if (CORRECT_OVERFLOWS === 2) {
+if (CORRECT_OVERFLOWS >= 2) {
CORRECT_OVERFLOWS_LINES = set(CORRECT_OVERFLOWS_LINES); // for fast checking
}
-if (CORRECT_ROUNDINGS === 2) {
+if (CORRECT_ROUNDINGS >= 2) {
CORRECT_ROUNDINGS_LINES = set(CORRECT_ROUNDINGS_LINES); // for fast checking
}
-if (SAFE_HEAP === 2) {
+if (SAFE_HEAP >= 2) {
SAFE_HEAP_LINES = set(SAFE_HEAP_LINES); // for fast checking
}
diff --git a/src/parseTools.js b/src/parseTools.js
index a2f946bc..9e0fc24c 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -592,32 +592,40 @@ function indentify(text, indent) {
// Correction tools
function correctSpecificSign() {
- assert(!(CORRECT_SIGNS === 2 && !Debugging.on), 'Need debugging for line-specific corrections');
- return CORRECT_SIGNS === 2 && Framework.currItem && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES;
+ assert(!(CORRECT_SIGNS >= 2 && !Debugging.on), 'Need debugging for line-specific corrections');
+ if (!Framework.currItem) return false;
+ return (CORRECT_SIGNS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES) ||
+ (CORRECT_SIGNS === 3 && !(Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES));
}
function correctSigns() {
return CORRECT_SIGNS === 1 || correctSpecificSign();
}
function correctSpecificOverflow() {
- assert(!(CORRECT_OVERFLOWS === 2 && !Debugging.on), 'Need debugging for line-specific corrections');
- return CORRECT_OVERFLOWS === 2 && Framework.currItem && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES;
+ assert(!(CORRECT_OVERFLOWS >= 2 && !Debugging.on), 'Need debugging for line-specific corrections');
+ if (!Framework.currItem) return false;
+ return (CORRECT_OVERFLOWS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES) ||
+ (CORRECT_OVERFLOWS === 3 && !(Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES));
}
function correctOverflows() {
return CORRECT_OVERFLOWS === 1 || correctSpecificOverflow();
}
function correctSpecificRounding() {
- assert(!(CORRECT_ROUNDINGS === 2 && !Debugging.on), 'Need debugging for line-specific corrections');
- return CORRECT_ROUNDINGS === 2 && Framework.currItem && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_ROUNDINGS_LINES;
+ assert(!(CORRECT_ROUNDINGS >= 2 && !Debugging.on), 'Need debugging for line-specific corrections');
+ if (!Framework.currItem) return false;
+ return (CORRECT_ROUNDINGS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_ROUNDINGS_LINES) ||
+ (CORRECT_ROUNDINGS === 3 && !(Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_ROUNDINGS_LINES));
}
function correctRoundings() {
return CORRECT_ROUNDINGS === 1 || correctSpecificRounding();
}
function checkSpecificSafeHeap() {
- assert(!(SAFE_HEAP === 2 && !Debugging.on), 'Need debugging for line-specific checks');
- return SAFE_HEAP === 2 && Framework.currItem && !(Debugging.getIdentifier(Framework.currItem.lineNum) in SAFE_HEAP_LINES);
+ assert(!(SAFE_HEAP >= 2 && !Debugging.on), 'Need debugging for line-specific checks');
+ if (!Framework.currItem) return false;
+ return (SAFE_HEAP === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in SAFE_HEAP_LINES) ||
+ (SAFE_HEAP === 3 && !(Debugging.getIdentifier(Framework.currItem.lineNum) in SAFE_HEAP_LINES));
}
function checkSafeHeap() {
return SAFE_HEAP === 1 || checkSpecificSafeHeap();
diff --git a/src/settings.js b/src/settings.js
index 249c8224..b50ac04d 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -17,7 +17,8 @@ CORRECT_SIGNS = 1; // Whether we make sure to convert unsigned values to signed
// Decreases performance with additional runtime checks. Might not be
// needed in some kinds of code.
// If equal to 2, done on a line-by-line basis according to
- // CORRECT_SIGNS_LINES
+ // CORRECT_SIGNS_LINES, correcting only the specified lines.
+ // If equal to 3, correcting all *but* the specified lines
CHECK_SIGNS = 0; // Runtime errors for signing issues that need correcting.
// It is recommended to use this in
// order to find if your code needs CORRECT_SIGNS. If you can get your
@@ -47,8 +48,9 @@ SKIP_STACK_IN_SMALL = 1; // When enabled, does not push/pop the stack at all in
// Generated code debugging options
SAFE_HEAP = 0; // Check each write to the heap against a list of blocked addresses
// If equal to 2, done on a line-by-line basis according to
- // SAFE_HEAP_LINES (note that these are the lines to *exclude*
- // from checking - the opposite of what CORRECT_*_LINES mean)
+ // SAFE_HEAP_LINES, checking only the specified lines.
+ // If equal to 3, checking all *but* the specified lines. Note
+ // that 3 is the option you usually want here.
SAFE_HEAP_LOG = 0; // Print out every single heap read and write (LOTS of output)
LABEL_DEBUG = 0; // Print out labels and functions as we enter them
EXCEPTION_DEBUG = 1; // Print out exceptions in emscriptened code
@@ -71,7 +73,8 @@ CORRECT_OVERFLOWS = 1; // Experimental code that tries to prevent unexpected JS
// it slows things down.
//
// If equal to 2, done on a line-by-line basis according to
- // CORRECT_OVERFLOWS_LINES
+ // CORRECT_OVERFLOWS_LINES, correcting only the specified lines.
+ // If equal to 3, correcting all *but* the specified lines
//
// NOTE: You can introduce signing issues by using this option. If you
// take a large enough 32-bit value, and correct it for overflows,
diff --git a/tests/runner.py b/tests/runner.py
index af1d283b..d24b2920 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1879,7 +1879,7 @@ if 'benchmark' not in sys.argv:
if SAFE_HEAP:
# Ignore bitfield warnings
- SAFE_HEAP = 2
+ SAFE_HEAP = 3
SAFE_HEAP_LINES = ['btVoronoiSimplexSolver.h:40', 'btVoronoiSimplexSolver.h:41',
'btVoronoiSimplexSolver.h:42', 'btVoronoiSimplexSolver.h:43']
COMPILER_TEST_OPTS = ['-g']
@@ -2200,7 +2200,7 @@ if 'benchmark' not in sys.argv:
global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g']
- SAFE_HEAP = 2
+ SAFE_HEAP = 3
SAFE_HEAP_LINES = ["src.cpp:7"]
self.do_test(src, '*ok*')
@@ -2215,6 +2215,21 @@ if 'benchmark' not in sys.argv:
# This test *should* fail, by throwing this exception
assert 'Assertion failed: Load-store consistency assumption failure!' in str(e), str(e)
+ # And reverse the checks with = 2
+
+ SAFE_HEAP = 2
+ SAFE_HEAP_LINES = ["src.cpp:99"]
+
+ self.do_test(src, '*ok*')
+
+ SAFE_HEAP_LINES = ["src.cpp:7"]
+
+ try:
+ self.do_test(src, '*nothingatall*')
+ except Exception, e:
+ # This test *should* fail, by throwing this exception
+ assert 'Assertion failed: Load-store consistency assumption failure!' in str(e), str(e)
+
def test_check_overflow(self):
global CHECK_OVERFLOWS; CHECK_OVERFLOWS = 1
global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 0
@@ -2302,6 +2317,14 @@ if 'benchmark' not in sys.argv:
CORRECT_SIGNS_LINES = ["src.cpp:3"]
self.do_test(src, '*1*')
+ # And reverse the checks with = 2
+ CORRECT_SIGNS = 3
+ CORRECT_SIGNS_LINES = ["src.cpp:3"]
+ self.do_test(src, '*0*')
+ CORRECT_SIGNS = 3
+ CORRECT_SIGNS_LINES = ["src.cpp:9"]
+ self.do_test(src, '*1*')
+
src = '''
#include<stdio.h>
int main() {
@@ -2343,6 +2366,19 @@ if 'benchmark' not in sys.argv:
assert 'UNEXPECTED' not in str(e), str(e)
assert 'Expected to find' in str(e), str(e)
+ # And reverse the checks with = 2
+ CORRECT_OVERFLOWS = 3
+ CORRECT_OVERFLOWS_LINES = ["src.cpp:3"]
+ self.do_test(src, correct)
+ CORRECT_OVERFLOWS = 3
+ CORRECT_OVERFLOWS_LINES = ["src.cpp:6"]
+ try:
+ self.do_test(src, correct)
+ raise Exception('UNEXPECTED-PASS')
+ except Exception, e:
+ assert 'UNEXPECTED' not in str(e), str(e)
+ assert 'Expected to find' in str(e), str(e)
+
# Roundings
src = '''
@@ -2380,6 +2416,12 @@ if 'benchmark' not in sys.argv:
self.do_test(src.replace('TYPE', 'long long'), '*-3**2**-5**5*')
self.do_test(src.replace('TYPE', 'int'), '*-2**2**-5**5*') # Here we are lucky and also get the first one right
+ # And reverse the check with = 2
+ CORRECT_ROUNDINGS = 3
+ CORRECT_ROUNDINGS_LINES = ["src.cpp:999"]
+ self.do_test(src.replace('TYPE', 'long long'), '*-2**2**-5**5*')
+ self.do_test(src.replace('TYPE', 'int'), '*-2**2**-5**5*')
+
# Generate tests for all our compilers
def make_test(name, compiler, llvm_opts, embetter, quantum_size):