[llvm] [llvm-debuginfo-analyzer] Use `LLVM_BUILD_DEBUG` in class definitions (PR #140265)

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Tue May 20 16:17:37 PDT 2025


compnerd wrote:

> May be some clarification:
> 
> ```
>   virtual void print(raw_ostream &OS, bool Full = true) const;
> 
> #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
>   virtual void dump() const { print(dbgs()); }
> #endif
> ```
> 
> `dump` should be called only for _debug_ builds. `print` can be called for both builds (_debug_ and _non debug_).

I think that you are misreading the condition:

`!defined(NDEBUG)`
You are focusing on this rather than the rest of the condition:

`|| defined(LLVM_ENABLE_DUMP)`
You can always build LLVM with `-D LLVM_ENABLE_DUMP` being passed to CMake to enable the `dump` API if you want.


> ```
> - Debug build:      print(dbgs())
> - Non Debug Build:  print(outs());
> ```
> 
> The downstream project should use `print`.

This is also an option that is available to downstream projects.

> * `LVObject::ID` (see [LVObject.h:174](https://github.com/llvm/llvm-project/pull/140265/files#diff-85d40304e38f0ab619a00f93fc3b5f5b04aa1e795319fab5589d2b06dc243326R174)) non-static data member is conditionally added depending on `NDEBUG`, which clearly violates the ODR if `NDEBUG` has a different definition when building a downstream project (actually, that is fairly common).

That is something to guard with `LLVM_ENABLE_ABI_BREAKING_CHANGES` as that is changing the object layout itself between release and debug builds. However, the returning of the value between `0` and `ID` is something that can remain as `NDEBUG` only.

https://github.com/llvm/llvm-project/pull/140265


More information about the llvm-commits mailing list