]> granicus.if.org Git - llvm/commitdiff
[BlockExtractor] Avoid assert with wrong line format
authorJinsong Ji <jji@us.ibm.com>
Tue, 20 Aug 2019 14:46:02 +0000 (14:46 +0000)
committerJinsong Ji <jji@us.ibm.com>
Tue, 20 Aug 2019 14:46:02 +0000 (14:46 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369389 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/BlockExtractor.cpp
test/Transforms/BlockExtractor/invalid-line.ll [new file with mode: 0644]

index 6c365f3f3cbe8d705e986e9f7c7740b61b6e1e65..56854fceac089a3323c41c34832ee4ed2749159f 100644 (file)
@@ -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);
diff --git a/test/Transforms/BlockExtractor/invalid-line.ll b/test/Transforms/BlockExtractor/invalid-line.ll
new file mode 100644 (file)
index 0000000..7e409d3
--- /dev/null
@@ -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
+}
+