llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) <details> <summary>Changes</summary> Upstream the addressof builtin --- Full diff: https://github.com/llvm/llvm-project/pull/177860.diff 2 Files Affected: - (modified) clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp (+1) - (added) clang/test/CIR/CodeGen/address-of.cpp (+28) ``````````diff 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 `````````` </details> https://github.com/llvm/llvm-project/pull/177860 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
