sdardis created this revision. sdardis added a reviewer: rsmith. Herald added a reviewer: javed.absar. Herald added subscribers: atanasyan, kristof.beyls, arichardson.
As reported in GCC bug #86069, LLVM currently provokes a bug in GCC where objects compiled for MIPS with PIC and optimizations where shrink wrapped functions can attempt to access the global pointer's spill slot before the global pointer is spilled. This bug is present in GCC since at least 4.9.2, and affects the AArch64 backend when LLVM is built for a MIPS host. However, setting CMAKE_C_FLAGS and CMAKE_CXX_FLAGS affects the compiler-rt tests which rely on the just built clang rather than the host or cross GCC. Since Clang doesn't support this flag, so the tests spuriously fail. Unfortunately, not all targets support shrink wrapping in LLVM at this time, so providing -fshrink-wrap would expose users to any number of wrong-codegen issues. For targets that do support shrink wrapping, this option performs as expected. Repository: rC Clang https://reviews.llvm.org/D47829 Files: include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp test/Driver/shrink-wrap.c Index: test/Driver/shrink-wrap.c =================================================================== --- /dev/null +++ test/Driver/shrink-wrap.c @@ -0,0 +1,12 @@ +// RUN: %clang -### %s -fno-shrink-wrap 2> %t +// RUN: FileCheck --check-prefix=CHECK-NO < %t %s + +// The below case should be handled when shrink wrapping is available for all +// targets. + +// FIXME: %clang -### %s -fshrink-wrap 2> %t +// FIXME: FileCheck --check-prefix=CHECK-YES < %t %s + +// CHECK-NO: "-mllvm" "-enable-shrink-wrap=false" + +// CHECK-YES: "-mllvm" "-enable-shrink-wrap=true" Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -4047,6 +4047,11 @@ Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ); + if (Args.hasArg(options::OPT_fno_shrink_wrap)) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-enable-shrink-wrap=false"); + } + // -fno-strict-overflow implies -fwrapv if it isn't disabled, but // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) { Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1388,6 +1388,8 @@ HelpText<"Do not include column number on diagnostics">; def fno_show_source_location : Flag<["-"], "fno-show-source-location">, Group<f_Group>, Flags<[CC1Option]>, HelpText<"Do not include source location information with diagnostics">; +def fno_shrink_wrap : Flag<["-"], "fno-shrink-wrap">, Group<f_Group>, + Flags<[CC1Option]>, HelpText<"Disable shrink wrapping">; def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, Group<f_Group>, Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in diagnostics">; def fno_spell_checking : Flag<["-"], "fno-spell-checking">, Group<f_Group>,
Index: test/Driver/shrink-wrap.c =================================================================== --- /dev/null +++ test/Driver/shrink-wrap.c @@ -0,0 +1,12 @@ +// RUN: %clang -### %s -fno-shrink-wrap 2> %t +// RUN: FileCheck --check-prefix=CHECK-NO < %t %s + +// The below case should be handled when shrink wrapping is available for all +// targets. + +// FIXME: %clang -### %s -fshrink-wrap 2> %t +// FIXME: FileCheck --check-prefix=CHECK-YES < %t %s + +// CHECK-NO: "-mllvm" "-enable-shrink-wrap=false" + +// CHECK-YES: "-mllvm" "-enable-shrink-wrap=true" Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -4047,6 +4047,11 @@ Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ); + if (Args.hasArg(options::OPT_fno_shrink_wrap)) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-enable-shrink-wrap=false"); + } + // -fno-strict-overflow implies -fwrapv if it isn't disabled, but // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) { Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1388,6 +1388,8 @@ HelpText<"Do not include column number on diagnostics">; def fno_show_source_location : Flag<["-"], "fno-show-source-location">, Group<f_Group>, Flags<[CC1Option]>, HelpText<"Do not include source location information with diagnostics">; +def fno_shrink_wrap : Flag<["-"], "fno-shrink-wrap">, Group<f_Group>, + Flags<[CC1Option]>, HelpText<"Disable shrink wrapping">; def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, Group<f_Group>, Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in diagnostics">; def fno_spell_checking : Flag<["-"], "fno-spell-checking">, Group<f_Group>,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits