diff --git a/Sources/Fuzzilli/Compiler/Compiler.swift b/Sources/Fuzzilli/Compiler/Compiler.swift index 3c30cfff4..cfd88a31b 100644 --- a/Sources/Fuzzilli/Compiler/Compiler.swift +++ b/Sources/Fuzzilli/Compiler/Compiler.swift @@ -446,7 +446,6 @@ public class JavaScriptCompiler { case .breakStatement: // If we're in both .loop and .switch context, then the loop must be the most recent context // (switch blocks don't propagate an outer .loop context) so we just need to check for .loop here - // TODO remove this comment once the Analyzer bug fixs has been merged. Until then the code in this switch case is buggy. if contextAnalyzer.context.contains(.loop){ emit(LoopBreak()) } else if contextAnalyzer.context.contains(.switchBlock){ diff --git a/Sources/Fuzzilli/FuzzIL/Analyzer.swift b/Sources/Fuzzilli/FuzzIL/Analyzer.swift index 3297a691f..4b7e348b2 100644 --- a/Sources/Fuzzilli/FuzzIL/Analyzer.swift +++ b/Sources/Fuzzilli/FuzzIL/Analyzer.swift @@ -169,7 +169,8 @@ struct ContextAnalyzer: Analyzer { newContext.formUnion(contextStack.secondToTop) } - // If we are in a loop, we don't want to propagate the switch context and vice versa. + // If we are in a loop, we don't want to propagate the switch context and vice versa. Otherwise we couldn't determine which break operation to emit. + // TODO Make this generic for similar logic cases as well. E.g. by using a instr.op.contextClosed list. if (instr.op.contextOpened.contains(.switchBlock) || instr.op.contextOpened.contains(.switchCase)) { newContext.remove(.loop) } else if (instr.op.contextOpened.contains(.loop)) { diff --git a/Tests/FuzzilliTests/AnalyzerTest.swift b/Tests/FuzzilliTests/AnalyzerTest.swift index 1e1c4eb77..1dac85577 100644 --- a/Tests/FuzzilliTests/AnalyzerTest.swift +++ b/Tests/FuzzilliTests/AnalyzerTest.swift @@ -305,6 +305,8 @@ class AnalyzerTests: XCTestCase { let _ = b.finalize() } + // Tests if the context is correctly identified in nested loops and switches. + // Needs to work to distinguish when to emit LoopBreak and SwitchBreak. func testBreakContext() { let fuzzer = makeMockFuzzer() let b = fuzzer.makeBuilder()