r174928 - Diagnose loads of 'half' l-values in OpenCL.

Richard Smith richard at metafoo.co.uk
Mon Feb 11 17:38:52 PST 2013


On Mon, Feb 11, 2013 at 5:37 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> On Mon, Feb 11, 2013 at 5:29 PM, John McCall <rjmccall at apple.com> wrote:
>
>> Author: rjmccall
>> Date: Mon Feb 11 19:29:43 2013
>> New Revision: 174928
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=174928&view=rev
>> Log:
>> Diagnose loads of 'half' l-values in OpenCL.
>> Patch by Joey Gouly!
>>
>> Modified:
>>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>     cfe/trunk/lib/Sema/SemaCast.cpp
>>     cfe/trunk/lib/Sema/SemaExpr.cpp
>>     cfe/trunk/lib/Sema/SemaType.cpp
>>     cfe/trunk/test/SemaOpenCL/half.cl
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=174928&r1=174927&r2=174928&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Feb 11
>> 19:29:43 2013
>> @@ -420,12 +420,9 @@ def err_object_cannot_be_passed_returned
>>    "; 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">;
>>
>
> Shouldn't the "assigning" half of this diagnostic be emitted somewhere?
> All the tests for it seem to have been removed too.
>

Ha, I see you've brought this up on the other thread. Never mind then!


>  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<
>>
>> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=174928&r1=174927&r2=174928&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaCast.cpp Mon Feb 11 19:29:43 2013
>> @@ -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.
>>
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=174928&r1=174927&r2=174928&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Feb 11 19:29:43 2013
>> @@ -482,6 +482,14 @@ ExprResult Sema::DefaultLvalueConversion
>>    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(Ex
>>                            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(QualTyp
>>    LHSType = Context.getCanonicalType(LHSType).getUnqualifiedType();
>>    RHSType = Context.getCanonicalType(RHSType).getUnqualifiedType();
>>
>> -
>>    // Common case: no conversion required.
>>    if (LHSType == RHSType) {
>>      Kind = CK_NoOp;
>> @@ -8241,13 +8241,6 @@ static QualType CheckIndirectionOperand(
>>        << OpTy << Op->getSourceRange();
>>      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;
>>
>> Modified: cfe/trunk/lib/Sema/SemaType.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=174928&r1=174927&r2=174928&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Feb 11 19:29:43 2013
>> @@ -2642,6 +2642,7 @@ static TypeSourceInfo *GetFullTypeForDec
>>                  S.Diag(Param->getLocation(),
>>                    diag::err_opencl_half_argument) << ArgTy;
>>                  D.setInvalidType();
>> +                Param->setInvalidDecl();
>>                }
>>              } else {
>>                S.Diag(Param->getLocation(),
>>
>> Modified: cfe/trunk/test/SemaOpenCL/half.cl
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/half.cl?rev=174928&r1=174927&r2=174928&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/SemaOpenCL/half.cl (original)
>> +++ cfe/trunk/test/SemaOpenCL/half.cl Mon Feb 11 19:29:43 2013
>> @@ -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-
>>  {
>>    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;
>>  }
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130211/2ae1434c/attachment.html>


More information about the cfe-commits mailing list