-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[JSON][NFC] Move print method out of NDEBUG || DUMP #131639
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
[JSON][NFC] Move print method out of NDEBUG || DUMP #131639
Conversation
@llvm/pr-subscribers-llvm-support Author: Nikolay Panchenko (npanchen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/131639.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Support/JSON.h b/llvm/include/llvm/Support/JSON.h
index 3e3f783ffb857..7f7f5f6228763 100644
--- a/llvm/include/llvm/Support/JSON.h
+++ b/llvm/include/llvm/Support/JSON.h
@@ -472,8 +472,8 @@ class Value {
return LLVM_LIKELY(Type == T_Array) ? &as<json::Array>() : nullptr;
}
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(llvm::raw_ostream &OS) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const {
print(llvm::dbgs());
llvm::dbgs() << '\n';
diff --git a/llvm/lib/Support/JSON.cpp b/llvm/lib/Support/JSON.cpp
index 98fef5dcf68a3..e7b762f550d46 100644
--- a/llvm/lib/Support/JSON.cpp
+++ b/llvm/lib/Support/JSON.cpp
@@ -182,9 +182,7 @@ void Value::destroy() {
}
}
-#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void Value::print(llvm::raw_ostream &OS) const { OS << *this; }
-#endif // !NDEBUG || LLVM_ENABLE_DUMP
bool operator==(const Value &L, const Value &R) {
if (L.kind() != R.kind())
|
The patch fixes the linking problem I was mentioning in the previous pull request (Release-build of LLVM + Debug-build of out-of-tree project), so it looks good from me. I am still not convinced about having this kind of conditional compilation inside a header file (if you do a global search, you will find such an ifdef only in implementation files). However I will let others discuss on this topic, as it may be fine as long as everything works. @dwblaikie @kuhar adding you as reviewers, as you are listed as maintainers for the Support library. |
Simple grep of |
Right, I was wrongly looking under a different, restricted, scope. |
Could you link to the artifacts/perhaps provide more details here about the caller, link error, etc? |
Sure, here is a reproducer for the issue that this PR aims to fix: https://gist.github.com/mscuttari/2b69f2bcbc6b0e22527d07eae10ead1e To reproduce the issue, LLVM needs to be built in Release mode and the project in Debug mode. Of course you also need to specify the The error is the classic undefined reference message, in this case related to the new |
Well, I don't think naming matters here. What matters is that |
Right, I've tried and indeed that is also problematic, I guess I have been just lucky up until now not to have ever stumbled across this problem. Imho that and similar headers should also be fixed (maybe by moving the implementation of |
I believe mixing asserts and non-asserts builds is supported in principle, but you need to take care on the exact configuration (LLVM_ENABLE_DUMP and LLVM_ENABLE_ABI_BREAKING_CHECKS need to be configured appropriately on both sides of the fence). But TBH, I'd be fine if we just generally (across the whole codebase) stopped making dump definitions conditional. I doubt that these take up enough code size for this to be worthwhile optimization. (We can keep the existing behavior that LLVM_DUMP_METHOD is only defined as LLVM_USED in assertions builds, so it can still be optimized out in LTO builds.) |
@nikic @dwblaikie are you ok if I merge this change ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print
functions shouldn't be guarded with these ifdefs AFAIK, so this looks correct
No description provided.