Author: Ole Strohm
Date: 2021-06-01T13:43:07+01:00
New Revision: 94b0aec0f5c6b4f6a27cf3a542f795bbba72e851

URL: 
https://github.com/llvm/llvm-project/commit/94b0aec0f5c6b4f6a27cf3a542f795bbba72e851
DIFF: 
https://github.com/llvm/llvm-project/commit/94b0aec0f5c6b4f6a27cf3a542f795bbba72e851.diff

LOG: [OpenCL] Fix ICE with invalid use of half

Because half is limited to the `cl_khr_fp16` extension being enabled,
`DefaultLvalueConversion` can fail when it's not enabled.
The original assumption that it will never fail is therefore wrong now.

Fixes: PR47976

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D103175

Added: 
    clang/test/SemaOpenCLCXX/half.clcpp

Modified: 
    clang/lib/Sema/SemaExprCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b31c484b11700..75ebeaea1072c 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4193,7 +4193,9 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   case ICK_Lvalue_To_Rvalue: {
     assert(From->getObjectKind() != OK_ObjCProperty);
     ExprResult FromRes = DefaultLvalueConversion(From);
-    assert(!FromRes.isInvalid() && "Can't perform deduced conversion?!");
+    if (FromRes.isInvalid())
+      return ExprError();
+
     From = FromRes.get();
     FromType = From->getType();
     break;

diff  --git a/clang/test/SemaOpenCLCXX/half.clcpp 
b/clang/test/SemaOpenCLCXX/half.clcpp
new file mode 100644
index 0000000000000..bcb422fe58bf3
--- /dev/null
+++ b/clang/test/SemaOpenCLCXX/half.clcpp
@@ -0,0 +1,15 @@
+//RUN: %clang_cc1 %s -triple spir -verify -fsyntax-only
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+typedef half half2 __attribute__((ext_vector_type(2)));
+
+half f(half2 h2) { // expected-error{{declaring function return value of type 
'half' is not allowed ; did you forget * ?}}
+    return h2.s0; // expected-error{{loading directly from pointer to type 
'__private half' requires cl_khr_fp16. Use vector data load builtin functions 
instead}}
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+half f(half2 h2) {
+    return h2.s0;
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to