diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-05-27 12:46:32 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-05-27 12:46:32 -0700 |
commit | 2f0867998ff917d44be000699db443737c153ed3 (patch) | |
tree | 476a3a39a7fe8f24414f510243c9722ca099b12e | |
parent | 196cc4113a0ab6a0f04d482689428951a19e3725 (diff) |
fix bug with invalid [#uses=?] parsing
-rw-r--r-- | src/analyzer.js | 10 | ||||
-rw-r--r-- | tests/runner.py | 15 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index e48395c6..caeedb56 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -260,13 +260,18 @@ function analyzer(data) { func.lines.forEach(function(item) { if (item.intertype === 'assign') { if (!item.value.tokens.slice(-1)[0].item) throw 'Did you run llvm-dis with -show-annotations?'; - func.variables[item.ident] = { + var commaIndex = getTokenIndexByText(item.value.tokens, ';'); + var variable = func.variables[item.ident] = { ident: item.ident, type: item.value.type, origin: item.value.intertype, lineNum: item.lineNum, - uses: parseInt(item.value.tokens.slice(-1)[0].item.tokens[0].text.split('=')[1]) + uses: parseInt(item.value.tokens[commaIndex+1].item.tokens[0].text.split('=')[1]) }; + assert(isNumber(variable.uses), 'Failed to find the # of uses of var: ' + item.ident); + if (variable.origin === 'alloca') { + variable.allocatedNum = item.value.allocatedNum; + } } }); @@ -338,6 +343,7 @@ function analyzer(data) { // A simple int value, can be implemented as a native variable variable.impl = VAR_NATIVE; } else if (OPTIMIZE && variable.origin === 'alloca' && !variable.hasAddrTaken && !variable.hasValueTaken && + variable.allocatedNum === 1 && (Runtime.isNumberType(pointedType) || Runtime.isPointerType(pointedType))) { // A pointer to a value which is only accessible through this pointer. Basically // a local value on the stack, which nothing fancy is done on. So we can diff --git a/tests/runner.py b/tests/runner.py index f6c62087..1a240240 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -1039,6 +1039,21 @@ if 'benchmark' not in sys.argv: ''' self.do_test(src, '*zzcheezzz*') + def test_alloca(self): + global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g'] # This can mess up our parsing of [#uses=..] + + src = ''' + #include <stdio.h> + + int main() { + char *pc; + pc = (char *)alloca(5); + printf("z:%d*%d*\\n", pc > 0, (int)pc); + return 0; + } + ''' + self.do_test(src, 'z:1*', force_c=True) + def test_array2(self): src = ''' #include <stdio.h> |