summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2018-11-01 13:50:14 -0700
committerIan Romanick <[email protected]>2018-11-08 11:00:00 -0800
commitc5a4c264508d3b36663779b89ec0dbaf7653df96 (patch)
tree0e27e48dc1617316c2312a271963ff36bc0befe4 /src
parent011abfc963a734953a0edd9c7a4fa01570627050 (diff)
glsl: Add pragma to disable all warnings
Use #pragma warning(off) and #pragma warning(on) to disable or enable all warnings. This is a big hammer. If we ever need a smaller hammer, we can enhance this functionality. There is one lame thing about this. Because we parse everything, create an AST, then convert the AST to GLSL IR, we have to treat the #pragma like a statment. This means that you can't do something like ' void ' #pragma warning(off) ' __foo ' #pragma warning(on) ' (float param0); Fixing that would, as far as I can tell, require a huge amount of work. I did try just handling the #pragma during parsing (like we do for state for the whole shader. v2: Fix the #pragma lines in the commit message that git-commit ate. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/glsl/ast.h14
-rw-r--r--src/compiler/glsl/ast_to_hir.cpp8
-rw-r--r--src/compiler/glsl/glsl_lexer.ll8
-rw-r--r--src/compiler/glsl/glsl_parser.yy24
-rw-r--r--src/compiler/glsl/glsl_parser_extras.cpp12
-rw-r--r--src/compiler/glsl/glsl_parser_extras.h7
-rw-r--r--src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert24
-rw-r--r--src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert.expected2
8 files changed, 89 insertions, 10 deletions
diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h
index 4d5e045b82c..94bcf644a26 100644
--- a/src/compiler/glsl/ast.h
+++ b/src/compiler/glsl/ast.h
@@ -1315,6 +1315,20 @@ private:
ast_layout_expression *local_size[3];
};
+class ast_warnings_toggle : public ast_node {
+public:
+ ast_warnings_toggle(bool _enable)
+ : enable(_enable)
+ {
+ /* empty */
+ }
+
+ virtual ir_rvalue *hir(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state);
+
+private:
+ bool enable;
+};
/*@}*/
extern void
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 7671041a454..95cef626ac3 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -8766,3 +8766,11 @@ remove_per_vertex_blocks(exec_list *instructions,
}
}
}
+
+ir_rvalue *
+ast_warnings_toggle::hir(exec_list *,
+ struct _mesa_glsl_parse_state *state)
+{
+ state->warnings_enabled = enable;
+ return NULL;
+}
diff --git a/src/compiler/glsl/glsl_lexer.ll b/src/compiler/glsl/glsl_lexer.ll
index 0a2bba6d38f..224418ed7ce 100644
--- a/src/compiler/glsl/glsl_lexer.ll
+++ b/src/compiler/glsl/glsl_lexer.ll
@@ -295,6 +295,14 @@ HASH ^{SPC}#{SPC}
BEGIN PP;
return PRAGMA_OPTIMIZE_OFF;
}
+^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}on{SPC}\) {
+ BEGIN PP;
+ return PRAGMA_WARNING_ON;
+ }
+^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}off{SPC}\) {
+ BEGIN PP;
+ return PRAGMA_WARNING_OFF;
+ }
^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) {
BEGIN PP;
return PRAGMA_INVARIANT_ALL;
diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy
index fd1592beca0..ddb54f4a4d6 100644
--- a/src/compiler/glsl/glsl_parser.yy
+++ b/src/compiler/glsl/glsl_parser.yy
@@ -164,6 +164,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
%token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
%token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
%token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
+%token PRAGMA_WARNING_ON PRAGMA_WARNING_OFF
%token PRAGMA_INVARIANT_ALL
%token LAYOUT_TOK
%token DOT_TOK
@@ -246,6 +247,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
%type <n> unary_operator
%type <expression> function_identifier
%type <node> external_declaration
+%type <node> pragma_statement
%type <declarator_list> init_declarator_list
%type <declarator_list> single_declaration
%type <expression> initializer
@@ -328,10 +330,10 @@ version_statement:
;
pragma_statement:
- PRAGMA_DEBUG_ON EOL
- | PRAGMA_DEBUG_OFF EOL
- | PRAGMA_OPTIMIZE_ON EOL
- | PRAGMA_OPTIMIZE_OFF EOL
+ PRAGMA_DEBUG_ON EOL { $$ = NULL; }
+ | PRAGMA_DEBUG_OFF EOL { $$ = NULL; }
+ | PRAGMA_OPTIMIZE_ON EOL { $$ = NULL; }
+ | PRAGMA_OPTIMIZE_OFF EOL { $$ = NULL; }
| PRAGMA_INVARIANT_ALL EOL
{
/* Pragma invariant(all) cannot be used in a fragment shader.
@@ -353,6 +355,18 @@ pragma_statement:
} else {
state->all_invariant = true;
}
+
+ $$ = NULL;
+ }
+ | PRAGMA_WARNING_ON EOL
+ {
+ void *mem_ctx = state->linalloc;
+ $$ = new(mem_ctx) ast_warnings_toggle(true);
+ }
+ | PRAGMA_WARNING_OFF EOL
+ {
+ void *mem_ctx = state->linalloc;
+ $$ = new(mem_ctx) ast_warnings_toggle(false);
}
;
@@ -2723,7 +2737,7 @@ jump_statement:
external_declaration:
function_definition { $$ = $1; }
| declaration { $$ = $1; }
- | pragma_statement { $$ = NULL; }
+ | pragma_statement { $$ = $1; }
| layout_defaults { $$ = $1; }
| ';' { $$ = NULL; }
;
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 2a58908c226..21ed34d79d0 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -62,7 +62,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
gl_shader_stage stage,
void *mem_ctx)
: ctx(_ctx), cs_input_local_size_specified(false), cs_input_local_size(),
- switch_state()
+ switch_state(), warnings_enabled(true)
{
assert(stage < MESA_SHADER_STAGES);
this->stage = stage;
@@ -527,11 +527,13 @@ void
_mesa_glsl_warning(const YYLTYPE *locp, _mesa_glsl_parse_state *state,
const char *fmt, ...)
{
- va_list ap;
+ if (state->warnings_enabled) {
+ va_list ap;
- va_start(ap, fmt);
- _mesa_glsl_msg(locp, state, MESA_DEBUG_TYPE_OTHER, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ _mesa_glsl_msg(locp, state, MESA_DEBUG_TYPE_OTHER, fmt, ap);
+ va_end(ap);
+ }
}
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index 985200ecab5..da8b2fa3ab5 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -615,6 +615,13 @@ struct _mesa_glsl_parse_state {
char *info_log;
/**
+ * Are warnings enabled?
+ *
+ * Emission of warngins is controlled by '#pragma warning(...)'.
+ */
+ bool warnings_enabled;
+
+ /**
* \name Enable bits for GLSL extensions
*/
/*@{*/
diff --git a/src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert b/src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert
new file mode 100644
index 00000000000..d0d8d915a40
--- /dev/null
+++ b/src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert
@@ -0,0 +1,24 @@
+#version 130
+
+float __foo(float x)
+{
+ return 6.0 * x;
+}
+
+#pragma warning(off)
+float __bar(float x)
+{
+ return 3.0 * x;
+}
+#pragma warning(on)
+
+float __blat(float x)
+{
+ return 2.0 * x;
+}
+
+void main()
+{
+ gl_Position = vec4(__foo(gl_Vertex.x), __bar(gl_Vertex.y), __blat(gl_Vertex.z), 1.0);
+}
+
diff --git a/src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert.expected b/src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert.expected
new file mode 100644
index 00000000000..4b490a9c879
--- /dev/null
+++ b/src/compiler/glsl/tests/warnings/032-__-in-function-name-pragma-disable.vert.expected
@@ -0,0 +1,2 @@
+0:3(7): warning: identifier `__foo' uses reserved `__' string
+0:15(7): warning: identifier `__blat' uses reserved `__' string