Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: Clean up and fix UB in VAST_[CHECK,ASSERT,UNREACHABLE] macros. #487

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions include/vast/Util/Warnings.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in include/vast/Util/Warnings.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on include/vast/Util/Warnings.hpp

File include/vast/Util/Warnings.hpp does not conform to Custom style guidelines. (lines 100, 102, 103, 105, 107, 108, 110, 111, 113, 114, 116, 117, 120, 121, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132)
* Copyright (c) 2021 Trail of Bits, Inc.
*/

Expand Down Expand Up @@ -85,32 +85,51 @@
llvm::raw_ostream& vast_debug();

#define VAST_ERROR(...) do { \
vast_error() << "[VAST Error] " << llvm::formatv(__VA_ARGS__) << "\n"; \
vast_error() << "[VAST error] " << llvm::formatv(__VA_ARGS__) << "\n"; \
} while(0)

#define VAST_REPORT(...) do { \
vast_debug() << "[VAST Debug] " << llvm::formatv(__VA_ARGS__) << "\n"; \
vast_debug() << "[VAST debug] " << llvm::formatv(__VA_ARGS__) << "\n"; \
} while(0)

#define VAST_UNREACHABLE(...) do { \
VAST_ERROR(__VA_ARGS__); \
llvm_unreachable(nullptr); \
} while (0)

#define VAST_UNIMPLEMENTED VAST_UNREACHABLE("not implemented: {0}", __PRETTY_FUNCTION__)
#define VAST_TRAP LLVM_BUILTIN_TRAP

#define VAST_UNIMPLEMENTED_MSG(msg) \
VAST_UNREACHABLE("not implemented: {0} because {1}", __PRETTY_FUNCTION__, msg)

#define VAST_UNIMPLEMENTED_IF(cond) \
if (cond) { VAST_UNREACHABLE("not implemented: {0}", __PRETTY_FUNCTION__); }
#define VAST_FATAL(...) do { \
vast_error() << "[VAST fatal] " << llvm::formatv(__VA_ARGS__) << "\n"; \
VAST_TRAP; \
} while(0)

#define VAST_DEBUG(fmt, ...) LLVM_DEBUG(VAST_REPORT(__VA_ARGS__))
#define VAST_CHECK(cond, fmt, ...) \
if (!(cond)) { VAST_FATAL(fmt __VA_OPT__(,) __VA_ARGS__); }

#define VAST_CHECK(cond, fmt, ...) if (!(cond)) { VAST_UNREACHABLE(fmt __VA_OPT__(,) __VA_ARGS__); }
#define VAST_UNIMPLEMENTED \
VAST_FATAL("not implemented: {0}", __PRETTY_FUNCTION__)

#define VAST_ASSERT(cond) if (!(cond)) { VAST_UNREACHABLE("assertion: " #cond " failed"); }
#define VAST_UNIMPLEMENTED_MSG(msg) \
VAST_FATAL("not implemented: {0} because {1}", __PRETTY_FUNCTION__, msg)

#define VAST_TODO(fmt, ... ) VAST_UNREACHABLE("[vast-todo]: " # fmt __VA_OPT__(,) __VA_ARGS__ )
#define VAST_UNIMPLEMENTED_IF(cond) \
if (cond) { VAST_FATAL("not implemented: {0}", __PRETTY_FUNCTION__); }


#define VAST_TODO(fmt, ... ) \
VAST_FATAL("[VAST TODO]: " # fmt __VA_OPT__(,) __VA_ARGS__ )

#if !defined(NDEBUG)
#define VAST_ASSERT(cond) \
if (!(cond)) { \
vast_error() << "[VAST assert] " << llvm::formatv(#cond) << " failed\n"; \
VAST_TRAP; \
}
#elif defined(VAST_RELEASE_WITH_ASSERTS)
#define VAST_ASSERT(...) VAST_CHECK(__VA_ARGS__)
#else
#define VAST_ASSERT(...)
#endif

} // namespace vast