Skip to content

Commit 93640d3

Browse files
committed
vpr: Re-work error suppression to use VPR_ERROR() instead of VPR_THROW()
Historically VPR_THROW() has been used to unconditionally throw an exception (to signal an error). Since some parts of the code rely on this unconditional behaviour, VPR_THROWs should not be suppress-able. (If VPR_THROW is allowed to be suppressible a number of new compiler warnings are generated since calls to it can now return.) Instead, this commit adds VPR_ERROR() which signals an error which (by default) throws an exception, but which may be converted/supressed to a warning (i.e. to signal a non-fatal error). * VPR_THROW() should now be used for unconditional fatal errors. * VPR_ERROR() should now be used for suppressible (non-fatal) errors. Since the code-base did not previously make the distinction between fatal/non-fatal errors, there are likely a number of legacy VPR_THROWs (but not all) which can be converted to VPR_ERRORs in the future.
1 parent 7fcf6ed commit 93640d3

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

vpr/src/util/vpr_error.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void vpr_throw(enum e_vpr_error type,
3434
// Reset variable argument list
3535
va_end(va_args);
3636

37-
throw VprError(type, msg, psz_file_name, line_num);
37+
vpr_throw_msg(type, psz_file_name, line_num, msg);
3838
}
3939

4040
void vvpr_throw(enum e_vpr_error type,
@@ -45,7 +45,7 @@ void vvpr_throw(enum e_vpr_error type,
4545
//Format the message
4646
std::string msg = vtr::vstring_fmt(psz_message, va_args);
4747

48-
throw VprError(type, msg, psz_file_name, line_num);
48+
vpr_throw_msg(type, psz_file_name, line_num, msg);
4949
}
5050

5151
void vpr_throw_msg(enum e_vpr_error type,
@@ -72,13 +72,13 @@ void vpr_throw_opt(enum e_vpr_error type,
7272
//Format the message
7373
std::string msg = vtr::vstring_fmt(psz_message, va_args);
7474

75+
// Reset variable argument list
76+
va_end(va_args);
77+
7578
auto result = functions_to_demote.find(func_name);
7679
if (result != functions_to_demote.end()) {
7780
VTR_LOGFF_WARN(psz_file_name, line_num, psz_func_name, msg.data());
7881
} else {
7982
vpr_throw_msg(type, psz_file_name, line_num, msg);
8083
}
81-
82-
// Reset variable argument list
83-
va_end(va_args);
8484
}

vpr/src/util/vpr_error.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,45 @@ void map_error_activation_status(std::string function_name);
6868

6969
void vpr_throw_opt(enum e_vpr_error type, const char* psz_func_name, const char* psz_file_name, unsigned int line_num, const char* psz_message, ...);
7070

71+
//Figure out what macro to use to get the name of the current function
72+
// We default to __func__ which is defined in C99
73+
//
74+
// g++ > 2.6 define __PRETTY_FUNC__ which includes class/namespace/overload
75+
// information, so we prefer to use it if possible
76+
#define VPR_THROW_FUNCTION __func__
77+
#ifdef __GNUC__
78+
# ifdef __GNUC_MINOR__
79+
# if __GNUC__ >= 2 && __GNUC_MINOR__ > 6
80+
# undef VPR_THROW_FUNCTION
81+
# define VPR_THROW_FUNCTION __PRETTY_FUNCTION__
82+
# endif
83+
# endif
84+
#endif
85+
86+
7187
/*
7288
* Macro wrapper around vpr_throw() which automatically
7389
* specifies file and line number of call site.
90+
*
91+
* VPR_THROW() is used to signal an *unconditional* fatal error which should
92+
* stop the program.
7493
*/
7594
#define VPR_THROW(type, ...) \
7695
do { \
77-
vpr_throw_opt(type, __func__, __FILE__, __LINE__, __VA_ARGS__); \
96+
vpr_throw(type, __FILE__, __LINE__, __VA_ARGS__); \
97+
} while (false)
98+
99+
/*
100+
* Macro wrapper around vpr_throw_opt() which automatically
101+
* specifies file and line number of call site.
102+
*
103+
* VPR_ERROR() is used to signal an error (potentially non-fatal) which by
104+
* default stops the program, but may be suppressed (i.e. converted to a
105+
* warning).
106+
*/
107+
#define VPR_ERROR(type, ...) \
108+
do { \
109+
vpr_throw_opt(type, VPR_THROW_FUNCTION, __FILE__, __LINE__, __VA_ARGS__); \
78110
} while (false)
79111

80112
#endif

0 commit comments

Comments
 (0)