From f37b1ad937dd2c420f4c9fd9aa5887942bd31f3f Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 31 Oct 2011 14:31:07 -0700 Subject: linker: Check that initializers for global variables match This requires tracking a couple extra fields in ir_variable: * A flag to indicate that a variable had an initializer. * For non-const variables, a field to track the constant value of the variable's initializer. For variables non-constant initalizers, ir_variable::has_initializer will be true, but ir_variable::constant_initializer will be NULL. The linker can use the values of these fields to check adherence to the GLSL 4.20 rules for shared global variables: "If a shared global has multiple initializers, the initializers must all be constant expressions, and they must all have the same value. Otherwise, a link error will result. (A shared global having only one initializer does not require that initializer to be a constant expression.)" Previous to 4.20 the GLSL spec simply said that initializers must have the same value. In this case of non-constant initializers, this was impossible to determine. As a result, no vendor actually implemented that behavior. The 4.20 behavior matches the behavior of NVIDIA's shipping implementations. NOTE: This is candidate for the 7.11 branch. This patch also needs the preceding patch "glsl: Refactor generate_ARB_draw_buffers_variables to use add_builtin_constant" Signed-off-by: Ian Romanick Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=34687 Reviewed-by: Kenneth Graunke Acked-by: Paul Berry --- src/glsl/ir_validate.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_validate.cpp') diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp index c387ecbcafd..a3520120f2d 100644 --- a/src/glsl/ir_validate.cpp +++ b/src/glsl/ir_validate.cpp @@ -496,6 +496,13 @@ ir_validate::visit(ir_variable *ir) } } + if (ir->constant_initializer != NULL && !ir->has_initializer) { + printf("ir_variable didn't have an initializer, but has a constant " + "initializer value.\n"); + ir->print(); + abort(); + } + return visit_continue; } -- cgit v1.2.3