https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83775
--- Comment #3 from prathamesh3492 at gcc dot gnu.org ---
(In reply to prathamesh3492 from comment #0)
> Hi,
> For the following test-case:
>
> #define STR "1234567"
>
> const char str[] = STR;
>
> char dst[10];
>
> void copy_from_global_str (void)
> {
> __builtin_strcpy (dst, str);
>
> if (__builtin_strlen (dst) != sizeof str - 1)
> __builtin_abort ();
> }
>
> With arm-linux-gnueabihf-gcc -O2 I get the following ICE:
Oops, this should be cc1, I didn't invoke the driver, but cc1 directly.
> strlenopt-39.c: In function 'copy_from_global_str':
> strlenopt-39.c:13:1: internal compiler error: Segmentation fault
> }
> ^
> 0xbc1f1f crash_signal
> ../../gcc/gcc/toplev.c:325
> 0xf4a5bb std::char_traits<char>::length(char const*)
> /usr/include/c++/6/bits/char_traits.h:267
> 0xf4a5bb std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::assign(char const*)
> /usr/include/c++/6/bits/basic_string.h:1268
> 0xf4a5bb std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::operator=(char const*)
> /usr/include/c++/6/bits/basic_string.h:605
> 0xf4a5bb arm_declare_function_name(_IO_FILE*, char const*, tree_node*)
> ../../gcc/gcc/config/arm/arm.c:30958
> 0xf4ad2d arm_asm_declare_function_name(_IO_FILE*, char const*, tree_node*)
> ../../gcc/gcc/config/arm/arm.c:19899
> 0xefd8fc assemble_start_function(tree_node*, char const*)
> ../../gcc/gcc/varasm.c:1880
> 0x87929f rest_of_handle_final
> ../../gcc/gcc/final.c:4549
> 0x87929f execute
> ../../gcc/gcc/final.c:4625
>
> This happens because of following in arm_declare_function_name():
> /* Only update the assembler .arch string if it is distinct from the last
> such string we printed. */
> std::string arch_to_print = targ_options->x_arm_arch_string;
>
> In this case, targ_options->x_arm_arch_string is NULL and hence the above
> error.
> Does the following (untested) fix look OK ?
>
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index 196aa6de1ac..868251a154c 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -30954,7 +30954,10 @@ arm_declare_function_name (FILE *stream, const char
> *name, tree decl)
>
> /* Only update the assembler .arch string if it is distinct from the last
> such string we printed. */
> - std::string arch_to_print = targ_options->x_arm_arch_string;
> + std::string arch_to_print;
> + if (targ_options->x_arm_arch_string)
> + arch_to_print = targ_options->x_arm_arch_string;
> +
> if (arch_to_print != arm_last_printed_arch_string)
> {
> std::string arch_name
>
>
> Thanks,
> Prathamesh