diff options
-rw-r--r-- | src/analyzer.js | 3 | ||||
-rw-r--r-- | tests/cases/emptyalloca.ll | 31 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 253c5505..17582ea3 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1662,11 +1662,13 @@ function analyzer(data, sidePass) { function stackAnalyzer() { data.functions.forEach(function(func) { var lines = func.labels[0].lines; + var hasAlloca = false; for (var i = 0; i < lines.length; i++) { var item = lines[i]; if (!item.assignTo || item.intertype != 'alloca' || !isNumber(item.ident)) break; item.allocatedSize = func.variables[item.assignTo].impl === VAR_EMULATED ? calcAllocatedSize(item.allocatedType)*item.ident: 0; + hasAlloca = true; if (USE_TYPED_ARRAYS === 2) { // We need to keep the stack aligned item.allocatedSize = Runtime.forceAlign(item.allocatedSize, Runtime.STACK_ALIGN); @@ -1682,6 +1684,7 @@ function analyzer(data, sidePass) { } func.initialStack = index; func.otherStackAllocations = false; + if (func.initialStack === 0 && hasAlloca) func.otherStackAllocations = true; // a single alloca of zero still requires us to emit stack support code while (func.initialStack == 0) { // one-time loop with possible abort in the middle // If there is no obvious need for stack management, perhaps we don't need it // (we try to optimize that way with SKIP_STACK_IN_SMALL). However, diff --git a/tests/cases/emptyalloca.ll b/tests/cases/emptyalloca.ll new file mode 100644 index 00000000..f12a4161 --- /dev/null +++ b/tests/cases/emptyalloca.ll @@ -0,0 +1,31 @@ +; ModuleID = '/tmp/tmpjSNiky/a.out.bc' +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + +@.str = private unnamed_addr constant [30 x i8] c"Module.print('hello, world!')\00", align 1 + +; Function Attrs: nounwind +define internal void @_Z9doNothingPi(i32* %arr) #0 { + %1 = alloca i32*, align 4 + store i32* %arr, i32** %1, align 4 + ret void +} + +define i32 @main() #1 { + %arr = alloca [0 x i32], align 4 + %1 = bitcast [0 x i32]* %arr to i8* + call void @llvm.memset.p0i8.i32(i8* %1, i8 0, i32 0, i32 4, i1 false) + %2 = getelementptr inbounds [0 x i32]* %arr, i32 0, i32 0 + call void @_Z9doNothingPi(i32* %2) + call void @emscripten_asm_const(i8* getelementptr inbounds ([30 x i8]* @.str, i32 0, i32 0)) + ret i32 0 +} + +; Function Attrs: nounwind +declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #2 + +declare void @emscripten_asm_const(i8*) #1 + +attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind } |