[PATCH] D112113: [ObjC] type method metadata `_imp`, messenger routine at callsite with program address space
Matt Jacobson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 19 17:15:25 PDT 2021
mhjacobson created this revision.
mhjacobson added reviewers: rjmccall, ddunbar.
Herald added subscribers: pengfei, Jim, dylanmckay.
mhjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
On targets with non-default program address space (e.g., Harvard architectures), clang crashes (example backtrace below) when emitting Objective-C method metadata, because the address of the method IMP cannot be bitcast to `i8*`. It similarly crashes at messenger callsite with a failed bitcast.
Define the `_imp` field instead as `i8 addrspace(1)*` (or whatever the target's program address space is). And in `getMessageSendInfo()`, create `signatureType` by specifying the program address space.
Add a regression test using the AVR target. Test failed previously and passes now. Checked codegen of the test for x86_64-apple-darwin19.6.0 and saw no difference, as expected.
Backtrace (when emitting method metadata):
Assertion failed: (CastInst::castIsValid(Instruction::BitCast, C, DstTy) && "Invalid constantexpr bitcast!"), function getBitCast, file /Users/matt/src/llvm/llvm/lib/IR/Constants.cpp, line 2224.
...
7 libsystem_c.dylib 0x00007fff6ec09ac6 err + 0
8 clang-14 0x0000000101800518 llvm::ConstantExpr::getBitCast(llvm::Constant*, llvm::Type*, bool) + 120
9 clang-14 0x000000010394ca70 clang::CodeGen::ConstantAggregateBuilderBase::addBitCast(llvm::Constant*, llvm::Type*) + 48
10 clang-14 0x0000000103999ac2 (anonymous namespace)::CGObjCNonFragileABIMac::emitMethodConstant(clang::CodeGen::ConstantArrayBuilder&, clang::ObjCMethodDecl const*, bool) + 402
11 clang-14 0x0000000103999102 (anonymous namespace)::CGObjCNonFragileABIMac::emitMethodList(llvm::Twine, (anonymous namespace)::(anonymous namespace)::MethodListType, llvm::ArrayRef<clang::ObjCMethodDecl const*>) + 1074
12 clang-14 0x000000010399a4c0 (anonymous namespace)::CGObjCNonFragileABIMac::BuildClassRoTInitializer(unsigned int, unsigned int, unsigned int, clang::ObjCImplementationDecl const*) + 1376
13 clang-14 0x0000000103990b9b (anonymous namespace)::CGObjCNonFragileABIMac::GenerateClass(clang::ObjCImplementationDecl const*) + 1995
14 clang-14 0x0000000103bb87d1 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 2065
15 clang-14 0x0000000103db5bf2 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 146
16 clang-14 0x0000000103b61014 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 228
17 clang-14 0x00000001070d7425 clang::ParseAST(clang::Sema&, bool, bool) + 533
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112113
Files:
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CGObjCRuntime.cpp
clang/test/CodeGen/avr/objc-method.m
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112113.380828.patch
Type: text/x-patch
Size: 3547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211020/619ac3a7/attachment.bin>
More information about the cfe-commits
mailing list