diff options
-rw-r--r-- | src/analyzer.js | 7 | ||||
-rw-r--r-- | tests/cases/allocavartop.ll | 17 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 1c643303..54e1ab43 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1223,8 +1223,7 @@ function analyzer(data, sidePass) { var lines = func.labels[0].lines; for (var i = 0; i < lines.length; i++) { var item = lines[i]; - if (!item.assignTo || item.intertype != 'alloca') break; - assert(isNumber(item.allocatedNum)); + if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.allocatedNum)) break; item.allocatedSize = func.variables[item.assignTo].impl === VAR_EMULATED ? calcAllocatedSize(item.allocatedType)*item.allocatedNum: 0; if (USE_TYPED_ARRAYS === 2) { @@ -1235,7 +1234,7 @@ function analyzer(data, sidePass) { var index = 0; for (var i = 0; i < lines.length; i++) { var item = lines[i]; - if (!item.assignTo || item.intertype != 'alloca') break; + if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.allocatedNum)) break; item.allocatedIndex = index; index += item.allocatedSize; delete item.allocatedSize; @@ -1260,7 +1259,7 @@ function analyzer(data, sidePass) { var finishedInitial = false; for (var i = 0; i < lines.length; i++) { var item = lines[i]; - if (!item.assignTo || item.intertype != 'alloca') { + if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.allocatedNum)) { finishedInitial = true; continue; } diff --git a/tests/cases/allocavartop.ll b/tests/cases/allocavartop.ll new file mode 100644 index 00000000..e9520a19 --- /dev/null +++ b/tests/cases/allocavartop.ll @@ -0,0 +1,17 @@ +; ModuleID = 'tests/hello_world.bc' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" +target triple = "i386-pc-linux-gnu" + +@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] + +; [#uses=0] +define i32 @main(i32 %argc) { +entry: + %retval = alloca i32, i32 %argc, align 4 ; [#uses=1 type=i32*] + store i32 0, i32* %retval + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] + ret i32 1 +} + +; [#uses=1] +declare i32 @printf(i8*, ...) |