diff options
author | Yaxun Liu <Yaxun.Liu@amd.com> | 2017-05-18 18:51:09 +0000 |
---|---|---|
committer | Yaxun Liu <Yaxun.Liu@amd.com> | 2017-05-18 18:51:09 +0000 |
commit | 3022dac388832e0bb669821e6677abd5cb8a8784 (patch) | |
tree | 56b8e786a48b3a0f55d90117a0e7aeea60860e48 /test/CodeGenCXX | |
parent | b7f27dbfdd43a5f42cc6f263eb50c22677eb4cb6 (diff) |
CodeGen: Cast alloca to expected address space
Alloca always returns a pointer in alloca address space, which may
be different from the type defined by the language. For example,
in C++ the auto variables are in the default address space. Therefore
cast alloca to the expected address space when necessary.
Differential Revision: https://reviews.llvm.org/D32248
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303370 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX')
-rw-r--r-- | test/CodeGenCXX/amdgcn-automatic-variable.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/CodeGenCXX/amdgcn-automatic-variable.cpp b/test/CodeGenCXX/amdgcn-automatic-variable.cpp new file mode 100644 index 0000000000..aab720770d --- /dev/null +++ b/test/CodeGenCXX/amdgcn-automatic-variable.cpp @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -O0 -triple amdgcn---amdgiz -emit-llvm %s -o - | FileCheck %s + +// CHECK-LABEL: define void @_Z5func1Pi(i32* %x) +void func1(int *x) { + // CHECK: %[[x_addr:.*]] = alloca i32*{{.*}}addrspace(5) + // CHECK: store i32* %x, i32* addrspace(5)* %[[x_addr]] + // CHECK: %[[r0:.*]] = load i32*, i32* addrspace(5)* %[[x_addr]] + // CHECK: store i32 1, i32* %[[r0]] + *x = 1; +} + +// CHECK-LABEL: define void @_Z5func2v() +void func2(void) { + // CHECK: %lv1 = alloca i32, align 4, addrspace(5) + // CHECK: %lv2 = alloca i32, align 4, addrspace(5) + // CHECK: %la = alloca [100 x i32], align 4, addrspace(5) + // CHECK: %lp1 = alloca i32*, align 4, addrspace(5) + // CHECK: %lp2 = alloca i32*, align 4, addrspace(5) + // CHECK: %lvc = alloca i32, align 4, addrspace(5) + + // CHECK: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32* + // CHECK: store i32 1, i32* %[[r0]] + int lv1; + lv1 = 1; + // CHECK: %[[r1:.*]] = addrspacecast i32 addrspace(5)* %lv2 to i32* + // CHECK: store i32 2, i32* %[[r1]] + int lv2 = 2; + + // CHECK: %[[r2:.*]] = addrspacecast [100 x i32] addrspace(5)* %la to [100 x i32]* + // CHECK: %[[arrayidx:.*]] = getelementptr inbounds [100 x i32], [100 x i32]* %[[r2]], i64 0, i64 0 + // CHECK: store i32 3, i32* %[[arrayidx]], align 4 + int la[100]; + la[0] = 3; + + // CHECK: %[[r3:.*]] = addrspacecast i32* addrspace(5)* %lp1 to i32** + // CHECK: store i32* %[[r0]], i32** %[[r3]], align 4 + int *lp1 = &lv1; + + // CHECK: %[[r4:.*]] = addrspacecast i32* addrspace(5)* %lp2 to i32** + // CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x i32]* %[[r2]], i32 0, i32 0 + // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 4 + int *lp2 = la; + + // CHECK: call void @_Z5func1Pi(i32* %[[r0]]) + func1(&lv1); + + // CHECK: %[[r5:.*]] = addrspacecast i32 addrspace(5)* %lvc to i32* + // CHECK: store i32 4, i32* %[[r5]] + // CHECK: store i32 4, i32* %[[r0]] + const int lvc = 4; + lv1 = lvc; +} + +void destroy(int x); + +class A { +int x; +public: + A():x(0) {} + ~A() { + destroy(x); + } +}; + +// CHECK-LABEL: define void @_Z5func3v +void func3() { + // CHECK: %[[a:.*]] = alloca %class.A, align 4, addrspace(5) + // CHECK: %[[r0:.*]] = addrspacecast %class.A addrspace(5)* %[[a]] to %class.A* + // CHECK: call void @_ZN1AC1Ev(%class.A* %[[r0]]) + // CHECK: call void @_ZN1AD1Ev(%class.A* %[[r0]]) + A a; +} |