Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,9 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
mlir::ptr::MemorySpaceAttrInterface EAS = cir::toCIRLangAddressSpaceAttr(
&getMLIRContext(), E->getType()->getPointeeType().getAddressSpace());
if (EAS != AAS) {
assert(false && "Non-default address space for alloca NYI");
mlir::Type TY = CGM.getTypes().convertType(E->getType());
return RValue::get(getTargetHooks().performAddrSpaceCast(
*this, AllocaAddr, AAS, EAS, TY));
}

// Bitcast the alloca to the expected type.
Expand Down
31 changes: 31 additions & 0 deletions clang/test/CIR/CodeGen/dynamic-alloca-with-address-space.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR

// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=LLVM

// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG

void allocas(unsigned long n) {
char *a = (char *)__builtin_alloca(n);
char *uninitialized_a = (char *)__builtin_alloca_uninitialized(n);
}

// CIR-LABEL: cir.func {{.*}} @allocas
// CIR: %[[ALLOCA1:.*]] = cir.alloca !u8i, !cir.ptr<!u8i>, {{.*}} ["bi_alloca"]
// CIR: cir.cast bitcast %[[ALLOCA1]] : !cir.ptr<!u8i> -> !cir.ptr<!void>
// CIR: %[[ALLOCA2:.*]] = cir.alloca !u8i, !cir.ptr<!u8i>, {{.*}} ["bi_alloca"]
// CIR: cir.cast bitcast %[[ALLOCA2]] : !cir.ptr<!u8i> -> !cir.ptr<!void>

// LLVM-LABEL: define {{.*}} void @allocas(i64 %{{.*}})
// LLVM: %[[BI_ALLOCA1:.*]] = alloca i8, i64 %{{.*}}, align 8, addrspace(5)
// LLVM: addrspacecast ptr addrspace(5) %[[BI_ALLOCA1]] to ptr
// LLVM: %[[BI_ALLOCA2:.*]] = alloca i8, i64 %{{.*}}, align 8, addrspace(5)
// LLVM: addrspacecast ptr addrspace(5) %[[BI_ALLOCA2]] to ptr

// OGCG-LABEL: define {{.*}} void @allocas(i64 {{.*}} %n)
// OGCG: %[[BI_ALLOCA1:.*]] = alloca i8, i64 %{{.*}}, align 8, addrspace(5)
// OGCG: addrspacecast ptr addrspace(5) %[[BI_ALLOCA1]] to ptr
// OGCG: %[[BI_ALLOCA2:.*]] = alloca i8, i64 %{{.*}}, align 8, addrspace(5)
// OGCG: addrspacecast ptr addrspace(5) %[[BI_ALLOCA2]] to ptr