diff options
author | Eric Fiselier <eric@efcs.ca> | 2019-04-24 02:23:30 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2019-04-24 02:23:30 +0000 |
commit | add16a8da9ccd07eabda2dffd0d32188f07da09c (patch) | |
tree | 4e300d103314248bfc7caf19a91ee8b872c78210 /clang/lib/Basic/Builtins.cpp | |
parent | 42a22370f2b7d83b9041498831fce804c1659628 (diff) | |
download | llvm-add16a8da9ccd07eabda2dffd0d32188f07da09c.zip llvm-add16a8da9ccd07eabda2dffd0d32188f07da09c.tar.gz llvm-add16a8da9ccd07eabda2dffd0d32188f07da09c.tar.bz2 |
[Builtins] Implement __builtin_is_constant_evaluated for use in C++2a
Summary:
This patch implements `__builtin_is_constant_evaluated` as specifier by [P0595R2](https://wg21.link/p0595r2). It is built on the back of Bill Wendling's work for `__builtin_constant_p()`.
More tests to come, but early feedback is appreciated.
I plan to implement warnings for common mis-usages like those belowe in a following patch:
```
void foo(int x) {
if constexpr (std::is_constant_evaluated())) { // condition is always `true`. Should use plain `if` instead.
foo_constexpr(x);
} else {
foo_runtime(x);
}
}
```
Reviewers: rsmith, MaskRay, bruno, void
Reviewed By: rsmith
Subscribers: dexonsmith, zoecarver, fdeazeve, kristina, cfe-commits
Differential Revision: https://reviews.llvm.org/D55500
llvm-svn: 359067
Diffstat (limited to 'clang/lib/Basic/Builtins.cpp')
-rw-r--r-- | clang/lib/Basic/Builtins.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index f04bc1f..cfc5927 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -75,9 +75,12 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo, bool OclCUnsupported = !LangOpts.OpenCL && (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES); bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG; + bool CPlusPlusUnsupported = + !LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG; return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported && !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported && - !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported; + !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported && + !CPlusPlusUnsupported; } /// initializeBuiltins - Mark the identifiers for all the builtins with their |