/[packages]/cauldron/mesa/current/SOURCES/0010-glsl-fixer-lexer-for-unreachable-defines.patch
ViewVC logotype

Contents of /cauldron/mesa/current/SOURCES/0010-glsl-fixer-lexer-for-unreachable-defines.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1257897 - (show annotations) (download)
Sat Sep 8 20:31:12 2018 UTC (5 years, 7 months ago) by tmb
File size: 4066 byte(s)
add fixes from staging/18.2 branch
1 From 8a471fe120f408bc2e016246e6416b6321739158 Mon Sep 17 00:00:00 2001
2 From: Timothy Arceri <tarceri@itsqueeze.com>
3 Date: Sat, 1 Sep 2018 23:57:38 +1000
4 Subject: [PATCH 10/20] glsl: fixer lexer for unreachable defines
5
6 If we have something like:
7
8 #ifdef NOT_DEFINED
9 #define A_MACRO(x) \
10 if (x)
11 #endif
12
13 The # on the #define is not skipped but the define itself is so
14 this then gets recognised as #if.
15
16 Until 28a3731e3f this didn't happen because we ended up in
17 <HASH>{NONSPACE} where BEGIN INITIAL was called stopping the
18 problem from happening.
19
20 This change makes sure we never call RETURN_TOKEN_NEVER_SKIP for
21 if/else/endif when processing a define.
22
23 Cc: Ian Romanick <idr@freedesktop.org>
24 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107772
25 Tested-By: Eero Tamminen <eero.t.tamminen@intel.com>
26 Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
27 (cherry picked from commit b9fe8ff23dcfe4956be1eac4de0838d4a3720315)
28 ---
29 src/compiler/glsl/glcpp/glcpp-lex.l | 60 ++++++++++++++++++-----------
30 src/compiler/glsl/glcpp/glcpp.h | 1 +
31 2 files changed, 38 insertions(+), 23 deletions(-)
32
33 diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l b/src/compiler/glsl/glcpp/glcpp-lex.l
34 index 9cfcc12022..05447b31e4 100644
35 --- a/src/compiler/glsl/glcpp/glcpp-lex.l
36 +++ b/src/compiler/glsl/glcpp/glcpp-lex.l
37 @@ -289,6 +289,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
38 * token. */
39 if (parser->first_non_space_token_this_line) {
40 BEGIN HASH;
41 + yyextra->in_define = false;
42 }
43
44 RETURN_TOKEN_NEVER_SKIP (HASH_TOKEN);
45 @@ -336,43 +337,55 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
46 /* For the pre-processor directives, we return these tokens
47 * even when we are otherwise skipping. */
48 <HASH>ifdef {
49 - BEGIN INITIAL;
50 - yyextra->lexing_directive = 1;
51 - yyextra->space_tokens = 0;
52 - RETURN_TOKEN_NEVER_SKIP (IFDEF);
53 + if (!yyextra->in_define) {
54 + BEGIN INITIAL;
55 + yyextra->lexing_directive = 1;
56 + yyextra->space_tokens = 0;
57 + RETURN_TOKEN_NEVER_SKIP (IFDEF);
58 + }
59 }
60
61 <HASH>ifndef {
62 - BEGIN INITIAL;
63 - yyextra->lexing_directive = 1;
64 - yyextra->space_tokens = 0;
65 - RETURN_TOKEN_NEVER_SKIP (IFNDEF);
66 + if (!yyextra->in_define) {
67 + BEGIN INITIAL;
68 + yyextra->lexing_directive = 1;
69 + yyextra->space_tokens = 0;
70 + RETURN_TOKEN_NEVER_SKIP (IFNDEF);
71 + }
72 }
73
74 <HASH>if/[^_a-zA-Z0-9] {
75 - BEGIN INITIAL;
76 - yyextra->lexing_directive = 1;
77 - yyextra->space_tokens = 0;
78 - RETURN_TOKEN_NEVER_SKIP (IF);
79 + if (!yyextra->in_define) {
80 + BEGIN INITIAL;
81 + yyextra->lexing_directive = 1;
82 + yyextra->space_tokens = 0;
83 + RETURN_TOKEN_NEVER_SKIP (IF);
84 + }
85 }
86
87 <HASH>elif/[^_a-zA-Z0-9] {
88 - BEGIN INITIAL;
89 - yyextra->lexing_directive = 1;
90 - yyextra->space_tokens = 0;
91 - RETURN_TOKEN_NEVER_SKIP (ELIF);
92 + if (!yyextra->in_define) {
93 + BEGIN INITIAL;
94 + yyextra->lexing_directive = 1;
95 + yyextra->space_tokens = 0;
96 + RETURN_TOKEN_NEVER_SKIP (ELIF);
97 + }
98 }
99
100 <HASH>else {
101 - BEGIN INITIAL;
102 - yyextra->space_tokens = 0;
103 - RETURN_TOKEN_NEVER_SKIP (ELSE);
104 + if (!yyextra->in_define) {
105 + BEGIN INITIAL;
106 + yyextra->space_tokens = 0;
107 + RETURN_TOKEN_NEVER_SKIP (ELSE);
108 + }
109 }
110
111 <HASH>endif {
112 - BEGIN INITIAL;
113 - yyextra->space_tokens = 0;
114 - RETURN_TOKEN_NEVER_SKIP (ENDIF);
115 + if (!yyextra->in_define) {
116 + BEGIN INITIAL;
117 + yyextra->space_tokens = 0;
118 + RETURN_TOKEN_NEVER_SKIP (ENDIF);
119 + }
120 }
121
122 <HASH>error[^\r\n]* {
123 @@ -399,7 +412,8 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
124 * and not whitespace). This will generate an error.
125 */
126 <HASH>define{HSPACE}* {
127 - if (! parser->skipping) {
128 + yyextra->in_define = true;
129 + if (!parser->skipping) {
130 BEGIN DEFINE;
131 yyextra->space_tokens = 0;
132 RETURN_TOKEN (DEFINE_TOKEN);
133 diff --git a/src/compiler/glsl/glcpp/glcpp.h b/src/compiler/glsl/glcpp/glcpp.h
134 index c7e382ed30..e786b24b13 100644
135 --- a/src/compiler/glsl/glcpp/glcpp.h
136 +++ b/src/compiler/glsl/glcpp/glcpp.h
137 @@ -197,6 +197,7 @@ struct glcpp_parser {
138 int first_non_space_token_this_line;
139 int newline_as_space;
140 int in_control_line;
141 + bool in_define;
142 int paren_count;
143 int commented_newlines;
144 skip_node_t *skip_stack;
145 --
146 2.18.0
147

  ViewVC Help
Powered by ViewVC 1.1.30