[clang] e7d9182 - Enable constexpr on BITREVERSE builtin intrinsics (PR47249)
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 22 06:44:13 PDT 2020
Author: Simon Pilgrim
Date: 2020-08-22T14:43:22+01:00
New Revision: e7d9182a666a2a8f903bd330c82d7c623b783371
URL: https://github.com/llvm/llvm-project/commit/e7d9182a666a2a8f903bd330c82d7c623b783371
DIFF: https://github.com/llvm/llvm-project/commit/e7d9182a666a2a8f903bd330c82d7c623b783371.diff
LOG: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)
This enables us to use the __builtin_bitreverse 8/16/32/64 intrinsics inside constexpr code.
Differential Revision: https://reviews.llvm.org/D86339
Added:
Modified:
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/constant-builtins-2.c
Removed:
################################################################################
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index fd563b0d59ba..a431239f887b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1984,7 +1984,7 @@ Query for this feature with ``__has_builtin(__builtin_convertvector)``.
The '``__builtin_bitreverse``' family of builtins is used to reverse
the bitpattern of an integer value; for example ``0b10110110`` becomes
-``0b01101101``.
+``0b01101101``. These builtins can be used within constant expressions.
``__builtin_rotateleft``
------------------------
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7a94039f9a26..ba2b540639ad 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -56,6 +56,10 @@ Improvements to Clang's diagnostics
Non-comprehensive list of changes in this release
-------------------------------------------------
+- The builtin intrinsics ``__builtin_bitreverse8``, ``__builtin_bitreverse16``,
+ ``__builtin_bitreverse32`` and ``__builtin_bitreverse64`` may now be used
+ within constant expressions.
+
- The builtin intrinsics ``__builtin_rotateleft8``, ``__builtin_rotateleft16``,
``__builtin_rotateleft32`` and ``__builtin_rotateleft64`` may now be used
within constant expressions.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 09ef5629182a..c23233ab8c8c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11180,6 +11180,17 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
return Success(AlignedVal, E);
}
+ case Builtin::BI__builtin_bitreverse8:
+ case Builtin::BI__builtin_bitreverse16:
+ case Builtin::BI__builtin_bitreverse32:
+ case Builtin::BI__builtin_bitreverse64: {
+ APSInt Val;
+ if (!EvaluateInteger(E->getArg(0), Val, Info))
+ return false;
+
+ return Success(Val.reverseBits(), E);
+ }
+
case Builtin::BI__builtin_bswap16:
case Builtin::BI__builtin_bswap32:
case Builtin::BI__builtin_bswap64: {
diff --git a/clang/test/Sema/constant-builtins-2.c b/clang/test/Sema/constant-builtins-2.c
index b0f566e9eecf..19d1599dc4a1 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,11 @@ char parity8[__builtin_parity(~0) == 0 ? 1 : -1];
char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1];
+char bitreverse1[__builtin_bitreverse8(0x01) == 0x80 ? 1 : -1];
+char bitreverse2[__builtin_bitreverse16(0x3C48) == 0x123C ? 1 : -1];
+char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];
+char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 0xF7B3D591E6A2C480 ? 1 : -1];
+
char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : -1];
More information about the cfe-commits
mailing list