Skip to content

Commit 43ab9a0

Browse files
author
Anastasia Stulova
committed
[OpenCL] Output OpenCL version in diagnostics.
Diagnostics should note version dependent issues by giving a hint about current version being compiled for. This patch changes diagnostics of static storage class specifier and generic type qualifier to specify OpenCL version as well as converts other diagnostics to match the style. Patch by Vedran Miletic! Review: http://reviews.llvm.org/D19780 llvm-svn: 269305
1 parent c285312 commit 43ab9a0

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -7865,13 +7865,13 @@ def err_opencl_builtin_pipe_invalid_access_modifier : Error<
78657865
def err_opencl_invalid_access_qualifier : Error<
78667866
"access qualifier can only be used for pipe and image type">;
78677867
def err_opencl_invalid_read_write : Error<
7868-
"access qualifier %0 can not be used for %1 %select{|earlier than OpenCL2.0 version}2">;
7868+
"access qualifier %0 can not be used for %1 %select{|earlier than OpenCL version 2.0}2">;
78697869
def err_opencl_multiple_access_qualifiers : Error<
78707870
"multiple access qualifiers">;
78717871

78727872
// OpenCL Section 6.8.g
78737873
def err_opencl_unknown_type_specifier : Error<
7874-
"OpenCL does not support the '%0' %select{type qualifier|storage class specifier}1">;
7874+
"OpenCL version %0 does not support the '%1' %select{type qualifier|storage class specifier}2">;
78757875

78767876
// OpenCL v2.0 s6.12.5 Blocks restrictions
78777877
def err_opencl_block_storage_type : Error<

clang/lib/Parse/ParseDecl.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/ADT/SmallSet.h"
2929
#include "llvm/ADT/SmallString.h"
3030
#include "llvm/ADT/StringSwitch.h"
31+
#include "llvm/Support/ScopedPrinter.h"
3132

3233
using namespace clang;
3334

@@ -3514,9 +3515,13 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
35143515
if (DiagID == diag::ext_duplicate_declspec)
35153516
Diag(Tok, DiagID)
35163517
<< PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
3517-
else if (DiagID == diag::err_opencl_unknown_type_specifier)
3518-
Diag(Tok, DiagID) << PrevSpec << isStorageClass;
3519-
else
3518+
else if (DiagID == diag::err_opencl_unknown_type_specifier) {
3519+
const int OpenCLVer = getLangOpts().OpenCLVersion;
3520+
std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
3521+
std::string (".") +
3522+
llvm::to_string((OpenCLVer % 100) / 10);
3523+
Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
3524+
} else
35203525
Diag(Tok, DiagID) << PrevSpec;
35213526
}
35223527

clang/test/Parser/opencl-cl20.cl

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ __generic int * __generic_test(__generic int *arg) {
1010
return var;
1111
}
1212
#ifndef CL20
13-
// expected-error@-5 {{OpenCL does not support the '__generic' type qualifier}}
14-
// expected-error@-6 {{OpenCL does not support the '__generic' type qualifier}}
15-
// expected-error@-6 {{OpenCL does not support the '__generic' type qualifier}}
13+
// expected-error@-5 {{OpenCL version 1.0 does not support the '__generic' type qualifier}}
14+
// expected-error@-6 {{OpenCL version 1.0 does not support the '__generic' type qualifier}}
15+
// expected-error@-6 {{OpenCL version 1.0 does not support the '__generic' type qualifier}}
1616
#endif
1717

1818
generic int * generic_test(generic int *arg) {
1919
generic int *var;
2020
return var;
2121
}
2222
#ifndef CL20
23-
// expected-error@-5 {{OpenCL does not support the 'generic' type qualifier}}
24-
// expected-error@-6 {{OpenCL does not support the 'generic' type qualifier}}
25-
// expected-error@-6 {{OpenCL does not support the 'generic' type qualifier}}
23+
// expected-error@-5 {{OpenCL version 1.0 does not support the 'generic' type qualifier}}
24+
// expected-error@-6 {{OpenCL version 1.0 does not support the 'generic' type qualifier}}
25+
// expected-error@-6 {{OpenCL version 1.0 does not support the 'generic' type qualifier}}
2626
#endif

clang/test/Parser/opencl-storage-class.cl

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
void test_storage_class_specs()
44
{
5-
static int a; // expected-error {{OpenCL does not support the 'static' storage class specifier}}
6-
register int b; // expected-error {{OpenCL does not support the 'register' storage class specifier}}
7-
extern int c; // expected-error {{OpenCL does not support the 'extern' storage class specifier}}
8-
auto int d; // expected-error {{OpenCL does not support the 'auto' storage class specifier}}
5+
static int a; // expected-error {{OpenCL version 1.0 does not support the 'static' storage class specifier}}
6+
register int b; // expected-error {{OpenCL version 1.0 does not support the 'register' storage class specifier}}
7+
extern int c; // expected-error {{OpenCL version 1.0 does not support the 'extern' storage class specifier}}
8+
auto int d; // expected-error {{OpenCL version 1.0 does not support the 'auto' storage class specifier}}
99

1010
#pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable
1111
static int e; // expected-error {{static local variable must reside in constant address space}}

clang/test/SemaOpenCL/invalid-access-qualifier.cl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ void test3(read_only read_only image1d_t i){} // expected-error{{multiple access
1010
#ifdef CL20
1111
void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
1212
#else
13-
void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL2.0 version}}
13+
void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL version 2.0}}
1414
#endif

clang/test/SemaOpenCL/storageclass.cl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void kernel foo() {
1313
constant int L1 = 0;
1414
local int L2;
1515

16-
auto int L3 = 7; // expected-error{{OpenCL does not support the 'auto' storage class specifier}}
16+
auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
1717
global int L4; // expected-error{{function scope variable cannot be declared in global address space}}
1818
}
1919

0 commit comments

Comments
 (0)