initial support for __[u]int128_t, which should be basically
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
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 58fc42b..6cd016c 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -251,6 +251,10 @@
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 @@
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 @@
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 @@
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 @@
(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 @@
return UnsignedLongTy;
case BuiltinType::LongLong:
return UnsignedLongLongTy;
+ case BuiltinType::Int128:
+ return UnsignedInt128Ty;
default:
assert(0 && "Unexpected signed integer type");
return QualType();
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 0331bbf..d6cf4bd 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -584,7 +584,7 @@
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 @@
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";
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 07663bf..a6439fc 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -640,6 +640,9 @@
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 @@
}
// 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);
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index f0bc6f6..a3f79d3 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -256,6 +256,10 @@
case BuiltinType::Double:
case BuiltinType::LongDouble:
return getTypeForFormat(Context.getFloatTypeSemantics(T));
+
+ case BuiltinType::UInt128:
+ case BuiltinType::Int128:
+ return llvm::IntegerType::get(128);
}
break;
}
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index 3a7fe9c..e6d643f 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -508,12 +508,14 @@
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;
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index ead6dcc..9323620 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -1663,12 +1663,14 @@
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;
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 8374e09..b28d0c8 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -1829,6 +1829,7 @@
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 @@
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;
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 367c9f5..8ce3ce0 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -108,6 +108,18 @@
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()) {