[clang] [Clang] prevent assertion failure when converting vectors to int/float with invalid expressions (PR #105727)

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 27 12:06:31 PDT 2024


================
@@ -9888,6 +9888,9 @@ static ExprResult convertVector(Expr *E, QualType ElementType, Sema &S) {
 /// IntTy without losing precision.
 static bool canConvertIntToOtherIntTy(Sema &S, ExprResult *Int,
                                       QualType OtherIntTy) {
+  if (Int->get()->isValueDependent())
+    return false;
----------------
a-tarasyuk wrote:

@shafik Thanks for the review. When converting a splat scalar into a vector, problems can occur when the scalar type is integral

https://github.com/llvm/llvm-project/blob/23144e87d2ef0ecf86b67d4aaa28cea332de41c3/clang/lib/Sema/SemaExpr.cpp#L10228-L10229

https://github.com/llvm/llvm-project/blob/23144e87d2ef0ecf86b67d4aaa28cea332de41c3/clang/lib/Sema/SemaExpr.cpp#L10004-L10011

https://github.com/llvm/llvm-project/blob/23144e87d2ef0ecf86b67d4aaa28cea332de41c3/clang/lib/Sema/SemaExpr.cpp#L10046-L10050

In cases where a (constant) integer can be cast to an int, two utilities

https://github.com/llvm/llvm-project/blob/23144e87d2ef0ecf86b67d4aaa28cea332de41c3/clang/lib/Sema/SemaExpr.cpp#L9927

https://github.com/llvm/llvm-project/blob/23144e87d2ef0ecf86b67d4aaa28cea332de41c3/clang/lib/Sema/SemaExpr.cpp#L9889

fail to account for invalid expressions before evaluating them,

https://github.com/llvm/llvm-project/blob/23144e87d2ef0ecf86b67d4aaa28cea332de41c3/clang/lib/Sema/SemaExpr.cpp#L9897

https://github.com/llvm/llvm-project/blob/23144e87d2ef0ecf86b67d4aaa28cea332de41c3/clang/lib/Sema/SemaExpr.cpp#L9934

leading to crashes. Should these utilities be made more robust, or should casting with an invalid expression be bypassed entirely? I'd appreciate your thoughts. Thanks

https://github.com/llvm/llvm-project/pull/105727


More information about the cfe-commits mailing list