From 2bb59549e11fdb1d6b6c4e68f4572783f414d67f Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 21 Dec 2022 08:09:56 -0500 Subject: [PATCH] clang: Respect function address space for __builtin_function_start Fixes assertion. --- clang/lib/CodeGen/CodeGenModule.cpp | 5 +++-- clang/test/CodeGen/avr/builtin-function-start.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/avr/builtin-function-start.c diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ac71346..fcb60e3 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4170,8 +4170,9 @@ llvm::Constant *CodeGenModule::GetFunctionStart(const ValueDecl *Decl) { llvm::GlobalValue *F = cast(GetAddrOfFunction(Decl)->stripPointerCasts()); - return llvm::ConstantExpr::getBitCast(llvm::NoCFIValue::get(F), - llvm::Type::getInt8PtrTy(VMContext)); + return llvm::ConstantExpr::getBitCast( + llvm::NoCFIValue::get(F), + llvm::Type::getInt8PtrTy(VMContext, F->getAddressSpace())); } static const FunctionDecl * diff --git a/clang/test/CodeGen/avr/builtin-function-start.c b/clang/test/CodeGen/avr/builtin-function-start.c new file mode 100644 index 0000000..293c806 --- /dev/null +++ b/clang/test/CodeGen/avr/builtin-function-start.c @@ -0,0 +1,13 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-globals +// RUN: %clang_cc1 -triple avr-- -emit-llvm -o - %s | FileCheck %s + +//. +// CHECK: @e = global ptr addrspacecast (ptr addrspace(1) no_cfi @a to ptr), align 1 +//. +// CHECK-LABEL: define {{[^@]+}}@a +// CHECK-SAME: () addrspace(1) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT: ret void +// +void a(void) {} +const void *e = __builtin_function_start(a); -- 2.7.4