[clang] [clang] Restrict use of scalar types in vector builtins (PR #119423)
Fraser Cormack via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 9 03:08:07 PST 2025
================
@@ -14604,57 +14611,63 @@ bool Sema::PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall) {
}
bool Sema::BuiltinElementwiseMath(CallExpr *TheCall, bool FPOnly) {
- QualType Res;
- if (BuiltinVectorMath(TheCall, Res, FPOnly))
- return true;
- TheCall->setType(Res);
- return false;
+ if (auto Res = BuiltinVectorMath(TheCall, FPOnly); Res.has_value()) {
+ TheCall->setType(*Res);
+ return false;
+ }
+ return true;
}
bool Sema::BuiltinVectorToScalarMath(CallExpr *TheCall) {
- QualType Res;
- if (BuiltinVectorMath(TheCall, Res))
+ std::optional<QualType> Res = BuiltinVectorMath(TheCall);
+ if (!Res)
return true;
- if (auto *VecTy0 = Res->getAs<VectorType>())
+ if (auto *VecTy0 = (*Res)->getAs<VectorType>())
TheCall->setType(VecTy0->getElementType());
else
- TheCall->setType(Res);
+ TheCall->setType(*Res);
return false;
}
-bool Sema::BuiltinVectorMath(CallExpr *TheCall, QualType &Res, bool FPOnly) {
+std::optional<QualType> Sema::BuiltinVectorMath(CallExpr *TheCall,
+ bool FPOnly) {
if (checkArgCount(TheCall, 2))
- return true;
+ return std::nullopt;
- ExprResult A = TheCall->getArg(0);
- ExprResult B = TheCall->getArg(1);
- // Do standard promotions between the two arguments, returning their common
- // type.
- Res = UsualArithmeticConversions(A, B, TheCall->getExprLoc(), ACK_Comparison);
- if (A.isInvalid() || B.isInvalid())
- return true;
+ checkEnumArithmeticConversions(TheCall->getArg(0), TheCall->getArg(1),
+ TheCall->getExprLoc(), ACK_Comparison);
----------------
frasercrmck wrote:
Alright, I've forbidden mixed enum types and have added some tests for them.
https://github.com/llvm/llvm-project/pull/119423
More information about the cfe-commits
mailing list