Skip to content

Commit c63d4fa

Browse files
committed
[mlir][sparse] Improving the FATAL macro
The previous macro definition using `{...}` would fail to compile when the callsite uses a semicolon followed by an else-statement (i.e., `if (...) FATAL(...); else ...;`). Replacing the simple braces with `do{...}while(0)` (n.b., semicolon not included in the macro definition) enables callsites to use the semicolon plus else-statement syntax without problems. The new definition now requires the semicolon at all callsites, but since it was already being called that way nothing changes. For more explanation, see <https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html> Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D126514
1 parent da9d41c commit c63d4fa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mlir/lib/ExecutionEngine/SparseTensorUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ static inline uint64_t checkedMul(uint64_t lhs, uint64_t rhs) {
8383
// to track down whether an error is coming from our code vs somewhere else
8484
// in MLIR.)
8585
#define FATAL(...) \
86-
{ \
86+
do { \
8787
fprintf(stderr, "SparseTensorUtils: " __VA_ARGS__); \
8888
exit(1); \
89-
}
89+
} while (0)
9090

9191
// TODO: try to unify this with `SparseTensorFile::assertMatchesShape`
9292
// which is used by `openSparseTensorCOO`. It's easy enough to resolve

0 commit comments

Comments
 (0)