Skip to content

Commit

Permalink
[BlockExtractor] Avoid assert with wrong line format
Browse files Browse the repository at this point in the history
Summary:
When the line format is wrong, we may end up accessing out of bound
memory. eg: the test with invalide line will cause assert.
Assertion `idx < size()' failed

The fix is to report fatal when we found mismatched line format.

Reviewers: qcolombet, volkan

Reviewed By: qcolombet

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66444

llvm-svn: 369389
  • Loading branch information
Jinsong Ji committed Aug 20, 2019
1 parent 16111d3 commit cda334b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/IPO/BlockExtractor.cpp
Expand Up @@ -119,6 +119,8 @@ void BlockExtractor::loadFile() {
/*KeepEmpty=*/false);
if (LineSplit.empty())
continue;
if (LineSplit.size()!=2)
report_fatal_error("Invalid line format, expecting lines like: 'funcname bb1[;bb2..]'");
SmallVector<StringRef, 4> BBNames;
LineSplit[1].split(BBNames, ';', /*MaxSplit=*/-1,
/*KeepEmpty=*/false);
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/Transforms/BlockExtractor/invalid-line.ll
@@ -0,0 +1,9 @@
; RUN: echo 'foo' > %t
; RUN: not opt -S -extract-blocks -extract-blocks-file=%t %s 2>&1 | FileCheck %s

; CHECK: Invalid line
define void @bar() {
bb:
ret void
}

0 comments on commit cda334b

Please sign in to comment.