Hi Eli,
I have to resend you PR16752 fix. Since I had changed it. The previous one causes failures on some buildbots.
This fix also contains customization for PPC case:
For 'XC' mode (96 bit float) PPC uses 128 bit fp type.

-Stepan.

Eli Friedman wrote:
LGTM.

-Eli


On Mon, Sep 9, 2013 at 5:04 AM, Stepan Dyatkovskiy <[email protected]
<mailto:[email protected]>> wrote:

    Since I had split the patch and committed only ASTContext and
    TargetInfo getIntTypeByWidth and friends, there is the second patch,
    that fixes PR16752 itself.

    Please, find it in attachment for review.

    -Stepan.
    Eli Friedman wrote:

        On Tue, Sep 3, 2013 at 2:16 AM, Stepan Dyatkovskiy
        <[email protected] <mailto:[email protected]>
        <mailto:[email protected] <mailto:[email protected]>>> wrote:

             Hi Eli,
             Sorry for latency.
             As you remember this patch should correct 'mode' attr
             implementation. You proposed to use generic way of type
        detection
             for each target: just scan for target types and select one with
             suitable width.

             Unfortunately I can't commit patch with generic
        implementation. I
             got test failure for clang. And I expect more failures for
        another
             targets. The reason is next.

             The target could still keep mode unsupported even if it has
        type of
             suitable width. I mean the next.
             For example this string should cause error for i686
        machines (128
             bit float):
             typedef          float f128ibm __attribute__ ((mode (TF)));
             But in case of generic approach for all targets it would be
        passed.
             In this case virtual functions allows to implement exceptions.


        The generic implementation is still essentially correct; the the
        issue
        is that getLongDoubleWidth() isn't actually the right value to
        check.
           It returns "sizeof(long double) * 8", not the actual width of the
        underlying float format.  You should be able to work around this by
        checking getLongDoubleFormat() instead of getLongDoubleWidth().

             In this case 'getIntTypeByWidth' may be a bit confusing name.
             Instead it is supposed to return type for some particular
        mode, not
             by width. Something like getInt/RealTypeForMode(width, sign).
             Though, currently I kept the original name.


        If you want to change it, that's fine.

        -Eli




diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp
index e993055..62cb434 100644
--- a/lib/Basic/TargetInfo.cpp
+++ b/lib/Basic/TargetInfo.cpp
@@ -175,7 +175,10 @@ TargetInfo::RealType TargetInfo::getRealTypeByWidth(unsigned BitWidth) const {
 
   switch (BitWidth) {
   case 96:
-    if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended)
+    if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended ||
+        // Due to test/Sema/attr-mode.c test it seems that
+        // PPC machines should use PPCDoubleDouble type for XC mode.
+        &getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble)
       return LongDouble;
     break;
   case 128:
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 756d56a..10ff4b8 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -3460,77 +3460,24 @@ static void handleModeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
 
   // FIXME: Sync this with InitializePredefinedMacros; we need to match int8_t
   // and friends, at least with glibc.
-  // FIXME: Make sure 32/64-bit integers don't get defined to types of the wrong
-  // width on unusual platforms.
   // FIXME: Make sure floating-point mappings are accurate
   // FIXME: Support XF and TF types
-  QualType NewTy;
-  switch (DestWidth) {
-  case 0:
+  if (!DestWidth) {
     S.Diag(Attr.getLoc(), diag::err_unknown_machine_mode) << Name;
     return;
-  default:
+  }
+
+  QualType NewTy;
+
+  if (IntegerMode)
+    NewTy = S.Context.getIntTypeForBitwidth(DestWidth,
+                                            OldTy->isSignedIntegerType());
+  else
+    NewTy = S.Context.getRealTypeForBitwidth(DestWidth);
+
+  if (NewTy.isNull()) {
     S.Diag(Attr.getLoc(), diag::err_unsupported_machine_mode) << Name;
     return;
-  case 8:
-    if (!IntegerMode) {
-      S.Diag(Attr.getLoc(), diag::err_unsupported_machine_mode) << Name;
-      return;
-    }
-    if (OldTy->isSignedIntegerType())
-      NewTy = S.Context.SignedCharTy;
-    else
-      NewTy = S.Context.UnsignedCharTy;
-    break;
-  case 16:
-    if (!IntegerMode) {
-      S.Diag(Attr.getLoc(), diag::err_unsupported_machine_mode) << Name;
-      return;
-    }
-    if (OldTy->isSignedIntegerType())
-      NewTy = S.Context.ShortTy;
-    else
-      NewTy = S.Context.UnsignedShortTy;
-    break;
-  case 32:
-    if (!IntegerMode)
-      NewTy = S.Context.FloatTy;
-    else if (OldTy->isSignedIntegerType())
-      NewTy = S.Context.IntTy;
-    else
-      NewTy = S.Context.UnsignedIntTy;
-    break;
-  case 64:
-    if (!IntegerMode)
-      NewTy = S.Context.DoubleTy;
-    else if (OldTy->isSignedIntegerType())
-      if (S.Context.getTargetInfo().getLongWidth() == 64)
-        NewTy = S.Context.LongTy;
-      else
-        NewTy = S.Context.LongLongTy;
-    else
-      if (S.Context.getTargetInfo().getLongWidth() == 64)
-        NewTy = S.Context.UnsignedLongTy;
-      else
-        NewTy = S.Context.UnsignedLongLongTy;
-    break;
-  case 96:
-    NewTy = S.Context.LongDoubleTy;
-    break;
-  case 128:
-    if (!IntegerMode && &S.Context.getTargetInfo().getLongDoubleFormat() !=
-        &llvm::APFloat::PPCDoubleDouble) {
-      S.Diag(Attr.getLoc(), diag::err_unsupported_machine_mode) << Name;
-      return;
-    }
-    if (IntegerMode) {
-      if (OldTy->isSignedIntegerType())
-        NewTy = S.Context.Int128Ty;
-      else
-        NewTy = S.Context.UnsignedInt128Ty;
-    } else
-      NewTy = S.Context.LongDoubleTy;
-    break;
   }
 
   if (ComplexMode) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to