@@ -561,6 +561,34 @@ def _configure_intermediate_build(self):
561561 self ._cmakeopts ['LLVM_ENABLE_PROJECTS' ] = self .list_to_cmake_arg (self .intermediate_projects )
562562 self ._cmakeopts ['LLVM_ENABLE_RUNTIMES' ] = self .list_to_cmake_arg (self .intermediate_runtimes )
563563
564+ def _remove_iterable_from_envvar (self , varname , to_remove , sep = ' ' ):
565+ """Remove items in to_remove from environment variable varname."""
566+ flags = os .getenv (varname , '' )
567+ flags = set (filter (None , flags .split (sep )))
568+ torm = flags & set (to_remove )
569+ if torm :
570+ self .log .info (
571+ "Removing unsupported options from %s for flang %s: `%s`" , varname , self .version , ', ' .join (torm )
572+ )
573+ setvar (varname , sep .join (flags - torm ))
574+
575+ def remove_unsupported_flang_opts (self ):
576+ """For version of LLVM where `flang` is invoched at build time to build modules, ensure that unsupported
577+ options are removed from F90FLAGS and FFLAGS."""
578+ unsupported_flang_opts = set ()
579+ if self .version >= '21' :
580+ if self .version < '22' :
581+ unsupported_flang_opts .update ([
582+ '-fmath-errno' , '-fno-math-errno' ,
583+ # These are supported since 21.x
584+ # '-fslp-vectorize', '-fvectorize', '-fno-vectorize',
585+ '-fno-unsafe-math-optimizations' ,
586+ ])
587+
588+ if unsupported_flang_opts :
589+ self ._remove_iterable_from_envvar ('F90FLAGS' , unsupported_flang_opts )
590+ self ._remove_iterable_from_envvar ('FFLAGS' , unsupported_flang_opts )
591+
564592 def _configure_final_build (self ):
565593 """Configure the final stage of the build."""
566594 self ._cmakeopts ['LLVM_ENABLE_PROJECTS' ] = self .list_to_cmake_arg (self .final_projects )
@@ -596,20 +624,7 @@ def _configure_final_build(self):
596624 self ._cmakeopts ['OPENMP_ENABLE_OMPT_TOOLS' ] = ompt_value
597625
598626 if 'flang' in self .final_projects :
599- # Filter unsupported flang options for the final build
600- unsupported_flang_opts = set ([
601- '-fmath-errno' , '-fno-math-errno' ,
602- '-fslp-vectorize' ,
603- '-fvectorize' , '-fno-vectorize' ,
604- '-fno-unsafe-math-optimizations' ,
605- ])
606- f90_flags = os .getenv ('F90FLAGS' , '' )
607- f90_flags = set (filter (None , f90_flags .split (' ' ))) - unsupported_flang_opts
608- setvar ('F90FLAGS' , ' ' .join (f90_flags ))
609-
610- ff_flags = os .getenv ('FFLAGS' , '' )
611- ff_flags = set (filter (None , ff_flags .split (' ' ))) - unsupported_flang_opts
612- setvar ('FFLAGS' , ' ' .join (ff_flags ))
627+ self .remove_unsupported_flang_opts ()
613628
614629 include_benchmarks = 'ON' if self .cfg ['test_suite_include_benchmarks' ] else 'OFF'
615630 self ._cmakeopts ['LLVM_INCLUDE_BENCHMARKS' ] = include_benchmarks
0 commit comments