Although treelang does not support global variables, if support for them is
ever added, there might be a problem with tree_code_create_variable()
(treetree.c). Inside tree_code_create_variable() is the following switch:

  switch (storage_class)
    {
    case STATIC_STORAGE:
      TREE_STATIC (var_decl) = 1;
      break;

    case AUTOMATIC_STORAGE:
      break;

    case EXTERNAL_DEFINITION_STORAGE:
      TREE_PUBLIC (var_decl) = 1;
      break;

    case EXTERNAL_REFERENCE_STORAGE:
      DECL_EXTERNAL (var_decl) = 1;
      break;

    default:
      gcc_unreachable ();
    }

Calling tree_code_create_variable() with a storage class of
"EXTERNAL_DEFINITION_STORAGE" while in file scope does not create the global
variable properly. No allocation for the variable will be done, because the
TREE_STATIC property is set to 0, as if this were an "auto" variable.

Here is my diff for the fix, with an added check that there cannot be auto
global variables (applied to treetree.c of the GCC 4.0.2):

548a549,553
>       if (current_function_decl == NULL_TREE)
>         {
>         error ("file-scope variable with automatic storage class");
>         return error_mark_node;
>         }
551a557,561
>       if (current_function_decl == NULL_TREE)
>         {
>         /* Global extern variables cannot also be auto.  */
>         TREE_STATIC (var_decl) = 1;
>         }


-- 
           Summary: tree_code_create_variable does not "handle" global
                    variables properly
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: treelang
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: someone42 at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25341

Reply via email to