This is an archive of the discontinued LLVM Phabricator instance.

Fix modules build with different technique to suppress Knuth debugging
ClosedPublic

Authored by t.p.northover on Aug 3 2018, 2:20 AM.

Details

Summary

Currently we use #pragma push_macro(LLVM_DEBUG) to fiddle with the LLVM_DEBUG macro so that we can silence debugging the Knuth division algorithm unless it's actually desired. Unfortunately this is incompatible with enabling modules while building LLVM (via LLVM_ENABLE_MODULES=ON) because the macro then has incompatible definitions in a single translation unit.

This patch changes the Knuth division function to use a special KNUTH_DEBUG throughout, which can be #defined to LLVM_DEBUG if debug output is desired. A default implementation doing nothing is provided locally (rather than in include/llvm/Support/Debug.h).

Diff Detail

Event Timeline

t.p.northover created this revision.Aug 3 2018, 2:20 AM
kristina added a subscriber: kristina.EditedAug 3 2018, 1:39 PM

This looks great, currently unable to build without manually fixing it as we do modular builds. I don't think those backslashes are within 80 col limit but otherwise LGTM.

(Looking closely seems that it's Phabricator rendering them oddly, excuse the previous remark)

kristina accepted this revision.Aug 3 2018, 3:32 PM

I don't have commit access but this fixes modular builds and is essentially NFC, so I don't think it needs any further review and is ready to land as-is. The whitespace comment was wrong since just seems to be a Phabricator quirk.

This revision is now accepted and ready to land.Aug 3 2018, 3:32 PM
teemperor accepted this revision.Aug 3 2018, 4:06 PM
teemperor added a subscriber: teemperor.

We could also land the original version of the patch that introduced this. It didn't contain the push/pop_macro and wouldn't change the functionality to people actually using KNUTH_DEBUG. https://reviews.llvm.org/D40404?id=124114 But I'm fine with both.

Unfortunately this is incompatible with enabling modules while building LLVM (via LLVM_ENABLE_MODULES=ON) because the macro then has incompatible definitions in a single translation unit.

I don't think that's what's going on here. The problem is that the first use of LLVM_DEBUG is from inside the push_macro pragma. But we don't update the LLVM_DEBUG IdentifierInfo with the data from the modules before pushing it, which means we just push the undefined identifier on the stack which later will be popped and used for the rest of the translation unit. This would be fixed by D33004 or by just manually updating the identifier from the push_macro code through calling updateOutOfDateIdentifier.

Thanks for fixing this! LGTM, but if possible update the explanation in the commit message.

Personal style preference but I think #define DEBUG_KNUTH(X) do {} while(false) on one line would be better as well instead of splitting it across three lines as well. It's how a lot of them are defined in headers in libLLVMSupport.

kristina added a comment.EditedAug 3 2018, 4:27 PM

The original version (the one you linked for D40404 without push/pop) does indeed look better, I haven't reviewed or tested it, but it seems others have so I'd say go for that one. Would probably be the best approach since it's truly NFC as it's basically just reverting push/pop for more traditional #define + #undef while leaving most of their original commits intact. Though personally I don't really mind which, sooner I can replace a local patch to APInt with one from upstream the better before it snowballs into a merge conflict but I think reverting is better than applying "fix" patches in situations like this.

kristina closed this revision.Aug 4 2018, 6:12 AM

Superseded by 3rd revision of D40404. Closing.

Thanks for the comments. I've committed basically the original version of the D40404 (modulo DEBUG -> LLVM_DEBUG renaming) as r339009.