Skip to content

Commit 94122d5

Browse files
authored
Lint: Replace -lint-abort-on-error cl::opt with pass parameter (#132933)
1 parent c9d90f1 commit 94122d5

File tree

6 files changed

+37
-20
lines changed

6 files changed

+37
-20
lines changed

llvm/include/llvm/Analysis/Lint.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ class Function;
2929
///
3030
/// This should only be used for debugging, because it plays games with
3131
/// PassManagers and stuff.
32-
void lintModule(const Module &M);
32+
void lintModule(const Module &M, bool AbortOnError = false);
3333

3434
// Lint a function.
35-
void lintFunction(const Function &F);
35+
void lintFunction(const Function &F, bool AbortOnError = false);
3636

3737
class LintPass : public PassInfoMixin<LintPass> {
38+
const bool AbortOnError;
39+
3840
public:
41+
LintPass(bool AbortOnError) : AbortOnError(AbortOnError) {}
3942
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
43+
44+
void printPipeline(raw_ostream &OS,
45+
function_ref<StringRef(StringRef)> MapClassName2PassName);
4046
};
4147

4248
} // namespace llvm

llvm/lib/Analysis/Lint.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@
7878

7979
using namespace llvm;
8080

81-
static const char LintAbortOnErrorArgName[] = "lint-abort-on-error";
82-
static cl::opt<bool>
83-
LintAbortOnError(LintAbortOnErrorArgName, cl::init(false),
84-
cl::desc("In the Lint pass, abort on errors."));
85-
8681
namespace {
8782
namespace MemRef {
8883
static const unsigned Read = 1;
@@ -747,20 +742,26 @@ PreservedAnalyses LintPass::run(Function &F, FunctionAnalysisManager &AM) {
747742
Lint L(Mod, DL, AA, AC, DT, TLI);
748743
L.visit(F);
749744
dbgs() << L.MessagesStr.str();
750-
if (LintAbortOnError && !L.MessagesStr.str().empty())
751-
report_fatal_error(Twine("Linter found errors, aborting. (enabled by --") +
752-
LintAbortOnErrorArgName + ")",
753-
false);
745+
if (AbortOnError && !L.MessagesStr.str().empty())
746+
report_fatal_error(
747+
"linter found errors, aborting. (enabled by abort-on-error)", false);
754748
return PreservedAnalyses::all();
755749
}
756750

751+
void LintPass::printPipeline(
752+
raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
753+
PassInfoMixin<LintPass>::printPipeline(OS, MapClassName2PassName);
754+
if (AbortOnError)
755+
OS << "<abort-on-error>";
756+
}
757+
757758
//===----------------------------------------------------------------------===//
758759
// Implement the public interfaces to this file...
759760
//===----------------------------------------------------------------------===//
760761

761762
/// lintFunction - Check a function for errors, printing messages on stderr.
762763
///
763-
void llvm::lintFunction(const Function &f) {
764+
void llvm::lintFunction(const Function &f, bool AbortOnError) {
764765
Function &F = const_cast<Function &>(f);
765766
assert(!F.isDeclaration() && "Cannot lint external functions");
766767

@@ -775,14 +776,14 @@ void llvm::lintFunction(const Function &f) {
775776
AA.registerFunctionAnalysis<TypeBasedAA>();
776777
return AA;
777778
});
778-
LintPass().run(F, FAM);
779+
LintPass(AbortOnError).run(F, FAM);
779780
}
780781

781782
/// lintModule - Check a module for errors, printing messages on stderr.
782783
///
783-
void llvm::lintModule(const Module &M) {
784+
void llvm::lintModule(const Module &M, bool AbortOnError) {
784785
for (const Function &F : M) {
785786
if (!F.isDeclaration())
786-
lintFunction(F);
787+
lintFunction(F, AbortOnError);
787788
}
788789
}

llvm/lib/Passes/PassBuilder.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,12 @@ Expected<HardwareLoopOptions> parseHardwareLoopOptions(StringRef Params) {
681681
return HardwareLoopOpts;
682682
}
683683

684+
/// Parser of parameters for Lint pass.
685+
Expected<bool> parseLintOptions(StringRef Params) {
686+
return PassBuilder::parseSinglePassOption(Params, "abort-on-error",
687+
"LintPass");
688+
}
689+
684690
/// Parser of parameters for LoopUnroll pass.
685691
Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
686692
LoopUnrollOptions UnrollOpts;

llvm/lib/Passes/PassRegistry.def

+5-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ FUNCTION_PASS("kcfi", KCFIPass())
397397
FUNCTION_PASS("kernel-info", KernelInfoPrinter(TM))
398398
FUNCTION_PASS("lcssa", LCSSAPass())
399399
FUNCTION_PASS("libcalls-shrinkwrap", LibCallsShrinkWrapPass())
400-
FUNCTION_PASS("lint", LintPass())
401400
FUNCTION_PASS("load-store-vectorizer", LoadStoreVectorizerPass())
402401
FUNCTION_PASS("loop-data-prefetch", LoopDataPrefetchPass())
403402
FUNCTION_PASS("loop-distribute", LoopDistributePass())
@@ -543,6 +542,11 @@ FUNCTION_PASS_WITH_PARAMS(
543542
parseInstCombineOptions,
544543
"no-use-loop-info;use-loop-info;no-verify-fixpoint;verify-fixpoint;"
545544
"max-iterations=N")
545+
FUNCTION_PASS_WITH_PARAMS(
546+
"lint", "LintPass",
547+
[](bool AbortOnError) { return LintPass(AbortOnError); },
548+
parseLintOptions,
549+
"abort-on-error")
546550
FUNCTION_PASS_WITH_PARAMS(
547551
"loop-unroll", "LoopUnrollPass",
548552
[](LoopUnrollOptions Opts) { return LoopUnrollPass(Opts); },

llvm/test/Analysis/Lint/abort-on-error.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
; RUN: not opt -passes=lint -disable-output --lint-abort-on-error %s 2>&1 | FileCheck %s
1+
; RUN: not opt -passes='lint<abort-on-error>' -disable-output %s 2>&1 | FileCheck %s
22

33
; CHECK: Undefined behavior: Division by zero
44
; CHECK-NEXT: %b = sdiv i32 %a, 0
5-
; CHECK-NEXT: LLVM ERROR: Linter found errors, aborting. (enabled by --lint-abort-on-error)
5+
; CHECK-NEXT: LLVM ERROR: linter found errors, aborting. (enabled by abort-on-error)
66

77
define i32 @sdiv_by_zero(i32 %a) {
88
%b = sdiv i32 %a, 0

llvm/test/Analysis/Lint/const-store.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
; RUN: not opt --mtriple=amdgcn --passes=lint --lint-abort-on-error %s -disable-output 2>&1 | FileCheck %s
1+
; RUN: not opt --mtriple=amdgcn --passes='lint<abort-on-error>' %s -disable-output 2>&1 | FileCheck %s
22
; RUN: opt --mtriple=amdgcn --mcpu=gfx1030 --passes=lint %s -disable-output 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK0
3-
; RUN: opt --mtriple=x86_64 --passes=lint --lint-abort-on-error %s -disable-output 2>&1 | FileCheck %s --allow-empty --check-prefix=NOERR
3+
; RUN: opt --mtriple=x86_64 --passes='lint<abort-on-error>' %s -disable-output 2>&1 | FileCheck %s --allow-empty --check-prefix=NOERR
44
; NOERR: {{^$}}
55

66
define amdgpu_kernel void @store_const(ptr addrspace(4) %out, i32 %a, i32 %b) {

0 commit comments

Comments
 (0)