[Mlir-commits] [mlir] c63d4fa - [mlir][sparse] Improving the FATAL macro
wren romano
llvmlistbot at llvm.org
Tue May 31 14:31:45 PDT 2022
Author: wren romano
Date: 2022-05-31T14:31:38-07:00
New Revision: c63d4fac4f2a726e1fe214dabbe574ef863fe896
URL: https://github.com/llvm/llvm-project/commit/c63d4fac4f2a726e1fe214dabbe574ef863fe896
DIFF: https://github.com/llvm/llvm-project/commit/c63d4fac4f2a726e1fe214dabbe574ef863fe896.diff
LOG: [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
Added:
Modified:
mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
index da3b705e9e9d..d307e5247ce5 100644
--- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
@@ -83,10 +83,10 @@ static inline uint64_t checkedMul(uint64_t lhs, uint64_t rhs) {
// to track down whether an error is coming from our code vs somewhere else
// in MLIR.)
#define FATAL(...) \
- { \
+ do { \
fprintf(stderr, "SparseTensorUtils: " __VA_ARGS__); \
exit(1); \
- }
+ } while (0)
// TODO: try to unify this with `SparseTensorFile::assertMatchesShape`
// which is used by `openSparseTensorCOO`. It's easy enough to resolve
More information about the Mlir-commits
mailing list