From 37106eebf48382d77ac886ea897ca196db22f6f5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 1 Mar 2013 19:49:48 -0500 Subject: do not emit code in a label after a return --- src/analyzer.js | 3 ++- tests/cases/breakinthemiddle2.ll | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/cases/breakinthemiddle2.ll diff --git a/src/analyzer.js b/src/analyzer.js index c930231f..f9b0c5af 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -18,6 +18,7 @@ function recomputeLines(func) { // Handy sets var BRANCH_INVOKE = set('branch', 'invoke'); +var LABEL_ENDERS = set('branch', 'return'); var SIDE_EFFECT_CAUSERS = set('call', 'invoke', 'atomic'); var UNUNFOLDABLE = set('value', 'structvalue', 'type', 'phiparam'); @@ -88,7 +89,7 @@ function analyzer(data, sidePass) { // Internal line if (!currLabelFinished) { item.functions.slice(-1)[0].labels.slice(-1)[0].lines.push(subItem); // If this line fails, perhaps missing a label? - if (subItem.intertype === 'branch') { + if (subItem.intertype in LABEL_ENDERS) { currLabelFinished = true; } } else { diff --git a/tests/cases/breakinthemiddle2.ll b/tests/cases/breakinthemiddle2.ll new file mode 100644 index 00000000..318b49dc --- /dev/null +++ b/tests/cases/breakinthemiddle2.ll @@ -0,0 +1,35 @@ +@.str = private constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1] + +define linkonce_odr i32 @main() align 2 { + %333 = call i32 @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0] + %199 = trunc i8 1 to i1 ; [#uses=1] + br i1 %199, label %label555, label %label569 + +label555: ; preds = %0 + br label %label569 ; branch should ignore all code after it in the block + ; No predecessors! + %a472 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) + cleanup + %a473 = extractvalue { i8*, i32 } %a472, 0 + %a474 = extractvalue { i8*, i32 } %a472, 1 + br label %label569 + +label569: ; preds = %0 + br i1 %199, label %label990, label %label999 + +label990: + ret i32 0 ; ret should ignore all code after it in the block + ; No predecessors! + %a472 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) + cleanup + %a473 = extractvalue { i8*, i32 } %a472, 0 + %a474 = extractvalue { i8*, i32 } %a472, 1 + br label %label569 + +label999: ; preds = %555 + ret i32 0 +} + +declare i32 @printf(i8*) +declare i32 @__gxx_personality_v0(...) + -- cgit v1.2.3-18-g5258