clang: Respect function address space for __builtin_function_start
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Wed, 21 Dec 2022 13:09:56 +0000 (08:09 -0500)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Wed, 21 Dec 2022 13:27:24 +0000 (08:27 -0500)
Fixes assertion.

clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/avr/builtin-function-start.c [new file with mode: 0644]

index ac71346..fcb60e3 100644 (file)
@@ -4170,8 +4170,9 @@ llvm::Constant *CodeGenModule::GetFunctionStart(const ValueDecl *Decl) {
   llvm::GlobalValue *F =
       cast<llvm::GlobalValue>(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 (file)
index 0000000..293c806
--- /dev/null
@@ -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);