This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Add LLVM_ENABLE_DEBUG variable which can be used to replace NDEBUG
AbandonedPublic

Authored by hintonda on Oct 3 2017, 12:40 PM.

Details

Summary

Remove the dependancy on NDEBUG, especially in public headers, by using
a new variable, LLVM_ENABLE_DEBUG, which will make it easier to include llvm
headers in other applications which may define NDEBUG differently.

This change only defines the new variable, but if accepted, the following
changes can be made to headers as needed:

s/#ifndef NDEBUG/#ifdef LLVM_ENABLE_DEBUG/
s/!defined(NDEBUG)/defined(LLVM_ENABLE_DEBUG)/

This is similar to changes originally proposed by @tstellar:
https://reviews.llvm.org/D11833 and https://reviews.llvm.org/D11834

  • This patch includes changes to CMakeLists.txt from D38406

which is still under review.

Event Timeline

hintonda created this revision.Oct 3 2017, 12:40 PM
MatzeB edited edge metadata.

Thanks for working on this!

Will we only use LLVM_DEBUG in the public headers or also in the implementation files and private headers?

Apart from NDEBUG there's also the peculiar case of assert()s in the headers; though they are probably less of a problem as they do not change the datastructures.

There is a danger that we will regress given that we are forced to set NDEBUG as well to keep assert() working, so we wouldn't notice if someone incorrectly adds new assert() or #ifdef NDEBUG into the headers. I sometimes wonder if we shouldn't add some verification/linting scripts to LLVM that are then run for each commit by a buildbot machine. In this case for example we could search the public headers for NDEBUG and warn/bail out if we find them. We can have this discussion separate from this patch of course.

CMakeLists.txt
393–402

I think we already have the LLVM_ENABLE_ASSERTIONS flag and should not introduce yet another one. We may or may not use LLVM_ENABLE_DEBUG instead of LLVM_ENABLE_ASSERTIONS for the preprocessor define.

include/llvm/Config/llvm-config.h.cmake
17–18

I think LLVM_ENABLE_DEBUG would be more in line with other existing flags.

Will we only use LLVM_DEBUG in the public headers or also in the implementation files and private headers?

I'd suggest outlawing NDEBUG, but initially the problem is usage of NDEBUG in public headers.

Apart from NDEBUG there's also the peculiar case of assert()s in the headers; though they are probably less of a problem as they do not change the datastructures.

We could always add something like LLVM_ASSERT (or llvm_assert), if that becomes an issue.

There is a danger that we will regress given that we are forced to set NDEBUG as well to keep assert() working, so we wouldn't notice if someone incorrectly adds new assert() or #ifdef NDEBUG into the headers. I sometimes wonder if we shouldn't add some verification/linting scripts to LLVM that are then run for each commit by a buildbot machine. In this case for example we could search the public headers for NDEBUG and warn/bail out if we find them. We can have this discussion separate from this patch of course.

Okay, sounds good.

CMakeLists.txt
393–402

This change only adds LLVM_DEBUG.

The other changes you see are from D38406 which hasn't been approved yet, and just clean up setting LLVM_ENABLE_DUMP.

include/llvm/Config/llvm-config.h.cmake
17–18

Will do...

hintonda updated this revision to Diff 117578.Oct 3 2017, 2:01 PM
  • s/LLVM_DEBUG/LLVM_ENABLE_DEBUG/
hintonda retitled this revision from [cmake] Add LLVM_DEBUG variable which can be used to replace NDEBUG to [cmake] Add LLVM_ENABLE_DEBUG variable which can be used to replace NDEBUG.Oct 3 2017, 2:27 PM
hintonda edited the summary of this revision. (Show Details)

Will we only use LLVM_DEBUG in the public headers or also in the implementation files and private headers?

I'd suggest outlawing NDEBUG, but initially the problem is usage of NDEBUG in public headers.

Apart from NDEBUG there's also the peculiar case of assert()s in the headers; though they are probably less of a problem as they do not change the datastructures.

Actually, I'd like to backpeddle a bit. It would not be appropriate to replace all instances of NDEBUG. Also, asserts should not be affected, so any code enabled when NDEBUG is not defined should still be available when asserts are enabled.

So the goal should be to remove only debugging code in headers not required by asserts, if they are enabled.

hintonda abandoned this revision.Dec 27 2017, 8:20 AM

Superseded by D38406.