From 131cddcba2c4c953a8a49d7adbf656cab9e9f1c7 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 24 Nov 2022 20:24:36 +0100 Subject: [AVR] Fix broken bitcast for aliases in non-zero address space This was triggered by some code in picolibc. The minimal version looks like this: double infinity(void) { return 5; } extern long double infinityl() __attribute__((__alias__("infinity"))); These two declarations have a different type (not because of the 'long double', which is also 'double' in IR, but because infinityl has variadic parameters). This led to a crash in the bitcast which assumed address space 0. Differential Revision: https://reviews.llvm.org/D138681 --- clang/lib/CodeGen/CodeGenModule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ae25767bc753..133c603622f8 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4002,7 +4002,8 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( // (If function is requested for a definition, we always need to create a new // function, not just return a bitcast.) if (!IsForDefinition) - return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo()); + return llvm::ConstantExpr::getBitCast( + Entry, Ty->getPointerTo(Entry->getAddressSpace())); } // This function doesn't have a complete type (for example, the return -- cgit v1.2.3