[CIR] Upstream addressof builtin (#177860)

Upstream the addressof builtin
This commit is contained in:
Amr Hesham 2026-01-26 17:47:43 +01:00 committed by GitHub
parent 21dad8e5cc
commit 4dd7535ca8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -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:

View 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