Skip to content

Commit 3a02d78

Browse files
committed
Revert "Reapply "Add support for #pragma float_control" with buildbot fixes"
This reverts commit f5360d4.
1 parent 2b32c4d commit 3a02d78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+274
-1386
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,41 +3197,6 @@ The pragma can also be used with ``off`` which turns FP contraction off for a
31973197
section of the code. This can be useful when fast contraction is otherwise
31983198
enabled for the translation unit with the ``-ffp-contract=fast`` flag.
31993199
3200-
The ``#pragma float_control`` pragma allows precise floating-point
3201-
semantics and floating-point exception behavior to be specified
3202-
for a section of the source code. This pragma can only appear at file scope or
3203-
at the start of a compound statement (excluding comments). When using within a
3204-
compound statement, the pragma is active within the scope of the compound
3205-
statement. This pragma is modeled after a Microsoft pragma with the
3206-
same spelling and syntax. For pragmas specified at file scope, a stack
3207-
is supported so that the ``pragma float_control`` settings can be pushed or popped.
3208-
3209-
When ``pragma float_control(precise, on)`` is enabled, the section of code
3210-
governed by the pragma uses precise floating point semantics, effectively
3211-
``-ffast-math`` is disabled and ``-ffp-contract=on``
3212-
(fused multiply add) is enabled.
3213-
3214-
When ``pragma float_control(except, on)`` is enabled, the section of code governed
3215-
by the pragma behaves as though the command-line option
3216-
``-ffp-exception-behavior=strict`` is enabled,
3217-
when ``pragma float_control(precise, off)`` is enabled, the section of code
3218-
governed by the pragma behaves as though the command-line option
3219-
``-ffp-exception-behavior=ignore`` is enabled.
3220-
3221-
The full syntax this pragma supports is
3222-
``float_control(except|precise, on|off [, push])`` and
3223-
``float_control(push|pop)``.
3224-
The ``push`` and ``pop`` forms, including using ``push`` as the optional
3225-
third argument, can only occur at file scope.
3226-
3227-
.. code-block:: c++
3228-
3229-
for(...) {
3230-
// This block will be compiled with -fno-fast-math and -ffp-contract=on
3231-
#pragma float_control(precise, on)
3232-
a = b[i] * c[i] + e;
3233-
}
3234-
32353200
Specifying an attribute for multiple declarations (#pragma clang attribute)
32363201
===========================================================================
32373202

clang/include/clang/AST/Expr.h

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,48 +2107,26 @@ class ParenExpr : public Expr {
21072107
/// applied to a non-complex value, the former returns its operand and the
21082108
/// later returns zero in the type of the operand.
21092109
///
2110-
class UnaryOperator final
2111-
: public Expr,
2112-
private llvm::TrailingObjects<UnaryOperator, FPOptions> {
2110+
class UnaryOperator : public Expr {
21132111
Stmt *Val;
21142112

2115-
size_t numTrailingObjects(OverloadToken<FPOptions>) const {
2116-
return UnaryOperatorBits.HasFPFeatures ? 1 : 0;
2117-
}
2118-
2119-
FPOptions &getTrailingFPFeatures() {
2120-
assert(UnaryOperatorBits.HasFPFeatures);
2121-
return *getTrailingObjects<FPOptions>();
2122-
}
2123-
2124-
const FPOptions &getTrailingFPFeatures() const {
2125-
assert(UnaryOperatorBits.HasFPFeatures);
2126-
return *getTrailingObjects<FPOptions>();
2127-
}
2128-
21292113
public:
21302114
typedef UnaryOperatorKind Opcode;
21312115

2132-
protected:
2133-
UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type,
2134-
ExprValueKind VK, ExprObjectKind OK, SourceLocation l,
2135-
bool CanOverflow, FPOptions FPFeatures);
2116+
UnaryOperator(Expr *input, Opcode opc, QualType type, ExprValueKind VK,
2117+
ExprObjectKind OK, SourceLocation l, bool CanOverflow)
2118+
: Expr(UnaryOperatorClass, type, VK, OK), Val(input) {
2119+
UnaryOperatorBits.Opc = opc;
2120+
UnaryOperatorBits.CanOverflow = CanOverflow;
2121+
UnaryOperatorBits.Loc = l;
2122+
setDependence(computeDependence(this));
2123+
}
21362124

21372125
/// Build an empty unary operator.
2138-
explicit UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
2139-
: Expr(UnaryOperatorClass, Empty) {
2126+
explicit UnaryOperator(EmptyShell Empty) : Expr(UnaryOperatorClass, Empty) {
21402127
UnaryOperatorBits.Opc = UO_AddrOf;
2141-
UnaryOperatorBits.HasFPFeatures = HasFPFeatures;
21422128
}
21432129

2144-
public:
2145-
static UnaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
2146-
2147-
static UnaryOperator *Create(const ASTContext &C, Expr *input, Opcode opc,
2148-
QualType type, ExprValueKind VK,
2149-
ExprObjectKind OK, SourceLocation l,
2150-
bool CanOverflow, FPOptions FPFeatures);
2151-
21522130
Opcode getOpcode() const {
21532131
return static_cast<Opcode>(UnaryOperatorBits.Opc);
21542132
}
@@ -2170,18 +2148,6 @@ class UnaryOperator final
21702148
bool canOverflow() const { return UnaryOperatorBits.CanOverflow; }
21712149
void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; }
21722150

2173-
// Get the FP contractability status of this operator. Only meaningful for
2174-
// operations on floating point types.
2175-
bool isFPContractableWithinStatement(const LangOptions &LO) const {
2176-
return getFPFeatures(LO).allowFPContractWithinStatement();
2177-
}
2178-
2179-
// Get the FENV_ACCESS status of this operator. Only meaningful for
2180-
// operations on floating point types.
2181-
bool isFEnvAccessOn(const LangOptions &LO) const {
2182-
return getFPFeatures(LO).allowFEnvAccess();
2183-
}
2184-
21852151
/// isPostfix - Return true if this is a postfix operation, like x++.
21862152
static bool isPostfix(Opcode Op) {
21872153
return Op == UO_PostInc || Op == UO_PostDec;
@@ -2248,30 +2214,6 @@ class UnaryOperator final
22482214
const_child_range children() const {
22492215
return const_child_range(&Val, &Val + 1);
22502216
}
2251-
2252-
/// Is FPFeatures in Trailing Storage?
2253-
bool hasStoredFPFeatures() const { return UnaryOperatorBits.HasFPFeatures; }
2254-
2255-
protected:
2256-
/// Get FPFeatures from trailing storage
2257-
FPOptions getStoredFPFeatures() const { return getTrailingFPFeatures(); }
2258-
2259-
/// Set FPFeatures in trailing storage, used only by Serialization
2260-
void setStoredFPFeatures(FPOptions F) { getTrailingFPFeatures() = F; }
2261-
2262-
public:
2263-
// Get the FP features status of this operator. Only meaningful for
2264-
// operations on floating point types.
2265-
FPOptions getFPFeatures(const LangOptions &LO) const {
2266-
if (UnaryOperatorBits.HasFPFeatures)
2267-
return getStoredFPFeatures();
2268-
return FPOptions::defaultWithoutTrailingStorage(LO);
2269-
}
2270-
2271-
friend TrailingObjects;
2272-
friend class ASTReader;
2273-
friend class ASTStmtReader;
2274-
friend class ASTStmtWriter;
22752217
};
22762218

22772219
/// Helper class for OffsetOfExpr.

clang/include/clang/AST/Stmt.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,6 @@ class alignas(void *) Stmt {
427427

428428
unsigned Opc : 5;
429429
unsigned CanOverflow : 1;
430-
//
431-
/// This is only meaningful for operations on floating point
432-
/// types when additional values need to be in trailing storage.
433-
/// It is 0 otherwise.
434-
unsigned HasFPFeatures : 1;
435430

436431
SourceLocation Loc;
437432
};
@@ -615,7 +610,7 @@ class alignas(void *) Stmt {
615610
unsigned OperatorKind : 6;
616611

617612
// Only meaningful for floating point types.
618-
unsigned FPFeatures : 14;
613+
unsigned FPFeatures : 8;
619614
};
620615

621616
class CXXRewrittenBinaryOperatorBitfields {

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,9 @@ def warn_pragma_init_seg_unsupported_target : Warning<
10971097
"'#pragma init_seg' is only supported when targeting a "
10981098
"Microsoft environment">,
10991099
InGroup<IgnoredPragmas>;
1100-
// - #pragma restricted to file scope or start of compound statement
1101-
def err_pragma_file_or_compound_scope : Error<
1102-
"'#pragma %0' can only appear at file scope or at the start of a "
1100+
// - #pragma fp_contract
1101+
def err_pragma_fp_contract_scope : Error<
1102+
"'#pragma fp_contract' can only appear at file scope or at the start of a "
11031103
"compound statement">;
11041104
// - #pragma stdc unknown
11051105
def ext_stdc_pragma_ignored : ExtWarn<"unknown pragma in STDC namespace">,
@@ -1118,10 +1118,6 @@ def warn_pragma_comment_ignored : Warning<"'#pragma comment %0' ignored">,
11181118
def err_pragma_detect_mismatch_malformed : Error<
11191119
"pragma detect_mismatch is malformed; it requires two comma-separated "
11201120
"string literals">;
1121-
// - #pragma float_control
1122-
def err_pragma_float_control_malformed : Error<
1123-
"pragma float_control is malformed; use 'float_control({push|pop})' or "
1124-
"'float_control({precise|except}, {on|off} [,push])'">;
11251121
// - #pragma pointers_to_members
11261122
def err_pragma_pointers_to_members_unknown_kind : Error<
11271123
"unexpected %0, expected to see one of %select{|'best_case', 'full_generality', }1"
@@ -1336,6 +1332,9 @@ def err_pragma_fp_invalid_option : Error<
13361332
def err_pragma_fp_invalid_argument : Error<
13371333
"unexpected argument '%0' to '#pragma clang fp %1'; "
13381334
"expected 'on', 'fast' or 'off'">;
1335+
def err_pragma_fp_scope : Error<
1336+
"'#pragma clang fp' can only appear at file scope or at the start of a "
1337+
"compound statement">;
13391338

13401339
def err_pragma_invalid_keyword : Error<
13411340
"invalid argument; expected 'enable'%select{|, 'full'}0%select{|, 'assume_safety'}1 or 'disable'">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,6 @@ def warn_pragma_pack_pop_identifier_and_alignment : Warning<
889889
"specifying both a name and alignment to 'pop' is undefined">;
890890
def warn_pragma_pop_failed : Warning<"#pragma %0(pop, ...) failed: %1">,
891891
InGroup<IgnoredPragmas>;
892-
def err_pragma_fc_pp_scope : Error<
893-
"'#pragma float_control push/pop' can only appear at file scope">;
894-
def err_pragma_fc_noprecise_requires_nofenv : Error<
895-
"'#pragma float_control(precise, off)' is illegal when fenv_access is enabled">;
896-
def err_pragma_fc_except_requires_precise : Error<
897-
"'#pragma float_control(except, on)' is illegal when precise is disabled">;
898-
def err_pragma_fc_noprecise_requires_noexcept : Error<
899-
"'#pragma float_control(precise, off)' is illegal when except is enabled">;
900-
def err_pragma_fenv_requires_precise : Error<
901-
"'#pragma STDC FENV_ACCESS ON' is illegal when precise is disabled">;
902892
def warn_cxx_ms_struct :
903893
Warning<"ms_struct may not produce Microsoft-compatible layouts for classes "
904894
"with base classes or virtual functions">,

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,6 @@ COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro")
191191
COMPATIBLE_LANGOPT(FastMath , 1, 0, "fast FP math optimizations, and __FAST_MATH__ predefined macro")
192192
COMPATIBLE_LANGOPT(FiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined macro")
193193
COMPATIBLE_LANGOPT(UnsafeFPMath , 1, 0, "Unsafe Floating Point Math")
194-
COMPATIBLE_LANGOPT(AllowFPReassoc , 1, 0, "Permit Floating Point reassociation")
195-
COMPATIBLE_LANGOPT(NoHonorNaNs , 1, 0, "Permit Floating Point optimization without regard to NaN")
196-
COMPATIBLE_LANGOPT(NoHonorInfs , 1, 0, "Permit Floating Point optimization without regard to infinities")
197-
COMPATIBLE_LANGOPT(NoSignedZero , 1, 0, "Permit Floating Point optimization without regard to signed zeros")
198-
COMPATIBLE_LANGOPT(AllowRecip , 1, 0, "Permit Floating Point reciprocal")
199-
COMPATIBLE_LANGOPT(ApproxFunc , 1, 0, "Permit Floating Point approximation")
200194

201195
BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for __weak/__strong ivars")
202196

clang/include/clang/Basic/LangOptions.h

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -385,33 +385,28 @@ class FPOptions {
385385
using RoundingMode = llvm::RoundingMode;
386386

387387
public:
388-
FPOptions()
389-
: fp_contract(LangOptions::FPC_Off), fenv_access(LangOptions::FEA_Off),
390-
rounding(LangOptions::FPR_ToNearest),
391-
exceptions(LangOptions::FPE_Ignore), allow_reassoc(0), no_nans(0),
392-
no_infs(0), no_signed_zeros(0), allow_reciprocal(0), approx_func(0) {}
388+
FPOptions() : fp_contract(LangOptions::FPC_Off),
389+
fenv_access(LangOptions::FEA_Off),
390+
rounding(LangOptions::FPR_ToNearest),
391+
exceptions(LangOptions::FPE_Ignore)
392+
{}
393393

394394
// Used for serializing.
395-
explicit FPOptions(unsigned I) { getFromOpaqueInt(I); }
395+
explicit FPOptions(unsigned I)
396+
: fp_contract(I & 3),
397+
fenv_access((I >> 2) & 1),
398+
rounding ((I >> 3) & 7),
399+
exceptions ((I >> 6) & 3)
400+
{}
396401

397402
explicit FPOptions(const LangOptions &LangOpts)
398403
: fp_contract(LangOpts.getDefaultFPContractMode()),
399404
fenv_access(LangOptions::FEA_Off),
400-
rounding(static_cast<unsigned>(LangOpts.getFPRoundingMode())),
401-
exceptions(LangOpts.getFPExceptionMode()),
402-
allow_reassoc(LangOpts.FastMath || LangOpts.AllowFPReassoc),
403-
no_nans(LangOpts.FastMath || LangOpts.NoHonorNaNs),
404-
no_infs(LangOpts.FastMath || LangOpts.NoHonorInfs),
405-
no_signed_zeros(LangOpts.FastMath || LangOpts.NoSignedZero),
406-
allow_reciprocal(LangOpts.FastMath || LangOpts.AllowRecip),
407-
approx_func(LangOpts.FastMath || LangOpts.ApproxFunc) {}
405+
rounding(LangOptions::FPR_ToNearest),
406+
exceptions(LangOptions::FPE_Ignore)
407+
{}
408408
// FIXME: Use getDefaultFEnvAccessMode() when available.
409409

410-
void setFastMath(bool B = true) {
411-
allow_reassoc = no_nans = no_infs = no_signed_zeros = approx_func =
412-
allow_reciprocal = B;
413-
}
414-
415410
/// Return the default value of FPOptions that's used when trailing
416411
/// storage isn't required.
417412
static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO);
@@ -446,18 +441,6 @@ class FPOptions {
446441
fenv_access = LangOptions::FEA_On;
447442
}
448443

449-
void setFPPreciseEnabled(bool Value) {
450-
if (Value) {
451-
/* Precise mode implies fp_contract=on and disables ffast-math */
452-
setFastMath(false);
453-
setAllowFPContractWithinStatement();
454-
} else {
455-
/* Precise mode implies fp_contract=fast and enables ffast-math */
456-
setFastMath(true);
457-
setAllowFPContractAcrossStatement();
458-
}
459-
}
460-
461444
void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
462445

463446
RoundingMode getRoundingMode() const {
@@ -476,22 +459,6 @@ class FPOptions {
476459
exceptions = EM;
477460
}
478461

479-
/// FMF Flag queries
480-
bool allowAssociativeMath() const { return allow_reassoc; }
481-
bool noHonorNaNs() const { return no_nans; }
482-
bool noHonorInfs() const { return no_infs; }
483-
bool noSignedZeros() const { return no_signed_zeros; }
484-
bool allowReciprocalMath() const { return allow_reciprocal; }
485-
bool allowApproximateFunctions() const { return approx_func; }
486-
487-
/// Flag setters
488-
void setAllowAssociativeMath(bool B = true) { allow_reassoc = B; }
489-
void setNoHonorNaNs(bool B = true) { no_nans = B; }
490-
void setNoHonorInfs(bool B = true) { no_infs = B; }
491-
void setNoSignedZeros(bool B = true) { no_signed_zeros = B; }
492-
void setAllowReciprocalMath(bool B = true) { allow_reciprocal = B; }
493-
void setAllowApproximateFunctions(bool B = true) { approx_func = B; }
494-
495462
bool isFPConstrained() const {
496463
return getRoundingMode() != RoundingMode::NearestTiesToEven ||
497464
getExceptionMode() != LangOptions::FPE_Ignore ||
@@ -501,23 +468,7 @@ class FPOptions {
501468
/// Used to serialize this.
502469
unsigned getAsOpaqueInt() const {
503470
return fp_contract | (fenv_access << 2) | (rounding << 3) |
504-
(exceptions << 6) | (allow_reassoc << 8) | (no_nans << 9) |
505-
(no_infs << 10) | (no_signed_zeros << 11) |
506-
(allow_reciprocal << 12) | (approx_func << 13);
507-
}
508-
509-
/// Used with getAsOpaqueInt() to manage the float_control pragma stack.
510-
void getFromOpaqueInt(unsigned I) {
511-
fp_contract = (static_cast<LangOptions::FPContractModeKind>(I & 3));
512-
fenv_access = (static_cast<LangOptions::FEnvAccessModeKind>((I >> 2) & 1));
513-
rounding = static_cast<unsigned>(static_cast<RoundingMode>((I >> 3) & 7));
514-
exceptions = (static_cast<LangOptions::FPExceptionModeKind>((I >> 6) & 3));
515-
allow_reassoc = ((I >> 8) & 1);
516-
no_nans = ((I >> 9) & 1);
517-
no_infs = ((I >> 10) & 1);
518-
no_signed_zeros = ((I >> 11) & 1);
519-
allow_reciprocal = ((I >> 12) & 1);
520-
approx_func = ((I >> 13) & 1);
471+
(exceptions << 6);
521472
}
522473

523474
private:
@@ -528,25 +479,6 @@ class FPOptions {
528479
unsigned fenv_access : 1;
529480
unsigned rounding : 3;
530481
unsigned exceptions : 2;
531-
/// Allow reassociation transformations for floating-point instructions.
532-
unsigned allow_reassoc : 1;
533-
/// No NaNs - Allow optimizations to assume the arguments and result
534-
/// are not NaN. If an argument is a nan, or the result would be a nan,
535-
/// it produces a :ref:`poison value <poisonvalues>` instead.
536-
unsigned no_nans : 1;
537-
/// No Infs - Allow optimizations to assume the arguments and result
538-
/// are not +/-Inf. If an argument is +/-Inf, or the result would be +/-Inf,
539-
/// it produces a :ref:`poison value <poisonvalues>` instead.
540-
unsigned no_infs : 1;
541-
/// No Signed Zeros - Allow optimizations to treat the sign of a zero
542-
/// argument or result as insignificant.
543-
unsigned no_signed_zeros : 1;
544-
/// Allow Reciprocal - Allow optimizations to use the reciprocal
545-
/// of an argument rather than perform division.
546-
unsigned allow_reciprocal : 1;
547-
/// Approximate functions - Allow substitution of approximate calculations
548-
/// for functions (sin, log, sqrt, etc).
549-
unsigned approx_func : 1;
550482
};
551483

552484
/// Describes the kind of translation unit being processed.

clang/include/clang/Basic/PragmaKinds.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ enum PragmaMSStructKind {
2525
PMSST_ON // #pragms ms_struct on
2626
};
2727

28-
enum PragmaFloatControlKind {
29-
PFC_Unknown,
30-
PFC_Precise, // #pragma float_control(precise, [,on])
31-
PFC_NoPrecise, // #pragma float_control(precise, off)
32-
PFC_Except, // #pragma float_control(except [,on])
33-
PFC_NoExcept, // #pragma float_control(except, off)
34-
PFC_Push, // #pragma float_control(push)
35-
PFC_Pop // #pragma float_control(pop)
36-
};
3728
}
3829

3930
#endif

0 commit comments

Comments
 (0)