[clang] Do not crash for unsupported fixed point to floating point conversion

- Fixed point to floating point conversion is unimplemented.
- If one of the operands has a floating type and the other operand has a fixed-point type, the function
   handleFloatConversion() is called because one of the operands has a floating type, but we do not handle fixed
   point type in this function (Implementation of fixed point to floating point conversion is missing), due to this
   compiler crashes. In order to avoid compiler crash, when one of the operands has a floating type and the other
   operand has a fixed-point type, return NULL.
- FIXME: Implementation of fixed point to floating point conversion.
- I am going to resolve FIXME in followup patches.
- Add the test case.

Reviewed By: ebevhan

Differential Revision: https://reviews.llvm.org/D81904
This commit is contained in:
Gousemoodhin Nadaf 2020-08-11 16:48:24 +02:00 committed by Bevin Hansson
parent 956582aa16
commit d4408fe17f
2 changed files with 10 additions and 0 deletions

View File

@ -1125,6 +1125,11 @@ static QualType handleFloatConversion(Sema &S, ExprResult &LHS,
bool LHSFloat = LHSType->isRealFloatingType();
bool RHSFloat = RHSType->isRealFloatingType();
// FIXME: Implement floating to fixed point conversion.(Bug 46268)
// Reference N1169 4.1.4 (Type conversion, usual arithmetic conversions).
if ((LHSType->isFixedPointType() && RHSFloat) ||
(LHSFloat && RHSType->isFixedPointType()))
return QualType();
// If we have two real floating types, convert the smaller operand
// to the bigger result.
if (LHSFloat && RHSFloat) {

View File

@ -286,3 +286,8 @@ short _Accum shl_sat = (_Sat short _Accum)200.0hk << 5;
// Division by zero
short _Accum div_zero = 4.5k / 0.0lr; // expected-error {{initializer element is not a compile-time constant}}
void foo(void) {
_Accum x = 0.5k;
if (x == 0.5) {} // expected-error{{invalid operands to binary expression ('_Accum' and 'double')}}
}