diff options
author | John McCall <rjmccall@apple.com> | 2013-02-12 01:29:43 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2013-02-12 01:29:43 +0000 |
commit | 9dd74c5504c743c96ea3a1d691d6a75ec3a98147 (patch) | |
tree | f1121c7876d52867edccb389dcfba07bb3f90526 | |
parent | c2808e705eb8a1a825a5807cabc16d55052c31bd (diff) |
Diagnose loads of 'half' l-values in OpenCL.
Patch by Joey Gouly!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174928 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 7 | ||||
-rw-r--r-- | lib/Sema/SemaCast.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 23 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 1 | ||||
-rw-r--r-- | test/SemaOpenCL/half.cl | 28 |
5 files changed, 24 insertions, 41 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b2f28d561b..44bcf632a6 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -420,12 +420,9 @@ def err_object_cannot_be_passed_returned_by_value : Error< "; did you forget * in %1?">; def err_parameters_retval_cannot_have_fp16_type : Error< "%select{parameters|function return value}0 cannot have __fp16 type; did you forget * ?">; -def err_opencl_half_dereferencing : Error< - "dereferencing pointer of type %0 is not allowed">; -def err_opencl_half_subscript : Error< - "subscript to array of type %0 is not allowed">; +def err_opencl_half_load_store : Error< + "%select{loading directly from|assigning directly to}0 pointer to type %1 is not allowed">; def err_opencl_cast_to_half : Error<"casting to type %0 is not allowed">; -def err_opencl_cast_from_half : Error<"casting from type %0 is not allowed">; def err_opencl_half_declaration : Error< "declaring variable of type %0 is not allowed">; def err_opencl_half_argument : Error< diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index d1e95d7df9..e6dc0bd8bc 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -2111,12 +2111,6 @@ void CastOperation::CheckCStyleCast() { SrcExpr = ExprError(); return; } - if (SrcExpr.get()->getType()->isHalfType()) { - Self.Diag(SrcExpr.get()->getLocStart(), diag::err_opencl_cast_from_half) - << SrcType << SrcExpr.get()->getSourceRange(); - SrcExpr = ExprError(); - return; - } } // ARC imposes extra restrictions on casts. diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d0aa6973b7..689c1497fd 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -482,6 +482,14 @@ ExprResult Sema::DefaultLvalueConversion(Expr *E) { if (T->isVoidType()) return Owned(E); + // OpenCL usually rejects direct accesses to values of 'half' type. + if (getLangOpts().OpenCL && !getOpenCLOptions().cl_khr_fp16 && + T->isHalfType()) { + Diag(E->getExprLoc(), diag::err_opencl_half_load_store) + << 0 << T; + return ExprError(); + } + CheckForNullPointerDereference(*this, E); // C++ [conv.lval]p1: @@ -3487,13 +3495,6 @@ 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()); @@ -5663,7 +5664,6 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS, LHSType = Context.getCanonicalType(LHSType).getUnqualifiedType(); RHSType = Context.getCanonicalType(RHSType).getUnqualifiedType(); - // Common case: no conversion required. if (LHSType == RHSType) { Kind = CK_NoOp; @@ -8242,13 +8242,6 @@ 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; diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index b257a59c10..109c8e4902 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -2642,6 +2642,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, S.Diag(Param->getLocation(), diag::err_opencl_half_argument) << ArgTy; D.setInvalidType(); + Param->setInvalidDecl(); } } else { S.Diag(Param->getLocation(), diff --git a/test/SemaOpenCL/half.cl b/test/SemaOpenCL/half.cl index 830d178d7c..0e6acb78c4 100644 --- a/test/SemaOpenCL/half.cl +++ b/test/SemaOpenCL/half.cl @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value #pragma OPENCL EXTENSION cl_khr_fp16 : disable @@ -7,16 +7,15 @@ half half_disabled(half *p, // expected-error{{declaring function return value o { half a[2]; // expected-error{{declaring variable of type 'half [2]' is not allowed}} half b; // expected-error{{declaring variable of type 'half' is not allowed}} - - b = *p; // expected-error{{dereferencing pointer of type 'half *' is not allowed}} - *p = b; // expected-error{{dereferencing pointer of type 'half *' is not allowed}} - - b = p[1]; // expected-error {{subscript to array of type 'half' is not allowed}} - p[1] = b; // expected-error {{subscript to array of type 'half' is not allowed}} + *p; // expected-error{{loading directly from pointer to type 'half' is not allowed}} + p[1]; // expected-error{{loading directly from pointer to type 'half' is not allowed}} float c = 1.0f; b = (half) c; // expected-error{{casting to type 'half' is not allowed}} - c = (float) h; // expected-error{{casting from type 'half' is not allowed}} + + half *allowed = &p[1]; + half *allowed2 = &*p; + half *allowed3 = p + 1; return h; } @@ -27,16 +26,15 @@ half half_enabled(half *p, half h) { half a[2]; half b; - - b = *p; - *p = b; - - b = p[1]; - p[1] = b; + *p; + p[1]; float c = 1.0f; b = (half) c; - c = (float) h; + + half *allowed = &p[1]; + half *allowed2 = &*p; + half *allowed3 = p + 1; return h; } |