14
14
//
15
15
// ===----------------------------------------------------------------------===//
16
16
17
+ #include " llvm/Support/CommandLine.h"
17
18
#include " swift/Basic/Assertions.h"
18
19
#undef NDEBUG
19
20
#include < cassert>
20
21
#include < iostream>
21
22
23
+ llvm::cl::opt<bool > AssertContinue (
24
+ " assert-continue" , llvm::cl::init(false ),
25
+ llvm::cl::desc(" Do not stop on an assertion failure" ));
26
+
27
+ llvm::cl::opt<bool > AssertHelp (
28
+ " assert-help" , llvm::cl::init(false ),
29
+ llvm::cl::desc(" Print help for managing assertions" ));
30
+
22
31
int CONDITIONAL_ASSERT_Global_enable_flag =
23
32
#ifdef NDEBUG
24
33
0 ; // Default to `off` in release builds
25
34
#else
26
35
0 ; // TODO: Default to `on` in debug builds
27
36
#endif
28
37
29
- [[noreturn]] void ASSERT_failure (const char *expr, const char *file, int line, const char *func) {
38
+ void ASSERT_failure (const char *expr, const char *file, int line, const char *func) {
30
39
// Only print the last component of `file`
31
40
const char *f = file;
32
41
for (const char *p = file; *p != ' \0 ' ; p++) {
@@ -35,6 +44,14 @@ int CONDITIONAL_ASSERT_Global_enable_flag =
35
44
f = p + 1 ;
36
45
}
37
46
}
47
+
48
+ if (AssertHelp) {
49
+ ASSERT_help ();
50
+ } else {
51
+ std::cerr << " Assertion help: -Xllvm -assert-help" << std::endl;
52
+ }
53
+
54
+
38
55
// Format here matches that used by `assert` on macOS:
39
56
std::cerr
40
57
<< " Assertion failed: "
@@ -43,9 +60,30 @@ int CONDITIONAL_ASSERT_Global_enable_flag =
43
60
<< " file " << f << " , "
44
61
<< " line " << line << " ."
45
62
<< std::endl;
63
+
64
+ if (AssertContinue) {
65
+ std::cerr << " Continuing after failed assertion (-Xllvm -assert-continue)" << std::endl;
66
+ return ;
67
+ }
68
+
46
69
abort ();
47
70
}
48
71
72
+ void ASSERT_help () {
73
+ static int ASSERT_help_shown = 0 ;
74
+ if (ASSERT_help_shown) {
75
+ return ;
76
+ }
77
+ ASSERT_help_shown = 1 ;
78
+
79
+ std::cerr << std::endl;
80
+ std::cerr << " Control assertion behavior with one or more of the following options:" << std::endl;
81
+ std::cerr << std::endl;
82
+ std::cerr << " -Xllvm -assert-continue" << std::endl;
83
+ std::cerr << " Continue after any failed assertion" << std::endl;
84
+ std::cerr << std::endl;
85
+ }
86
+
49
87
// This has to be callable in the same way as the macro version,
50
88
// so we can't put it inside a namespace.
51
89
#undef CONDITIONAL_ASSERT_enabled
0 commit comments