Skip to content

Commit e750e98

Browse files
committed
fix assert_unreachable
1 parent a550477 commit e750e98

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

include/deal.II/base/exception_macros.h

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -870,43 +870,33 @@
870870
* This macro is first used in step-7, where we show another example of
871871
* a context where it is frequently used.
872872
*/
873-
#if DEAL_II_KOKKOS_VERSION_GTE(3, 6, 0)
874-
# define DEAL_II_ASSERT_UNREACHABLE() \
875-
Kokkos::abort("ASSERT_UNREACHABLE reached.");
876-
#else
877-
# define DEAL_II_ASSERT_UNREACHABLE() \
878-
::dealii::deal_II_exceptions::internals::issue_error_noreturn( \
879-
::dealii::deal_II_exceptions::internals::ExceptionHandling:: \
880-
abort_or_throw_on_exception, \
881-
__FILE__, \
882-
__LINE__, \
883-
__PRETTY_FUNCTION__, \
884-
nullptr, \
885-
nullptr, \
886-
::dealii::StandardExceptions::ExcMessage( \
887-
"The program has hit a line of code that the programmer " \
888-
"marked with the macro DEAL_II_ASSERT_UNREACHABLE() to " \
889-
"indicate that the program should never reach this " \
890-
"location. You will have to find out (best done in a " \
891-
"debugger) why that happened. Typical reasons include " \
892-
"passing invalid arguments to functions (for example, if " \
893-
"a function takes an 'enum' with two possible values " \
894-
"as argument, but you call the function with a third " \
895-
"value), or if the programmer of the code that triggered " \
896-
"the error believed that a variable can only have " \
897-
"specific values, but either that assumption is wrong " \
898-
"or the computation of that value is buggy." \
899-
"\n\n" \
900-
"In those latter conditions, where some internal " \
901-
"assumption is not satisfied, there may not be very " \
902-
"much you can do if you encounter such an exception, " \
903-
"since it indicates an error in deal.II, not in your " \
904-
"own program. If that is the situation you encounter, " \
905-
"try to come up with " \
906-
"the smallest possible program that still demonstrates " \
907-
"the error and contact the deal.II mailing lists with it " \
908-
"to obtain help."))
909-
#endif
873+
#define DEAL_II_ASSERT_UNREACHABLE() \
874+
::dealii::deal_II_exceptions::internals::do_unreachable( \
875+
__FILE__, \
876+
__LINE__, \
877+
__PRETTY_FUNCTION__, \
878+
"The program has hit a line of code that the programmer " \
879+
"marked with the macro DEAL_II_ASSERT_UNREACHABLE() to " \
880+
"indicate that the program should never reach this " \
881+
"location. You will have to find out (best done in a " \
882+
"debugger) why that happened. Typical reasons include " \
883+
"passing invalid arguments to functions (for example, if " \
884+
"a function takes an 'enum' with two possible values " \
885+
"as argument, but you call the function with a third " \
886+
"value), or if the programmer of the code that triggered " \
887+
"the error believed that a variable can only have " \
888+
"specific values, but either that assumption is wrong " \
889+
"or the computation of that value is buggy." \
890+
"\n\n" \
891+
"In those latter conditions, where some internal " \
892+
"assumption is not satisfied, there may not be very " \
893+
"much you can do if you encounter such an exception, " \
894+
"since it indicates an error in deal.II, not in your " \
895+
"own program. If that is the situation you encounter, " \
896+
"try to come up with " \
897+
"the smallest possible program that still demonstrates " \
898+
"the error and contact the deal.II mailing lists with it " \
899+
"to obtain help.")
910900

911901
/**
912902
* Special assertion for dimension mismatch.

include/deal.II/base/exceptions.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,40 @@ namespace deal_II_exceptions
10771077
}
10781078
}
10791079

1080+
/**
1081+
* Internal function that performs the error handling when
1082+
* DEAL_II_ASSERT_UNREACHABLE is triggered.
1083+
*/
1084+
DEAL_II_HOST_DEVICE void
1085+
do_unreachable(const char *file,
1086+
int line,
1087+
const char *function,
1088+
const char *msg)
1089+
{
1090+
#if DEAL_II_KOKKOS_VERSION_GTE(3, 6, 0)
1091+
KOKKOS_IF_ON_DEVICE(({ Kokkos::abort(msg); }))
1092+
KOKKOS_IF_ON_HOST(({
1093+
issue_error_noreturn(::dealii::deal_II_exceptions::internals::
1094+
ExceptionHandling::abort_or_throw_on_exception,
1095+
file,
1096+
line,
1097+
function,
1098+
nullptr,
1099+
nullptr,
1100+
::dealii::StandardExceptions::ExcMessage(msg));
1101+
}))
1102+
#else
1103+
issue_error_noreturn(::dealii::deal_II_exceptions::internals::
1104+
ExceptionHandling::abort_or_throw_on_exception,
1105+
file,
1106+
line,
1107+
function,
1108+
nullptr,
1109+
nullptr,
1110+
::dealii::StandardExceptions::ExcMessage(msg));
1111+
#endif
1112+
}
1113+
10801114
/**
10811115
* Internal function that does the work of issue_error_nothrow.
10821116
*/

0 commit comments

Comments
 (0)