aykevl created this revision. aykevl added reviewers: dylanmckay, rjmccall, MaskRay. aykevl added a project: LLVM. Herald added subscribers: cfe-commits, Jim. Herald added a project: clang. aykevl edited the summary of this revision.
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. --- Two remarks on this diff: 1. I wasn't sure whether there is a way to set the address space on a function. I at least couldn't seem to get it to work. If it is possible to set the address space, I think the fix is slightly wrong and should somehow get the address space from the function declaration instead of using `getProgramAddressSpace` (please let me know how or where to find this information). 2. I hoped there was a test file already where I could include this test, but at least CodeGen/address-space.c seemed a bit too complex to also test with AVR (for example, `int` is 16-bit on AVR). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D78125 Files: clang/lib/CodeGen/CGExpr.cpp clang/test/CodeGen/address-space-avr.c Index: clang/test/CodeGen/address-space-avr.c =================================================================== --- /dev/null +++ clang/test/CodeGen/address-space-avr.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s + +// 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); +} Index: clang/lib/CodeGen/CGExpr.cpp =================================================================== --- clang/lib/CodeGen/CGExpr.cpp +++ clang/lib/CodeGen/CGExpr.cpp @@ -5048,7 +5048,8 @@ // to the function type. if (isa<FunctionNoProtoType>(FnType) || Chain) { llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo); - CalleeTy = CalleeTy->getPointerTo(); + int AS = getTypes().getDataLayout().getProgramAddressSpace(); + CalleeTy = CalleeTy->getPointerTo(AS); llvm::Value *CalleePtr = Callee.getFunctionPointer(); CalleePtr = Builder.CreateBitCast(CalleePtr, CalleeTy, "callee.knr.cast");
Index: clang/test/CodeGen/address-space-avr.c =================================================================== --- /dev/null +++ clang/test/CodeGen/address-space-avr.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple avr -emit-llvm < %s | FileCheck %s + +// 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); +} Index: clang/lib/CodeGen/CGExpr.cpp =================================================================== --- clang/lib/CodeGen/CGExpr.cpp +++ clang/lib/CodeGen/CGExpr.cpp @@ -5048,7 +5048,8 @@ // to the function type. if (isa<FunctionNoProtoType>(FnType) || Chain) { llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo); - CalleeTy = CalleeTy->getPointerTo(); + int AS = getTypes().getDataLayout().getProgramAddressSpace(); + CalleeTy = CalleeTy->getPointerTo(AS); llvm::Value *CalleePtr = Callee.getFunctionPointer(); CalleePtr = Builder.CreateBitCast(CalleePtr, CalleeTy, "callee.knr.cast");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits