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/AST/Type.h =================================================================== --- include/clang/AST/Type.h +++ include/clang/AST/Type.h @@ -1666,6 +1666,7 @@ bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half) + bool isFloat16Type() const; // FIXME bool isRealType() const; // C99 6.2.5p17 (real floating + integer) bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) bool isVoidType() const; // C99 6.2.5p19 @@ -5898,6 +5899,12 @@ return false; } +inline bool Type::isFloat16Type() const { + if (const BuiltinType *BT = dyn_cast(CanonicalType)) + return BT->getKind() == BuiltinType::Float16; + return false; +} + inline bool Type::isNullPtrType() const { if (const BuiltinType *BT = getAs()) return BT->getKind() == BuiltinType::NullPtr; 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/Lex/LiteralSupport.h =================================================================== --- include/clang/Lex/LiteralSupport.h +++ include/clang/Lex/LiteralSupport.h @@ -65,6 +65,7 @@ bool isHalf : 1; // 1.0h bool isFloat : 1; // 1.0f bool isImaginary : 1; // 1.0i + bool isFloat16 : 1; // 1.0f16 bool isFloat128 : 1; // 1.0q uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64. 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/StmtPrinter.cpp =================================================================== --- lib/AST/StmtPrinter.cpp +++ lib/AST/StmtPrinter.cpp @@ -1431,6 +1431,7 @@ // Emit suffixes. Float literals are always a builtin float type. switch (Node->getType()->getAs()->getKind()) { default: llvm_unreachable("Unexpected type for float literal!"); + case BuiltinType::Float16: case BuiltinType::Half: break; // FIXME: suffix? case BuiltinType::Double: break; // no suffix. case BuiltinType::Float: OS << 'F'; break; 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/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -1698,7 +1698,7 @@ } case CK_IntToOCLSampler: - return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF); + return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF); } // end of switch @@ -1929,7 +1929,9 @@ FS = &CGF.getTarget().getFloat128Format(); else if (value->getType()->isHalfTy()) FS = &CGF.getTarget().getHalfFormat(); - else + else if (value->getType()->isFloat16Ty()) { + FS = &CGF.getTarget().getHalfFormat(); //FIXME? + } else FS = &CGF.getTarget().getLongDoubleFormat(); F.convert(*FS, llvm::APFloat::rmTowardZero, &ignored); amt = llvm::ConstantFP::get(VMContext, F); Index: lib/CodeGen/CodeGenTypes.cpp =================================================================== --- lib/CodeGen/CodeGenTypes.cpp +++ lib/CodeGen/CodeGenTypes.cpp @@ -439,6 +439,12 @@ static_cast(Context.getTypeSize(T))); break; + case BuiltinType::Float16: + ResultType = + getTypeForFormat(getLLVMContext(), Context.getFloatTypeSemantics(T), + true); + break; + 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 @@ -537,6 +537,7 @@ isHalf = false; isFloat = false; isImaginary = false; + isFloat16 = false; isFloat128 = false; MicrosoftInteger = 0; hadError = false; @@ -582,6 +583,13 @@ if (!isFPConstant) break; // Error for integer constant. if (isHalf || isFloat || isLong || isFloat128) break; // HF, FF, LF, QF invalid. + + if (s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') { + s += 2; // success, eat up 2 tokens. + isFloat16 = true; + continue; + } + isFloat = true; continue; // Success. case 'q': // FP Suffix for "__float128" @@ -677,6 +685,7 @@ isUnsigned = false; isLongLong = false; isFloat = false; + isFloat16 = false; isHalf = false; isImaginary = false; MicrosoftInteger = 0; 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/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -3419,6 +3419,8 @@ Ty = Context.FloatTy; else if (Literal.isLong) Ty = Context.LongDoubleTy; + else if (Literal.isFloat16) + Ty = Context.Float16Ty; else if (Literal.isFloat128) Ty = Context.Float128Ty; else 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.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/float16-declarations.cpp @@ -0,0 +1,132 @@ +// RUN: %clang -std=c++11 --target=aarch64-arm--eabi -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH64 +// RUN: %clang -std=c++11 --target=x86_64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X86 + +/* Various contexts where type _Float16 can appear. */ + + +/* Namespace */ + +namespace { + _Float16 f1n; +// CHECK-DAG: @_ZN12_GLOBAL__N_13f1nE = internal global half 0xH0000, align 2 + + _Float16 f2n = 33.f16; +// CHECK-AARCH64-DAG: @_ZN12_GLOBAL__N_13f2nE = internal global half 0xH5020, align 2 +// CHECK-X86-DAG: @_ZN12_GLOBAL__N_13f2nE = internal global i16 20512, align 2 + + _Float16 arr1n[10]; +// CHECK-AARCH64-DAG: @_ZN12_GLOBAL__N_15arr1nE = internal global [10 x half] zeroinitializer, align 2 +// CHECK-X86-DAG: @_ZN12_GLOBAL__N_15arr1nE = internal global [10 x half] zeroinitializer, align 16 + + _Float16 arr2n[] = { 1.2, 3.0, 3.e4 }; +// CHECK-AARCH64-DAG: @_ZN12_GLOBAL__N_15arr2nE = internal global [3 x half] [half 0xH3CCD, half 0xH4200, half 0xH7753], align 2 +// CHECK-X86-DAG: @_ZN12_GLOBAL__N_15arr2nE = internal global [3 x i16] [i16 15565, i16 16896, i16 30547], align 2 + + const volatile _Float16 func1n(const _Float16 &arg) { + return arg + f2n + arr1n[4] - arr2n[1]; + } +} + + +/* File */ + +_Float16 f1f; +// CHECK-AARCH64-DAG: @f1f = global half 0xH0000, align 2 +// CHECK-X86-DAG: @f1f = global half 0xH0000, align 2 + +_Float16 f2f = 32.4; +// CHECK-AARCH64-DAG: @f2f = global half 0xH500D, align 2 +// CHECK-X86-DAG: @f2f = global i16 20493, align 2 + +_Float16 arr1f[10]; +// CHECK-AARCH64-DAG: @arr1f = global [10 x half] zeroinitializer, align 2 +// CHECK-X86-DAG: @arr1f = global [10 x half] zeroinitializer, align 16 + +_Float16 arr2f[] = { -1.2, -3.0, -3.e4 }; +// CHECK-AARCH64-DAG: @arr2f = global [3 x half] [half 0xHBCCD, half 0xHC200, half 0xHF753], align 2 +// CHECK-X86-DAG: @arr2f = global [3 x i16] [i16 -17203, i16 -15872, i16 -2221], align 2 + +_Float16 func1f(_Float16 arg); + + +/* Class */ + +class C1 { + _Float16 f1c; + + static const _Float16 f2c; +// CHECK-DAG: @_ZN2C13f2cE = external constant half, align 2 + + volatile _Float16 f3c; + +public: + C1(_Float16 arg) : f1c(arg), f3c(arg) { } +// CHECK-DAG: define linkonce_odr void @_ZN2C1C2EDh(%class.C1* %this, half %arg) + + _Float16 func1c(_Float16 arg ) { + return f1c + arg; + } +// CHECK-DAG: define linkonce_odr half @_ZN2C16func1cEDh(%class.C1* %this, half %arg) + + static _Float16 func2c(_Float16 arg) { + return arg * C1::f2c; + } +// CHECK-DAG: define linkonce_odr half @_ZN2C16func2cEDh(half %arg) +}; + +/* Template */ + +template C func1t(C arg) { + return arg * 2.f16; +} +// CHECK-DAG: define linkonce_odr half @_Z6func1tIDhET_S0_(half %arg) + +template struct S1 { + C mem1; +}; + +template <> struct S1<_Float16> { + _Float16 mem2; +}; + + +/* Local */ + +int main(void) { + _Float16 f1l = 1e3f16; +// CHECK-DAG: store half 0xH63D0, half* %f1l, align 2 + + _Float16 f2l = -0.f16; +// CHECK-DAG: store half 0xH8000, half* %f2l, align 2 + + _Float16 f3l = 1.000976562; +// CHECK-DAG: store half 0xH3C01, half* %f3l, align 2 + + C1 c1(f1l); +// CHECK-DAG: [[F1L:%[a-z0-9]+]] = load half, half* %f1l, align 2 +// CHECK-DAG: call void @_ZN2C1C2EDh(%class.C1* %c1, half [[F1L]]) + + S1<_Float16> s1 = { 132.f16 }; +// CHECK-AARCH64-DAG: @_ZZ4mainE2s1 = private unnamed_addr constant %struct.S1 { half 0xH5820 }, align 2 +// CHECK-X86-DAG: @_ZZ4mainE2s1 = private unnamed_addr constant { i16 } { i16 22560 }, align 2 +// CHECK-DAG: [[S1:%[0-9]+]] = bitcast %struct.S1* %s1 to i8* +// CHECK-AARCH64-DAG: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[S1]], i8* bitcast (%struct.S1* @_ZZ4mainE2s1 to i8*), i64 2, i32 2, i1 false) +// CHECK-X86-DAG: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* bitcast ({ i16 }* @_ZZ4mainE2s1 to i8*), i64 2, i32 2, i1 false) + + _Float16 f4l = func1n(f1l) + func1f(f2l) + c1.func1c(f3l) + c1.func2c(f1l) + + func1t(f1l) + s1.mem2 - f1n + f2n; + + auto f5l = -1.f16, *f6l = &f2l, f7l = func1t(f3l); +// CHECK-DAG: store half 0xHBC00, half* %f5l, align 2 +// CHECK-DAG: store half* %f2l, half** %f6l, align 8 + + _Float16 f8l = f4l++; +// CHECK-DAG: [[F4L:%[a-z0-9]+]] = load half, half* %f4l, align 2 +// CHECK-DAG: [[INC:%inc[0-9]*]] = fadd half [[F4L]], 0xH3C00 +// CHECK-DAG: store half [[INC]], half* %f4l, align 2 + + _Float16 arr1l[] = { -1.f16, -0.f16, -11.f16 }; +// CHECK-AARCH64-DAG: @_ZZ4mainE5arr1l = private unnamed_addr constant [3 x half] [half 0xHBC00, half 0xH8000, half 0xHC980], align 2 +// CHECK-X86-DAG: @_ZZ4mainE5arr1l = private unnamed_addr constant [3 x i16] [i16 -17408, i16 -32768, i16 -13952], align 2 + +} Index: test/Lexer/half-literal.cpp =================================================================== --- test/Lexer/half-literal.cpp +++ test/Lexer/half-literal.cpp @@ -1,3 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s float a = 1.0h; // expected-error{{invalid suffix 'h' on floating constant}} float b = 1.0H; // expected-error{{invalid suffix 'H' on floating constant}} + +_Float16 c = 1.f166; // expected-error{{invalid suffix 'f166' on floating constant}} +_Float16 d = 1.f1; // expected-error{{invalid suffix 'f1' on floating constant}} 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);