diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Basic/IdentifierTable.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/Sema/Sema.cpp | 23 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 27 |
3 files changed, 60 insertions, 5 deletions
diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index db148f493f4..bd2840db4c7 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -106,9 +106,11 @@ namespace { KEYC11 = 0x400, KEYARC = 0x800, KEYNOMS18 = 0x01000, - WCHARSUPPORT = 0x02000, - HALFSUPPORT = 0x04000, - KEYALL = (0xffff & ~KEYNOMS18) // Because KEYNOMS18 is used to exclude. + KEYNOOPENCL = 0x02000, + WCHARSUPPORT = 0x04000, + HALFSUPPORT = 0x08000, + KEYALL = (0xffff & ~KEYNOMS18 & + ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude. }; /// \brief How a keyword is treated in the selected standard. @@ -156,7 +158,12 @@ static void AddKeyword(StringRef Keyword, // Don't add this keyword under MSVCCompat. if (LangOpts.MSVCCompat && (Flags & KEYNOMS18) && !LangOpts.isCompatibleWithMSVC(19)) - return; + return; + + // Don't add this keyword under OpenCL. + if (LangOpts.OpenCL && (Flags & KEYNOOPENCL)) + return; + // Don't add this keyword if disabled in this language. if (AddResult == KS_Disabled) return; diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index a851ce14556..a1a9b9d0b8c 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -212,6 +212,29 @@ void Sema::Initialize() { addImplicitTypedef("image3d_t", Context.OCLImage3dTy); addImplicitTypedef("sampler_t", Context.OCLSamplerTy); addImplicitTypedef("event_t", Context.OCLEventTy); + if (getLangOpts().OpenCLVersion >= 200) { + addImplicitTypedef("atomic_int", Context.getAtomicType(Context.IntTy)); + addImplicitTypedef("atomic_uint", + Context.getAtomicType(Context.UnsignedIntTy)); + addImplicitTypedef("atomic_long", Context.getAtomicType(Context.LongTy)); + addImplicitTypedef("atomic_ulong", + Context.getAtomicType(Context.UnsignedLongTy)); + addImplicitTypedef("atomic_float", + Context.getAtomicType(Context.FloatTy)); + addImplicitTypedef("atomic_double", + Context.getAtomicType(Context.DoubleTy)); + // OpenCLC v2.0, s6.13.11.6 requires that atomic_flag is implemented as + // 32-bit integer and OpenCLC v2.0, s6.1.1 int is always 32-bit wide. + addImplicitTypedef("atomic_flag", Context.getAtomicType(Context.IntTy)); + addImplicitTypedef("atomic_intptr_t", + Context.getAtomicType(Context.getIntPtrType())); + addImplicitTypedef("atomic_uintptr_t", + Context.getAtomicType(Context.getUIntPtrType())); + addImplicitTypedef("atomic_size_t", + Context.getAtomicType(Context.getSizeType())); + addImplicitTypedef("atomic_ptrdiff_t", + Context.getAtomicType(Context.getPointerDiffType())); + } } DeclarationName BuiltinVaList = &Context.Idents.get("__builtin_va_list"); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 56142253a08..669cb9a9772 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -871,7 +871,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { if (S.getLangOpts().OpenCL && !((S.getLangOpts().OpenCLVersion >= 120) || S.getOpenCLOptions().cl_khr_fp64)) { - S.Diag(DS.getTypeSpecTypeLoc(), diag::err_double_requires_fp64); + S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) + << Result << "cl_khr_fp64"; declarator.setInvalidType(true); } break; @@ -947,6 +948,30 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { << DS.getSourceRange(); declarator.setInvalidType(true); } + } else if (S.getLangOpts().OpenCL) { + if (const AtomicType *AT = Result->getAs<AtomicType>()) { + const BuiltinType *BT = AT->getValueType()->getAs<BuiltinType>(); + bool NoExtTypes = BT && (BT->getKind() == BuiltinType::Int || + BT->getKind() == BuiltinType::UInt || + BT->getKind() == BuiltinType::Float); + if (!S.getOpenCLOptions().cl_khr_int64_base_atomics && !NoExtTypes) { + S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) + << Result << "cl_khr_int64_base_atomics"; + declarator.setInvalidType(true); + } + if (!S.getOpenCLOptions().cl_khr_int64_extended_atomics && + !NoExtTypes) { + S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) + << Result << "cl_khr_int64_extended_atomics"; + declarator.setInvalidType(true); + } + if (!S.getOpenCLOptions().cl_khr_fp64 && BT && + BT->getKind() == BuiltinType::Double) { + S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) + << Result << "cl_khr_fp64"; + declarator.setInvalidType(true); + } + } } // TypeQuals handled by caller. |

