Skip to content

Commit 756ff96

Browse files
authored
[Lint] Add option --lint-abort-on-error (#81999)
This option makes the lint pass abort if errors were found. This is intended to help lit testing where the lint pass is used and lint errors should be detected. Previously, this required checking for non-empty stderr.
1 parent 283a6b9 commit 756ff96

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

llvm/lib/Analysis/Lint.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777

7878
using namespace llvm;
7979

80+
static const char LintAbortOnErrorArgName[] = "lint-abort-on-error";
81+
static cl::opt<bool>
82+
LintAbortOnError(LintAbortOnErrorArgName, cl::init(false),
83+
cl::desc("In the Lint pass, abort on errors."));
84+
8085
namespace {
8186
namespace MemRef {
8287
static const unsigned Read = 1;
@@ -715,6 +720,10 @@ PreservedAnalyses LintPass::run(Function &F, FunctionAnalysisManager &AM) {
715720
Lint L(Mod, DL, AA, AC, DT, TLI);
716721
L.visit(F);
717722
dbgs() << L.MessagesStr.str();
723+
if (LintAbortOnError && !L.MessagesStr.str().empty())
724+
report_fatal_error(Twine("Linter found errors, aborting. (enabled by --") +
725+
LintAbortOnErrorArgName + ")",
726+
false);
718727
return PreservedAnalyses::all();
719728
}
720729

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not opt -passes=lint -disable-output --lint-abort-on-error %s 2>&1 | FileCheck %s
2+
3+
; CHECK: Undefined behavior: Division by zero
4+
; CHECK-NEXT: %b = sdiv i32 %a, 0
5+
; CHECK-NEXT: LLVM ERROR: Linter found errors, aborting. (enabled by --lint-abort-on-error)
6+
7+
define i32 @sdiv_by_zero(i32 %a) {
8+
%b = sdiv i32 %a, 0
9+
ret i32 %b
10+
}

0 commit comments

Comments
 (0)