Skip to content

Commit 0563186

Browse files
authored
[llvm] properly guard dump methods in Support lib classes (#139938)
## 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 * Annotates all `dump` methods in Support and ADT source with the `LLVM_DUMP_METHOD` macro. * Conditionally includes all `dump` method definitions in Support and ADT source so they are only present on debug/assert builds and when `LLVM_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](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/Compiler.h#L637), `dump` methods should be annotated with `LLVM_DUMP_METHOD` and conditionally included as follows: ``` #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void dump() const; #endif ``` ## Validation * Local release build succeeds. * CI
1 parent e24d866 commit 0563186

20 files changed

+82
-20
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
301301
llvm_unreachable("Unsupported expression to reason about!");
302302
}
303303

304+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
304305
/// Dumps SMT formula
305306
LLVM_DUMP_METHOD void dump() const { Solver->dump(); }
307+
#endif
306308

307309
protected:
308310
// Check whether a new model is satisfiable, and update the program state.

llvm/include/llvm/ADT/APFixedPoint.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ class APFixedPoint {
249249
}
250250

251251
void print(raw_ostream &) const;
252-
void dump() const;
252+
253+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
254+
LLVM_DUMP_METHOD void dump() const;
255+
#endif
253256

254257
// If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1.
255258
int compare(const APFixedPoint &Other) const;

llvm/include/llvm/ADT/APFloat.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,10 @@ class APFloat : public APFloatBase {
14831483
}
14841484

14851485
void print(raw_ostream &) const;
1486-
void dump() const;
1486+
1487+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1488+
LLVM_DUMP_METHOD void dump() const;
1489+
#endif
14871490

14881491
bool getExactInverse(APFloat *inv) const {
14891492
APFLOAT_DISPATCH_ON_SEMANTICS(getExactInverse(inv));

llvm/include/llvm/ADT/APInt.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,8 +1896,10 @@ class [[nodiscard]] APInt {
18961896
/// FoldingSets.
18971897
void Profile(FoldingSetNodeID &id) const;
18981898

1899+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
18991900
/// debug method
1900-
void dump() const;
1901+
LLVM_DUMP_METHOD void dump() const;
1902+
#endif
19011903

19021904
/// Returns whether this instance allocated memory.
19031905
bool needsCleanup() const { return !isSingleWord(); }

llvm/include/llvm/ADT/DynamicAPInt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ class DynamicAPInt {
216216
void static_assert_layout(); // NOLINT
217217

218218
raw_ostream &print(raw_ostream &OS) const;
219+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
219220
LLVM_DUMP_METHOD void dump() const;
221+
#endif
220222
};
221223

222224
inline raw_ostream &operator<<(raw_ostream &OS, const DynamicAPInt &X) {

llvm/include/llvm/ADT/SlowDynamicAPInt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ class SlowDynamicAPInt {
7979
unsigned getBitWidth() const { return Val.getBitWidth(); }
8080

8181
void print(raw_ostream &OS) const;
82+
83+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
8284
LLVM_DUMP_METHOD void dump() const;
85+
#endif
8386
};
8487

8588
inline raw_ostream &operator<<(raw_ostream &OS, const SlowDynamicAPInt &X) {

llvm/include/llvm/ADT/TrieRawHashMap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class ThreadSafeTrieRawHashMapBase {
9090
static void *operator new(size_t Size) { return ::operator new(Size); }
9191
void operator delete(void *Ptr) { ::operator delete(Ptr); }
9292

93+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
9394
LLVM_DUMP_METHOD void dump() const;
95+
#endif
96+
9497
void print(raw_ostream &OS) const;
9598

9699
protected:
@@ -214,7 +217,10 @@ class ThreadSafeTrieRawHashMap : public ThreadSafeTrieRawHashMapBase {
214217
using ThreadSafeTrieRawHashMapBase::operator delete;
215218
using HashType = HashT;
216219

220+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
217221
using ThreadSafeTrieRawHashMapBase::dump;
222+
#endif
223+
218224
using ThreadSafeTrieRawHashMapBase::print;
219225

220226
private:

llvm/include/llvm/ADT/Twine.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,16 @@ namespace llvm {
507507
/// stream \p OS.
508508
void print(raw_ostream &OS) const;
509509

510-
/// Dump the concatenated string represented by this twine to stderr.
511-
void dump() const;
512-
513510
/// Write the representation of this twine to the stream \p OS.
514511
void printRepr(raw_ostream &OS) const;
515512

513+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
514+
/// Dump the concatenated string represented by this twine to stderr.
515+
LLVM_DUMP_METHOD void dump() const;
516+
516517
/// Dump the representation of this twine to stderr.
517-
void dumpRepr() const;
518+
LLVM_DUMP_METHOD void dumpRepr() const;
519+
#endif
518520

519521
/// @}
520522
};

llvm/include/llvm/Support/BranchProbability.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class BranchProbability {
7777

7878
LLVM_ABI raw_ostream &print(raw_ostream &OS) const;
7979

80-
LLVM_ABI void dump() const;
80+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
81+
LLVM_DUMP_METHOD void dump() const;
82+
#endif
8183

8284
/// Scale a large integer.
8385
///

llvm/include/llvm/Support/DebugCounter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ class DebugCounter {
119119
Counter.CurrChunkIdx = State.ChunkIdx;
120120
}
121121

122+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
122123
// Dump or print the current counter set into llvm::dbgs().
123-
LLVM_ABI LLVM_DUMP_METHOD void dump() const;
124+
LLVM_DUMP_METHOD void dump() const;
125+
#endif
124126

125127
LLVM_ABI void print(raw_ostream &OS) const;
126128

0 commit comments

Comments
 (0)