diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0d5f696bf0406..4eacc05f85e69 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -10325,7 +10325,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, return NewFD; } - if (getLangOpts().OpenCL) { + if (getLangOpts().OpenCL || getLangOpts().HLSL) { + // Neither OpenCL nor HLSL allow an address space qualifyer on a return + // type. + // // OpenCL v1.1 s6.5: Using an address space qualifier in a function return // type declaration will generate a compilation error. LangAS AddressSpace = NewFD->getReturnType().getAddressSpace(); @@ -10360,13 +10363,6 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } } } - // HLSL does not support specifying an address space on a function return - // type. - LangAS AddressSpace = NewFD->getReturnType().getAddressSpace(); - if (AddressSpace != LangAS::Default) { - Diag(NewFD->getLocation(), diag::err_return_value_with_address_space); - NewFD->setInvalidDecl(); - } } if (!getLangOpts().CPlusPlus) {