https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/177860
Upstream the addressof builtin >From 20f2206809851cc57fd9b45764dfe25dc7e14dfb Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Sun, 25 Jan 2026 16:37:06 +0100 Subject: [PATCH] [CIR] Upstream addressof builtin --- clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 1 + clang/test/CIR/CodeGen/address-of.cpp | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 clang/test/CIR/CodeGen/address-of.cpp diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 0e5a5b531df78..88d37d56fcd78 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -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: diff --git a/clang/test/CIR/CodeGen/address-of.cpp b/clang/test/CIR/CodeGen/address-of.cpp new file mode 100644 index 0000000000000..3b7f710977066 --- /dev/null +++ b/clang/test/CIR/CodeGen/address-of.cpp @@ -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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
