Author: Joseph Huber Date: 2026-01-12T14:49:08Z New Revision: a823a2ab6d9032be7cf037ec2e1db3ec501659db
URL: https://github.com/llvm/llvm-project/commit/a823a2ab6d9032be7cf037ec2e1db3ec501659db DIFF: https://github.com/llvm/llvm-project/commit/a823a2ab6d9032be7cf037ec2e1db3ec501659db.diff LOG: [SPIR-V] Do not allow AS(2) to convert to generic (#175275) Summary: The original logic permitted this, while it's not permitted by the standard. --------- Co-authored-by: Dmitry Sidorov <[email protected]> Added: Modified: clang/lib/Basic/Targets/SPIR.h clang/test/Sema/spirv-address-space.c Removed: ################################################################################ diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h index 8030aa9e10370..ea992b0e01dbe 100644 --- a/clang/lib/Basic/Targets/SPIR.h +++ b/clang/lib/Basic/Targets/SPIR.h @@ -320,12 +320,13 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRVTargetInfo : public BaseSPIRTargetInfo { virtual bool isAddressSpaceSupersetOf(LangAS A, LangAS B) const override { // The generic space AS(4) is a superset of all the other address - // spaces used by the backend target. + // spaces used by the backend target except constant address space. return A == B || ((A == LangAS::Default || (isTargetAddressSpace(A) && toTargetAddressSpace(A) == /*Generic=*/4)) && isTargetAddressSpace(B) && - toTargetAddressSpace(B) <= /*Generic=*/4); + (toTargetAddressSpace(B) <= /*Generic=*/4 && + toTargetAddressSpace(B) != /*Constant=*/2)); } void getTargetDefines(const LangOptions &Opts, diff --git a/clang/test/Sema/spirv-address-space.c b/clang/test/Sema/spirv-address-space.c index 7ec41fd79bd96..fc212577b4841 100644 --- a/clang/test/Sema/spirv-address-space.c +++ b/clang/test/Sema/spirv-address-space.c @@ -9,7 +9,7 @@ #define _AS999 __attribute__((address_space(999))) void *p1(void _AS1 *p) { return p; } -void *p2(void _AS2 *p) { return p; } +void *p2(void _AS2 *p) { return p; } // expected-error {{returning '_AS2 void *' from a function with result type 'void *' changes address space of pointer}} void *p3(void _AS3 *p) { return p; } void *p4(void _AS4 *p) { return p; } void *p5(void _AS5 *p) { return p; } // expected-error {{returning '_AS5 void *' from a function with result type 'void *' changes address space of pointer}} @@ -18,4 +18,3 @@ void *pc(void __attribute__((opencl_local)) *p) { return p; } // expected-error void _AS1 *r0(void _AS1 *p) { return p; } void _AS1 *r1(void *p) { return p; } // expected-error {{returning 'void *' from a function with result type '_AS1 void *' changes address space of pointer}} void _AS1 *r2(void *p) { return (void _AS1 *)p; } - _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
