[Fixed Point Arithmetic] FixedPointCast


[Fixed Point Arithmetic] FixedPointCast

This patch is a part of https://reviews.llvm.org/D48456 in an attempt to
split them up. This contains the code for casting between fixed point types
and other fixed point types.

The method for converting between fixed point types is based off the convert()
method in APFixedPoint.

Differential Revision: https://reviews.llvm.org/D50616


Event Timeline

bjope added a subscriber: bjope.Oct 15 2018, 11:33 AM

I think this will give problems when building with clang-tools-extra, and having -Werror.
Such as:
../tools/clang/tools/extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:22:11: error: enumeration value 'STK_FixedPoint' not handled in switch [-Werror,-Wswitch]

In our out-of-tree target we have this patch in clang-tools-extra:

diff --git a/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index 374fcb34..d05b25f6 100644
--- a/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -47,6 +47,25 @@ static StringRef getValueOfValueInit(const QualType InitType) {
       return "0";
+  case Type::STK_FixedPoint: {
+    llvm_unreachable("FIXME, not yet implemented: DSP-C types for C++. File a bug report!");
+    /* Test case:
+      struct A {
+        A() : j() {}
+        A(int i) : j(0.0r) {}
+        short __fixed j;
+      };
+      clang-tidy -checks="-*,modernize-use-default-member-init" -config="{CheckOptions: [{key: modernize-use-default-member-init.UseAssignment, value: '1'}]}" use-default-member-init.cc -- -fflexc -std=c++11
+      This will give an error message for 'j(0.0r)', "cannot initialize a member
+      subobject of type 'short __fixed' with an rvalue of type '__fixed'",
+      unless promotions of DSP-C types are implemented for C++.
+    */
+    return "0.0r";
+  }
   case Type::STK_Floating:
     switch (InitType->getAs<BuiltinType>()->getKind()) {
     case BuiltinType::Half:

Maybe something similar is acceptable to avoid any build problems?

I found those earlier when working on the monorepo. In fixing them now.

I found those earlier when working on the monorepo. In fixing them now.

Ok, great!

Sorry for the delay. Made patch https://reviews.llvm.org/D53299. Not
sure if I needed to make a patch for this or can commit right away,
but wanted to run it by you first.

  • Leonard