xref: /llvm-project/clang/test/CodeGenCXX/template-param-objects-address-space.cpp (revision e13cbaca6925629165e3cced90b33777f0fe09fe)
157a0416eSAlex Voicu // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -std=c++20 %s -emit-llvm -o - | FileCheck %s
2*e13cbacaSAlex Voicu // RUN: %clang_cc1 -triple spirv64-amd-amdhsa -std=c++20 %s -emit-llvm -o - | FileCheck %s --check-prefix=WITH-NONZERO-DEFAULT-AS
357a0416eSAlex Voicu 
457a0416eSAlex Voicu struct S { char buf[32]; };
557a0416eSAlex Voicu template<S s> constexpr const char *begin() { return s.buf; }
657a0416eSAlex Voicu template<S s> constexpr const char *end() { return s.buf + __builtin_strlen(s.buf); }
757a0416eSAlex Voicu template<S s> constexpr const void *retval() { return &s; }
857a0416eSAlex Voicu extern const void *callee(const S*);
957a0416eSAlex Voicu template<S s> constexpr const void* observable_addr() { return callee(&s); }
1057a0416eSAlex Voicu 
1157a0416eSAlex Voicu // CHECK: [[HELLO:@_ZTAXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EEEE]]
1210edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: [[HELLO:@_ZTAXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EEEE]]
1357a0416eSAlex Voicu // CHECK-SAME: = linkonce_odr addrspace(1) constant { <{ [11 x i8], [21 x i8] }> } { <{ [11 x i8], [21 x i8] }> <{ [11 x i8] c"hello world", [21 x i8] zeroinitializer }> }, comdat
1457a0416eSAlex Voicu 
1557a0416eSAlex Voicu // CHECK: @p
1657a0416eSAlex Voicu // CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) [[HELLO]] to ptr)
1710edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: addrspace(1) global ptr addrspace(4) addrspacecast (ptr addrspace(1) [[HELLO]] to ptr addrspace(4))
1857a0416eSAlex Voicu const char *p = begin<S{"hello world"}>();
1957a0416eSAlex Voicu 
2057a0416eSAlex Voicu // CHECK: @q
2157a0416eSAlex Voicu // CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) getelementptr (i8, ptr addrspace(1) [[HELLO]], i64 11) to ptr)
2210edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: addrspace(1) global ptr addrspace(4) addrspacecast (ptr addrspace(1) getelementptr (i8, ptr addrspace(1) [[HELLO]], i64 11) to ptr addrspace(4))
2357a0416eSAlex Voicu const char *q = end<S{"hello world"}>();
2457a0416eSAlex Voicu 
2557a0416eSAlex Voicu const void *(*r)() = &retval<S{"hello world"}>;
2657a0416eSAlex Voicu 
2757a0416eSAlex Voicu // CHECK: @s
2857a0416eSAlex Voicu // CHECK-SAME: addrspace(1) global ptr null
2910edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: addrspace(1) global ptr addrspace(4) null
3057a0416eSAlex Voicu const void *s = observable_addr<S{"hello world"}>();
3157a0416eSAlex Voicu 
3257a0416eSAlex Voicu // CHECK: define linkonce_odr noundef ptr @_Z6retvalIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EEEEEPKvv()
3310edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: define linkonce_odr {{.*}} noundef ptr addrspace(4) @_Z6retvalIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EEEEEPKvv()
3457a0416eSAlex Voicu // CHECK: ret ptr addrspacecast (ptr addrspace(1) [[HELLO]] to ptr)
3510edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: ret ptr addrspace(4) addrspacecast (ptr addrspace(1) [[HELLO]] to ptr addrspace(4))
3657a0416eSAlex Voicu 
3757a0416eSAlex Voicu // CHECK: define linkonce_odr noundef ptr @_Z15observable_addrIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EEEEEPKvv()
3810edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: define linkonce_odr {{.*}} noundef ptr addrspace(4) @_Z15observable_addrIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EEEEEPKvv()
3957a0416eSAlex Voicu // CHECK: %call = call noundef ptr @_Z6calleePK1S(ptr noundef addrspacecast (ptr addrspace(1) [[HELLO]] to ptr))
40*e13cbacaSAlex Voicu // WITH-NONZERO-DEFAULT-AS: %call = call {{.*}} noundef{{.*}} ptr addrspace(4) @_Z6calleePK1S(ptr addrspace(4) noundef addrspacecast (ptr addrspace(1) [[HELLO]] to ptr addrspace(4)))
4157a0416eSAlex Voicu // CHECK: declare noundef ptr @_Z6calleePK1S(ptr noundef)
4210edb499SAlex Voicu // WITH-NONZERO-DEFAULT-AS: declare {{.*}} noundef ptr addrspace(4) @_Z6calleePK1S(ptr addrspace(4) noundef)
43