5959C_ENDINGS = ('.c' , '.i' )
6060CXX_ENDINGS = ('.cpp' , '.cxx' , '.cc' , '.c++' , '.CPP' , '.CXX' , '.C' , '.CC' , '.C++' , '.ii' )
6161OBJC_ENDINGS = ('.m' , '.mi' )
62+ PREPROCESSED_ENDINGS = ('.i' , '.ii' )
6263OBJCXX_ENDINGS = ('.mm' , '.mii' )
6364SPECIAL_ENDINGLESS_FILENAMES = (os .devnull ,)
6465
@@ -791,10 +792,6 @@ def array_contains_any_of(hay, needles):
791792 if n in hay :
792793 return True
793794
794- # relaxed-simd implies simd128.
795- if '-mrelaxed-simd' in user_args :
796- user_args += ['-msimd128' ]
797-
798795 if array_contains_any_of (user_args , SIMD_INTEL_FEATURE_TOWER ) or array_contains_any_of (user_args , SIMD_NEON_FLAGS ):
799796 if '-msimd128' not in user_args :
800797 exit_with_error ('Passing any of ' + ', ' .join (SIMD_INTEL_FEATURE_TOWER + SIMD_NEON_FLAGS ) + ' flags also requires passing -msimd128!' )
@@ -825,10 +822,55 @@ def array_contains_any_of(hay, needles):
825822 return cflags + ['-Xclang' , '-iwithsysroot' + os .path .join ('/include' , 'compat' )]
826823
827824
828- def get_clang_flags ():
825+ def get_asm_flags ():
829826 return ['-target' , shared .get_llvm_target ()]
830827
831828
829+ def get_clang_flags (user_args ):
830+ flags = get_asm_flags ()
831+
832+ # if exception catching is disabled, we can prevent that code from being
833+ # generated in the frontend
834+ if settings .DISABLE_EXCEPTION_CATCHING and not settings .WASM_EXCEPTIONS :
835+ flags .append ('-fignore-exceptions' )
836+
837+ if settings .INLINING_LIMIT :
838+ flags .append ('-fno-inline-functions' )
839+
840+ if settings .RELOCATABLE and '-fPIC' not in user_args :
841+ flags .append ('-fPIC' )
842+
843+ # We use default visiibilty=default in emscripten even though the upstream
844+ # backend defaults visibility=hidden. This matched the expectations of C/C++
845+ # code in the wild which expects undecorated symbols to be exported to other
846+ # DSO's by default.
847+ if not any (a .startswith ('-fvisibility' ) for a in user_args ):
848+ flags .append ('-fvisibility=default' )
849+
850+ if settings .LTO :
851+ if not any (a .startswith ('-flto' ) for a in user_args ):
852+ flags .append ('-flto=' + settings .LTO )
853+ # setjmp/longjmp handling using Wasm EH
854+ # For non-LTO, '-mllvm -wasm-enable-eh' added in
855+ # building.llvm_backend_args() sets this feature in clang. But in LTO, the
856+ # argument is added to wasm-ld instead, so clang needs to know that EH is
857+ # enabled so that it can be added to the attributes in LLVM IR.
858+ if settings .SUPPORT_LONGJMP == 'wasm' :
859+ flags .append ('-mexception-handling' )
860+
861+ else :
862+ # In LTO mode these args get passed instead at link time when the backend runs.
863+ for a in building .llvm_backend_args ():
864+ flags += ['-mllvm' , a ]
865+
866+
867+ # relaxed-simd implies simd128.
868+ if '-mrelaxed-simd' in user_args :
869+ user_args += ['-msimd128' ]
870+
871+ return flags
872+
873+
832874cflags = None
833875
834876
@@ -839,7 +881,7 @@ def get_cflags(user_args):
839881
840882 # Flags we pass to the compiler when building C/C++ code
841883 # We add these to the user's flags (newargs), but not when building .s or .S assembly files
842- cflags = get_clang_flags ()
884+ cflags = get_clang_flags (user_args )
843885
844886 if settings .EMSCRIPTEN_TRACING :
845887 cflags .append ('-D__EMSCRIPTEN_TRACING__=1' )
@@ -861,40 +903,6 @@ def get_cflags(user_args):
861903 '-D__EMSCRIPTEN_minor__=' + str (shared .EMSCRIPTEN_VERSION_MINOR ),
862904 '-D__EMSCRIPTEN_tiny__=' + str (shared .EMSCRIPTEN_VERSION_TINY )]
863905
864- # if exception catching is disabled, we can prevent that code from being
865- # generated in the frontend
866- if settings .DISABLE_EXCEPTION_CATCHING and not settings .WASM_EXCEPTIONS :
867- cflags .append ('-fignore-exceptions' )
868-
869- if settings .INLINING_LIMIT :
870- cflags .append ('-fno-inline-functions' )
871-
872- if settings .RELOCATABLE and '-fPIC' not in user_args :
873- cflags .append ('-fPIC' )
874-
875- # We use default visiibilty=default in emscripten even though the upstream
876- # backend defaults visibility=hidden. This matched the expectations of C/C++
877- # code in the wild which expects undecorated symbols to be exported to other
878- # DSO's by default.
879- if not any (a .startswith ('-fvisibility' ) for a in user_args ):
880- cflags .append ('-fvisibility=default' )
881-
882- if settings .LTO :
883- if not any (a .startswith ('-flto' ) for a in user_args ):
884- cflags .append ('-flto=' + settings .LTO )
885- # setjmp/longjmp handling using Wasm EH
886- # For non-LTO, '-mllvm -wasm-enable-eh' added in
887- # building.llvm_backend_args() sets this feature in clang. But in LTO, the
888- # argument is added to wasm-ld instead, so clang needs to know that EH is
889- # enabled so that it can be added to the attributes in LLVM IR.
890- if settings .SUPPORT_LONGJMP == 'wasm' :
891- cflags .append ('-mexception-handling' )
892-
893- else :
894- # In LTO mode these args get passed instead at link time when the backend runs.
895- for a in building .llvm_backend_args ():
896- cflags += ['-mllvm' , a ]
897-
898906 # Changes to default clang behavior
899907
900908 # Implicit functions can cause horribly confusing function pointer type errors, see #2175
@@ -1048,7 +1056,7 @@ def run(args):
10481056 if len (args ) == 2 and args [1 ] == '-v' :
10491057 # autoconf likes to see 'GNU' in the output to enable shared object support
10501058 print (version_string (), file = sys .stderr )
1051- return shared .check_call ([clang , '-v' ] + get_clang_flags (), check = False ).returncode
1059+ return shared .check_call ([clang , '-v' ] + get_target_flags (), check = False ).returncode
10521060
10531061 # Additional compiler flags that we treat as if they were passed to us on the
10541062 # commandline
@@ -2712,8 +2720,11 @@ def get_compiler(src_file):
27122720 def get_clang_command (src_file ):
27132721 return get_compiler (src_file ) + get_cflags (state .orig_args ) + compile_args + [src_file ]
27142722
2723+ def get_clang_command_preprocessed (src_file ):
2724+ return get_compiler (src_file ) + get_clang_flags (state .orig_args ) + compile_args + [src_file ]
2725+
27152726 def get_clang_command_asm (src_file ):
2716- return get_compiler (src_file ) + get_clang_flags () + compile_args + [src_file ]
2727+ return get_compiler (src_file ) + get_asm_flags () + compile_args + [src_file ]
27172728
27182729 # preprocessor-only (-E) support
27192730 if state .mode == Mode .PREPROCESS_ONLY :
@@ -2768,6 +2779,8 @@ def compile_source_file(i, input_file):
27682779 linker_inputs .append ((i , output_file ))
27692780 if get_file_suffix (input_file ) in ASSEMBLY_ENDINGS :
27702781 cmd = get_clang_command_asm (input_file )
2782+ elif get_file_suffix (input_file ) in PREPROCESSED_ENDINGS :
2783+ cmd = get_clang_command_preprocessed (input_file )
27712784 else :
27722785 cmd = get_clang_command (input_file )
27732786 if not state .has_dash_c :
0 commit comments