diff options
author | gkoehler <gkoehler@cvs.openbsd.org> | 2020-09-10 20:28:15 +0000 |
---|---|---|
committer | gkoehler <gkoehler@cvs.openbsd.org> | 2020-09-10 20:28:15 +0000 |
commit | e2cae62ed6b62f7343f5e791b412e1c865ac3ba3 (patch) | |
tree | ef958e3d84ebc80e47434c39ddef836e13a1662b /gnu | |
parent | 0b2472c62a46cead1e9ed9a29cf3e83833088682 (diff) |
Disable strict floating point if not X86
Disable options like clang -fno-unsafe-math-optimizations for all
targets except X86 (and SystemZ). This prevents a crash of clang,
reported by cwen@, in graphics/babl or emulators/mednafen for powerpc.
ok mortimer@
This change comes from llvm 11.x:
https://github.com/llvm/llvm-project/commit/d4ce862
Reland "[FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support."
We currently have strict floating point/constrained floating point enabled
for all targets. Constrained SDAG nodes get converted to the regular ones
before reaching the target layer. In theory this should be fine.
However, the changes are exposed to users through multiple clang options
already in use in the field, and the changes are _completely_ _untested_
on almost all of our targets. Bugs have already been found, like
"https://bugs.llvm.org/show_bug.cgi?id=45274".
This patch disables constrained floating point options in clang everywhere
except X86 and SystemZ. A warning will be printed when this happens.
Use the new -fexperimental-strict-floating-point flag to force allowing
strict floating point on hosts that aren't already marked as supporting
it (X86 and SystemZ).
Differential Revision: https://reviews.llvm.org/D80952
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/llvm/clang/docs/ClangCommandLineReference.rst | 8 | ||||
-rw-r--r-- | gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def | 2 | ||||
-rw-r--r-- | gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td | 6 | ||||
-rw-r--r-- | gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td | 1 | ||||
-rw-r--r-- | gnu/llvm/clang/include/clang/Basic/LangOptions.def | 1 | ||||
-rw-r--r-- | gnu/llvm/clang/include/clang/Basic/TargetInfo.h | 4 | ||||
-rw-r--r-- | gnu/llvm/clang/include/clang/Driver/Options.td | 11 | ||||
-rw-r--r-- | gnu/llvm/clang/lib/Basic/TargetInfo.cpp | 1 | ||||
-rw-r--r-- | gnu/llvm/clang/lib/Basic/Targets/SystemZ.h | 1 | ||||
-rw-r--r-- | gnu/llvm/clang/lib/Basic/Targets/X86.h | 1 | ||||
-rw-r--r-- | gnu/llvm/clang/lib/Frontend/CompilerInstance.cpp | 13 | ||||
-rw-r--r-- | gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp | 3 |
12 files changed, 52 insertions, 0 deletions
diff --git a/gnu/llvm/clang/docs/ClangCommandLineReference.rst b/gnu/llvm/clang/docs/ClangCommandLineReference.rst index 10c14db1b89..c59412b0b45 100644 --- a/gnu/llvm/clang/docs/ClangCommandLineReference.rst +++ b/gnu/llvm/clang/docs/ClangCommandLineReference.rst @@ -818,6 +818,10 @@ Enables the experimental global instruction selector Enables an experimental new pass manager in LLVM. +.. option:: -fexperimental-strict-floating-point + +Enables the use of non-default rounding modes and non-default exception handling on targets that are not currently ready. + .. option:: -ffine-grained-bitfield-accesses, -fno-fine-grained-bitfield-accesses Use separate accesses for consecutive bitfield runs with legal widths and alignments. @@ -2577,6 +2581,10 @@ Use Intel MCU ABI Generate branches with extended addressability, usually via indirect jumps. +.. option:: -mlvi-cfi, -mno-lvi-cfi + +Enable only control-flow mitigations for Load Value Injection (LVI) + .. option:: -mmacosx-version-min=<arg>, -mmacos-version-min=<arg> Set Mac OS X deployment target diff --git a/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def b/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def index 58c55b33953..776ad6117e0 100644 --- a/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def +++ b/gnu/llvm/clang/include/clang/Basic/CodeGenOptions.def @@ -58,6 +58,8 @@ CODEGENOPT(DisableLLVMPasses , 1, 0) ///< Don't run any LLVM IR passes to get ///< frontend. CODEGENOPT(DisableLifetimeMarkers, 1, 0) ///< Don't emit any lifetime markers CODEGENOPT(DisableO0ImplyOptNone , 1, 0) ///< Don't annonate function with optnone at O0 +CODEGENOPT(ExperimentalStrictFloatingPoint, 1, 0) ///< Enables the new, experimental + ///< strict floating point. CODEGENOPT(ExperimentalNewPassManager, 1, 0) ///< Enables the new, experimental ///< pass manager. CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new diff --git a/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 87fdfc89c63..e46069a3204 100644 --- a/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/gnu/llvm/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -37,6 +37,12 @@ def note_fe_backend_plugin: Note<"%0">, BackendInfo; def warn_fe_override_module : Warning< "overriding the module target triple with %0">, InGroup<DiagGroup<"override-module">>; +def warn_fe_backend_unsupported_fp_rounding : Warning< + "overriding currently unsupported rounding mode on this target">, + InGroup<UnsupportedFPOpt>; +def warn_fe_backend_unsupported_fp_exceptions : Warning< + "overriding currently unsupported use of floating point exceptions " + "on this target">, InGroup<UnsupportedFPOpt>; def remark_fe_backend_optimization_remark : Remark<"%0">, BackendInfo, InGroup<BackendOptimizationRemark>; diff --git a/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td b/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td index 8e43052f30e..e4233c85043 100644 --- a/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td +++ b/gnu/llvm/clang/include/clang/Basic/DiagnosticGroups.td @@ -103,6 +103,7 @@ def DoublePromotion : DiagGroup<"double-promotion">; def EnumTooLarge : DiagGroup<"enum-too-large">; def UnsupportedNan : DiagGroup<"unsupported-nan">; def UnsupportedAbs : DiagGroup<"unsupported-abs">; +def UnsupportedFPOpt : DiagGroup<"unsupported-floating-point-opt">; def UnsupportedCB : DiagGroup<"unsupported-cb">; def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">; def UnsupportedTargetOpt : DiagGroup<"unsupported-target-opt">; diff --git a/gnu/llvm/clang/include/clang/Basic/LangOptions.def b/gnu/llvm/clang/include/clang/Basic/LangOptions.def index 3319a312397..42f759322ab 100644 --- a/gnu/llvm/clang/include/clang/Basic/LangOptions.def +++ b/gnu/llvm/clang/include/clang/Basic/LangOptions.def @@ -257,6 +257,7 @@ LANGOPT(SinglePrecisionConstants , 1, 0, "treating double-precision floating poi LANGOPT(FastRelaxedMath , 1, 0, "OpenCL fast relaxed math") /// FP_CONTRACT mode (on/off/fast). ENUM_LANGOPT(DefaultFPContractMode, FPContractModeKind, 2, FPC_Off, "FP contraction type") +COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point") ENUM_LANGOPT(FPRoundingMode, FPRoundingModeKind, 3, FPR_ToNearest, "FP Rounding Mode type") ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Ignore, "FP Exception Behavior Mode type") LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment") diff --git a/gnu/llvm/clang/include/clang/Basic/TargetInfo.h b/gnu/llvm/clang/include/clang/Basic/TargetInfo.h index 3a8e3552469..6a6804a21ca 100644 --- a/gnu/llvm/clang/include/clang/Basic/TargetInfo.h +++ b/gnu/llvm/clang/include/clang/Basic/TargetInfo.h @@ -176,6 +176,7 @@ protected: // LLVM IR type. bool HasFloat128; bool HasFloat16; + bool HasStrictFP; unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; unsigned short SimdDefaultAlign; @@ -533,6 +534,9 @@ public: /// Determine whether the _Float16 type is supported on this target. virtual bool hasFloat16Type() const { return HasFloat16; } + /// Determine whether constrained floating point is supported on this target. + virtual bool hasStrictFP() const { return HasStrictFP; } + /// Return the alignment that is suitable for storing any /// object with a fundamental alignment requirement. unsigned getSuitableAlign() const { return SuitableAlign; } diff --git a/gnu/llvm/clang/include/clang/Driver/Options.td b/gnu/llvm/clang/include/clang/Driver/Options.td index bf878919ac1..98991a57abb 100644 --- a/gnu/llvm/clang/include/clang/Driver/Options.td +++ b/gnu/llvm/clang/include/clang/Driver/Options.td @@ -1235,6 +1235,9 @@ def fexperimental_isel : Flag<["-"], "fexperimental-isel">, Group<f_clang_Group> def fexperimental_new_pass_manager : Flag<["-"], "fexperimental-new-pass-manager">, Group<f_clang_Group>, Flags<[CC1Option]>, HelpText<"Enables an experimental new pass manager in LLVM.">; +def fexperimental_strict_floating_point : Flag<["-"], "fexperimental-strict-floating-point">, + Group<f_clang_Group>, Flags<[CC1Option]>, + HelpText<"Enables experimental strict floating point in LLVM.">; def finput_charset_EQ : Joined<["-"], "finput-charset=">, Group<f_Group>; def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group<f_Group>; def finstrument_functions : Flag<["-"], "finstrument-functions">, Group<f_Group>, Flags<[CC1Option]>, @@ -2275,6 +2278,14 @@ def mspeculative_load_hardening : Flag<["-"], "mspeculative-load-hardening">, Group<m_Group>, Flags<[CoreOption,CC1Option]>; def mno_speculative_load_hardening : Flag<["-"], "mno-speculative-load-hardening">, Group<m_Group>, Flags<[CoreOption]>; +def mlvi_hardening : Flag<["-"], "mlvi-hardening">, Group<m_Group>, Flags<[CoreOption,DriverOption]>, + HelpText<"Enable all mitigations for Load Value Injection (LVI)">; +def mno_lvi_hardening : Flag<["-"], "mno-lvi-hardening">, Group<m_Group>, Flags<[CoreOption,DriverOption]>, + HelpText<"Disable mitigations for Load Value Injection (LVI)">; +def mlvi_cfi : Flag<["-"], "mlvi-cfi">, Group<m_Group>, Flags<[CoreOption,DriverOption]>, + HelpText<"Enable only control-flow mitigations for Load Value Injection (LVI)">; +def mno_lvi_cfi : Flag<["-"], "mno-lvi-cfi">, Group<m_Group>, Flags<[CoreOption,DriverOption]>, + HelpText<"Disable control-flow mitigations for Load Value Injection (LVI)">; def mrelax : Flag<["-"], "mrelax">, Group<m_riscv_Features_Group>, HelpText<"Enable linker relaxation">; diff --git a/gnu/llvm/clang/lib/Basic/TargetInfo.cpp b/gnu/llvm/clang/lib/Basic/TargetInfo.cpp index 3a21a19e1f1..cf933c88b53 100644 --- a/gnu/llvm/clang/lib/Basic/TargetInfo.cpp +++ b/gnu/llvm/clang/lib/Basic/TargetInfo.cpp @@ -36,6 +36,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) { HasLegalHalfType = false; HasFloat128 = false; HasFloat16 = false; + HasStrictFP = false; PointerWidth = PointerAlign = 32; BoolWidth = BoolAlign = 8; IntWidth = IntAlign = 32; diff --git a/gnu/llvm/clang/lib/Basic/Targets/SystemZ.h b/gnu/llvm/clang/lib/Basic/Targets/SystemZ.h index e751806f474..f86cdc00e3e 100644 --- a/gnu/llvm/clang/lib/Basic/Targets/SystemZ.h +++ b/gnu/llvm/clang/lib/Basic/Targets/SystemZ.h @@ -47,6 +47,7 @@ public: MinGlobalAlign = 16; resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"); MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; + HasStrictFP = true; } void getTargetDefines(const LangOptions &Opts, diff --git a/gnu/llvm/clang/lib/Basic/Targets/X86.h b/gnu/llvm/clang/lib/Basic/Targets/X86.h index 8ffb491fcf7..4c04f0b9394 100644 --- a/gnu/llvm/clang/lib/Basic/Targets/X86.h +++ b/gnu/llvm/clang/lib/Basic/Targets/X86.h @@ -148,6 +148,7 @@ public: : TargetInfo(Triple) { LongDoubleFormat = &llvm::APFloat::x87DoubleExtended(); AddrSpaceMap = &X86AddrSpaceMap; + HasStrictFP = true; } const char *getLongDoubleMangling() const override { diff --git a/gnu/llvm/clang/lib/Frontend/CompilerInstance.cpp b/gnu/llvm/clang/lib/Frontend/CompilerInstance.cpp index 688f21dd090..c9a65bc0ec1 100644 --- a/gnu/llvm/clang/lib/Frontend/CompilerInstance.cpp +++ b/gnu/llvm/clang/lib/Frontend/CompilerInstance.cpp @@ -927,6 +927,19 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO)); } + if (!getTarget().hasStrictFP() && !getLangOpts().ExpStrictFP) { + if (getLangOpts().getFPRoundingMode() != + LangOptions::FPR_ToNearest) { + getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_rounding); + getLangOpts().setFPRoundingMode(LangOptions::FPR_ToNearest); + } + if (getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore) { + getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_exceptions); + getLangOpts().setFPExceptionMode(LangOptions::FPE_Ignore); + } + // FIXME: can we disable FEnvAccess? + } + // Inform the target of the language options. // // FIXME: We shouldn't need to do this, the target should be immutable once diff --git a/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp b/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp index 62596e9c6ee..e33e80f5b37 100644 --- a/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp +++ b/gnu/llvm/clang/lib/Frontend/CompilerInvocation.cpp @@ -3175,6 +3175,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } + if (Args.hasArg(OPT_fexperimental_strict_floating_point)) + Opts.ExpStrictFP = true; + LangOptions::FPRoundingModeKind FPRM = LangOptions::FPR_ToNearest; if (Args.hasArg(OPT_frounding_math)) { FPRM = LangOptions::FPR_Dynamic; |