From d0960ed3a020151497ae1167a28242f54a527ee4 Mon Sep 17 00:00:00 2001 From: Andrew Savonichev Date: Mon, 17 Sep 2018 10:39:46 +0000 Subject: [PATCH] Merge two attribute diagnostics into one Summary: Merged the recently added `err_attribute_argument_negative` diagnostic with existing `err_attribute_requires_positive_integer` diagnostic: the former allows only strictly positive integer, while the latter also allows zero. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51853 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342367 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 5 ++--- lib/Sema/SemaDeclAttr.cpp | 3 ++- lib/Sema/SemaStmtAttr.cpp | 2 +- test/SemaOpenCL/invalid-kernel-attrs.cl | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 08dfbd3c74..59f35b4fd4 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2498,7 +2498,8 @@ def err_attribute_invalid_vector_type : Error<"invalid vector element type %0">; def err_attribute_bad_neon_vector_size : Error< "Neon vector size must be 64 or 128 bits">; def err_attribute_requires_positive_integer : Error< - "%0 attribute requires a positive integral compile time constant expression">; + "%0 attribute requires a %select{positive|non-negative}1 " + "integral compile time constant expression">; def err_attribute_requires_opencl_version : Error< "%0 attribute requires OpenCL version %1%select{| or above}2">; def warn_unsupported_target_attribute @@ -2531,8 +2532,6 @@ def err_attribute_argument_type : Error< "constant|a string|an identifier}1">; def err_attribute_argument_outof_range : Error< "%0 attribute requires integer constant between %1 and %2 inclusive">; -def err_attribute_argument_negative : Error< - "negative argument is not allowed for %0 attribute">; def err_init_priority_object_attr : Error< "can only use 'init_priority' attribute on file-scope definitions " "of objects of class type">; diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index b58976a729..f921d3e7d7 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -254,7 +254,8 @@ static bool checkUInt32Argument(Sema &S, const AttrInfo &AI, const Expr *Expr, } if (StrictlyUnsigned && I.isSigned() && I.isNegative()) { - S.Diag(getAttrLoc(AI), diag::err_attribute_argument_negative) << AI; + S.Diag(getAttrLoc(AI), diag::err_attribute_requires_positive_integer) + << AI << /*non-negative*/ 1; return false; } diff --git a/lib/Sema/SemaStmtAttr.cpp b/lib/Sema/SemaStmtAttr.cpp index ba96ba9c23..c720aff064 100644 --- a/lib/Sema/SemaStmtAttr.cpp +++ b/lib/Sema/SemaStmtAttr.cpp @@ -304,7 +304,7 @@ static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A, if (Val <= 0) { S.Diag(A.getRange().getBegin(), diag::err_attribute_requires_positive_integer) - << A; + << A << /* positive */ 0; return nullptr; } UnrollFactor = Val; diff --git a/test/SemaOpenCL/invalid-kernel-attrs.cl b/test/SemaOpenCL/invalid-kernel-attrs.cl index 9a0bcd83e9..a96e85c9ee 100644 --- a/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -38,8 +38,8 @@ __attribute__((intel_reqd_sub_group_size(8))) void kernel14(){} // expected-erro kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15(){} // expected-error {{'intel_reqd_sub_group_size' attribute must be greater than 0}} kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel16() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} -__kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{negative argument is not allowed for 'work_group_size_hint' attribute}} -__kernel __attribute__((reqd_work_group_size(8,16,-32))) void neg2(){} // expected-error{{negative argument is not allowed for 'reqd_work_group_size' attribute}} +__kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} +__kernel __attribute__((reqd_work_group_size(8,16,-32))) void neg2(){} // expected-error{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression}} // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. -- 2.40.0