Skip to content

Commit 09133dd

Browse files
committed
Merge from 'main' to 'sycl-web' (#9)
CONFLICT (content): Merge conflict in clang/include/clang/Sema/Sema.h CONFLICT (content): Merge conflict in clang/include/clang/Basic/Builtins.def
2 parents 1b45e18 + e773216 commit 09133dd

39 files changed

+1279
-368
lines changed

clang/docs/UsersManual.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,26 @@ Note that floating-point operations performed as part of constant initialization
14781478
* ``maytrap`` The compiler avoids transformations that may raise exceptions that would not have been raised by the original code. Constant folding performed by the compiler is exempt from this option.
14791479
* ``strict`` The compiler ensures that all transformations strictly preserve the floating point exception semantics of the original code.
14801480

1481+
.. option:: -f[no-]protect-parens:
1482+
1483+
This option pertains to floating-point types, complex types with
1484+
floating-point components, and vectors of these types. Some arithmetic
1485+
expression transformations that are mathematically correct and permissible
1486+
according to the C and C++ language standards may be incorrect when dealing
1487+
with floating-point types, such as reassociation and distribution. Further,
1488+
the optimizer may ignore parentheses when computing arithmetic expressions
1489+
in circumstances where the parenthesized and unparenthesized expression
1490+
express the same mathematical value. For example (a+b)+c is the same
1491+
mathematical value as a+(b+c), but the optimizer is free to evaluate the
1492+
additions in any order regardless of the parentheses. When enabled, this
1493+
option forces the optimizer to honor the order of operations with respect
1494+
to parentheses in all circumstances.
1495+
1496+
Note that floating-point contraction (option `-ffp-contract=`) is disabled
1497+
when `-fprotect-parens` is enabled. Also note that in safe floating-point
1498+
modes, such as `-ffp-model=precise` or `-ffp-model=strict`, this option
1499+
has no effect because the optimizer is prohibited from making unsafe
1500+
transformations.
14811501

14821502
.. _fp-constant-eval:
14831503

clang/include/clang/Basic/Builtins.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,9 @@ BUILTIN(__builtin_ms_va_start, "vc*&.", "nt")
16571657
BUILTIN(__builtin_ms_va_end, "vc*&", "n")
16581658
BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n")
16591659

1660+
// Arithmetic Fence: to prevent FP reordering and reassociation optimizations
1661+
LANGBUILTIN(__arithmetic_fence, "v.", "t", ALL_LANGUAGES)
1662+
16601663
// Builtins for Intel FPGA
16611664
BUILTIN(__builtin_intel_fpga_reg, "v.", "nt")
16621665
BUILTIN(__builtin_intel_fpga_mem, "v.", "nt")

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8580,6 +8580,9 @@ def err_typecheck_expect_scalar_operand : Error<
85808580
"operand of type %0 where arithmetic or pointer type is required">;
85818581
def err_typecheck_cond_incompatible_operands : Error<
85828582
"incompatible operand types%diff{ ($ and $)|}0,1">;
8583+
def err_typecheck_expect_flt_or_vector : Error<
8584+
"invalid operand of type %0 where floating, complex or "
8585+
"a vector of such types is required">;
85838586
def err_cast_selector_expr : Error<
85848587
"cannot type cast @selector expression">;
85858588
def ext_typecheck_cond_incompatible_pointers : ExtWarn<

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro")
199199
COMPATIBLE_LANGOPT(FastMath , 1, 0, "fast FP math optimizations, and __FAST_MATH__ predefined macro")
200200
COMPATIBLE_LANGOPT(FiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined macro")
201201
COMPATIBLE_LANGOPT(UnsafeFPMath , 1, 0, "Unsafe Floating Point Math")
202+
COMPATIBLE_LANGOPT(ProtectParens , 1, 0, "optimizer honors parentheses "
203+
"when floating-point expressions are evaluated")
202204
BENIGN_LANGOPT(AllowFPReassoc , 1, 0, "Permit Floating Point reassociation")
203205
BENIGN_LANGOPT(NoHonorNaNs , 1, 0, "Permit Floating Point optimization without regard to NaN")
204206
BENIGN_LANGOPT(NoHonorInfs , 1, 0, "Permit Floating Point optimization without regard to infinities")

clang/include/clang/Basic/TargetInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,9 @@ class TargetInfo : public virtual TransferrableTargetInfo,
14241424
/// Whether the option -fextend-arguments={32,64} is supported on the target.
14251425
virtual bool supportsExtendIntArgs() const { return false; }
14261426

1427+
/// Controls if __arithmetic_fence is supported in the targeted backend.
1428+
virtual bool checkArithmeticFenceSupported() const { return false; }
1429+
14271430
/// Gets the default calling convention for the given target and
14281431
/// declaration context.
14291432
virtual CallingConv getDefaultCallingConv() const {

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,13 @@ defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
17821782
" of the target's native float-to-int conversion instructions">,
17831783
PosFlag<SetTrue, [], "Assume that overflowing float-to-int casts are undefined (default)">>;
17841784

1785+
defm protect_parens : BoolFOption<"protect-parens",
1786+
LangOpts<"ProtectParens">, DefaultFalse,
1787+
PosFlag<SetTrue, [CoreOption, CC1Option],
1788+
"Determines whether the optimizer honors parentheses when "
1789+
"floating-point expressions are evaluated">,
1790+
NegFlag<SetFalse>>;
1791+
17851792
def ffor_scope : Flag<["-"], "ffor-scope">, Group<f_Group>;
17861793
def fno_for_scope : Flag<["-"], "fno-for-scope">, Group<f_Group>;
17871794

@@ -4497,7 +4504,7 @@ defm integer_4_integer_8 : BooleanFFlag<"integer-4-integer-8">, Group<gfortran_G
44974504
defm max_identifier_length : BooleanFFlag<"max-identifier-length">, Group<gfortran_Group>;
44984505
defm module_private : BooleanFFlag<"module-private">, Group<gfortran_Group>;
44994506
defm pack_derived : BooleanFFlag<"pack-derived">, Group<gfortran_Group>;
4500-
defm protect_parens : BooleanFFlag<"protect-parens">, Group<gfortran_Group>;
4507+
//defm protect_parens : BooleanFFlag<"protect-parens">, Group<gfortran_Group>;
45014508
defm range_check : BooleanFFlag<"range-check">, Group<gfortran_Group>;
45024509
defm real_4_real_10 : BooleanFFlag<"real-4-real-10">, Group<gfortran_Group>;
45034510
defm real_4_real_16 : BooleanFFlag<"real-4-real-16">, Group<gfortran_Group>;

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "clang/AST/TypeLoc.h"
3737
#include "clang/AST/TypeOrdering.h"
3838
#include "clang/Basic/BitmaskEnum.h"
39+
#include "clang/Basic/Builtins.h"
3940
#include "clang/Basic/DiagnosticSema.h"
4041
#include "clang/Basic/ExpressionTraits.h"
4142
#include "clang/Basic/Module.h"
@@ -5667,6 +5668,8 @@ class Sema final {
56675668
Expr *ExecConfig = nullptr,
56685669
bool IsExecConfig = false,
56695670
bool AllowRecovery = false);
5671+
Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id,
5672+
MultiExprArg CallArgs);
56705673
enum class AtomicArgumentOrder { API, AST };
56715674
ExprResult
56725675
BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
@@ -12924,6 +12927,7 @@ class Sema final {
1292412927
private:
1292512928
bool SemaBuiltinPrefetch(CallExpr *TheCall);
1292612929
bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall);
12930+
bool SemaBuiltinArithmeticFence(CallExpr *TheCall);
1292712931
bool SemaBuiltinAssume(CallExpr *TheCall);
1292812932
bool SemaBuiltinAssumeAligned(CallExpr *TheCall);
1292912933
bool SemaBuiltinLongjmp(CallExpr *TheCall);

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13724,6 +13724,9 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
1372413724
Result.changeSign();
1372513725
return true;
1372613726

13727+
case Builtin::BI__arithmetic_fence:
13728+
return EvaluateFloat(E->getArg(0), Result, Info);
13729+
1372713730
// FIXME: Builtin::BI__builtin_powi
1372813731
// FIXME: Builtin::BI__builtin_powif
1372913732
// FIXME: Builtin::BI__builtin_powil

clang/lib/Basic/TargetInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
430430
// its corresponding signed type.
431431
PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
432432
CheckFixedPointBits();
433+
434+
if (Opts.ProtectParens && !checkArithmeticFenceSupported()) {
435+
Diags.Report(diag::err_opt_not_valid_on_target) << "-fprotect-parens";
436+
Opts.ProtectParens = false;
437+
}
433438
}
434439

435440
bool TargetInfo::initFeatureMap(

clang/lib/Basic/Targets/X86.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
362362
}
363363
}
364364

365+
bool checkArithmeticFenceSupported() const override { return true; }
366+
365367
CallingConv getDefaultCallingConv() const override {
366368
return CC_C;
367369
}

0 commit comments

Comments
 (0)