1
- // ===---------------- BPFAdjustOpt .cpp - Adjust Optimization ------ --------===//
1
+ // ===--------- BPFCheckUnreachableIR .cpp - Issue Unreachable Error --------===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
//
9
- // Check 'unreachable' IRs and issue proper warnings .
9
+ // Check 'unreachable' IRs and issue proper errors .
10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
19
19
#include " llvm/IR/Value.h"
20
20
#include " llvm/Pass.h"
21
21
22
- #define DEBUG_TYPE " bpf-check-undef -ir"
22
+ #define DEBUG_TYPE " bpf-check-unreachable -ir"
23
23
24
24
using namespace llvm ;
25
25
26
+ static cl::opt<bool >
27
+ DisableCheckUnreachableIR (" bpf-disable-check-unreachable-ir" , cl::Hidden,
28
+ cl::desc (" BPF: Disable Checking Unreachable IR" ),
29
+ cl::init(false ));
30
+
26
31
namespace {
27
32
28
- class BPFCheckUndefIR final : public ModulePass {
33
+ class BPFCheckUnreachableIR final : public ModulePass {
29
34
bool runOnModule (Module &F) override ;
30
35
31
36
public:
32
37
static char ID;
33
- BPFCheckUndefIR () : ModulePass(ID) {}
38
+ BPFCheckUnreachableIR () : ModulePass(ID) {}
34
39
35
40
private:
36
- void BPFCheckUndefIRImpl (Function &F);
41
+ void BPFCheckUnreachableIRImpl (Function &F);
37
42
void BPFCheckInst (Function &F, BasicBlock &BB, Instruction &I);
38
43
void HandleUnreachableInsn (Function &F, BasicBlock &BB, Instruction &I);
39
44
};
40
45
} // End anonymous namespace
41
46
42
- char BPFCheckUndefIR ::ID = 0 ;
43
- INITIALIZE_PASS (BPFCheckUndefIR , DEBUG_TYPE, " BPF Check Undef IRs" , false ,
44
- false )
47
+ char BPFCheckUnreachableIR ::ID = 0 ;
48
+ INITIALIZE_PASS (BPFCheckUnreachableIR , DEBUG_TYPE, " BPF Check Unreachable IRs" ,
49
+ false , false )
45
50
46
- ModulePass *llvm::createBPFCheckUndefIR() { return new BPFCheckUndefIR (); }
51
+ ModulePass *llvm::createBPFCheckUnreachableIR() {
52
+ return new BPFCheckUnreachableIR ();
53
+ }
47
54
48
- void BPFCheckUndefIR ::HandleUnreachableInsn (Function &F, BasicBlock &BB,
49
- Instruction &I) {
55
+ void BPFCheckUnreachableIR ::HandleUnreachableInsn (Function &F, BasicBlock &BB,
56
+ Instruction &I) {
50
57
// LLVM may create a switch statement with default to a 'unreachable' basic
51
58
// block. Do not warn for such cases.
52
59
unsigned NumNoSwitches = 0 , NumSwitches = 0 ;
@@ -73,17 +80,18 @@ void BPFCheckUndefIR::HandleUnreachableInsn(Function &F, BasicBlock &BB,
73
80
F.getContext ().diagnose (
74
81
DiagnosticInfoGeneric (Twine (" unreachable in func " )
75
82
.concat (F.getName ())
76
- .concat (" , due to uninitialized variable?" ),
77
- DS_Warning));
83
+ .concat (" , due to uninitialized variable?" )
84
+ .concat (" try -Wuninitialized?" ),
85
+ DS_Error));
78
86
}
79
87
80
- void BPFCheckUndefIR ::BPFCheckInst (Function &F, BasicBlock &BB,
81
- Instruction &I) {
88
+ void BPFCheckUnreachableIR ::BPFCheckInst (Function &F, BasicBlock &BB,
89
+ Instruction &I) {
82
90
if (I.getOpcode () == Instruction::Unreachable)
83
91
HandleUnreachableInsn (F, BB, I);
84
92
}
85
93
86
- void BPFCheckUndefIR::BPFCheckUndefIRImpl (Function &F) {
94
+ void BPFCheckUnreachableIR::BPFCheckUnreachableIRImpl (Function &F) {
87
95
// A 'unreachable' will be added to the end of naked function.
88
96
// Let ignore these naked functions.
89
97
if (F.hasFnAttribute (Attribute::Naked))
@@ -95,8 +103,10 @@ void BPFCheckUndefIR::BPFCheckUndefIRImpl(Function &F) {
95
103
}
96
104
}
97
105
98
- bool BPFCheckUndefIR::runOnModule (Module &M) {
106
+ bool BPFCheckUnreachableIR::runOnModule (Module &M) {
107
+ if (DisableCheckUnreachableIR)
108
+ return false ;
99
109
for (Function &F : M)
100
- BPFCheckUndefIRImpl (F);
110
+ BPFCheckUnreachableIRImpl (F);
101
111
return false ;
102
112
}
0 commit comments