Author: Ayke van Laethem Date: 2020-04-15T23:44:51+02:00 New Revision: 215dc2e203341f7d1edc4c4a191b048af4ace43d
URL: https://github.com/llvm/llvm-project/commit/215dc2e203341f7d1edc4c4a191b048af4ace43d DIFF: https://github.com/llvm/llvm-project/commit/215dc2e203341f7d1edc4c4a191b048af4ace43d.diff LOG: [AVR] Use the correct address space for non-prototyped function calls Some function declarations like this: void foo(); do not have a type declaration, for that you'd use: void foo(void); Clang internally bitcasts the variadic function declaration to a function pointer, but doesn't use the correct address space on AVR. This commit fixes that. This fix is necessary to let Clang compile compiler-rt for AVR. Differential Revision: https://reviews.llvm.org/D78125 Added: clang/test/CodeGen/address-space-avr.c Modified: clang/lib/CodeGen/CGExpr.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index eca76f36eda8..85c2d318c196 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -5063,7 +5063,8 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee // to the function type. if (isa<FunctionNoProtoType>(FnType) || Chain) { llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo); - CalleeTy = CalleeTy->getPointerTo(); + int AS = Callee.getFunctionPointer()->getType()->getPointerAddressSpace(); + CalleeTy = CalleeTy->getPointerTo(AS); llvm::Value *CalleePtr = Callee.getFunctionPointer(); CalleePtr = Builder.CreateBitCast(CalleePtr, CalleeTy, "callee.knr.cast"); diff --git a/clang/test/CodeGen/address-space-avr.c b/clang/test/CodeGen/address-space-avr.c new file mode 100644 index 000000000000..58518e5e3453 --- /dev/null +++ b/clang/test/CodeGen/address-space-avr.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s + +// Test that function declarations in nonzero address spaces without prototype +// are called correctly. + +// CHECK: define void @bar() addrspace(1) +// CHECK: call addrspace(1) void bitcast (void (...) addrspace(1)* @foo to void (i16) addrspace(1)*)(i16 3) +// CHECK: declare void @foo(...) addrspace(1) +void foo(); +void bar(void) { + foo(3); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits