Skip to content

Commit 8fde44c

Browse files
committed
Make fatal_assertion actually "no return"
The function which actually triggers a trap, assumeDontCallMeDirectlyImpl, cannot be marked as no-return, because it only traps when handling fatal assertions. Since fatal_assertion doesn't call any no-return functions, it cannot be marked as no-return. This PR moves the call to trap directly into fatal_assertion and assertion, so that fatal_assertion can actually be declared "no return". As a side effect, assumeDontCallMeDirectly is now only doing debug printing, so it's been renamed to traceAssertionFailure, to indicate it's more limited role in assertion failure. Signed-off-by: Robert Young <rwy0717@gmail.com>
1 parent 4c5291a commit 8fde44c

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

compiler/infra/Assert.cpp

+15-18
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,13 @@ void OMR_NORETURN TR::trap()
7575
}
7676
}
7777

78-
static void assumeDontCallMeDirectlyImpl( const char * file, int32_t line, const char *condition, const char *s, va_list ap, bool fatal)
78+
79+
static void traceAssertionFailure(const char * file, int32_t line, const char *condition, const char *s, va_list ap)
7980
{
8081
TR::Compilation *comp = TR::comp();
8182

82-
// if the ignoreAssert option is set, then we ignore failing assert
83-
if (comp && comp->getOption(TR_IgnoreAssert) && !fatal)
84-
return;
85-
8683
if (!condition) condition = "";
8784

88-
// Fatal assertions fire always, however, non fatal assertions
89-
// can be disabled via TR_SoftFailOnAssume.
90-
if (comp && comp->getOption(TR_SoftFailOnAssume) && !fatal)
91-
comp->failCompilation<TR::AssertionFailure>("Assertion Failure");
92-
9385
// Default is to always print to screen
9486
bool printOnscreen = true;
9587

@@ -143,26 +135,31 @@ static void assumeDontCallMeDirectlyImpl( const char * file, int32_t line, const
143135
}
144136
comp->diagnosticImpl("\n");
145137
}
146-
147-
TR::trap();
148138
}
149139

150140
namespace TR
151141
{
152142
void assertion(const char *file, int line, const char *condition, const char *format, ...)
153143
{
154-
va_list ap;
155-
va_start(ap, format);
156-
assumeDontCallMeDirectlyImpl( file, line, condition, format, ap, false);
157-
va_end(ap);
144+
TR::Compilation *comp = TR::comp();
145+
if (comp)
146+
{
147+
// TR_IgnoreAssert: ignore nonfatal assertion failures.
148+
if (comp->getOption(TR_IgnoreAssert))
149+
return;
150+
// TR_SoftFailOnAssume: on nonfatal assertion failure, cancel the compilation without crashing the process.
151+
if (comp->getOption(TR_SoftFailOnAssume))
152+
comp->failCompilation<TR::AssertionFailure>("Assertion Failure");
153+
}
154+
fatal_assertion(file, line, condition, format);
158155
}
159156

160157
void OMR_NORETURN fatal_assertion(const char *file, int line, const char *condition, const char *format, ...)
161158
{
162159
va_list ap;
163160
va_start(ap, format);
164-
assumeDontCallMeDirectlyImpl( file, line, condition, format, ap, true);
161+
traceAssertionFailure(file, line, condition, format, ap);
165162
va_end(ap);
163+
TR::trap();
166164
}
167-
168165
}

0 commit comments

Comments
 (0)