diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-04 18:19:37 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-04 18:19:37 -0500 |
commit | 1968ba1aa8a899193483c917e8c2534a4836e4fa (patch) | |
tree | 32344c67e35d7bbf410ed66517ac23549fffcc31 | |
parent | 42c6bbe2eaa2f1ceedb8c0b9d4d44bb8b676dcb8 (diff) |
WARN_UNALIGNED option for fastcomp
-rwxr-xr-x | emscripten.py | 2 | ||||
-rw-r--r-- | src/settings.js | 3 | ||||
-rw-r--r-- | tests/test_other.py | 21 |
3 files changed, 26 insertions, 0 deletions
diff --git a/emscripten.py b/emscripten.py index b75df587..c96c56a0 100755 --- a/emscripten.py +++ b/emscripten.py @@ -742,6 +742,8 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, backend_args = [backend_compiler, infile, '-march=js', '-filetype=asm', '-o', temp_js] if settings['PRECISE_F32']: backend_args += ['-emscripten-precise-f32'] + if settings['WARN_UNALIGNED']: + backend_args += ['-emscripten-warn-unaligned'] if DEBUG: logging.debug('emscript: llvm backend: ' + ' '.join(backend_args)) t = time.time() diff --git a/src/settings.js b/src/settings.js index 1cfb4030..8f3ef70b 100644 --- a/src/settings.js +++ b/src/settings.js @@ -104,6 +104,9 @@ var FORCE_ALIGNED_MEMORY = 0; // If enabled, assumes all reads and writes are fu // for ways to help find places in your code where unaligned reads/writes are done - // you might be able to refactor your codebase to prevent them, which leads to // smaller and faster code, or even the option to turn this flag on. +var WARN_UNALIGNED = 1; // Warn at compile time about instructions that LLVM tells us are not fully aligned. + // This is useful to find places in your code where you might refactor to ensure proper + // alignment. (this option is fastcomp-only) var PRECISE_I64_MATH = 1; // If enabled, i64 addition etc. is emulated - which is slow but precise. If disabled, // we use the 'double trick' which is fast but incurs rounding at high values. // Note that we do not catch 32-bit multiplication by default (which must be done in diff --git a/tests/test_other.py b/tests/test_other.py index 47d26416..a6a9c52f 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2353,3 +2353,24 @@ int main() { err = Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h', '-Xclang', '-print-stats'], stderr=PIPE).communicate() assert '*** PCH/Modules Loaded:\nModule: header.h.gch' not in err[1], err[1] + def test_warn_unaligned(self): + if os.environ.get('EMCC_FAST_COMPILER') != '1': return self.skip('need fastcomp') + open('src.cpp', 'w').write(r''' +#include <stdio.h> +static const double grid[4][2] = {{-3 / 3., -1 / 3.}, + {+1 / 3., -3 / 3.}, + {-1 / 3., +3 / 3.}, + {+3 / 3., +1 / 3.}}; +int main() { + for (int i = 0; i < 4; i++) + printf("%d:%.2f,%.2f ", i, grid[i][0], grid[i][1]); + printf("\n"); + return 0; +} +''') + output = Popen([PYTHON, EMCC, 'src.cpp', '-O1', '-s', 'WARN_UNALIGNED=1'], stderr=PIPE).communicate() + assert 'emcc: warning: unaligned store' in output[1] + output = Popen([PYTHON, EMCC, 'src.cpp', '-s', 'WARN_UNALIGNED=1', '-g'], stderr=PIPE).communicate() + assert 'emcc: warning: unaligned store' in output[1] + assert '@line 9 "src.cpp"' in output[1] + |