[PATCH] D66444: [BlockExtractor] Avoid assert with wrong line format
Jinsong Ji via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 19 14:55:57 PDT 2019
jsji created this revision.
jsji added reviewers: qcolombet, volkan.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66444
Files:
llvm/lib/Transforms/IPO/BlockExtractor.cpp
llvm/test/Transforms/BlockExtractor/invalid-line.ll
Index: llvm/test/Transforms/BlockExtractor/invalid-line.ll
===================================================================
--- /dev/null
+++ 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
+}
+
Index: llvm/lib/Transforms/IPO/BlockExtractor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/BlockExtractor.cpp
+++ llvm/lib/Transforms/IPO/BlockExtractor.cpp
@@ -119,6 +119,8 @@
/*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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66444.215995.patch
Type: text/x-patch
Size: 970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190819/bb029c29/attachment.bin>
More information about the llvm-commits
mailing list