Author: Gousemoodhin Nadaf
Date: 2020-08-11T17:26:19+02:00
New Revision: d4408fe17f33bcd664ec8f468abfd1094e84a7c1

URL: 
https://github.com/llvm/llvm-project/commit/d4408fe17f33bcd664ec8f468abfd1094e84a7c1
DIFF: 
https://github.com/llvm/llvm-project/commit/d4408fe17f33bcd664ec8f468abfd1094e84a7c1.diff

LOG: [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

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp
    clang/test/Frontend/fixed_point_errors.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 79340a9c7d7b..bea693f999ab 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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) {

diff  --git a/clang/test/Frontend/fixed_point_errors.c 
b/clang/test/Frontend/fixed_point_errors.c
index 6c41bf6df163..5aaf59876dcb 100644
--- a/clang/test/Frontend/fixed_point_errors.c
+++ b/clang/test/Frontend/fixed_point_errors.c
@@ -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')}}
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to