]> granicus.if.org Git - clang/commitdiff
Generalize the float type generation code, and specifically fix the
authorEli Friedman <eli.friedman@gmail.com>
Tue, 27 May 2008 04:20:05 +0000 (04:20 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 27 May 2008 04:20:05 +0000 (04:20 +0000)
codegen of X86 long double.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51578 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenTypes.cpp
test/CodeGen/long-double-x86.c [new file with mode: 0644]

index b640c912e5ce8873c4c7bb0b43d4ce88fb63c241..aa0d2ed0531f37ea8d1634094bda191ec5a90f1a 100644 (file)
@@ -161,6 +161,21 @@ void CodeGenTypes::CollectObjCIvarTypes(ObjCInterfaceDecl *ObjCClass,
   }
 }
 
+static const llvm::Type* getTypeForFormat(const llvm::fltSemantics * format) {
+  if (format == &llvm::APFloat::IEEEsingle)
+    return llvm::Type::FloatTy;
+  if (format == &llvm::APFloat::IEEEdouble)
+    return llvm::Type::DoubleTy;
+  if (format == &llvm::APFloat::IEEEquad)
+    return llvm::Type::FP128Ty;
+  if (format == &llvm::APFloat::PPCDoubleDouble)
+    return llvm::Type::PPC_FP128Ty;
+  if (format == &llvm::APFloat::x87DoubleExtended)
+    return llvm::Type::X86_FP80Ty;
+  assert(9 && "Unknown float format!");
+  return 0;
+}
+
 const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
   const clang::Type &Ty = *T.getCanonicalType();
   
@@ -195,13 +210,12 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
       return llvm::IntegerType::get(
         static_cast<unsigned>(Context.getTypeSize(T)));
       
-    case BuiltinType::Float:      return llvm::Type::FloatTy;
+    case BuiltinType::Float:
+      return getTypeForFormat(Context.Target.getFloatFormat());
     case BuiltinType::Double:
-      return (Context.Target.getDoubleFormat() == &llvm::APFloat::IEEEdouble) ? 
-        llvm::Type::DoubleTy : llvm::Type::FloatTy;
+      return getTypeForFormat(Context.Target.getDoubleFormat());
     case BuiltinType::LongDouble:
-      // FIXME: mapping long double onto double.
-      return llvm::Type::DoubleTy;
+      return getTypeForFormat(Context.Target.getLongDoubleFormat());
     }
     break;
   }
diff --git a/test/CodeGen/long-double-x86.c b/test/CodeGen/long-double-x86.c
new file mode 100644 (file)
index 0000000..88ac0c9
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: clang %s -emit-llvm -o - -triple=i686-apple-darwin9 | grep x86_fp80
+
+long double x = 0;
+int checksize[sizeof(x) == 12 ? 1 : -1];