Index: cfe/trunk/include/clang/Basic/Attr.td =================================================================== --- cfe/trunk/include/clang/Basic/Attr.td +++ cfe/trunk/include/clang/Basic/Attr.td @@ -239,6 +239,7 @@ def Borland : LangOpt<"Borland">; def CUDA : LangOpt<"CUDA">; def COnly : LangOpt<"CPlusPlus", 1>; +def OpenCL : LangOpt<"OpenCL">; // Defines targets for target-specific attributes. The list of strings should // specify architectures for which the target applies, based off the ArchType @@ -719,6 +720,14 @@ let Documentation = [OpenCLAddressSpaceGenericDocs]; } +def OpenCLNoSVM : Attr { + let Spellings = [GNU<"nosvm">]; + let Subjects = SubjectList<[Var]>; + let Documentation = [OpenCLNoSVMDocs]; + let LangOpts = [OpenCL]; + let ASTNode = 0; +} + def Deprecated : InheritableAttr { let Spellings = [GCC<"deprecated">, Declspec<"deprecated">, CXX11<"","deprecated", 201309>]; Index: cfe/trunk/include/clang/Basic/AttrDocs.td =================================================================== --- cfe/trunk/include/clang/Basic/AttrDocs.td +++ cfe/trunk/include/clang/Basic/AttrDocs.td @@ -1773,6 +1773,17 @@ }]; } +def OpenCLNoSVMDocs : Documentation { + let Category = DocCatVariable; + let Content = [{ +OpenCL 2.0 supports the optional ``__attribute__((nosvm))`` qualifier for +pointer variable. It informs the compiler that the pointer does not refer +to a shared virtual memory region. See OpenCL v2.0 s6.7.2 for details. + +Since it is not widely used and has been removed from OpenCL 2.1, it is ignored +by Clang. + }]; +} def NullabilityDocs : DocumentationCategory<"Nullability Attributes"> { let Content = [{ Whether a particular pointer may be "null" is an important concern when working with pointers in the C family of languages. The various nullability attributes indicate whether a particular pointer can be null or not, which makes APIs more expressive and can help static analysis tools identify bugs involving null pointers. Clang supports several kinds of nullability attributes: the ``nonnull`` and ``returns_nonnull`` attributes indicate which function or method parameters and result types can never be null, while nullability type qualifiers indicate which pointer types can be null (``_Nullable``) or cannot be null (``_Nonnull``). Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td @@ -2129,7 +2129,7 @@ def err_attribute_requires_positive_integer : Error< "%0 attribute requires a positive integral compile time constant expression">; def err_attribute_requires_opencl_version : Error< - "%0 attribute requires OpenCL version %1 or above">; + "%0 attribute requires OpenCL version %1%select{| or above}2">; def warn_unsupported_target_attribute : Warning<"Ignoring unsupported '%0' in the target attribute string">, InGroup; @@ -7775,6 +7775,9 @@ "pointer to type %0 is invalid in OpenCL">; def err_opencl_type_can_only_be_used_as_function_parameter : Error < "type %0 can only be used as a function parameter in OpenCL">; +def warn_opencl_attr_deprecated_ignored : Warning < + "%0 attribute is deprecated and ignored in OpenCL version %1">, + InGroup; // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions def err_opencl_builtin_pipe_first_arg : Error< Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -5214,6 +5214,15 @@ D->addAttr(Internal); } +static void handleOpenCLNoSVMAttr(Sema &S, Decl *D, const AttributeList &Attr) { + if (S.LangOpts.OpenCLVersion != 200) + S.Diag(Attr.getLoc(), diag::err_attribute_requires_opencl_version) + << Attr.getName() << "2.0" << 0; + else + S.Diag(Attr.getLoc(), diag::warn_opencl_attr_deprecated_ignored) + << Attr.getName() << "2.0"; +} + /// Handles semantic checking for features that are common to all attributes, /// such as checking whether a parameter was properly specified, or the correct /// number of arguments were passed, etc. @@ -5706,6 +5715,9 @@ case AttributeList::AT_SwiftIndirectResult: handleParameterABIAttr(S, D, Attr, ParameterABI::SwiftIndirectResult); break; + case AttributeList::AT_OpenCLNoSVM: + handleOpenCLNoSVMAttr(S, D, Attr); + break; case AttributeList::AT_InternalLinkage: handleInternalLinkageAttr(S, D, Attr); break; Index: cfe/trunk/lib/Sema/SemaStmtAttr.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaStmtAttr.cpp +++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp @@ -221,7 +221,7 @@ if (S.getLangOpts().OpenCLVersion < 200) { S.Diag(A.getLoc(), diag::err_attribute_requires_opencl_version) - << A.getName() << "2.0"; + << A.getName() << "2.0" << 1; return nullptr; } Index: cfe/trunk/test/SemaOpenCL/nosvm.cl =================================================================== --- cfe/trunk/test/SemaOpenCL/nosvm.cl +++ cfe/trunk/test/SemaOpenCL/nosvm.cl @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -verify -cl-std=CL2.0 -D CL20 %s +// RUN: %clang_cc1 -verify -x c -D NOCL %s + +#ifndef NOCL +kernel void f(__attribute__((nosvm)) global int* a); +#ifndef CL20 +// expected-error@-2 {{'nosvm' attribute requires OpenCL version 2.0}} +#else +// expected-warning@-4 {{'nosvm' attribute is deprecated and ignored in OpenCL version 2.0}} +#endif + +__attribute__((nosvm)) void g(); // expected-warning {{'nosvm' attribute only applies to variables}} + +#else +void f(__attribute__((nosvm)) int* a); // expected-warning {{'nosvm' attribute ignored}} +#endif