-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[llvm] properly guard dump methods in Support lib classes #139938
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
Conversation
@llvm/pr-subscribers-llvm-adt @llvm/pr-subscribers-clang Author: Andrew Rogers (andrurogerz) ChangesPurposeAdd proper preprocessor guards for all Overview
NOTE: For many of these BackgroundThis PR is a redo of #139804 with some changes to fix clang and unit test build breaks. This issue was raised in comments on #136629. I am addressing it as a separate change since it is independent from the changes being made in that PR. According to this documentation,
Validation
Full diff: https://github.com/llvm/llvm-project/pull/139938.diff 20 Files Affected:
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index d4052ef90de6e..3105dfa4dae55 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -301,8 +301,10 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
llvm_unreachable("Unsupported expression to reason about!");
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Dumps SMT formula
LLVM_DUMP_METHOD void dump() const { Solver->dump(); }
+#endif
protected:
// Check whether a new model is satisfiable, and update the program state.
diff --git a/llvm/include/llvm/ADT/APFixedPoint.h b/llvm/include/llvm/ADT/APFixedPoint.h
index 70d7f325702cf..89d2a93a06a26 100644
--- a/llvm/include/llvm/ADT/APFixedPoint.h
+++ b/llvm/include/llvm/ADT/APFixedPoint.h
@@ -249,7 +249,10 @@ class APFixedPoint {
}
void print(raw_ostream &) const;
- void dump() const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
// If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1.
int compare(const APFixedPoint &Other) const;
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index ed49380cfc05f..b88cbc56c105c 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -1483,7 +1483,10 @@ class APFloat : public APFloatBase {
}
void print(raw_ostream &) const;
- void dump() const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
bool getExactInverse(APFloat *inv) const {
APFLOAT_DISPATCH_ON_SEMANTICS(getExactInverse(inv));
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 7fbf09b44e6c4..44260c7eca309 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1896,8 +1896,10 @@ class [[nodiscard]] APInt {
/// FoldingSets.
void Profile(FoldingSetNodeID &id) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// debug method
- void dump() const;
+ LLVM_DUMP_METHOD void dump() const;
+#endif
/// Returns whether this instance allocated memory.
bool needsCleanup() const { return !isSingleWord(); }
diff --git a/llvm/include/llvm/ADT/DynamicAPInt.h b/llvm/include/llvm/ADT/DynamicAPInt.h
index ff958d48e7731..bb65a08a968d9 100644
--- a/llvm/include/llvm/ADT/DynamicAPInt.h
+++ b/llvm/include/llvm/ADT/DynamicAPInt.h
@@ -216,7 +216,9 @@ class DynamicAPInt {
void static_assert_layout(); // NOLINT
raw_ostream &print(raw_ostream &OS) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
+#endif
};
inline raw_ostream &operator<<(raw_ostream &OS, const DynamicAPInt &X) {
diff --git a/llvm/include/llvm/ADT/SlowDynamicAPInt.h b/llvm/include/llvm/ADT/SlowDynamicAPInt.h
index ec1021892cf4d..c9aef96b9e1c3 100644
--- a/llvm/include/llvm/ADT/SlowDynamicAPInt.h
+++ b/llvm/include/llvm/ADT/SlowDynamicAPInt.h
@@ -79,7 +79,10 @@ class SlowDynamicAPInt {
unsigned getBitWidth() const { return Val.getBitWidth(); }
void print(raw_ostream &OS) const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
+#endif
};
inline raw_ostream &operator<<(raw_ostream &OS, const SlowDynamicAPInt &X) {
diff --git a/llvm/include/llvm/ADT/TrieRawHashMap.h b/llvm/include/llvm/ADT/TrieRawHashMap.h
index e312967edeb58..1382eac1c768f 100644
--- a/llvm/include/llvm/ADT/TrieRawHashMap.h
+++ b/llvm/include/llvm/ADT/TrieRawHashMap.h
@@ -90,7 +90,10 @@ class ThreadSafeTrieRawHashMapBase {
static void *operator new(size_t Size) { return ::operator new(Size); }
void operator delete(void *Ptr) { ::operator delete(Ptr); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
+#endif
+
void print(raw_ostream &OS) const;
protected:
@@ -214,7 +217,10 @@ class ThreadSafeTrieRawHashMap : public ThreadSafeTrieRawHashMapBase {
using ThreadSafeTrieRawHashMapBase::operator delete;
using HashType = HashT;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
using ThreadSafeTrieRawHashMapBase::dump;
+#endif
+
using ThreadSafeTrieRawHashMapBase::print;
private:
diff --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h
index 1f1fd1967efbc..d9e553a8a8c77 100644
--- a/llvm/include/llvm/ADT/Twine.h
+++ b/llvm/include/llvm/ADT/Twine.h
@@ -507,14 +507,16 @@ namespace llvm {
/// stream \p OS.
void print(raw_ostream &OS) const;
- /// Dump the concatenated string represented by this twine to stderr.
- void dump() const;
-
/// Write the representation of this twine to the stream \p OS.
void printRepr(raw_ostream &OS) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ /// Dump the concatenated string represented by this twine to stderr.
+ LLVM_DUMP_METHOD void dump() const;
+
/// Dump the representation of this twine to stderr.
- void dumpRepr() const;
+ LLVM_DUMP_METHOD void dumpRepr() const;
+#endif
/// @}
};
diff --git a/llvm/include/llvm/Support/BranchProbability.h b/llvm/include/llvm/Support/BranchProbability.h
index 570531e6b9e92..42fe225709ef8 100644
--- a/llvm/include/llvm/Support/BranchProbability.h
+++ b/llvm/include/llvm/Support/BranchProbability.h
@@ -77,7 +77,9 @@ class BranchProbability {
LLVM_ABI raw_ostream &print(raw_ostream &OS) const;
- LLVM_ABI void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
/// Scale a large integer.
///
diff --git a/llvm/include/llvm/Support/DebugCounter.h b/llvm/include/llvm/Support/DebugCounter.h
index 529a9f86f2e34..9611586a92c3b 100644
--- a/llvm/include/llvm/Support/DebugCounter.h
+++ b/llvm/include/llvm/Support/DebugCounter.h
@@ -119,8 +119,10 @@ class DebugCounter {
Counter.CurrChunkIdx = State.ChunkIdx;
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
// Dump or print the current counter set into llvm::dbgs().
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+ LLVM_DUMP_METHOD void dump() const;
+#endif
LLVM_ABI void print(raw_ostream &OS) const;
diff --git a/llvm/include/llvm/Support/KnownBits.h b/llvm/include/llvm/Support/KnownBits.h
index 6a14328d431a4..e8dc1c2422646 100644
--- a/llvm/include/llvm/Support/KnownBits.h
+++ b/llvm/include/llvm/Support/KnownBits.h
@@ -513,7 +513,10 @@ struct KnownBits {
bool operator!=(const KnownBits &Other) const { return !(*this == Other); }
LLVM_ABI void print(raw_ostream &OS) const;
- LLVM_ABI void dump() const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
private:
// Internal helper for getting the initial KnownBits for an `srem` or `urem`
diff --git a/llvm/include/llvm/Support/SMTAPI.h b/llvm/include/llvm/Support/SMTAPI.h
index f1bb86cf81f1c..aed6241219c39 100644
--- a/llvm/include/llvm/Support/SMTAPI.h
+++ b/llvm/include/llvm/Support/SMTAPI.h
@@ -71,7 +71,9 @@ class SMTSort {
virtual void print(raw_ostream &OS) const = 0;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
protected:
/// Query the SMT solver and returns true if two sorts are equal (same kind
@@ -118,7 +120,9 @@ class SMTExpr {
virtual void print(raw_ostream &OS) const = 0;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
protected:
/// Query the SMT solver and returns true if two sorts are equal (same kind
@@ -136,7 +140,9 @@ class SMTSolverStatistics {
virtual void print(raw_ostream &OS) const = 0;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
};
/// Shared pointer for SMTExprs, used by SMTSolver API.
@@ -152,7 +158,9 @@ class SMTSolver {
SMTSolver() = default;
virtual ~SMTSolver() = default;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
// Returns an appropriate floating-point sort for the given bitwidth.
SMTSortRef getFloatSort(unsigned BitWidth) {
diff --git a/llvm/include/llvm/Support/ScaledNumber.h b/llvm/include/llvm/Support/ScaledNumber.h
index 87a56809976a3..3d38677f0eb61 100644
--- a/llvm/include/llvm/Support/ScaledNumber.h
+++ b/llvm/include/llvm/Support/ScaledNumber.h
@@ -424,7 +424,10 @@ class ScaledNumberBase {
public:
static constexpr int DefaultPrecision = 10;
- LLVM_ABI static void dump(uint64_t D, int16_t E, int Width);
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD static void dump(uint64_t D, int16_t E, int Width);
+#endif
+
LLVM_ABI static raw_ostream &print(raw_ostream &OS, uint64_t D, int16_t E,
int Width, unsigned Precision);
LLVM_ABI static std::string toString(uint64_t D, int16_t E, int Width,
@@ -607,7 +610,12 @@ template <class DigitsT> class ScaledNumber : ScaledNumberBase {
unsigned Precision = DefaultPrecision) const {
return ScaledNumberBase::print(OS, Digits, Scale, Width, Precision);
}
- void dump() const { return ScaledNumberBase::dump(Digits, Scale, Width); }
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const {
+ return ScaledNumberBase::dump(Digits, Scale, Width);
+ }
+#endif
ScaledNumber &operator+=(const ScaledNumber &X) {
std::tie(Digits, Scale) =
diff --git a/llvm/lib/Support/APFixedPoint.cpp b/llvm/lib/Support/APFixedPoint.cpp
index f395919287b72..9a7caa4112625 100644
--- a/llvm/lib/Support/APFixedPoint.cpp
+++ b/llvm/lib/Support/APFixedPoint.cpp
@@ -439,7 +439,10 @@ void APFixedPoint::print(raw_ostream &OS) const {
Sema.print(OS);
OS << "})";
}
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void APFixedPoint::dump() const { print(llvm::errs()); }
+#endif
APFixedPoint APFixedPoint::negate(bool *Overflow) const {
if (!isSaturated()) {
diff --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp
index a6de07a55482a..9c4a4429ca0ee 100644
--- a/llvm/lib/Support/DebugCounter.cpp
+++ b/llvm/lib/Support/DebugCounter.cpp
@@ -248,6 +248,8 @@ bool DebugCounter::shouldExecuteImpl(unsigned CounterName) {
return true;
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DebugCounter::dump() const {
print(dbgs());
}
+#endif
diff --git a/llvm/lib/Support/DynamicAPInt.cpp b/llvm/lib/Support/DynamicAPInt.cpp
index bfcb97e0cc96a..9def5c782af4c 100644
--- a/llvm/lib/Support/DynamicAPInt.cpp
+++ b/llvm/lib/Support/DynamicAPInt.cpp
@@ -32,4 +32,6 @@ raw_ostream &DynamicAPInt::print(raw_ostream &OS) const {
return OS << ValLarge;
}
-void DynamicAPInt::dump() const { print(dbgs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void DynamicAPInt::dump() const { print(dbgs()); }
+#endif
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 16229598b612a..94a04ab90987a 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -1152,7 +1152,10 @@ void KnownBits::print(raw_ostream &OS) const {
OS << "?";
}
}
-void KnownBits::dump() const {
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void KnownBits::dump() const {
print(dbgs());
dbgs() << "\n";
}
+#endif
diff --git a/llvm/lib/Support/ScaledNumber.cpp b/llvm/lib/Support/ScaledNumber.cpp
index 85d7afbea5c69..33e8cc3030873 100644
--- a/llvm/lib/Support/ScaledNumber.cpp
+++ b/llvm/lib/Support/ScaledNumber.cpp
@@ -317,7 +317,9 @@ raw_ostream &ScaledNumberBase::print(raw_ostream &OS, uint64_t D, int16_t E,
return OS << toString(D, E, Width, Precision);
}
-void ScaledNumberBase::dump(uint64_t D, int16_t E, int Width) {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void ScaledNumberBase::dump(uint64_t D, int16_t E, int Width) {
print(dbgs(), D, E, Width, 0) << "[" << Width << ":" << D << "*2^" << E
<< "]";
}
+#endif
diff --git a/llvm/lib/Support/SlowDynamicAPInt.cpp b/llvm/lib/Support/SlowDynamicAPInt.cpp
index 8b4030ddf9fc4..a57fec2f824e1 100644
--- a/llvm/lib/Support/SlowDynamicAPInt.cpp
+++ b/llvm/lib/Support/SlowDynamicAPInt.cpp
@@ -283,4 +283,6 @@ SlowDynamicAPInt &SlowDynamicAPInt::operator--() {
/// ---------------------------------------------------------------------------
void SlowDynamicAPInt::print(raw_ostream &OS) const { OS << Val; }
-void SlowDynamicAPInt::dump() const { print(dbgs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void SlowDynamicAPInt::dump() const { print(dbgs()); }
+#endif
diff --git a/llvm/lib/Support/Z3Solver.cpp b/llvm/lib/Support/Z3Solver.cpp
index 9aece099b0629..27027093a0c6f 100644
--- a/llvm/lib/Support/Z3Solver.cpp
+++ b/llvm/lib/Support/Z3Solver.cpp
@@ -989,7 +989,9 @@ llvm::SMTSolverRef llvm::CreateZ3Solver() {
#endif
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void SMTSort::dump() const { print(llvm::errs()); }
LLVM_DUMP_METHOD void SMTExpr::dump() const { print(llvm::errs()); }
LLVM_DUMP_METHOD void SMTSolver::dump() const { print(llvm::errs()); }
LLVM_DUMP_METHOD void SMTSolverStatistics::dump() const { print(llvm::errs()); }
+#endif
|
@llvm/pr-subscribers-llvm-support Author: Andrew Rogers (andrurogerz) ChangesPurposeAdd proper preprocessor guards for all Overview
NOTE: For many of these BackgroundThis PR is a redo of #139804 with some changes to fix clang and unit test build breaks. This issue was raised in comments on #136629. I am addressing it as a separate change since it is independent from the changes being made in that PR. According to this documentation,
Validation
Full diff: https://github.com/llvm/llvm-project/pull/139938.diff 20 Files Affected:
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index d4052ef90de6e..3105dfa4dae55 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -301,8 +301,10 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
llvm_unreachable("Unsupported expression to reason about!");
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Dumps SMT formula
LLVM_DUMP_METHOD void dump() const { Solver->dump(); }
+#endif
protected:
// Check whether a new model is satisfiable, and update the program state.
diff --git a/llvm/include/llvm/ADT/APFixedPoint.h b/llvm/include/llvm/ADT/APFixedPoint.h
index 70d7f325702cf..89d2a93a06a26 100644
--- a/llvm/include/llvm/ADT/APFixedPoint.h
+++ b/llvm/include/llvm/ADT/APFixedPoint.h
@@ -249,7 +249,10 @@ class APFixedPoint {
}
void print(raw_ostream &) const;
- void dump() const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
// If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1.
int compare(const APFixedPoint &Other) const;
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index ed49380cfc05f..b88cbc56c105c 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -1483,7 +1483,10 @@ class APFloat : public APFloatBase {
}
void print(raw_ostream &) const;
- void dump() const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
bool getExactInverse(APFloat *inv) const {
APFLOAT_DISPATCH_ON_SEMANTICS(getExactInverse(inv));
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 7fbf09b44e6c4..44260c7eca309 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1896,8 +1896,10 @@ class [[nodiscard]] APInt {
/// FoldingSets.
void Profile(FoldingSetNodeID &id) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// debug method
- void dump() const;
+ LLVM_DUMP_METHOD void dump() const;
+#endif
/// Returns whether this instance allocated memory.
bool needsCleanup() const { return !isSingleWord(); }
diff --git a/llvm/include/llvm/ADT/DynamicAPInt.h b/llvm/include/llvm/ADT/DynamicAPInt.h
index ff958d48e7731..bb65a08a968d9 100644
--- a/llvm/include/llvm/ADT/DynamicAPInt.h
+++ b/llvm/include/llvm/ADT/DynamicAPInt.h
@@ -216,7 +216,9 @@ class DynamicAPInt {
void static_assert_layout(); // NOLINT
raw_ostream &print(raw_ostream &OS) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
+#endif
};
inline raw_ostream &operator<<(raw_ostream &OS, const DynamicAPInt &X) {
diff --git a/llvm/include/llvm/ADT/SlowDynamicAPInt.h b/llvm/include/llvm/ADT/SlowDynamicAPInt.h
index ec1021892cf4d..c9aef96b9e1c3 100644
--- a/llvm/include/llvm/ADT/SlowDynamicAPInt.h
+++ b/llvm/include/llvm/ADT/SlowDynamicAPInt.h
@@ -79,7 +79,10 @@ class SlowDynamicAPInt {
unsigned getBitWidth() const { return Val.getBitWidth(); }
void print(raw_ostream &OS) const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
+#endif
};
inline raw_ostream &operator<<(raw_ostream &OS, const SlowDynamicAPInt &X) {
diff --git a/llvm/include/llvm/ADT/TrieRawHashMap.h b/llvm/include/llvm/ADT/TrieRawHashMap.h
index e312967edeb58..1382eac1c768f 100644
--- a/llvm/include/llvm/ADT/TrieRawHashMap.h
+++ b/llvm/include/llvm/ADT/TrieRawHashMap.h
@@ -90,7 +90,10 @@ class ThreadSafeTrieRawHashMapBase {
static void *operator new(size_t Size) { return ::operator new(Size); }
void operator delete(void *Ptr) { ::operator delete(Ptr); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void dump() const;
+#endif
+
void print(raw_ostream &OS) const;
protected:
@@ -214,7 +217,10 @@ class ThreadSafeTrieRawHashMap : public ThreadSafeTrieRawHashMapBase {
using ThreadSafeTrieRawHashMapBase::operator delete;
using HashType = HashT;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
using ThreadSafeTrieRawHashMapBase::dump;
+#endif
+
using ThreadSafeTrieRawHashMapBase::print;
private:
diff --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h
index 1f1fd1967efbc..d9e553a8a8c77 100644
--- a/llvm/include/llvm/ADT/Twine.h
+++ b/llvm/include/llvm/ADT/Twine.h
@@ -507,14 +507,16 @@ namespace llvm {
/// stream \p OS.
void print(raw_ostream &OS) const;
- /// Dump the concatenated string represented by this twine to stderr.
- void dump() const;
-
/// Write the representation of this twine to the stream \p OS.
void printRepr(raw_ostream &OS) const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ /// Dump the concatenated string represented by this twine to stderr.
+ LLVM_DUMP_METHOD void dump() const;
+
/// Dump the representation of this twine to stderr.
- void dumpRepr() const;
+ LLVM_DUMP_METHOD void dumpRepr() const;
+#endif
/// @}
};
diff --git a/llvm/include/llvm/Support/BranchProbability.h b/llvm/include/llvm/Support/BranchProbability.h
index 570531e6b9e92..42fe225709ef8 100644
--- a/llvm/include/llvm/Support/BranchProbability.h
+++ b/llvm/include/llvm/Support/BranchProbability.h
@@ -77,7 +77,9 @@ class BranchProbability {
LLVM_ABI raw_ostream &print(raw_ostream &OS) const;
- LLVM_ABI void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
/// Scale a large integer.
///
diff --git a/llvm/include/llvm/Support/DebugCounter.h b/llvm/include/llvm/Support/DebugCounter.h
index 529a9f86f2e34..9611586a92c3b 100644
--- a/llvm/include/llvm/Support/DebugCounter.h
+++ b/llvm/include/llvm/Support/DebugCounter.h
@@ -119,8 +119,10 @@ class DebugCounter {
Counter.CurrChunkIdx = State.ChunkIdx;
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
// Dump or print the current counter set into llvm::dbgs().
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+ LLVM_DUMP_METHOD void dump() const;
+#endif
LLVM_ABI void print(raw_ostream &OS) const;
diff --git a/llvm/include/llvm/Support/KnownBits.h b/llvm/include/llvm/Support/KnownBits.h
index 6a14328d431a4..e8dc1c2422646 100644
--- a/llvm/include/llvm/Support/KnownBits.h
+++ b/llvm/include/llvm/Support/KnownBits.h
@@ -513,7 +513,10 @@ struct KnownBits {
bool operator!=(const KnownBits &Other) const { return !(*this == Other); }
LLVM_ABI void print(raw_ostream &OS) const;
- LLVM_ABI void dump() const;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
private:
// Internal helper for getting the initial KnownBits for an `srem` or `urem`
diff --git a/llvm/include/llvm/Support/SMTAPI.h b/llvm/include/llvm/Support/SMTAPI.h
index f1bb86cf81f1c..aed6241219c39 100644
--- a/llvm/include/llvm/Support/SMTAPI.h
+++ b/llvm/include/llvm/Support/SMTAPI.h
@@ -71,7 +71,9 @@ class SMTSort {
virtual void print(raw_ostream &OS) const = 0;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
protected:
/// Query the SMT solver and returns true if two sorts are equal (same kind
@@ -118,7 +120,9 @@ class SMTExpr {
virtual void print(raw_ostream &OS) const = 0;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
protected:
/// Query the SMT solver and returns true if two sorts are equal (same kind
@@ -136,7 +140,9 @@ class SMTSolverStatistics {
virtual void print(raw_ostream &OS) const = 0;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
};
/// Shared pointer for SMTExprs, used by SMTSolver API.
@@ -152,7 +158,9 @@ class SMTSolver {
SMTSolver() = default;
virtual ~SMTSolver() = default;
- LLVM_ABI LLVM_DUMP_METHOD void dump() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
// Returns an appropriate floating-point sort for the given bitwidth.
SMTSortRef getFloatSort(unsigned BitWidth) {
diff --git a/llvm/include/llvm/Support/ScaledNumber.h b/llvm/include/llvm/Support/ScaledNumber.h
index 87a56809976a3..3d38677f0eb61 100644
--- a/llvm/include/llvm/Support/ScaledNumber.h
+++ b/llvm/include/llvm/Support/ScaledNumber.h
@@ -424,7 +424,10 @@ class ScaledNumberBase {
public:
static constexpr int DefaultPrecision = 10;
- LLVM_ABI static void dump(uint64_t D, int16_t E, int Width);
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD static void dump(uint64_t D, int16_t E, int Width);
+#endif
+
LLVM_ABI static raw_ostream &print(raw_ostream &OS, uint64_t D, int16_t E,
int Width, unsigned Precision);
LLVM_ABI static std::string toString(uint64_t D, int16_t E, int Width,
@@ -607,7 +610,12 @@ template <class DigitsT> class ScaledNumber : ScaledNumberBase {
unsigned Precision = DefaultPrecision) const {
return ScaledNumberBase::print(OS, Digits, Scale, Width, Precision);
}
- void dump() const { return ScaledNumberBase::dump(Digits, Scale, Width); }
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const {
+ return ScaledNumberBase::dump(Digits, Scale, Width);
+ }
+#endif
ScaledNumber &operator+=(const ScaledNumber &X) {
std::tie(Digits, Scale) =
diff --git a/llvm/lib/Support/APFixedPoint.cpp b/llvm/lib/Support/APFixedPoint.cpp
index f395919287b72..9a7caa4112625 100644
--- a/llvm/lib/Support/APFixedPoint.cpp
+++ b/llvm/lib/Support/APFixedPoint.cpp
@@ -439,7 +439,10 @@ void APFixedPoint::print(raw_ostream &OS) const {
Sema.print(OS);
OS << "})";
}
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void APFixedPoint::dump() const { print(llvm::errs()); }
+#endif
APFixedPoint APFixedPoint::negate(bool *Overflow) const {
if (!isSaturated()) {
diff --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp
index a6de07a55482a..9c4a4429ca0ee 100644
--- a/llvm/lib/Support/DebugCounter.cpp
+++ b/llvm/lib/Support/DebugCounter.cpp
@@ -248,6 +248,8 @@ bool DebugCounter::shouldExecuteImpl(unsigned CounterName) {
return true;
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DebugCounter::dump() const {
print(dbgs());
}
+#endif
diff --git a/llvm/lib/Support/DynamicAPInt.cpp b/llvm/lib/Support/DynamicAPInt.cpp
index bfcb97e0cc96a..9def5c782af4c 100644
--- a/llvm/lib/Support/DynamicAPInt.cpp
+++ b/llvm/lib/Support/DynamicAPInt.cpp
@@ -32,4 +32,6 @@ raw_ostream &DynamicAPInt::print(raw_ostream &OS) const {
return OS << ValLarge;
}
-void DynamicAPInt::dump() const { print(dbgs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void DynamicAPInt::dump() const { print(dbgs()); }
+#endif
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 16229598b612a..94a04ab90987a 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -1152,7 +1152,10 @@ void KnownBits::print(raw_ostream &OS) const {
OS << "?";
}
}
-void KnownBits::dump() const {
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void KnownBits::dump() const {
print(dbgs());
dbgs() << "\n";
}
+#endif
diff --git a/llvm/lib/Support/ScaledNumber.cpp b/llvm/lib/Support/ScaledNumber.cpp
index 85d7afbea5c69..33e8cc3030873 100644
--- a/llvm/lib/Support/ScaledNumber.cpp
+++ b/llvm/lib/Support/ScaledNumber.cpp
@@ -317,7 +317,9 @@ raw_ostream &ScaledNumberBase::print(raw_ostream &OS, uint64_t D, int16_t E,
return OS << toString(D, E, Width, Precision);
}
-void ScaledNumberBase::dump(uint64_t D, int16_t E, int Width) {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void ScaledNumberBase::dump(uint64_t D, int16_t E, int Width) {
print(dbgs(), D, E, Width, 0) << "[" << Width << ":" << D << "*2^" << E
<< "]";
}
+#endif
diff --git a/llvm/lib/Support/SlowDynamicAPInt.cpp b/llvm/lib/Support/SlowDynamicAPInt.cpp
index 8b4030ddf9fc4..a57fec2f824e1 100644
--- a/llvm/lib/Support/SlowDynamicAPInt.cpp
+++ b/llvm/lib/Support/SlowDynamicAPInt.cpp
@@ -283,4 +283,6 @@ SlowDynamicAPInt &SlowDynamicAPInt::operator--() {
/// ---------------------------------------------------------------------------
void SlowDynamicAPInt::print(raw_ostream &OS) const { OS << Val; }
-void SlowDynamicAPInt::dump() const { print(dbgs()); }
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void SlowDynamicAPInt::dump() const { print(dbgs()); }
+#endif
diff --git a/llvm/lib/Support/Z3Solver.cpp b/llvm/lib/Support/Z3Solver.cpp
index 9aece099b0629..27027093a0c6f 100644
--- a/llvm/lib/Support/Z3Solver.cpp
+++ b/llvm/lib/Support/Z3Solver.cpp
@@ -989,7 +989,9 @@ llvm::SMTSolverRef llvm::CreateZ3Solver() {
#endif
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void SMTSort::dump() const { print(llvm::errs()); }
LLVM_DUMP_METHOD void SMTExpr::dump() const { print(llvm::errs()); }
LLVM_DUMP_METHOD void SMTSolver::dump() const { print(llvm::errs()); }
LLVM_DUMP_METHOD void SMTSolverStatistics::dump() const { print(llvm::errs()); }
+#endif
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/7708 Here is the relevant piece of the build log for the reference
|
This approach causes issues when LLVM is built in release mode (with
where our There is a reason I'm tracking down where this reference to |
Minimal reproducer is #include <llvm/IR/ModuleSummaryIndex.h>
int main() {} Compile and link this without any special options (specifically: without |
Taking a look now. Will revert today if there isn't a straight-forward fix. |
Ok, this link error makes sense when building an external project in debug mode against an llvm release build. I didn't realize that was a thing, but it makes sense so my mistake. The issue is that we must only guard |
Specifically here,
That would avoid the error, so that would be a big improvement, thanks. From a user perspective, I think it's better if we make sure declarations of |
…#140574) ## Purpose Reverts the preprocessor guards added to the `dump()` methods in `llvm/Support/ScaledNumber.h` in #139938 so that the header can be included when building an external project in debug mode against a release LLVM build. ## Overview This is a clean revert of two files modified in #139938. The rest of that change should not cause similar problems. ## Background The following new build error was reported on #139938, which was merged last week: ``` module.cpp:(.text._ZNK4llvm12ScaledNumberImE4dumpEv[_ZNK4llvm12ScaledNumberImE4dumpEv]+0x34): undefined reference to `llvm::ScaledNumberBase::dump(unsigned long, short, int)' ``` See further discussion on #139938. ## Validation Implemented a simple external LLVM project to reproduce the issue. Verified the the following link failure is observed on LLVM main (Windows + Clang) without this change: ``` C:\WINDOWS\system32\cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console -fuse-ld=lld-link CMakeFiles/llvm-dump-test.dir/main.cxx.obj -o llvm-dump-test.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:llvm-dump-test.lib -Xlinker /pdb:llvm-dump-test.pdb -Xlinker /version:0.0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ." lld-link: error: undefined symbol: public: static void __cdecl llvm::ScaledNumberBase::dump(unsigned __int64, short, int) >>> referenced by S:\llvm\llvm-project\llvm\include\llvm\Support\ScaledNumber.h:614 >>> CMakeFiles/llvm-dump-test.dir/main.cxx.obj:(public: void __cdecl llvm::ScaledNumber<unsigned __int64>::dump(void) const) clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed. ``` Verified the link issue is resolved after applying this change. Also, manually included all header files that were modified in #139938 in the test program and verified there are no other link errors.
Purpose
Add proper preprocessor guards for all
dump()
methods in the LLVM support library. This change ensures these methods are not part of the public ABI for release builds.Overview
dump
methods in Support and ADT source with theLLVM_DUMP_METHOD
macro.dump
method definitions in Support and ADT source so they are only present on debug/assert builds and whenLLVM_ENABLE_DUMP
is explicitly defined.NOTE: For many of these
dump
methods, the implementation was already properly guarded but the declaration in the header file was not.Background
This PR is a redo of #139804 with some changes to fix clang and unit test build breaks.
This issue was raised in comments on #136629. I am addressing it as a separate change since it is independent from the changes being made in that PR.
According to this documentation,
dump
methods should be annotated withLLVM_DUMP_METHOD
and conditionally included as follows:Validation