Skip to content

Commit

Permalink
[flang] Do not print backtrace for most TODOs.
Browse files Browse the repository at this point in the history
There are two ways to interrupt flang when a TODO is hit: abort or
exit with non-zero exit code. Abort implies printing the backtrace
and "PLEASE submit a bug report" message. We used to use abort
only in debug compiler build. Since the TODOs are already known
problems it may be counterproductive to ask debug compiler users
to submit bug reports. In addition, the TODO messages are pretty
self-explanatory, so the backtrace printing seems to be redundant.

This change makes all TODOs non-aborting. I added TODO_.*TRACE macros
for TODOs that may benefit from the backtrace and the "bug report"
message in the debug compiler. These macros are currently unused.

Differential Revision: https://reviews.llvm.org/D143761
  • Loading branch information
vzakhari committed Feb 10, 2023
1 parent d2cc2c5 commit e8a79dc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
54 changes: 23 additions & 31 deletions flang/include/flang/Optimizer/Builder/Todo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,40 @@
#undef TODOQUOTE
#define TODOQUOTE(X) #X

// Give backtrace only in debug builds.
#undef GEN_TRACE
#ifdef NDEBUG

// In a release build, just give a message and exit.
#define TODO_NOLOC(ToDoMsg) \
do { \
llvm::errs() << __FILE__ << ':' << __LINE__ \
<< ": not yet implemented: " << ToDoMsg << '\n'; \
std::exit(1); \
} while (false)

#undef TODO_DEFN
#define TODO_DEFN(MlirLoc, ToDoMsg, ToDoFile, ToDoLine) \
do { \
mlir::emitError(MlirLoc, ToDoFile ":" TODOQUOTE( \
ToDoLine) ": not yet implemented: " ToDoMsg); \
std::exit(1); \
} while (false)

#define TODO(MlirLoc, ToDoMsg) TODO_DEFN(MlirLoc, ToDoMsg, __FILE__, __LINE__)

#define GEN_TRACE false
#else
#define GEN_TRACE true
#endif

// In a developer build, print a message and give a backtrace.
#undef TODO_NOLOCDEFN
#define TODO_NOLOCDEFN(ToDoMsg, ToDoFile, ToDoLine) \
#define TODO_NOLOCDEFN(ToDoMsg, ToDoFile, ToDoLine, GenTrace) \
do { \
llvm::report_fatal_error( \
ToDoFile ":" TODOQUOTE(ToDoLine) ": not yet implemented: " ToDoMsg); \
llvm::report_fatal_error(llvm::Twine(ToDoFile ":" TODOQUOTE( \
ToDoLine) ": not yet implemented: ") + \
llvm::Twine(ToDoMsg), \
GenTrace); \
} while (false)

#define TODO_NOLOC(ToDoMsg) TODO_NOLOCDEFN(ToDoMsg, __FILE__, __LINE__)
#define TODO_NOLOC(ToDoMsg) TODO_NOLOCDEFN(ToDoMsg, __FILE__, __LINE__, false)
#define TODO_NOLOC_TRACE(ToDoMsg) \
TODO_NOLOCDEFN(ToDoMsg, __FILE__, __LINE__, GENTRACE)

#undef TODO_DEFN
#define TODO_DEFN(MlirLoc, ToDoMsg, ToDoFile, ToDoLine) \
#define TODO_DEFN(MlirLoc, ToDoMsg, ToDoFile, ToDoLine, GenTrace) \
do { \
fir::emitFatalError( \
MlirLoc, \
ToDoFile ":" TODOQUOTE(ToDoLine) ": not yet implemented: " ToDoMsg); \
fir::emitFatalError(MlirLoc, \
llvm::Twine(ToDoFile ":" TODOQUOTE( \
ToDoLine) ": not yet implemented: ") + \
llvm::Twine(ToDoMsg), \
GenTrace); \
} while (false)

#define TODO(MlirLoc, ToDoMsg) TODO_DEFN(MlirLoc, ToDoMsg, __FILE__, __LINE__)

#endif
#define TODO(MlirLoc, ToDoMsg) \
TODO_DEFN(MlirLoc, ToDoMsg, __FILE__, __LINE__, false)
#define TODO_TRACE(MlirLoc, ToDoMsg) \
TODO_DEFN(MlirLoc, ToDoMsg, __FILE__, __LINE__, GEN_TRACE)

#endif // FORTRAN_LOWER_TODO_H
9 changes: 6 additions & 3 deletions flang/include/flang/Optimizer/Support/FatalError.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
namespace fir {

/// Fatal error reporting helper. Report a fatal error with a source location
/// and immediately abort flang.
/// and immediately interrupt flang. If `genCrashDiag` is true, then
/// the execution is aborted and the backtrace is printed, otherwise,
/// flang exits with non-zero exit code and without backtrace printout.
[[noreturn]] inline void emitFatalError(mlir::Location loc,
const llvm::Twine &message) {
const llvm::Twine &message,
bool genCrashDiag = true) {
mlir::emitError(loc, message);
llvm::report_fatal_error("aborting");
llvm::report_fatal_error("aborting", genCrashDiag);
}

} // namespace fir
Expand Down
15 changes: 9 additions & 6 deletions flang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@
ToolSubst('%flang_fc1', command=FindTool('flang-new'), extra_args=['-fc1'],
unresolved='fatal')]

# Flang has several unimplemented features. TODO messages are used to mark and fail if these
# features are exercised. TODOs exit with an error in non-assert builds but in assert builds
# it aborts. To catch aborts, the `--crash` option for the `not` command has to be used.
# Flang has several unimplemented features. TODO messages are used to mark
# and fail if these features are exercised. Some TODOs exit with a non-zero
# exit code, but others abort the execution in assert builds.
# To catch aborts, the `--crash` option for the `not` command has to be used.
tools.append(ToolSubst('%not_todo_cmd', command=FindTool('not'), unresolved='fatal'))
if 'asserts' in config.available_features:
tools.append(ToolSubst('%not_todo_cmd', command=FindTool('not'), extra_args=['--crash'],
unresolved='fatal'))
tools.append(ToolSubst('%not_todo_abort_cmd', command=FindTool('not'),
extra_args=['--crash'], unresolved='fatal'))
else:
tools.append(ToolSubst('%not_todo_cmd', command=FindTool('not'), unresolved='fatal'))
tools.append(ToolSubst('%not_todo_abort_cmd', command=FindTool('not'),
unresolved='fatal'))

# Define some variables to help us test that the flang runtime doesn't depend on
# the C++ runtime libraries. For this we need a C compiler. If for some reason
Expand Down

0 comments on commit e8a79dc

Please sign in to comment.