On Fri, Mar 14, 2025 at 2:22 AM Robert Dubner <rdub...@symas.com> wrote:
>
> Based on the PR119214 discussion about "-O -ftracer" causing the assembler
> to fail, I offer the following patch.
>
> Okay for trunk?  (Gives me shivers to say that the first time!)

OK, but see below

> Author: Robert Dubner <rdub...@symas.com>
> Date:   Thu Mar 13 21:03:46 2025 -0400
>
>     COBOL: Prevent use of ASM_EXPR for optimized COBOL compilations
> [PR119214]
>
>     The creation of assembler labels using ASM_EXPR causes name collisions
> in the
>     assembly language because some optimizations repeat code, and those
> labels
>     can get repeated. Use of "if( !optimize )" prevents (at least) that
> problem when
>     it cropped up with "-O -ftrace"
>
>     gcc/cobol/ChangeLog:
>
>             PR cobol/119214
>             * prevent use of ASM_EXPR for optimized cobol compilations
>             This temporary fix will be replaced with a LABEL_DECL solution

this needs to be

           * gengen.cc (gg_insert_into_assembler): Prevent use ...

and the sentence should be terminated by a '.'.

Thanks,
Richard.

>
> diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc
> index 4fc0a830c1e..e4331204d0a 100644
> --- a/gcc/cobol/gengen.cc
> +++ b/gcc/cobol/gengen.cc
> @@ -3429,30 +3429,35 @@ gg_trans_unit_var_decl(const char *var_name)
>  void
>  gg_insert_into_assembler(const char *format, ...)
>    {
> -  // This routine inserts text directly into the assembly language
> stream.
> -
> -  // Note that if for some reason your text has to have a '%' character,
> it
> -  // needs to be doubled in the GENERIC tag.  And that means if it is in
> the
> -  // 'format' variable, it needs to be quadrupled.
> +  // Temporarily defeat all ASM_EXPR for optimized code per PR119214
> +  // The correct solution using LABEL_DECL is forthcoming
> +  if( !optimize )
> +    {
> +    // This routine inserts text directly into the assembly language
> stream.
> +
> +    // Note that if for some reason your text has to have a '%'
> character, it
> +    // needs to be doubled in the GENERIC tag.  And that means if it is
> in the
> +    // 'format' variable, it needs to be quadrupled.
> +
> +    // Create the string to be inserted:
> +    char ach[256];
> +    va_list ap;
> +    va_start(ap, format);
> +    vsnprintf(ach, sizeof(ach), format, ap);
> +    va_end(ap);
> +
> +    // Create the required generic tag
> +    tree asm_expr = build5_loc( location_from_lineno(),
> +                            ASM_EXPR,
> +                            VOID,
> +                            build_string(strlen(ach), ach),
> +                            NULL_TREE,
> +                            NULL_TREE,
> +                            NULL_TREE,
> +                            NULL_TREE);
> +    //SET_EXPR_LOCATION (asm_expr, UNKNOWN_LOCATION);
>
> -  // Create the string to be inserted:
> -  char ach[256];
> -  va_list ap;
> -  va_start(ap, format);
> -  vsnprintf(ach, sizeof(ach), format, ap);
> -  va_end(ap);
> -
> -  // Create the required generic tag
> -  tree asm_expr = build5_loc( location_from_lineno(),
> -                          ASM_EXPR,
> -                          VOID,
> -                          build_string(strlen(ach), ach),
> -                          NULL_TREE,
> -                          NULL_TREE,
> -                          NULL_TREE,
> -                          NULL_TREE);
> -  //SET_EXPR_LOCATION (asm_expr, UNKNOWN_LOCATION);
> -
> -  // And insert it as a statement
> -  gg_append_statement(asm_expr);
> +    // And insert it as a statement
> +    gg_append_statement(asm_expr);
> +    }
>    }

Reply via email to