This is an archive of the discontinued LLVM Phabricator instance.

[libc] Make predicate macros be usable in `if constexpr (...)` contexts.
Needs ReviewPublic

Authored by sivachandra on May 19 2023, 1:10 AM.

Details

Reviewers
gchatelet
Summary

DO NOT SUBMIT - sending it out just to collect opinion.

Diff Detail

Event Timeline

sivachandra created this revision.May 19 2023, 1:10 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 19 2023, 1:10 AM
sivachandra requested review of this revision.May 19 2023, 1:10 AM
sivachandra added inline comments.May 19 2023, 1:12 AM
libc/src/__support/macros/properties/architectures.h
44

This allows us to use LIBC_TARGET_ARCH_IS_ARM is all of the following contexts:

#ifdef LIBC_TARGET_ARCH_IS_ARM
 ...
#endif

#ifndef LIBC_TARGET_ARCH_IS_ARM
...
#endif

if constexpr (LIBC_TARGET_ARCH_IS_ARM) {
 ...
}

The pattern is smart but I can see two issues with it:

  1. Depending on the context, the literal (i.e. LIBC_TARGET_ARCH_IS_ARM) is a preprocessor definition or a variable, this can be confusing.
  2. It's easy to mess up when defining (or renaming) the preprocessor definitions.

Also, we can already achieve the same behavior - although I agree it is more verbose.

if constexpr (LLVM_LIBC_IS_DEFINED(LIBC_TARGET_ARCH_IS_ARM)) {
 ...
}

I'm not completely sure it's worth the complexity.