go-gcc.cc (Gcc_backend::global_variable): If type is zero-sized, add a VIEW_CONVERT_E...
authorIan Lance Taylor <iant@google.com>
Tue, 22 Dec 2015 00:10:07 +0000 (00:10 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 22 Dec 2015 00:10:07 +0000 (00:10 +0000)
* go-gcc.cc (Gcc_backend::global_variable): If type is zero-sized,
add a VIEW_CONVERT_EXPR to the tree.
(Gcc_backend::global_variable_set_init): Remove any
VIEW_CONVERT_EXPR.
(Gcc_backend::write_global_definitions): Likewise.

From-SVN: r231888

gcc/go/ChangeLog
gcc/go/go-gcc.cc

index 1a120950a134ec3d66b177ee7244d59e56bdca83..2a011ddc60ec46ea94b743dee06186b8b6b8fd55 100644 (file)
@@ -1,3 +1,11 @@
+2015-12-21  Ian Lance Taylor  <iant@google.com>
+
+       * go-gcc.cc (Gcc_backend::global_variable): If type is zero-sized,
+       add a VIEW_CONVERT_EXPR to the tree.
+       (Gcc_backend::global_variable_set_init): Remove any
+       VIEW_CONVERT_EXPR.
+       (Gcc_backend::write_global_definitions): Likewise.
+
 2015-11-30  Ian Lance Taylor  <iant@google.com>
 
        PR go/68477
index cfb1995faf211ce7985fd440de09c22f461db3ed..cb196b32fdee6b7eaf1d6de3367179b77d6c8e5b 100644 (file)
@@ -2390,6 +2390,7 @@ Gcc_backend::global_variable(const std::string& package_name,
     return this->error_variable();
 
   // The GNU linker does not like dynamic variables with zero size.
+  tree orig_type_tree = type_tree;
   if ((is_external || !is_hidden) && int_size_in_bytes(type_tree) == 0)
     type_tree = this->non_zero_size_type(type_tree);
 
@@ -2419,6 +2420,10 @@ Gcc_backend::global_variable(const std::string& package_name,
 
   go_preserve_from_gc(decl);
 
+  if (orig_type_tree != type_tree)
+    decl = fold_build1_loc(location.gcc_location(), VIEW_CONVERT_EXPR,
+                          orig_type_tree, decl);
+
   return new Bvariable(decl);
 }
 
@@ -2434,6 +2439,10 @@ Gcc_backend::global_variable_set_init(Bvariable* var, Bexpression* expr)
   tree var_decl = var->get_tree();
   if (var_decl == error_mark_node)
     return;
+  // Undo the VIEW_CONVERT_EXPR that may have been added by
+  // global_variable.
+  if (TREE_CODE(var_decl) == VIEW_CONVERT_EXPR)
+    var_decl = TREE_OPERAND(var_decl, 0);
   DECL_INITIAL(var_decl) = expr_tree;
 
   // If this variable goes in a unique section, it may need to go into
@@ -3030,7 +3039,12 @@ Gcc_backend::write_global_definitions(
     {
       if ((*p)->get_tree() != error_mark_node)
         {
-          defs[i] = (*p)->get_tree();
+         tree t = (*p)->get_tree();
+         // Undo the VIEW_CONVERT_EXPR that may have been added by
+         // global_variable.
+         if (TREE_CODE(t) == VIEW_CONVERT_EXPR)
+           t = TREE_OPERAND(t, 0);
+          defs[i] = t;
           go_preserve_from_gc(defs[i]);
           ++i;
         }