150
|
1 #if GC
|
|
2 # define GCONST const
|
|
3 #else
|
|
4 # define GCONST
|
|
5 #endif
|
|
6
|
|
7 // gconst-note@8 {{variable 'glb' declared const here}}
|
|
8 GCONST int glb = 5;
|
|
9
|
|
10
|
|
11 // Check various correct prefix spellings and combinations.
|
|
12 //
|
|
13 // RUN: %clang_cc1 -DGC -verify=gconst %s
|
|
14 // RUN: %clang_cc1 -Wcast-qual -DLC -verify=lconst %s
|
|
15 // RUN: %clang_cc1 -DSC -verify=expected %s
|
|
16 // RUN: %clang_cc1 -DSC -verify %s
|
|
17 // RUN: %clang_cc1 -DSC -verify -verify %s
|
|
18 // RUN: %clang_cc1 -verify=nconst %s
|
|
19 // RUN: %clang_cc1 -verify=n-const %s
|
|
20 // RUN: %clang_cc1 -verify=n_const %s
|
|
21 // RUN: %clang_cc1 -verify=NConst %s
|
|
22 // RUN: %clang_cc1 -verify=NConst2 %s
|
|
23 // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst,lconst %s
|
|
24 // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -DSC -verify=gconst,lconst,expected %s
|
|
25 // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst -verify=lconst %s
|
|
26 // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -DSC -verify=gconst,lconst -verify %s
|
|
27 // RUN: %clang_cc1 -DGC -DSC -verify -verify=gconst -verify %s
|
|
28 //
|
|
29 // Duplicate prefixes.
|
|
30 // RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst,lconst,gconst %s
|
|
31 // RUN: %clang_cc1 -DGC -verify=gconst -verify=gconst,gconst %s
|
|
32 // RUN: %clang_cc1 -DSC -verify=expected -verify=expected %s
|
|
33 // RUN: %clang_cc1 -DSC -verify -verify=expected %s
|
|
34 //
|
|
35 // Various tortured cases: multiple directives with different prefixes per
|
|
36 // line, prefixes used as comments, prefixes prefixing prefixes, and prefixes
|
|
37 // with special suffixes.
|
|
38 // RUN: %clang_cc1 -Wcast-qual -DLC -verify=foo %s
|
|
39 // RUN: %clang_cc1 -DSC -verify=bar %s
|
|
40 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,bar %s
|
|
41 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,foo %s
|
|
42 // RUN: %clang_cc1 -DSC -verify=foo-bar %s
|
|
43 // RUN: %clang_cc1 -Wcast-qual -DLC -verify=bar-foo %s
|
|
44 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,foo-bar %s
|
|
45 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-bar,foo %s
|
|
46 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,bar-foo %s
|
|
47 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar-foo,bar %s
|
|
48 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-bar,bar-foo %s
|
|
49 // RUN: %clang_cc1 -DSC -verify=foo-warning %s
|
|
50 // RUN: %clang_cc1 -Wcast-qual -DLC -verify=bar-warning-re %s
|
|
51 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,foo-warning %s
|
|
52 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-warning,foo %s
|
|
53 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,bar-warning-re %s
|
|
54 // RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar-warning-re,bar %s
|
|
55
|
|
56
|
|
57 // Check invalid prefixes. Check that there's no additional output, which
|
|
58 // might indicate that diagnostic verification became enabled even though it
|
|
59 // was requested incorrectly. Check that prefixes are reported in command-line
|
|
60 // order.
|
|
61 //
|
|
62 // RUN: not %clang_cc1 -verify=5abc,-xy,foo,_k -verify='#a,b$' %s 2> %t
|
|
63 // RUN: FileCheck --check-prefixes=ERR %s < %t
|
|
64 //
|
|
65 // ERR-NOT: {{.}}
|
|
66 // ERR: error: invalid value '5abc' in '-verify='
|
|
67 // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
|
|
68 // ERR-NEXT: error: invalid value '-xy' in '-verify='
|
|
69 // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
|
|
70 // ERR-NEXT: error: invalid value '_k' in '-verify='
|
|
71 // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
|
|
72 // ERR-NEXT: error: invalid value '#a' in '-verify='
|
|
73 // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
|
|
74 // ERR-NEXT: error: invalid value 'b$' in '-verify='
|
|
75 // ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores
|
|
76 // ERR-NOT: {{.}}
|
|
77
|
|
78
|
|
79 // Check that our test code actually has expected diagnostics when there's no
|
|
80 // -verify.
|
|
81 //
|
|
82 // RUN: not %clang_cc1 -Wcast-qual -DGC -DLC -DSC %s 2> %t
|
|
83 // RUN: FileCheck --check-prefix=ALL %s < %t
|
|
84 //
|
|
85 // ALL: cannot assign to variable 'glb' with const-qualified type 'const int'
|
|
86 // ALL: variable 'glb' declared const here
|
|
87 // ALL: cast from 'const int *' to 'int *' drops const qualifier
|
|
88 // ALL: initializing 'int *' with an expression of type 'const int *' discards qualifiers
|
|
89
|
|
90
|
|
91 #if LC
|
|
92 # define LCONST const
|
|
93 #else
|
|
94 # define LCONST
|
|
95 #endif
|
|
96
|
|
97 #if SC
|
|
98 # define SCONST const
|
|
99 #else
|
|
100 # define SCONST
|
|
101 #endif
|
|
102
|
|
103 void foo() {
|
|
104 LCONST int loc = 5;
|
|
105 SCONST static int sta = 5;
|
|
106 // We don't actually expect 1-2 occurrences of this error. We're just
|
|
107 // checking the parsing.
|
|
108 glb = 6; // gconst-error1-2 {{cannot assign to variable 'glb' with const-qualified type 'const int'}}
|
|
109 *(int*)(&loc) = 6; // lconst-warning {{cast from 'const int *' to 'int *' drops const qualifier}}
|
|
110 ; // Code, comments, and many directives with different prefixes per line, including cases where some prefixes (foo and bar) prefix others (such as foo-bar and bar-foo), such that some prefixes appear as normal comments and some have special suffixes (-warning and -re): foo-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} foo-bar-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} foo-warning-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} bar-warning-re-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} bar-foo-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} bar-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
|
|
111 int *p = &sta; // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
|
|
112 }
|
|
113
|
|
114 // nconst-no-diagnostics
|
|
115 // n-const-no-diagnostics
|
|
116 // n_const-no-diagnostics
|
|
117 // NConst-no-diagnostics
|
|
118 // NConst2-no-diagnostics
|