summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3cca25a814b..2e1188164db 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -545,9 +545,8 @@ ExprResult Sema::UsualUnaryConversions(Expr *E) {
QualType Ty = E->getType();
assert(!Ty.isNull() && "UsualUnaryConversions - missing type");
- // Half FP is a bit different: it's a storage-only type, meaning that any
- // "use" of it should be promoted to float.
- if (Ty->isHalfType())
+ // Half FP have to be promoted to float unless it is natively supported
+ if (Ty->isHalfType() && !getLangOpts().NativeHalfType)
return ImpCastExprToType(Res.take(), Context.FloatTy, CK_FloatingCast);
// Try to perform integral promotions if the object has a theoretically
@@ -3470,6 +3469,13 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
diag::err_subscript_incomplete_type, BaseExpr))
return ExprError();
+ if (ResultType->isHalfType() && getLangOpts().OpenCL &&
+ !getOpenCLOptions().cl_khr_fp16) {
+ Diag(BaseExpr->getLocStart(), diag::err_opencl_half_subscript) << ResultType
+ << BaseExpr->getType() << BaseExpr->getSourceRange();
+ return ExprError();
+ }
+
assert(VK == VK_RValue || LangOpts.CPlusPlus ||
!ResultType.isCForbiddenLValueType());
@@ -8210,6 +8216,13 @@ static QualType CheckIndirectionOperand(Sema &S, Expr *Op, ExprValueKind &VK,
return QualType();
}
+ if (Result->isHalfType() && S.getLangOpts().OpenCL &&
+ !S.getOpenCLOptions().cl_khr_fp16) {
+ S.Diag(OpLoc, diag::err_opencl_half_dereferencing)
+ << OpTy << Op->getSourceRange();
+ return QualType();
+ }
+
// Dereferences are usually l-values...
VK = VK_LValue;
@@ -8831,7 +8844,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
resultType = Input.get()->getType();
// Though we still have to promote half FP to float...
- if (resultType->isHalfType()) {
+ if (resultType->isHalfType() && !Context.getLangOpts().NativeHalfType) {
Input = ImpCastExprToType(Input.take(), Context.FloatTy, CK_FloatingCast).take();
resultType = Context.FloatTy;
}
OpenPOWER on IntegriCloud