public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Fix an ODR violation
@ 2024-02-01 21:54 Xi Ruoyao
  2024-02-02  2:42 ` chenglulu
  0 siblings, 1 reply; 3+ messages in thread
From: Xi Ruoyao @ 2024-02-01 21:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: chenglulu, i, xuchenghua, Xi Ruoyao

When bootstrapping GCC 14 --with-build-config=bootstrap-lto, an ODR
violation is detected:

    ../../gcc/config/loongarch/loongarch-opts.cc:57: warning:
    'abi_minimal_isa' violates the C++ One Definition Rule [-Wodr]
    57 | abi_minimal_isa[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES];
    ../../gcc/config/loongarch/loongarch-def.cc:186: note:
    'abi_minimal_isa' was previously declared here
    186 |   abi_minimal_isa = array<array<loongarch_isa, N_ABI_EXT_TYPES>,
    ../../gcc/config/loongarch/loongarch-def.cc:186: note:
    code may be misoptimized unless '-fno-strict-aliasing' is used

Fix it by adding a proper declaration of abi_minimal_isa into
loongarch-def.h and remove the ODR-violating local declaration in
loongarch-opts.cc.

gcc/ChangeLog:

	* config/loongarch/loongarch-def.h (abi_minimal_isa): Declare.
	* config/loongarch/loongarch-opts.cc (abi_minimal_isa): Remove
	the ODR-violating locale declaration.
---

Bootstrapped on loongarch64-linux-gnu.  Not fully regtested but it
should be an obvious fix.  Ok for trunk?

 gcc/config/loongarch/loongarch-def.h   | 3 +++
 gcc/config/loongarch/loongarch-opts.cc | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/config/loongarch/loongarch-def.h b/gcc/config/loongarch/loongarch-def.h
index a1237ecf1fd..2dbf006d013 100644
--- a/gcc/config/loongarch/loongarch-def.h
+++ b/gcc/config/loongarch/loongarch-def.h
@@ -203,5 +203,8 @@ extern loongarch_def_array<loongarch_align, N_TUNE_TYPES>
   loongarch_cpu_align;
 extern loongarch_def_array<loongarch_rtx_cost_data, N_TUNE_TYPES>
   loongarch_cpu_rtx_cost_data;
+extern loongarch_def_array<
+  loongarch_def_array<loongarch_isa, N_ABI_EXT_TYPES>,
+  N_ABI_BASE_TYPES> abi_minimal_isa;
 
 #endif /* LOONGARCH_DEF_H */
diff --git a/gcc/config/loongarch/loongarch-opts.cc b/gcc/config/loongarch/loongarch-opts.cc
index b87299513c9..7eeac43ed2f 100644
--- a/gcc/config/loongarch/loongarch-opts.cc
+++ b/gcc/config/loongarch/loongarch-opts.cc
@@ -53,8 +53,6 @@ static const int tm_multilib_list[] = { TM_MULTILIB_LIST };
 static int enabled_abi_types[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES] = { 0 };
 
 #define isa_required(ABI) (abi_minimal_isa[(ABI).base][(ABI).ext])
-extern "C" const struct loongarch_isa
-abi_minimal_isa[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES];
 
 static inline int
 is_multilib_enabled (struct loongarch_abi abi)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] LoongArch: Fix an ODR violation
  2024-02-01 21:54 [PATCH] LoongArch: Fix an ODR violation Xi Ruoyao
@ 2024-02-02  2:42 ` chenglulu
  2024-02-03 10:29   ` Pushed: " Xi Ruoyao
  0 siblings, 1 reply; 3+ messages in thread
From: chenglulu @ 2024-02-02  2:42 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: i, xuchenghua

LGTM!

Thanks!

在 2024/2/2 上午5:54, Xi Ruoyao 写道:
> When bootstrapping GCC 14 --with-build-config=bootstrap-lto, an ODR
> violation is detected:
>
>      ../../gcc/config/loongarch/loongarch-opts.cc:57: warning:
>      'abi_minimal_isa' violates the C++ One Definition Rule [-Wodr]
>      57 | abi_minimal_isa[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES];
>      ../../gcc/config/loongarch/loongarch-def.cc:186: note:
>      'abi_minimal_isa' was previously declared here
>      186 |   abi_minimal_isa = array<array<loongarch_isa, N_ABI_EXT_TYPES>,
>      ../../gcc/config/loongarch/loongarch-def.cc:186: note:
>      code may be misoptimized unless '-fno-strict-aliasing' is used
>
> Fix it by adding a proper declaration of abi_minimal_isa into
> loongarch-def.h and remove the ODR-violating local declaration in
> loongarch-opts.cc.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch-def.h (abi_minimal_isa): Declare.
> 	* config/loongarch/loongarch-opts.cc (abi_minimal_isa): Remove
> 	the ODR-violating locale declaration.
> ---
>
> Bootstrapped on loongarch64-linux-gnu.  Not fully regtested but it
> should be an obvious fix.  Ok for trunk?
>
>   gcc/config/loongarch/loongarch-def.h   | 3 +++
>   gcc/config/loongarch/loongarch-opts.cc | 2 --
>   2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/config/loongarch/loongarch-def.h b/gcc/config/loongarch/loongarch-def.h
> index a1237ecf1fd..2dbf006d013 100644
> --- a/gcc/config/loongarch/loongarch-def.h
> +++ b/gcc/config/loongarch/loongarch-def.h
> @@ -203,5 +203,8 @@ extern loongarch_def_array<loongarch_align, N_TUNE_TYPES>
>     loongarch_cpu_align;
>   extern loongarch_def_array<loongarch_rtx_cost_data, N_TUNE_TYPES>
>     loongarch_cpu_rtx_cost_data;
> +extern loongarch_def_array<
> +  loongarch_def_array<loongarch_isa, N_ABI_EXT_TYPES>,
> +  N_ABI_BASE_TYPES> abi_minimal_isa;
>   
>   #endif /* LOONGARCH_DEF_H */
> diff --git a/gcc/config/loongarch/loongarch-opts.cc b/gcc/config/loongarch/loongarch-opts.cc
> index b87299513c9..7eeac43ed2f 100644
> --- a/gcc/config/loongarch/loongarch-opts.cc
> +++ b/gcc/config/loongarch/loongarch-opts.cc
> @@ -53,8 +53,6 @@ static const int tm_multilib_list[] = { TM_MULTILIB_LIST };
>   static int enabled_abi_types[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES] = { 0 };
>   
>   #define isa_required(ABI) (abi_minimal_isa[(ABI).base][(ABI).ext])
> -extern "C" const struct loongarch_isa
> -abi_minimal_isa[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES];
>   
>   static inline int
>   is_multilib_enabled (struct loongarch_abi abi)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Pushed: [PATCH] LoongArch: Fix an ODR violation
  2024-02-02  2:42 ` chenglulu
@ 2024-02-03 10:29   ` Xi Ruoyao
  0 siblings, 0 replies; 3+ messages in thread
From: Xi Ruoyao @ 2024-02-03 10:29 UTC (permalink / raw)
  To: chenglulu, gcc-patches; +Cc: i, xuchenghua

On Fri, 2024-02-02 at 10:42 +0800, chenglulu wrote:
> LGTM!
> 
> Thanks!

Pushed r14-8773.

> 在 2024/2/2 上午5:54, Xi Ruoyao 写道:
> > When bootstrapping GCC 14 --with-build-config=bootstrap-lto, an ODR
> > violation is detected:
> > 
> >      ../../gcc/config/loongarch/loongarch-opts.cc:57: warning:
> >      'abi_minimal_isa' violates the C++ One Definition Rule [-Wodr]
> >      57 | abi_minimal_isa[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES];
> >      ../../gcc/config/loongarch/loongarch-def.cc:186: note:
> >      'abi_minimal_isa' was previously declared here
> >      186 |   abi_minimal_isa = array<array<loongarch_isa, N_ABI_EXT_TYPES>,
> >      ../../gcc/config/loongarch/loongarch-def.cc:186: note:
> >      code may be misoptimized unless '-fno-strict-aliasing' is used
> > 
> > Fix it by adding a proper declaration of abi_minimal_isa into
> > loongarch-def.h and remove the ODR-violating local declaration in
> > loongarch-opts.cc.
> > 
> > gcc/ChangeLog:
> > 
> > 	* config/loongarch/loongarch-def.h (abi_minimal_isa): Declare.
> > 	* config/loongarch/loongarch-opts.cc (abi_minimal_isa): Remove
> > 	the ODR-violating locale declaration.
> > ---
> > 
> > Bootstrapped on loongarch64-linux-gnu.  Not fully regtested but it
> > should be an obvious fix.  Ok for trunk?
> > 
> >   gcc/config/loongarch/loongarch-def.h   | 3 +++
> >   gcc/config/loongarch/loongarch-opts.cc | 2 --
> >   2 files changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/gcc/config/loongarch/loongarch-def.h b/gcc/config/loongarch/loongarch-def.h
> > index a1237ecf1fd..2dbf006d013 100644
> > --- a/gcc/config/loongarch/loongarch-def.h
> > +++ b/gcc/config/loongarch/loongarch-def.h
> > @@ -203,5 +203,8 @@ extern loongarch_def_array<loongarch_align, N_TUNE_TYPES>
> >     loongarch_cpu_align;
> >   extern loongarch_def_array<loongarch_rtx_cost_data, N_TUNE_TYPES>
> >     loongarch_cpu_rtx_cost_data;
> > +extern loongarch_def_array<
> > +  loongarch_def_array<loongarch_isa, N_ABI_EXT_TYPES>,
> > +  N_ABI_BASE_TYPES> abi_minimal_isa;
> >   
> >   #endif /* LOONGARCH_DEF_H */
> > diff --git a/gcc/config/loongarch/loongarch-opts.cc b/gcc/config/loongarch/loongarch-opts.cc
> > index b87299513c9..7eeac43ed2f 100644
> > --- a/gcc/config/loongarch/loongarch-opts.cc
> > +++ b/gcc/config/loongarch/loongarch-opts.cc
> > @@ -53,8 +53,6 @@ static const int tm_multilib_list[] = { TM_MULTILIB_LIST };
> >   static int enabled_abi_types[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES] = { 0 };
> >   
> >   #define isa_required(ABI) (abi_minimal_isa[(ABI).base][(ABI).ext])
> > -extern "C" const struct loongarch_isa
> > -abi_minimal_isa[N_ABI_BASE_TYPES][N_ABI_EXT_TYPES];
> >   
> >   static inline int
> >   is_multilib_enabled (struct loongarch_abi abi)
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-03 10:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01 21:54 [PATCH] LoongArch: Fix an ODR violation Xi Ruoyao
2024-02-02  2:42 ` chenglulu
2024-02-03 10:29   ` Pushed: " Xi Ruoyao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).