]> granicus.if.org Git - clang/commitdiff
initial support for __[u]int128_t, which should be basically
authorChris Lattner <sabre@nondot.org>
Thu, 30 Apr 2009 02:43:43 +0000 (02:43 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 30 Apr 2009 02:43:43 +0000 (02:43 +0000)
compatible with VC++ and GCC.  The codegen/mangling angle hasn't
been fully ironed out yet.  Note that we accept int128_t even in
32-bit mode, unlike gcc.

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

15 files changed:
include/clang/AST/ASTContext.h
include/clang/AST/Type.h
include/clang/Frontend/PCHBitCodes.h
lib/AST/ASTContext.cpp
lib/AST/Type.cpp
lib/CodeGen/CGCall.cpp
lib/CodeGen/CodeGenTypes.cpp
lib/CodeGen/Mangle.cpp
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp
lib/Sema/Sema.cpp
test/CodeGen/uint128_t.c [new file with mode: 0644]
test/CodeGenCXX/mangle.cpp
test/CodeGenObjC/encode-test-5.m
test/Sema/types.c

index f4a01c4cf01b063ebe767f7cfbd76e6d7e0cc6ae..8cb1056110fa23f0a6e4676222747809e6db7bdb 100644 (file)
@@ -174,9 +174,9 @@ public:
   QualType BoolTy;
   QualType CharTy;
   QualType WCharTy; // [C++ 3.9.1p5], integer type in C99.
-  QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy;
+  QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
   QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
-  QualType UnsignedLongLongTy;
+  QualType UnsignedLongLongTy, UnsignedInt128Ty;
   QualType FloatTy, DoubleTy, LongDoubleTy;
   QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
   QualType VoidPtrTy;
index 5374c00949d4f7ded5100316ad468ce6b31e916c..3e8d024d72c5a445ed42d273aa6e68f4c12aa0c1 100644 (file)
@@ -537,6 +537,7 @@ public:
     UInt,
     ULong,
     ULongLong,
+    UInt128,  // __uint128_t
     
     Char_S,   // This is 'char' for targets where char is signed.
     SChar,    // This is explicitly qualified signed char.
@@ -545,6 +546,7 @@ public:
     Int,
     Long,
     LongLong,
+    Int128,   // __int128_t
     
     Float, Double, LongDouble,
 
index a4da70438626c1fe390d96745ee0bfb1ed01f999..bb5c91b8e060a5a05fa2c988c3bcf927a6eed668 100644 (file)
@@ -315,7 +315,11 @@ namespace clang {
       /// \brief The placeholder type for overloaded function sets.
       PREDEF_TYPE_OVERLOAD_ID   = 19,
       /// \brief The placeholder type for dependent types.
-      PREDEF_TYPE_DEPENDENT_ID  = 20
+      PREDEF_TYPE_DEPENDENT_ID  = 20,
+      /// \brief The '__uint128_t' type.
+      PREDEF_TYPE_UINT128_ID    = 21,
+      /// \brief The '__int128_t' type.
+      PREDEF_TYPE_INT128_ID     = 22
     };
 
     /// \brief The number of predefined type IDs that are reserved for
index 58fc42b036b073f206f9cec504e6a55432147283..6cd016cab818ba2fdf7de0fa803c367cdb2345e4 100644 (file)
@@ -251,6 +251,10 @@ void ASTContext::InitBuiltinTypes() {
   InitBuiltinType(DoubleTy,            BuiltinType::Double);
   InitBuiltinType(LongDoubleTy,        BuiltinType::LongDouble);
 
+  // GNU extension, 128-bit integers.
+  InitBuiltinType(Int128Ty,            BuiltinType::Int128);
+  InitBuiltinType(UnsignedInt128Ty,    BuiltinType::UInt128);
+
   if (LangOpts.CPlusPlus) // C++ 3.9.1p5
     InitBuiltinType(WCharTy,           BuiltinType::WChar);
   else // C99
@@ -421,6 +425,13 @@ ASTContext::getTypeInfo(const Type *T) {
       Width = Target.getLongDoubleWidth();
       Align = Target.getLongDoubleAlign();
       break;
+    case BuiltinType::Int128:
+    case BuiltinType::UInt128:
+      Width = 128;
+          
+      // FIXME: Is this correct for all targets?
+      Align = 128;
+      break;
     }
     break;
   case Type::FixedWidthInt:
@@ -1923,6 +1934,9 @@ unsigned ASTContext::getIntegerRank(Type *T) {
   case BuiltinType::LongLong:
   case BuiltinType::ULongLong:
     return 6 + (getIntWidth(LongLongTy) << 3);
+  case BuiltinType::Int128:
+  case BuiltinType::UInt128:
+    return 7 + (getIntWidth(Int128Ty) << 3);
   }
 }
 
@@ -2291,6 +2305,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
           encoding = 
             (const_cast<ASTContext *>(this))->getIntWidth(T) == 32 ? 'L' : 'Q'; 
           break;
+      case BuiltinType::UInt128:    encoding = 'T'; break;
       case BuiltinType::ULongLong:  encoding = 'Q'; break;
       case BuiltinType::Char_S:
       case BuiltinType::SChar:      encoding = 'c'; break;
@@ -2301,6 +2316,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
           (const_cast<ASTContext *>(this))->getIntWidth(T) == 32 ? 'l' : 'q'; 
         break;
       case BuiltinType::LongLong:   encoding = 'q'; break;
+      case BuiltinType::Int128:     encoding = 't'; break;
       case BuiltinType::Float:      encoding = 'f'; break;
       case BuiltinType::Double:     encoding = 'd'; break;
       case BuiltinType::LongDouble: encoding = 'd'; break;
@@ -3244,6 +3260,8 @@ QualType ASTContext::getCorrespondingUnsignedType(QualType T) {
     return UnsignedLongTy;
   case BuiltinType::LongLong:
     return UnsignedLongLongTy;
+  case BuiltinType::Int128:
+    return UnsignedInt128Ty;
   default:
     assert(0 && "Unexpected signed integer type");
     return QualType();
index 0331bbf40ddc2851b4975d8e7d177462d356b234..d6cf4bd0c35b75597667d3e9b6c39bc73a507824 100644 (file)
@@ -584,7 +584,7 @@ Type::getAsTemplateSpecializationType() const {
 bool Type::isIntegerType() const {
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() >= BuiltinType::Bool &&
-           BT->getKind() <= BuiltinType::LongLong;
+           BT->getKind() <= BuiltinType::Int128;
   if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
     // Incomplete enum types are not treated as integer types.
     // FIXME: In C++, enum types are never integer types.
@@ -901,11 +901,13 @@ const char *BuiltinType::getName() const {
   case Int:               return "int";
   case Long:              return "long";
   case LongLong:          return "long long";
+  case Int128:            return "__int128_t";
   case UChar:             return "unsigned char";
   case UShort:            return "unsigned short";
   case UInt:              return "unsigned int";
   case ULong:             return "unsigned long";
   case ULongLong:         return "unsigned long long";
+  case UInt128:           return "__uint128_t";
   case Float:             return "float";
   case Double:            return "double";
   case LongDouble:        return "long double";
index 07663bfaea4eddaa7daf4479ee5b507104c89baa..a6439fcb03641342b0cf4ceb64ede76b93264deb 100644 (file)
@@ -640,6 +640,9 @@ void X86_64ABIInfo::classify(QualType Ty,
 
     if (k == BuiltinType::Void) {
       Current = NoClass; 
+    } else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) {
+      Lo = Memory;
+      Hi = Memory;
     } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
       Current = Integer;
     } else if (k == BuiltinType::Float || k == BuiltinType::Double) {
@@ -650,7 +653,6 @@ void X86_64ABIInfo::classify(QualType Ty,
     }
     // FIXME: _Decimal32 and _Decimal64 are SSE.
     // FIXME: _float128 and _Decimal128 are (SSE, SSEUp).
-    // FIXME: __int128 is (Integer, Integer).
   } else if (const EnumType *ET = Ty->getAsEnumType()) {
     // Classify the underlying integer type.
     classify(ET->getDecl()->getIntegerType(), Context, OffsetBase, Lo, Hi);
index f0bc6f696135e1b14eeb04c9f3168c83aef10b66..a3f79d3d59cca0c063f23dbb8d0aa7ea367f06ec 100644 (file)
@@ -256,6 +256,10 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
     case BuiltinType::Double:
     case BuiltinType::LongDouble:
       return getTypeForFormat(Context.getFloatTypeSemantics(T));
+          
+    case BuiltinType::UInt128:
+    case BuiltinType::Int128:
+      return llvm::IntegerType::get(128);
     }
     break;
   }
index 3a7fe9c1f79882d24a627473bddc2cafd441daa8..e6d643f7ca8b33d2c95bc5c4e68077f8df8ab182 100644 (file)
@@ -508,12 +508,14 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
   case BuiltinType::UInt: Out << 'j'; break;
   case BuiltinType::ULong: Out << 'm'; break;
   case BuiltinType::ULongLong: Out << 'y'; break;
+  case BuiltinType::UInt128: Out << 'o'; break;
   case BuiltinType::SChar: Out << 'a'; break;
   case BuiltinType::WChar: Out << 'w'; break;
   case BuiltinType::Short: Out << 's'; break;
   case BuiltinType::Int: Out << 'i'; break;
   case BuiltinType::Long: Out << 'l'; break;
   case BuiltinType::LongLong: Out << 'x'; break;
+  case BuiltinType::Int128: Out << 'n'; break;
   case BuiltinType::Float: Out << 'f'; break;
   case BuiltinType::Double: Out << 'd'; break;
   case BuiltinType::LongDouble: Out << 'e'; break;
index ead6dcc1016ca1a933ccd23438927278a15a8feb..932362093802ee83c211466d87bb2cefec54bafe 100644 (file)
@@ -1663,12 +1663,14 @@ QualType PCHReader::GetType(pch::TypeID ID) {
     case pch::PREDEF_TYPE_UINT_ID:       T = Context->UnsignedIntTy;      break;
     case pch::PREDEF_TYPE_ULONG_ID:      T = Context->UnsignedLongTy;     break;
     case pch::PREDEF_TYPE_ULONGLONG_ID:  T = Context->UnsignedLongLongTy; break;
+    case pch::PREDEF_TYPE_UINT128_ID:    T = Context->UnsignedInt128Ty;   break;
     case pch::PREDEF_TYPE_SCHAR_ID:      T = Context->SignedCharTy;       break;
     case pch::PREDEF_TYPE_WCHAR_ID:      T = Context->WCharTy;            break;
     case pch::PREDEF_TYPE_SHORT_ID:      T = Context->ShortTy;            break;
     case pch::PREDEF_TYPE_INT_ID:        T = Context->IntTy;              break;
     case pch::PREDEF_TYPE_LONG_ID:       T = Context->LongTy;             break;
     case pch::PREDEF_TYPE_LONGLONG_ID:   T = Context->LongLongTy;         break;
+    case pch::PREDEF_TYPE_INT128_ID:     T = Context->Int128Ty;           break;
     case pch::PREDEF_TYPE_FLOAT_ID:      T = Context->FloatTy;            break;
     case pch::PREDEF_TYPE_DOUBLE_ID:     T = Context->DoubleTy;           break;
     case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy;       break;
index 8374e092a5377a3005f386504192643aaf92e7f7..b28d0c8cf9f8fbc8b3346cd72879f8e9dbb5ef37 100644 (file)
@@ -1829,6 +1829,7 @@ void PCHWriter::AddTypeRef(QualType T, RecordData &Record) {
     case BuiltinType::UInt:       ID = pch::PREDEF_TYPE_UINT_ID;       break;
     case BuiltinType::ULong:      ID = pch::PREDEF_TYPE_ULONG_ID;      break;
     case BuiltinType::ULongLong:  ID = pch::PREDEF_TYPE_ULONGLONG_ID;  break;
+    case BuiltinType::UInt128:    ID = pch::PREDEF_TYPE_UINT128_ID;    break;
     case BuiltinType::Char_S:     ID = pch::PREDEF_TYPE_CHAR_S_ID;     break;
     case BuiltinType::SChar:      ID = pch::PREDEF_TYPE_SCHAR_ID;      break;
     case BuiltinType::WChar:      ID = pch::PREDEF_TYPE_WCHAR_ID;      break;
@@ -1836,6 +1837,7 @@ void PCHWriter::AddTypeRef(QualType T, RecordData &Record) {
     case BuiltinType::Int:        ID = pch::PREDEF_TYPE_INT_ID;        break;
     case BuiltinType::Long:       ID = pch::PREDEF_TYPE_LONG_ID;       break;
     case BuiltinType::LongLong:   ID = pch::PREDEF_TYPE_LONGLONG_ID;   break;
+    case BuiltinType::Int128:     ID = pch::PREDEF_TYPE_INT128_ID;     break;
     case BuiltinType::Float:      ID = pch::PREDEF_TYPE_FLOAT_ID;      break;
     case BuiltinType::Double:     ID = pch::PREDEF_TYPE_DOUBLE_ID;     break;
     case BuiltinType::LongDouble: ID = pch::PREDEF_TYPE_LONGDOUBLE_ID; break;
index 367c9f5756ba3412d93e2c6f038f188a84425793..8ce3ce0be63ee50fa6742498b90c7a6b10bc8126 100644 (file)
@@ -108,6 +108,18 @@ static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name) {
 void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
   TUScope = S;
   PushDeclContext(S, Context.getTranslationUnitDecl());
+  
+  // Install [u]int128_t.
+  PushOnScopeChains(TypedefDecl::Create(Context, CurContext,
+                                        SourceLocation(),
+                                        &Context.Idents.get("__int128_t"),
+                                        Context.Int128Ty), TUScope);
+  PushOnScopeChains(TypedefDecl::Create(Context, CurContext,
+                                        SourceLocation(),
+                                        &Context.Idents.get("__uint128_t"),
+                                        Context.UnsignedInt128Ty), TUScope);
+  
+  
   if (!PP.getLangOptions().ObjC1) return;
   
   if (Context.getObjCSelType().isNull()) {
diff --git a/test/CodeGen/uint128_t.c b/test/CodeGen/uint128_t.c
new file mode 100644 (file)
index 0000000..b3261dd
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: clang-cc %s -emit-llvm -o -
+
+typedef unsigned long long uint64_t;
+extern uint64_t numer;
+extern uint64_t denom;
+
+uint64_t
+f(uint64_t val)
+{
+    __uint128_t tmp;
+
+    tmp = val;
+    tmp *= numer;
+    tmp /= denom;
+
+    return tmp;
+}
+
index 0f135270233a553dd7836292eedd94d53b516323..5540a6868f41b212c1308e45b416504dcc51f2c1 100644 (file)
@@ -46,5 +46,8 @@ namespace N { int i; }
 namespace N { int f(int, int) { static int b; return b; } }
 
 // RUN: grep "_ZZN1N1gEvE1a =" %t | count 1 &&
-// RUN: grep "_ZGVZN1N1gEvE1a =" %t | count 1
+// RUN: grep "_ZGVZN1N1gEvE1a =" %t | count 1 &&
 namespace N { int h(); void g() { static int a = h(); } }
+
+// RUN: grep "_Z1fno" %t | count 1
+void f(__int128_t, __uint128_t) { } 
index 970df3da87840ff1a62e1c31af98d0010e37109a..bf1a0a67254022489f7e83599ad0f6bbe68da07f 100644 (file)
@@ -6,6 +6,11 @@ char *a = @encode(_Complex int);
 // RUN: grep jf %t | count 1 &&
 char *b = @encode(_Complex float);
 
-// RUN: grep jd %t | count 1
+// RUN: grep jd %t | count 1 &&
 char *c = @encode(_Complex double);
 
+// RUN: grep "t.00" %t | count 1 &&
+char *e = @encode(__int128_t);
+
+// RUN: grep "T.00" %t | count 1
+char *f = @encode(__uint128_t);
index 40dfd89c4fdb07dcb4ab8a0df52f84203996b605..d1e9fcc0528d03f1b618cfd2c9a267d62f842359 100644 (file)
@@ -8,3 +8,14 @@ typedef int *S[2];
 restrict S y; // expected-error {{restrict requires a pointer or reference ('S' (aka 'int *[2]') is invalid)}}
 
 
+
+// int128_t is available.
+int a() {
+  __int128_t s;
+  __uint128_t t;
+}
+// but not a keyword
+int b() {
+  int __int128_t;
+  int __uint128_t;
+}