xref: /aosp_15_r20/external/clang/test/Preprocessor/line-directive.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c99 -fsyntax-only -verify -pedantic %s
2*67e74705SXin Li // RUN: not %clang_cc1 -E %s 2>&1 | grep 'blonk.c:92:2: error: ABC'
3*67e74705SXin Li // RUN: not %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: DEF'
4*67e74705SXin Li 
5*67e74705SXin Li #line 'a'            // expected-error {{#line directive requires a positive integer argument}}
6*67e74705SXin Li #line 0              // expected-warning {{#line directive with zero argument is a GNU extension}}
7*67e74705SXin Li #line 00             // expected-warning {{#line directive with zero argument is a GNU extension}}
8*67e74705SXin Li #line 2147483648     // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}}
9*67e74705SXin Li #line 42             // ok
10*67e74705SXin Li #line 42 'a'         // expected-error {{invalid filename for #line directive}}
11*67e74705SXin Li #line 42 "foo/bar/baz.h"  // ok
12*67e74705SXin Li 
13*67e74705SXin Li 
14*67e74705SXin Li // #line directives expand macros.
15*67e74705SXin Li #define A 42 "foo"
16*67e74705SXin Li #line A
17*67e74705SXin Li 
18*67e74705SXin Li # 42
19*67e74705SXin Li # 42 "foo"
20*67e74705SXin Li # 42 "foo" 2 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
21*67e74705SXin Li # 42 "foo" 1 3  // enter
22*67e74705SXin Li # 42 "foo" 2 3  // exit
23*67e74705SXin Li # 42 "foo" 2 3 4 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
24*67e74705SXin Li # 42 "foo" 3 4
25*67e74705SXin Li 
26*67e74705SXin Li # 'a'            // expected-error {{invalid preprocessing directive}}
27*67e74705SXin Li # 42 'f'         // expected-error {{invalid filename for line marker directive}}
28*67e74705SXin Li # 42 1 3         // expected-error {{invalid filename for line marker directive}}
29*67e74705SXin Li # 42 "foo" 3 1   // expected-error {{invalid flag line marker directive}}
30*67e74705SXin Li # 42 "foo" 42    // expected-error {{invalid flag line marker directive}}
31*67e74705SXin Li # 42 "foo" 1 2   // expected-error {{invalid flag line marker directive}}
32*67e74705SXin Li # 42a33          // expected-error {{GNU line marker directive requires a simple digit sequence}}
33*67e74705SXin Li 
34*67e74705SXin Li // These are checked by the RUN line.
35*67e74705SXin Li #line 92 "blonk.c"
36*67e74705SXin Li #error ABC
37*67e74705SXin Li #error DEF
38*67e74705SXin Li // expected-error@-2 {{ABC}}
39*67e74705SXin Li #line 150
40*67e74705SXin Li // expected-error@-3 {{DEF}}
41*67e74705SXin Li 
42*67e74705SXin Li 
43*67e74705SXin Li // Verify that linemarker diddling of the system header flag works.
44*67e74705SXin Li 
45*67e74705SXin Li # 192 "glomp.h" // not a system header.
46*67e74705SXin Li typedef int x;  // expected-note {{previous definition is here}}
47*67e74705SXin Li typedef int x;  // expected-warning {{redefinition of typedef 'x' is a C11 feature}}
48*67e74705SXin Li 
49*67e74705SXin Li # 192 "glomp.h" 3 // System header.
50*67e74705SXin Li typedef int y;  // ok
51*67e74705SXin Li typedef int y;  // ok
52*67e74705SXin Li 
53*67e74705SXin Li typedef int q;  // q is in system header.
54*67e74705SXin Li 
55*67e74705SXin Li #line 42 "blonk.h"  // doesn't change system headerness.
56*67e74705SXin Li 
57*67e74705SXin Li typedef int z;  // ok
58*67e74705SXin Li typedef int z;  // ok
59*67e74705SXin Li 
60*67e74705SXin Li # 97     // doesn't change system headerness.
61*67e74705SXin Li 
62*67e74705SXin Li typedef int z1;  // ok
63*67e74705SXin Li typedef int z1;  // ok
64*67e74705SXin Li 
65*67e74705SXin Li # 42 "blonk.h"  // DOES change system headerness.
66*67e74705SXin Li 
67*67e74705SXin Li typedef int w;  // expected-note {{previous definition is here}}
68*67e74705SXin Li typedef int w;  // expected-warning {{redefinition of typedef 'w' is a C11 feature}}
69*67e74705SXin Li 
70*67e74705SXin Li typedef int q;  // original definition in system header, should not diagnose.
71*67e74705SXin Li 
72*67e74705SXin Li // This should not produce an "extra tokens at end of #line directive" warning,
73*67e74705SXin Li // because #line is allowed to contain expanded tokens.
74*67e74705SXin Li #define EMPTY()
75*67e74705SXin Li #line 2 "foo.c" EMPTY( )
76*67e74705SXin Li #line 2 "foo.c" NONEMPTY( )  // expected-warning{{extra tokens at end of #line directive}}
77*67e74705SXin Li 
78*67e74705SXin Li // PR3940
79*67e74705SXin Li #line 0xf  // expected-error {{#line directive requires a simple digit sequence}}
80*67e74705SXin Li #line 42U  // expected-error {{#line directive requires a simple digit sequence}}
81*67e74705SXin Li 
82*67e74705SXin Li 
83*67e74705SXin Li // Line markers are digit strings interpreted as decimal numbers, this is
84*67e74705SXin Li // 10, not 8.
85*67e74705SXin Li #line 010  // expected-warning {{#line directive interprets number as decimal, not octal}}
86*67e74705SXin Li extern int array[__LINE__ == 10 ? 1:-1];
87*67e74705SXin Li 
88*67e74705SXin Li # 020      // expected-warning {{GNU line marker directive interprets number as decimal, not octal}}
89*67e74705SXin Li extern int array_gnuline[__LINE__ == 20 ? 1:-1];
90*67e74705SXin Li 
91*67e74705SXin Li /* PR3917 */
92*67e74705SXin Li #line 41
93*67e74705SXin Li extern char array2[\
94*67e74705SXin Li _\
95*67e74705SXin Li _LINE__ == 42 ? 1: -1];  /* line marker is location of first _ */
96*67e74705SXin Li 
97*67e74705SXin Li # 51
98*67e74705SXin Li extern char array2_gnuline[\
99*67e74705SXin Li _\
100*67e74705SXin Li _LINE__ == 52 ? 1: -1];  /* line marker is location of first _ */
101*67e74705SXin Li 
102*67e74705SXin Li // rdar://11550996
103*67e74705SXin Li #line 0 "line-directive.c" // expected-warning {{#line directive with zero argument is a GNU extension}}
104*67e74705SXin Li undefined t; // expected-error {{unknown type name 'undefined'}}
105*67e74705SXin Li 
106*67e74705SXin Li 
107