Fix bug: when checking compatibility between GLOBAL and EXTERNAL variables, must only enforce GLOBAL CONSTANT => EXTERNAL CONSTANT.
authormjsousa
Wed, 12 Feb 2014 17:02:08 +0000
changeset 865 7365c3e5c9ae
parent 864 300c27c08753
child 866 c8c48ab075e0
Fix bug: when checking compatibility between GLOBAL and EXTERNAL variables, must only enforce GLOBAL CONSTANT => EXTERNAL CONSTANT.
Reverse CONSTANT implication is not enforced, and neither is RETAIN compatibility.
stage3/declaration_check.cc
--- a/stage3/declaration_check.cc	Tue Feb 11 10:55:27 2014 +0000
+++ b/stage3/declaration_check.cc	Wed Feb 12 17:02:08 2014 +0000
@@ -112,8 +112,14 @@
         continue;
       }
       
-      if (search_var_instance_glo_decl->get_option(var_name) != search_var_instance_ext_decl.get_option(var_name))
-        STAGE3_ERROR(0, glo_decl, glo_decl, "Declaration error.  The external variable options do not match with thos of the global variable.");
+      /* Check whether variable's constness (CONSTANT) is compatible.
+       *        VAR_GLOBAL is contant     => VAR_EXTERNAL must also be CONSTANT
+       *        VAR_GLOBAL is not contant => VAR_EXTERNAL may be CONSTANT, or not!
+       */
+      search_var_instance_decl_c::opt_t ext_opt = search_var_instance_ext_decl. get_option(var_name);
+      search_var_instance_decl_c::opt_t glo_opt = search_var_instance_glo_decl->get_option(var_name);
+      if ((glo_opt == search_var_instance_decl_c::constant_opt) && (ext_opt != search_var_instance_decl_c::constant_opt))
+        STAGE3_ERROR(0, glo_decl, glo_decl, "Declaration error. The external variable must be declared as constant, as it maps to a constant global variable.");
 
       /* TODO: Check redefinition data type.
        *       We need a new class (like search_base_type class) to get type id by variable declaration.