[CIR] Upstream addressof builtin (#177860)
Upstream the addressof builtin
This commit is contained in:
parent
21dad8e5cc
commit
4dd7535ca8
@ -1646,6 +1646,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
|
||||
case Builtin::BIaddressof:
|
||||
case Builtin::BI__addressof:
|
||||
case Builtin::BI__builtin_addressof:
|
||||
return RValue::get(emitLValue(e->getArg(0)).getPointer());
|
||||
case Builtin::BI__builtin_function_start:
|
||||
return errorBuiltinNYI(*this, e, builtinID);
|
||||
case Builtin::BI__builtin_operator_new:
|
||||
|
||||
28
clang/test/CIR/CodeGen/address-of.cpp
Normal file
28
clang/test/CIR/CodeGen/address-of.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
|
||||
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
|
||||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
|
||||
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
|
||||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
|
||||
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
|
||||
|
||||
struct Container {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
void builtin_address_of() {
|
||||
Container a;
|
||||
Container* b = __builtin_addressof(a);
|
||||
}
|
||||
|
||||
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_Container, !cir.ptr<!rec_Container>, ["a"]
|
||||
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Container>, !cir.ptr<!cir.ptr<!rec_Container>>, ["b", init]
|
||||
// CIR: cir.store {{.*}} %[[A_ADDR]], %[[B_ADDR]] : !cir.ptr<!rec_Container>, !cir.ptr<!cir.ptr<!rec_Container>>
|
||||
|
||||
// LLVM: %[[A_ADDR:.*]] = alloca %struct.Container, i64 1, align 4
|
||||
// LLVM: %[[B_ADDR:.*]] = alloca ptr, i64 1, align 8
|
||||
// LLVM: store ptr %[[A_ADDR]], ptr %[[B_ADDR]], align 8
|
||||
|
||||
// OGCG: %[[A_ADDR:.*]] = alloca %struct.Container, align 4
|
||||
// OGCG: %[[B_ADDR:.*]] = alloca ptr, align 8
|
||||
// OGCG: store ptr %[[A_ADDR]], ptr %[[B_ADDR]], align 8
|
||||
Loading…
x
Reference in New Issue
Block a user