33
33
34
34
using namespace swift ;
35
35
36
+ // Print the message string of encountered `cond_fail` instructions the first
37
+ // time the message string is encountered.
38
+ static llvm::cl::opt<bool > PrintCondFailMessages (
39
+ " print-cond-fail-messages" , llvm::cl::init(false ),
40
+ llvm::cl::desc(" print cond_fail messages" ));
41
+ static llvm::DenseSet<StringRef> CondFailMessages;
42
+
36
43
static bool cleanFunction (SILFunction &fn) {
37
44
bool madeChange = false ;
38
45
@@ -43,6 +50,26 @@ static bool cleanFunction(SILFunction &fn) {
43
50
SILInstruction *inst = &*i;
44
51
++i;
45
52
53
+ // Print cond_fail messages the first time a specific cond_fail message
54
+ // string is encountered.
55
+ // Run the swift-frontend in a mode that will generate LLVM IR adding
56
+ // the option `-print-cond-fail-messages` will dump all cond_fail
57
+ // message strings encountered in the SIL.
58
+ // ```
59
+ // % swift-frontend -Xllvm -print-cond-fail-messages -emit-ir/-c ...
60
+ // ...
61
+ // cond_fail message encountered: Range out of bounds
62
+ // cond_fail message encountered: Array index is out of range
63
+ // ...
64
+ // ```
65
+ if (PrintCondFailMessages) {
66
+ if (auto CFI = dyn_cast<CondFailInst>(inst)) {
67
+ auto msg = CFI->getMessage ();
68
+ if (CondFailMessages.insert (msg).second )
69
+ llvm::dbgs () << " cond_fail message encountered: " << msg << " \n " ;
70
+ }
71
+ }
72
+
46
73
// Remove calls to Builtin.poundAssert() and Builtin.staticReport().
47
74
auto *bi = dyn_cast<BuiltinInst>(inst);
48
75
if (!bi) {
0 commit comments