From: Anastasia Stulova Date: Wed, 30 Sep 2015 11:48:15 +0000 (+0000) Subject: [OpenCL 2.0] Fix wrong atomic type detection in the diagnostics of allowed types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3da00790946d349c0fe42a6080ae50accd8199c5;p=clang [OpenCL 2.0] Fix wrong atomic type detection in the diagnostics of allowed types git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248891 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 96c51a94eb..e4b7360b93 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -1390,11 +1390,13 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { if (Result.isNull()) { declarator.setInvalidType(true); } else if (S.getLangOpts().OpenCL) { - if (const AtomicType *AT = Result->getAs()) { - const BuiltinType *BT = AT->getValueType()->getAs(); - bool NoExtTypes = BT && (BT->getKind() == BuiltinType::Int || - BT->getKind() == BuiltinType::UInt || - BT->getKind() == BuiltinType::Float); + if (Result->getAs()) { + StringRef TypeName = Result.getBaseTypeIdentifier()->getName(); + bool NoExtTypes = + llvm::StringSwitch(TypeName) + .Cases("atomic_int", "atomic_uint", "atomic_float", + "atomic_flag", true) + .Default(false); if (!S.getOpenCLOptions().cl_khr_int64_base_atomics && !NoExtTypes) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_int64_base_atomics"; @@ -1406,8 +1408,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { << Result << "cl_khr_int64_extended_atomics"; declarator.setInvalidType(true); } - if (!S.getOpenCLOptions().cl_khr_fp64 && BT && - BT->getKind() == BuiltinType::Double) { + if (!S.getOpenCLOptions().cl_khr_fp64 && + !TypeName.compare("atomic_double")) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); diff --git a/test/Parser/opencl-atomics-cl20.cl b/test/Parser/opencl-atomics-cl20.cl index 65cc6f88aa..c62142b2aa 100644 --- a/test/Parser/opencl-atomics-cl20.cl +++ b/test/Parser/opencl-atomics-cl20.cl @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -verify -pedantic -fsyntax-only -// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -DCL20 -// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -verify -fsyntax-only -cl-std=CL2.0 -DCL20 -DEXT +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -DCL20 +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -DCL20 -DEXT #ifdef EXT #pragma OPENCL EXTENSION cl_khr_int64_base_atomics:enable