[llvm] r369389 - [BlockExtractor] Avoid assert with wrong line format
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 07:46:02 PDT 2019
Author: jsji
Date: Tue Aug 20 07:46:02 2019
New Revision: 369389
URL: http://llvm.org/viewvc/llvm-project?rev=369389&view=rev
Log:
[BlockExtractor] Avoid assert with wrong line format
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
Added:
llvm/trunk/test/Transforms/BlockExtractor/invalid-line.ll
Modified:
llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp
Modified: llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp?rev=369389&r1=369388&r2=369389&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp Tue Aug 20 07:46:02 2019
@@ -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);
Added: llvm/trunk/test/Transforms/BlockExtractor/invalid-line.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/BlockExtractor/invalid-line.ll?rev=369389&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/BlockExtractor/invalid-line.ll (added)
+++ llvm/trunk/test/Transforms/BlockExtractor/invalid-line.ll Tue Aug 20 07:46:02 2019
@@ -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
+}
+
More information about the llvm-commits
mailing list