llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Wenju He (wenju-he)

<details>
<summary>Changes</summary>

Fix crash in clang PrepareScalarCast when compiling OpenCL source: void foo() {
  int a[3] = {1, 2, 3};
  int3 b = (int3)(a);
}

PrepareScalarCast requires scalar src, but the provided src is a pointer.

Resolves https://github.com/intel/compute-runtime/issues/888

---
Full diff: https://github.com/llvm/llvm-project/pull/180318.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+6) 
- (modified) clang/test/SemaOpenCL/invalid-vector-literals.cl (+2) 


``````````diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 77d3c4ef63f1f..0653a13ee88e0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8112,6 +8112,12 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation 
LParenLoc,
     // it will be replicated to all components of the vector.
     if (getLangOpts().OpenCL && VTy->getVectorKind() == VectorKind::Generic &&
         numExprs == 1) {
+      if (!exprs[0]->getType()->isArithmeticType()) {
+        Diag(exprs[0]->getBeginLoc(), diag::err_typecheck_convert_incompatible)
+            << Ty << exprs[0]->getType() << 4 << 0 << 0 << ""
+            << exprs[0]->getSourceRange();
+        return ExprError();
+      }
       QualType ElemTy = VTy->getElementType();
       ExprResult Literal = DefaultLvalueConversion(exprs[0]);
       if (Literal.isInvalid())
diff --git a/clang/test/SemaOpenCL/invalid-vector-literals.cl 
b/clang/test/SemaOpenCL/invalid-vector-literals.cl
index 1d82fedf29de1..9ae5142b4a1b3 100644
--- a/clang/test/SemaOpenCL/invalid-vector-literals.cl
+++ b/clang/test/SemaOpenCL/invalid-vector-literals.cl
@@ -10,4 +10,6 @@ void vector_literals_invalid()
   int4 b = (int4)(1,2,3,4,5); // expected-error{{excess elements in vector}}
   int8 d = (int8)(a,(float4)(1)); // expected-error{{initializing 'int' with 
an expression of incompatible type 'float4'}}
   ((int4)(0)).x = 8; // expected-error{{expression is not assignable}}
+  int arr[4];
+  int4 e = (int4)(arr); // expected-error{{initializing 'int4' (vector of 4 
'int' values) with an expression of incompatible type '__private int[4]'}}
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/180318
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to