[PATCH] D124974: [clang] Include clang config.h in LangStandards.cpp

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 12 15:07:57 PDT 2022


dexonsmith added a comment.

In D124974#3504986 <https://reviews.llvm.org/D124974#3504986>, @porglezomp wrote:

> Ah, so it'd be a test that passes pretty trivially on any bot that doesn't have a custom version of `CLANG_DEFAULT_STD_C` and `CLANG_DEFAULT_STD_CXX` like the default config, but could get caught by any other bots that do set it?
>
> What's the best way to get the compiler to report the standard it's using for this test?
>
> For C++ I can do:
>
>   clang++ -xc++ -dM -E - < /dev/null | grep cplusplus
>
> And it will print e.g.
>
>   #define __cplusplus 199711L
>
> But that requires quite some decoding to compare against `CLANG_DEFAULT_STD_CXX` which would look like `LangStandard::lang_gnucxx98`.

Yeah, that seems awkward.

My concern with lacking a test is that someone could easily remove this in the future when trying to prune unused `#include`s.

Another solution might be to change this to a compile error. I think it'd work to change the `#cmakedefine` logic to:

  #cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
  // Always #define something so that missing the config.h #include at use sites
  // becomes a compile error.
  #ifndef CLANG_DEFAULT_STD_C
  #define CLANG_DEFAULT_STD_C LangStandard::lang_unknown
  #endif

and then update the code to:

  case Language::C:
    if (CLANG_DEFAULT_STD_C != LangStandard::lang_unknown)
      return CLANG_DEFAULT_STD_C;
  
    // The PS4 uses C99 as the default C standard.
    if (T.isPS4())
      return LangStandard::lang_gnu99;
    return LangStandard::lang_gnu17;

(without the `#ifdef`)

WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124974/new/

https://reviews.llvm.org/D124974



More information about the cfe-commits mailing list