Author: Joseph Huber Date: 2026-01-09T13:40:09-06:00 New Revision: ac508575ed13787e4d7ed928670c3d6144fce137
URL: https://github.com/llvm/llvm-project/commit/ac508575ed13787e4d7ed928670c3d6144fce137 DIFF: https://github.com/llvm/llvm-project/commit/ac508575ed13787e4d7ed928670c3d6144fce137.diff LOG: [SPIR-V] Permit implicit conversion to generic AS (#175109) Summary: We rely on this in most places we work with address spaces. This allows target address spaces to implicity convert to generic ones. I actually have no clue if this is valid or correct with SPIR-V, hoping someone with more target / backend knowledge can chime in. --------- Co-authored-by: Matt Arsenault <[email protected]> Added: clang/test/Sema/spirv-address-space.c Modified: clang/lib/Basic/Targets/SPIR.h Removed: ################################################################################ diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h index d5374602caeaa..8030aa9e10370 100644 --- a/clang/lib/Basic/Targets/SPIR.h +++ b/clang/lib/Basic/Targets/SPIR.h @@ -14,6 +14,7 @@ #define LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H #include "Targets.h" +#include "clang/Basic/AddressSpaces.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "llvm/Support/Compiler.h" @@ -317,6 +318,16 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRVTargetInfo : public BaseSPIRTargetInfo { return Feature == "spirv"; } + 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. + return A == B || ((A == LangAS::Default || + (isTargetAddressSpace(A) && + toTargetAddressSpace(A) == /*Generic=*/4)) && + isTargetAddressSpace(B) && + toTargetAddressSpace(B) <= /*Generic=*/4); + } + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override; }; diff --git a/clang/test/Sema/spirv-address-space.c b/clang/test/Sema/spirv-address-space.c new file mode 100644 index 0000000000000..7ec41fd79bd96 --- /dev/null +++ b/clang/test/Sema/spirv-address-space.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 %s -triple spirv64 -fsyntax-only -verify + +#define _AS0 __attribute__((address_space(0))) +#define _AS1 __attribute__((address_space(1))) +#define _AS2 __attribute__((address_space(2))) +#define _AS3 __attribute__((address_space(3))) +#define _AS4 __attribute__((address_space(4))) +#define _AS5 __attribute__((address_space(5))) +#define _AS999 __attribute__((address_space(999))) + +void *p1(void _AS1 *p) { return p; } +void *p2(void _AS2 *p) { return p; } +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}} +void *pi(void _AS999 *p) { return p; } // expected-error {{returning '_AS999 void *' from a function with result type 'void *' changes address space of pointer}} +void *pc(void __attribute__((opencl_local)) *p) { return p; } // expected-error {{returning '__local void *' from a function with result type 'void *' changes address space of pointer}} +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
