[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 25 11:15:17 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 5c94dd73b2df1f6b469e858ff29055ac117e8494 0e4c511107f76da085a8019cf2eca78c3a5a0754 --extensions cpp,h -- clang/test/AST/ByteCode/constexpr-vectors.cpp clang/include/clang/AST/ASTContext.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/Compiler.h clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExpr.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index fa329fa8cc..48f177d4d9 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5316,7 +5316,7 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) {
template <class Emitter>
bool Compiler<Emitter>::VisitVectorUnaryOp(const UnaryOperator *E) {
- const Expr *SubExpr = E->getSubExpr();
+ const Expr *SubExpr = E->getSubExpr();
assert(SubExpr->getType()->isVectorType());
if (DiscardResult)
@@ -5374,10 +5374,13 @@ bool Compiler<Emitter>::VisitVectorUnaryOp(const UnaryOperator *E) {
if (!createTemp())
return false;
- // In C++, the logic operators !, &&, || are available for vectors. !v is equivalent to v == 0.
- // https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html
- QualType SignedVecT = Ctx.getASTContext().GetSignedVectorType(SubExpr->getType());
- PrimType SignedElemT = classifyPrim(SignedVecT->getAs<VectorType>()->getElementType());
+ // In C++, the logic operators !, &&, || are available for vectors. !v is
+ // equivalent to v == 0.
+ // https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html
+ QualType SignedVecT =
+ Ctx.getASTContext().GetSignedVectorType(SubExpr->getType());
+ PrimType SignedElemT =
+ classifyPrim(SignedVecT->getAs<VectorType>()->getElementType());
for (unsigned I = 0; I != VecT->getNumElements(); ++I) {
if (!getElem(SubExprOffset, I))
return false;
@@ -5393,13 +5396,14 @@ bool Compiler<Emitter>::VisitVectorUnaryOp(const UnaryOperator *E) {
if (!this->emitNeg(ElemT, E))
return false;
if (ElemT != SignedElemT &&
- !this->emitPrimCast(ElemT, SignedElemT, SignedVecT, E))
- return false;
+ !this->emitPrimCast(ElemT, SignedElemT, SignedVecT, E))
+ return false;
} else {
- // Float types result in an int of the same size, but -1 for true, or 0 for
- // false.
+ // Float types result in an int of the same size, but -1 for true, or 0
+ // for false.
auto &FpSemantics = Ctx.getFloatSemantics(VecT->getElementType());
- unsigned NumBits = Ctx.getBitWidth(SignedVecT->getAs<VectorType>()->getElementType());
+ unsigned NumBits =
+ Ctx.getBitWidth(SignedVecT->getAs<VectorType>()->getElementType());
auto Zero = APFloat::getZero(FpSemantics);
APSInt SIntZero(APSInt::getZero(NumBits));
APSInt SIntAllOne(APSInt::getAllOnes(NumBits));
``````````
</details>
https://github.com/llvm/llvm-project/pull/105996
More information about the cfe-commits
mailing list