[llvm] [Lint] Add option --lint-abort-on-error (PR #81999)
Jannik Silvanus via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 16 07:21:53 PST 2024
https://github.com/jasilvanus created https://github.com/llvm/llvm-project/pull/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.
>From 7af9340f21f97ae59e27d88c499323c6005efca7 Mon Sep 17 00:00:00 2001
From: Jannik Silvanus <jannik.silvanus at amd.com>
Date: Fri, 16 Feb 2024 16:15:49 +0100
Subject: [PATCH] [Lint] Add option --lint-abort-on-error
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.
---
llvm/lib/Analysis/Lint.cpp | 9 +++++++++
llvm/test/Analysis/Lint/abort-on-error.ll | 10 ++++++++++
2 files changed, 19 insertions(+)
create mode 100644 llvm/test/Analysis/Lint/abort-on-error.ll
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index 16635097d20afe..0694c2995dfcce 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -77,6 +77,11 @@
using namespace llvm;
+static const char LintAbortOnErrorArgName[] = "lint-abort-on-error";
+static cl::opt<bool>
+ LintAbortOnError(LintAbortOnErrorArgName, cl::init(false),
+ cl::desc("In the Lint pass, abort on errors."));
+
namespace {
namespace MemRef {
static const unsigned Read = 1;
@@ -715,6 +720,10 @@ PreservedAnalyses LintPass::run(Function &F, FunctionAnalysisManager &AM) {
Lint L(Mod, DL, AA, AC, DT, TLI);
L.visit(F);
dbgs() << L.MessagesStr.str();
+ if (LintAbortOnError && !L.MessagesStr.str().empty())
+ report_fatal_error(Twine("Linter found errors, aborting. (enabled by --") +
+ LintAbortOnErrorArgName + ")",
+ false);
return PreservedAnalyses::all();
}
diff --git a/llvm/test/Analysis/Lint/abort-on-error.ll b/llvm/test/Analysis/Lint/abort-on-error.ll
new file mode 100644
index 00000000000000..3efc38aea887cc
--- /dev/null
+++ b/llvm/test/Analysis/Lint/abort-on-error.ll
@@ -0,0 +1,10 @@
+; RUN: not opt -passes=lint -disable-output --lint-abort-on-error %s 2>&1 | FileCheck %s
+
+; CHECK: Undefined behavior: Division by zero
+; CHECK-NEXT: %b = sdiv i32 %a, 0
+; CHECK-NEXT: LLVM ERROR: Linter found errors, aborting. (enabled by --lint-abort-on-error)
+
+define i32 @sdiv_by_zero(i32 %a) {
+ %b = sdiv i32 %a, 0
+ ret i32 %b
+}
More information about the llvm-commits
mailing list