diff options
| author | Jinsong Ji <jji@us.ibm.com> | 2019-08-20 14:46:02 +0000 |
|---|---|---|
| committer | Jinsong Ji <jji@us.ibm.com> | 2019-08-20 14:46:02 +0000 |
| commit | cda334ba5417d7702be755adc2f8414c877f0482 (patch) | |
| tree | eb790275fc731b3257194bbb1504906e3430299c | |
| parent | 16111d3795c72b6674a5a2875fe328e16d91966e (diff) | |
| download | bcm5719-llvm-cda334ba5417d7702be755adc2f8414c877f0482.tar.gz bcm5719-llvm-cda334ba5417d7702be755adc2f8414c877f0482.zip | |
[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
llvm-svn: 369389
| -rw-r--r-- | llvm/lib/Transforms/IPO/BlockExtractor.cpp | 2 | ||||
| -rw-r--r-- | llvm/test/Transforms/BlockExtractor/invalid-line.ll | 9 |
2 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/BlockExtractor.cpp b/llvm/lib/Transforms/IPO/BlockExtractor.cpp index 6c365f3f3cb..56854fceac0 100644 --- a/llvm/lib/Transforms/IPO/BlockExtractor.cpp +++ b/llvm/lib/Transforms/IPO/BlockExtractor.cpp @@ -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/llvm/test/Transforms/BlockExtractor/invalid-line.ll b/llvm/test/Transforms/BlockExtractor/invalid-line.ll new file mode 100644 index 00000000000..7e409d35916 --- /dev/null +++ b/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 +} + |

