Skip to content

Commit e7b78ff

Browse files
authored
Backport -Wdouble-promotion from Clang 3.8 (#6574)
This adds the Clang 3.8 `-Wdouble-promotion` warning group to DXC. This is added as part of the mitigations for the HLSL 202x conforming literals feature which (among other things) changes the conversion rank of unsuffixed literal values. Resolves #6571
1 parent 0c45099 commit e7b78ff

4 files changed

Lines changed: 339 additions & 2 deletions

File tree

tools/clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def BoolConversion : DiagGroup<"bool-conversion", [PointerBoolConversion,
4444
def IntConversion : DiagGroup<"int-conversion">;
4545
def EnumConversion : DiagGroup<"enum-conversion">;
4646
def FloatConversion : DiagGroup<"float-conversion">;
47+
def DoublePromotion : DiagGroup<"double-promotion">; // HLSL Change - backport.
4748
def EnumTooLarge : DiagGroup<"enum-too-large">;
4849
def UnsupportedNan : DiagGroup<"unsupported-nan">;
4950
def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,13 @@ def warn_impcast_null_pointer_to_integer : Warning<
26392639
def warn_impcast_floating_point_to_bool : Warning<
26402640
"implicit conversion turns floating-point number into bool: %0 to %1">,
26412641
InGroup<ImplicitConversionFloatingPointToBool>;
2642+
// HLSL Change - Begin
2643+
// This backports the Clang change to emit warnings for floating point
2644+
// promotions.
2645+
def warn_impcast_double_promotion : Warning<
2646+
"implicit conversion increases floating-point precision: %0 to %1">,
2647+
InGroup<DoublePromotion>, DefaultIgnore;
2648+
// HLSL Change - End
26422649

26432650
def warn_impcast_pointer_to_bool : Warning<
26442651
"address of%select{| function| array}0 '%1' will always evaluate to "

tools/clang/lib/Sema/SemaChecking.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7135,12 +7135,15 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
71357135
if (TargetBT && TargetBT->isFloatingPoint()) {
71367136
// ...then warn if we're dropping FP rank.
71377137

7138-
// HLSL Change - unless source is literal float
7138+
// HLSL Change Begin - Warn on both promotions and conversions.
7139+
// Don't warn on Literal float.
71397140
if (SourceBT->getKind() == BuiltinType::LitFloat)
71407141
return;
7142+
int Order = S.getASTContext().getFloatingTypeOrder(QualType(SourceBT, 0),
7143+
QualType(TargetBT, 0));
71417144

71427145
// Builtin FP kinds are ordered by increasing FP rank.
7143-
if (SourceBT->getKind() > TargetBT->getKind()) {
7146+
if (Order > 0) {
71447147
// Don't warn about float constants that are precisely
71457148
// representable in the target type.
71467149
Expr::EvalResult result;
@@ -7156,7 +7159,10 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
71567159
return;
71577160

71587161
DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_float_precision);
7162+
} else if (Order < 0) {
7163+
DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_double_promotion);
71597164
}
7165+
// HLSL Change End
71607166
return;
71617167
}
71627168

0 commit comments

Comments
 (0)