aboutsummaryrefslogtreecommitdiff
path: root/test/Frontend/verify.c
blob: 3d71e04980c56a6f7f2f637574a7c8d3a591d18a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// RUN: %clang_cc1 -DTEST1 -verify %s
// RUN: %clang_cc1 -DTEST2 -verify %s 2>&1 | FileCheck -check-prefix=CHECK2 %s
// RUN: %clang_cc1 -DTEST3 -verify %s 2>&1 | FileCheck -check-prefix=CHECK3 %s
// RUN: %clang_cc1 -DTEST4 -verify %s 2>&1 | FileCheck -check-prefix=CHECK4 %s
// RUN: %clang_cc1 -DTEST5 -verify %s 2>&1 | FileCheck -check-prefix=CHECK5 %s

// expected-warning@ malformed
// expected-error@7 1 {{missing or invalid line number}}

// expected-warning@0 malformed
// expected-error@10 {{missing or invalid line number}}

// expected-warning@-50 malformed
// expected-error@13 {{missing or invalid line number}}

// expected-warning malformed
// expected-error@16 {{cannot find start}}

// expected-error 0+ {{should also be ignored}}

#ifdef TEST1
#if 0
// expected-error {{should be ignored}}
#endif
// eexpected-error {{should also be ignored: unrecognised directive}}
#error should not be ignored
// expected-error@-1 1+ {{should not be ignored}}

#line 90
unexpected a; // expected-error@+0 + {{unknown type}}

#line 60
unexpected b; // expected-error@33 1-1 {{unknown type}}

// expected-error@+2 {{file not found}} check that multi-line handled correctly: \

#include "missing_header_file.include"
#endif

#ifdef TEST2
#define MACRO some_value // expected-error {{define_error}}
#undef MACRO extra_token // expected-warning {{undef_error}}
#line -2                 // expected-error {{line_error}}
#error AAA               // expected-error {{BBB}} <- this shall be part of diagnostic
#warning CCC             // expected-warning {{DDD}} <- this shall be part of diagnostic

#if 0
// This is encapsulated in "#if 0" so that the expected-* checks below
// are not inadvertently included in the diagnostic checking!

//      CHECK2: error: 'error' diagnostics expected but not seen:
// CHECK2-NEXT:   Line 41: define_error
// CHECK2-NEXT:   Line 43: line_error
// CHECK2-NEXT: error: 'error' diagnostics seen but not expected:
// CHECK2-NEXT:   Line 43: #line directive requires a positive integer argument
// CHECK2-NEXT:   Line 44: AAA // expected-error {{[{][{]BBB[}][}]}} <- this shall be part of diagnostic
// CHECK2-NEXT: error: 'warning' diagnostics expected but not seen:
// CHECK2-NEXT:   Line 42: undef_error
// CHECK2-NEXT: error: 'warning' diagnostics seen but not expected:
// CHECK2-NEXT:   Line 42: extra tokens at end of #undef directive
// CHECK2-NEXT:   Line 45: CCC // expected-warning {{[{][{]DDD[}][}]}} <- this shall be part of diagnostic
// CHECK2-NEXT: 7 errors generated.
#endif
#endif

#ifdef TEST3
#ifndef TEST3         // expected-note {{line_67}}
                      // expected-note {{line_68_ignored}}
# ifdef UNDEFINED     // expected-note {{line_69_ignored}}
# endif               // expected-note {{line_70_ignored}}
#elif defined(TEST3)  // expected-note {{line_71}}
# if 1                // expected-note {{line_72}}
                      // expected-note {{line_73}}
# else                // expected-note {{line_74}}
                      // expected-note {{line_75_ignored}}
#  ifndef TEST3       // expected-note {{line_76_ignored}}
#  endif              // expected-note {{line_77_ignored}}
# endif               // expected-note {{line_78}}
#endif

//      CHECK3: error: 'note' diagnostics expected but not seen:
// CHECK3-NEXT:   Line 67: line_67
// CHECK3-NEXT:   Line 71: line_71
// CHECK3-NEXT:   Line 72: line_72
// CHECK3-NEXT:   Line 73: line_73
// CHECK3-NEXT:   Line 74: line_74
// CHECK3-NEXT:   Line 78: line_78
// CHECK3-NEXT: 6 errors generated.
#endif

#ifdef TEST4
#include "missing_header_file.include" // expected-error {{include_error}}

//      CHECK4: error: 'error' diagnostics expected but not seen:
// CHECK4-NEXT:   Line 92: include_error
// CHECK4-NEXT: error: 'error' diagnostics seen but not expected:
// CHECK4-NEXT:   Line 92: 'missing_header_file.include' file not found
// CHECK4-NEXT: 2 errors generated.
#endif

#ifdef TEST5
#include "verify-directive.h"
// expected-error@50 {{source file test}}

//      CHECK5: error: 'error' diagnostics expected but not seen:
// CHECK5-NEXT:   Line 1 (directive at {{.*}}verify-directive.h:2): include file test
// CHECK5-NEXT:   Line 50 (directive at {{.*}}verify.c:103): source file test
// CHECK5-NEXT: 2 errors generated.
#endif

#if 0
// RUN: %clang_cc1 -verify %t.invalid 2>&1 | FileCheck -check-prefix=CHECK6 %s

//      CHECK6: error: no expected directives found: consider use of 'expected-no-diagnostics'
// CHECK6-NEXT: error: 'error' diagnostics seen but not expected:
// CHECK6-NEXT:   (frontend): error reading '{{.*}}verify.c.tmp.invalid'
// CHECK6-NEXT: 2 errors generated.

// RUN: echo -e '//expected-error@2{{1}}\n#error 2' | %clang_cc1 -verify 2>&1 | FileCheck -check-prefix=CHECK7 %s

//      CHECK7: error: 'error' diagnostics expected but not seen:
// CHECK7-NEXT:   Line 2 (directive at <stdin>:1): 1
// CHECK7-NEXT: error: 'error' diagnostics seen but not expected:
// CHECK7-NEXT:   Line 2: 2
// CHECK7-NEXT: 2 errors generated.
#endif

#ifdef TEST8
// RUN: %clang_cc1 -DTEST8 -verify %s 2>&1 | FileCheck -check-prefix=CHECK8 %s

// expected-warning@nonexistant-file:1 {{ }}
// expected-error@-1 {{file 'nonexistant-file' could not be located}}

// expected-warning@verify-directive.h: {{ }}
// expected-error@-1 {{missing or invalid line number}}

// expected-warning@verify-directive.h:1 {{diagnostic}}

//      CHECK8: error: 'warning' diagnostics expected but not seen:
// CHECK8-NEXT:   File {{.*}}verify-directive.h Line 1 (directive at {{.*}}verify.c:137): diagnostic
// CHECK8-NEXT: 1 error generated.
#endif