diff options
author | Joey Gouly <joey.gouly@arm.com> | 2013-01-23 11:56:20 +0000 |
---|---|---|
committer | Joey Gouly <joey.gouly@arm.com> | 2013-01-23 11:56:20 +0000 |
commit | 19dbb20ac4371fae3190379a7e7bd467af3c00aa (patch) | |
tree | 4ad0ff118896e57acd79d0f76e8a57311af4bd19 /lib/Sema/SemaExpr.cpp | |
parent | 218b6dfaee321cec558e15d47b68155dd9f35684 (diff) |
Add a new LangOpt NativeHalfType. This option allows for native half/fp16
operations (as opposed to storage only half/fp16).
Also add some semantic checks for OpenCL half types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173254 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 3cca25a814..2e1188164d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/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; } |