Index: include/clang-c/Index.h =================================================================== --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -3012,8 +3012,9 @@ CXType_ObjCSel = 29, CXType_Float128 = 30, CXType_Half = 31, + CXType_Float16 = 32, CXType_FirstBuiltin = CXType_Void, - CXType_LastBuiltin = CXType_Half, + CXType_LastBuiltin = CXType_Float16, CXType_Complex = 100, CXType_Pointer = 101, Index: include/clang/AST/ASTContext.h =================================================================== --- include/clang/AST/ASTContext.h +++ include/clang/AST/ASTContext.h @@ -973,6 +973,7 @@ CanQualType UnsignedLongLongTy, UnsignedInt128Ty; CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty; CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON + CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; CanQualType Float128ComplexTy; CanQualType VoidPtrTy, NullPtrTy; Index: include/clang/AST/BuiltinTypes.def =================================================================== --- include/clang/AST/BuiltinTypes.def +++ include/clang/AST/BuiltinTypes.def @@ -133,6 +133,9 @@ // 'long double' FLOATING_TYPE(LongDouble, LongDoubleTy) +// '_Float16' +FLOATING_TYPE(Float16, HalfTy) + // '__float128' FLOATING_TYPE(Float128, Float128Ty) Index: include/clang/Basic/Specifiers.h =================================================================== --- include/clang/Basic/Specifiers.h +++ include/clang/Basic/Specifiers.h @@ -52,6 +52,7 @@ TST_int, TST_int128, TST_half, // OpenCL half, ARM NEON __fp16 + TST_Float16, // C11 extension ISO/IEC TS 18661-3 TST_float, TST_double, TST_float128, Index: include/clang/Basic/TokenKinds.def =================================================================== --- include/clang/Basic/TokenKinds.def +++ include/clang/Basic/TokenKinds.def @@ -375,6 +375,9 @@ MODULES_KEYWORD(module) MODULES_KEYWORD(import) +// C11 Extension +KEYWORD(_Float16 , KEYALL) + // GNU Extensions (in impl-reserved namespace) KEYWORD(_Decimal32 , KEYALL) KEYWORD(_Decimal64 , KEYALL) Index: include/clang/Sema/DeclSpec.h =================================================================== --- include/clang/Sema/DeclSpec.h +++ include/clang/Sema/DeclSpec.h @@ -280,6 +280,7 @@ static const TST TST_half = clang::TST_half; static const TST TST_float = clang::TST_float; static const TST TST_double = clang::TST_double; + static const TST TST_float16 = clang::TST_Float16; static const TST TST_float128 = clang::TST_float128; static const TST TST_bool = clang::TST_bool; static const TST TST_decimal32 = clang::TST_decimal32; Index: include/clang/Serialization/ASTBitCodes.h =================================================================== --- include/clang/Serialization/ASTBitCodes.h +++ include/clang/Serialization/ASTBitCodes.h @@ -823,6 +823,8 @@ PREDEF_TYPE_OMP_ARRAY_SECTION = 42, /// \brief The '__float128' type PREDEF_TYPE_FLOAT128_ID = 43, + /// \brief The '_Float16' type + PREDEF_TYPE_FLOAT16_ID = 44, /// \brief OpenCL image types with auto numeration #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ PREDEF_TYPE_##Id##_ID, Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1093,6 +1093,9 @@ // GNU extension, __float128 for IEEE quadruple precision InitBuiltinType(Float128Ty, BuiltinType::Float128); + // C11 extension ISO/IEC TS 18661-3 + InitBuiltinType(Float16Ty, BuiltinType::Float16); + // GNU extension, 128-bit integers. InitBuiltinType(Int128Ty, BuiltinType::Int128); InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128); @@ -1413,7 +1416,9 @@ assert(BT && "Not a floating point type!"); switch (BT->getKind()) { default: llvm_unreachable("Not a floating point type!"); - case BuiltinType::Half: return Target->getHalfFormat(); + case BuiltinType::Float16: + case BuiltinType::Half: + return Target->getHalfFormat(); case BuiltinType::Float: return Target->getFloatFormat(); case BuiltinType::Double: return Target->getDoubleFormat(); case BuiltinType::LongDouble: return Target->getLongDoubleFormat(); @@ -1740,6 +1745,7 @@ Width = 128; Align = 128; // int128_t is 128-bit aligned on all targets. break; + case BuiltinType::Float16: case BuiltinType::Half: Width = Target->getHalfWidth(); Align = Target->getHalfAlign(); @@ -5046,7 +5052,9 @@ assert(T->getAs() && "getFloatingRank(): not a floating type"); switch (T->getAs()->getKind()) { default: llvm_unreachable("getFloatingRank(): not a floating type"); - case BuiltinType::Half: return HalfRank; + case BuiltinType::Float16: + case BuiltinType::Half: + return HalfRank; case BuiltinType::Float: return FloatRank; case BuiltinType::Double: return DoubleRank; case BuiltinType::LongDouble: return LongDoubleRank; @@ -5930,6 +5938,7 @@ case BuiltinType::LongDouble: return 'D'; case BuiltinType::NullPtr: return '*'; // like char* + case BuiltinType::Float16: case BuiltinType::Float128: case BuiltinType::Half: // FIXME: potentially need @encodes for these! Index: lib/AST/ItaniumMangle.cpp =================================================================== --- lib/AST/ItaniumMangle.cpp +++ lib/AST/ItaniumMangle.cpp @@ -2444,6 +2444,7 @@ case BuiltinType::Int128: Out << 'n'; break; + case BuiltinType::Float16: case BuiltinType::Half: Out << "Dh"; break; Index: lib/AST/MicrosoftMangle.cpp =================================================================== --- lib/AST/MicrosoftMangle.cpp +++ lib/AST/MicrosoftMangle.cpp @@ -1809,6 +1809,7 @@ Out << "$$T"; break; + case BuiltinType::Float16: case BuiltinType::Float128: case BuiltinType::Half: { DiagnosticsEngine &Diags = Context.getDiags(); Index: lib/AST/NSAPI.cpp =================================================================== --- lib/AST/NSAPI.cpp +++ lib/AST/NSAPI.cpp @@ -441,6 +441,7 @@ case BuiltinType::Int128: case BuiltinType::LongDouble: case BuiltinType::UInt128: + case BuiltinType::Float16: case BuiltinType::Float128: case BuiltinType::NullPtr: case BuiltinType::ObjCClass: Index: lib/AST/Type.cpp =================================================================== --- lib/AST/Type.cpp +++ lib/AST/Type.cpp @@ -2557,6 +2557,8 @@ return "double"; case LongDouble: return "long double"; + case Float16: + return "_Float16"; case Float128: return "__float128"; case WChar_S: Index: lib/AST/TypeLoc.cpp =================================================================== --- lib/AST/TypeLoc.cpp +++ lib/AST/TypeLoc.cpp @@ -319,6 +319,7 @@ case BuiltinType::Float: case BuiltinType::Double: case BuiltinType::LongDouble: + case BuiltinType::Float16: case BuiltinType::Float128: llvm_unreachable("Builtin type needs extra local data!"); // Fall through, if the impossible happens. Index: lib/Analysis/PrintfFormatString.cpp =================================================================== --- lib/Analysis/PrintfFormatString.cpp +++ lib/Analysis/PrintfFormatString.cpp @@ -654,6 +654,7 @@ case BuiltinType::UInt128: case BuiltinType::Int128: case BuiltinType::Half: + case BuiltinType::Float16: case BuiltinType::Float128: // Various types which are non-trivial to correct. return false; Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -645,6 +645,7 @@ case BuiltinType::Half: case BuiltinType::Float: case BuiltinType::LongDouble: + case BuiltinType::Float16: case BuiltinType::Float128: case BuiltinType::Double: // FIXME: For targets where long double and __float128 have the same size, Index: lib/CodeGen/CodeGenTypes.cpp =================================================================== --- lib/CodeGen/CodeGenTypes.cpp +++ lib/CodeGen/CodeGenTypes.cpp @@ -439,6 +439,7 @@ static_cast(Context.getTypeSize(T))); break; + case BuiltinType::Float16: case BuiltinType::Half: // Half FP can either be storage-only (lowered to i16) or native. ResultType = Index: lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- lib/CodeGen/ItaniumCXXABI.cpp +++ lib/CodeGen/ItaniumCXXABI.cpp @@ -2629,6 +2629,7 @@ case BuiltinType::Float: case BuiltinType::Double: case BuiltinType::LongDouble: + case BuiltinType::Float16: case BuiltinType::Float128: case BuiltinType::Char16: case BuiltinType::Char32: Index: lib/Format/FormatToken.cpp =================================================================== --- lib/Format/FormatToken.cpp +++ lib/Format/FormatToken.cpp @@ -52,6 +52,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_wchar_t: case tok::kw_bool: Index: lib/Index/USRGeneration.cpp =================================================================== --- lib/Index/USRGeneration.cpp +++ lib/Index/USRGeneration.cpp @@ -676,6 +676,7 @@ c = 'K'; break; case BuiltinType::Int128: c = 'J'; break; + case BuiltinType::Float16: case BuiltinType::Half: c = 'h'; break; case BuiltinType::Float: Index: lib/Lex/LiteralSupport.cpp =================================================================== --- lib/Lex/LiteralSupport.cpp +++ lib/Lex/LiteralSupport.cpp @@ -583,6 +583,13 @@ if (isHalf || isFloat || isLong || isFloat128) break; // HF, FF, LF, QF invalid. isFloat = true; + + if (s+1 < ThisTokEnd && s[1] == '1') { + if(s+2 < ThisTokEnd && s[2] == '6') { + s += 2; // success, eat up 2 tokens. + } else + break; // only accept 'f16' + } continue; // Success. case 'q': // FP Suffix for "__float128" case 'Q': Index: lib/Parse/ParseDecl.cpp =================================================================== --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -3492,6 +3492,10 @@ isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID, Policy); break; + case tok::kw__Float16: + isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec, + DiagID, Policy); + break; case tok::kw___float128: isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, DiagID, Policy); @@ -4487,6 +4491,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_bool: case tok::kw__Bool: @@ -4562,6 +4567,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_bool: case tok::kw__Bool: @@ -4718,6 +4724,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_bool: case tok::kw__Bool: Index: lib/Parse/ParseExpr.cpp =================================================================== --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -1188,6 +1188,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_void: case tok::kw_typename: Index: lib/Parse/ParseExprCXX.cpp =================================================================== --- lib/Parse/ParseExprCXX.cpp +++ lib/Parse/ParseExprCXX.cpp @@ -1925,6 +1925,9 @@ case tok::kw_double: DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID, Policy); break; + case tok::kw__Float16: + DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec, DiagID, Policy); + break; case tok::kw___float128: DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, DiagID, Policy); break; Index: lib/Parse/ParseTentative.cpp =================================================================== --- lib/Parse/ParseTentative.cpp +++ lib/Parse/ParseTentative.cpp @@ -1022,6 +1022,7 @@ case tok::kw_char: case tok::kw_const: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_enum: case tok::kw_half: @@ -1504,6 +1505,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_void: case tok::annot_decltype: @@ -1594,6 +1596,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_void: case tok::kw___unknown_anytype: Index: lib/Sema/DeclSpec.cpp =================================================================== --- lib/Sema/DeclSpec.cpp +++ lib/Sema/DeclSpec.cpp @@ -336,6 +336,7 @@ case TST_decimal32: case TST_decimal64: case TST_double: + case TST_Float16: case TST_float128: case TST_enum: case TST_error: @@ -505,6 +506,7 @@ case DeclSpec::TST_half: return "half"; case DeclSpec::TST_float: return "float"; case DeclSpec::TST_double: return "double"; + case DeclSpec::TST_float16: return "_Float16"; case DeclSpec::TST_float128: return "__float128"; case DeclSpec::TST_bool: return Policy.Bool ? "bool" : "_Bool"; case DeclSpec::TST_decimal32: return "_Decimal32"; Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -108,6 +108,7 @@ case tok::kw_half: case tok::kw_float: case tok::kw_double: + case tok::kw__Float16: case tok::kw___float128: case tok::kw_wchar_t: case tok::kw_bool: Index: lib/Sema/SemaTemplateVariadic.cpp =================================================================== --- lib/Sema/SemaTemplateVariadic.cpp +++ lib/Sema/SemaTemplateVariadic.cpp @@ -725,6 +725,7 @@ case TST_half: case TST_float: case TST_double: + case TST_Float16: case TST_float128: case TST_bool: case TST_decimal32: Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1394,8 +1394,9 @@ else Result = Context.Int128Ty; break; - case DeclSpec::TST_half: Result = Context.HalfTy; break; - case DeclSpec::TST_float: Result = Context.FloatTy; break; + case DeclSpec::TST_float16: Result = Context.Float16Ty; break; + case DeclSpec::TST_half: Result = Context.HalfTy; break; + case DeclSpec::TST_float: Result = Context.FloatTy; break; case DeclSpec::TST_double: if (DS.getTypeSpecWidth() == DeclSpec::TSW_long) Result = Context.LongDoubleTy; Index: lib/Serialization/ASTCommon.cpp =================================================================== --- lib/Serialization/ASTCommon.cpp +++ lib/Serialization/ASTCommon.cpp @@ -91,6 +91,9 @@ case BuiltinType::LongDouble: ID = PREDEF_TYPE_LONGDOUBLE_ID; break; + case BuiltinType::Float16: + ID = PREDEF_TYPE_FLOAT16_ID; + break; case BuiltinType::Float128: ID = PREDEF_TYPE_FLOAT128_ID; break; Index: lib/Serialization/ASTReader.cpp =================================================================== --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -6568,6 +6568,9 @@ case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; + case PREDEF_TYPE_FLOAT16_ID: + T = Context.Float16Ty; + break; case PREDEF_TYPE_FLOAT128_ID: T = Context.Float128Ty; break; Index: test/CodeGenCXX/float16-declarations-error.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/float16-declarations-error.cpp @@ -0,0 +1,11 @@ +// RUN: not %clang -S -emit-llvm --target=aarch64 %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR + +_Float16 a0 = 1.f166; +_Float16 a1 = 1.f1; + +//CHECK-ERROR: error: invalid suffix 'f166' on floating constant +//CHECK-ERROR-NEXT: _Float16 a0 = 1.f166; +//CHECK-ERROR-NEXT: ^ +//CHECK-ERROR-NEXT: error: invalid suffix 'f1' on floating constant +//CHECK-ERROR-NEXT: _Float16 a1 = 1.f1; +//CHECK-ERROR-NEXT: ^ Index: test/CodeGenCXX/float16-declarations.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/float16-declarations.cpp @@ -0,0 +1,90 @@ +// RUN: %clang -S -emit-llvm --target=aarch64 %s -o - | FileCheck %s +// +/* Various contexts where type _Float16 can appear. The different check + prefixes are due to different mangling on X86 and different calling + convention on SystemZ. */ + +/* Namespace */ +namespace { + _Float16 f1n; + _Float16 f2n = 33.f16; + _Float16 arr1n[10]; + _Float16 arr2n[] = { 1.2, 3.0, 3.e4 }; + const volatile _Float16 func1n(const _Float16 &arg) { + return arg + f2n + arr1n[4] - arr2n[1]; + } +} + +/* File */ +_Float16 f1f; +_Float16 f2f = 32.4; +static _Float16 f3f = f2f; +_Float16 arr1f[10]; +_Float16 arr2f[] = { -1.2, -3.0, -3.e4 }; +_Float16 func1f(_Float16 arg); + +/* Class */ +class C1 { + _Float16 f1c; + static const _Float16 f2c; + volatile _Float16 f3c; +public: + C1(_Float16 arg) : f1c(arg), f3c(arg) { } + _Float16 func1c(_Float16 arg ) { + return f1c + arg; + } + static _Float16 func2c(_Float16 arg) { + return arg * C1::f2c; + } +}; + +/* Template */ +template C func1t(C arg) { return arg * 2.f16; } +template struct S1 { + C mem1; +}; +template <> struct S1<_Float16> { + _Float16 mem2; +}; + +/* Local */ +int main(void) { + _Float16 f1l = 123e220q; + _Float16 f2l = -0.f16; + _Float16 f3l = 1.000976562; + C1 c1(f1l); + S1<_Float16> s1 = { 132.f16 }; + _Float16 f4l = func1n(f1l) + func1f(f2l) + c1.func1c(f3l) + c1.func2c(f1l) + + func1t(f1l) + s1.mem2 - f1n + f2n; +#if (__cplusplus >= 201103L) + auto f5l = -1.f16, *f6l = &f2l, f7l = func1t(f3l); +#endif + _Float16 f8l = f4l++; + _Float16 arr1l[] = { -1.f16, -0.f16, -11.f16 }; +} + + +// CHECK-DAG: @f1f = global half 0xH0000, align 2 +// CHECK-DAG: @f2f = global half 0xH500D, align 2 +// CHECK-DAG: @arr1f = global [10 x half] zeroinitializer, align 2 +// CHECK-DAG: @arr2f = global [3 x half] [half 0xHBCCD, half 0xHC200, half 0xHF753], align 2 +// CHECK-DAG: @_ZZ4mainE2s1 = private unnamed_addr constant %struct.S1 { half 0xH5820 }, align 2 +// CHECK-DAG: @_ZN12_GLOBAL__N_13f1nE = internal global half 0xH0000, align 2 +// CHECK-DAG: @_ZN12_GLOBAL__N_13f2nE = internal global half 0xH5020, align 2 +// CHECK-DAG: @_ZZ4mainE5arr1l = private unnamed_addr constant [3 x half] [half 0xHBC00, half 0xH8000, half 0xHC980], align 2 +// CHECK-DAG: @_ZN12_GLOBAL__N_15arr1nE = internal global [10 x half] zeroinitializer, align 2 +// CHECK-DAG: @_ZN12_GLOBAL__N_15arr2nE = internal global [3 x half] [half 0xH3CCD, half 0xH4200, half 0xH7753], align 2 +// CHECK-DAG: @_ZN2C13f2cE = external constant half, align 2 + +// CHECK-DAG: define linkonce_odr void @_ZN2C1C2EDh(%class.C1* %this, half %arg) +// CHECK-DAG: define linkonce_odr half @_ZN2C16func1cEDh(%class.C1* %this, half %arg) +// CHECK-DAG: define linkonce_odr half @_ZN2C16func2cEDh(half %arg) +// CHECK-DAG: define linkonce_odr half @_Z6func1tIDhET_S0_(half %arg) + +// CHECK-DAG: store half 0xH7C00, half* %f1l, align 2 +// CHECK-DAG: store half 0xH8000, half* %f2l, align 2 +// CHECK-DAG: store half 0xH3C01, half* %f3l, align 2 + +// CHECK-DAG: [[F4L:%[a-z0-9]+]] = load half, half* %f4l, align 2 +// CHECK-DAG: [[INC:%[a-z0-9]+]] = fadd half [[F4L]], 0xH3C00 +// CHECK-DAG: store half [[INC]], half* %f4l, align 2 Index: tools/libclang/CXType.cpp =================================================================== --- tools/libclang/CXType.cpp +++ tools/libclang/CXType.cpp @@ -52,6 +52,7 @@ BTCASE(Float); BTCASE(Double); BTCASE(LongDouble); + BTCASE(Float16); BTCASE(Float128); BTCASE(NullPtr); BTCASE(Overload); @@ -490,7 +491,7 @@ TKIND(Char_U); TKIND(UChar); TKIND(Char16); - TKIND(Char32); + TKIND(Char32); TKIND(UShort); TKIND(UInt); TKIND(ULong); @@ -508,6 +509,7 @@ TKIND(Float); TKIND(Double); TKIND(LongDouble); + TKIND(Float16); TKIND(Float128); TKIND(NullPtr); TKIND(Overload);