Skip to content

[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

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion llvm/include/llvm/ADT/APFixedPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion llvm/include/llvm/ADT/APFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/ADT/APInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/ADT/DynamicAPInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/ADT/SlowDynamicAPInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/ADT/TrieRawHashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/ADT/Twine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// @}
};
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/Support/BranchProbability.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/Support/DebugCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion llvm/include/llvm/Support/KnownBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
16 changes: 12 additions & 4 deletions llvm/include/llvm/Support/SMTAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions llvm/include/llvm/Support/ScaledNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) =
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Support/APFixedPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Support/DebugCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion llvm/lib/Support/DynamicAPInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion llvm/lib/Support/KnownBits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion llvm/lib/Support/ScaledNumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion llvm/lib/Support/SlowDynamicAPInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions llvm/lib/Support/Z3Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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