Page MenuHomePhabricator

[ObjC] avoid crashing when emitting synthesized getter/setter and ptrdiff_t is smaller than long
Needs ReviewPublic

Authored by mhjacobson on Oct 18 2021, 7:28 PM.

Details

Summary

On targets where ptrdiff_t is smaller than long, clang crashes (backtrace below) when emitting synthesized getters/setters that call objc_[gs]etProperty. Explicitly emit a zext/trunc of the ivar offset value (which is defined to long) to ptrdiff_t, which objc_[gs]etProperty takes.

Add a test using the AVR target, where ptrdiff_t is smaller than long. Test failed previously and passes now.

Backtrace:

Assertion failed: (castIsValid(op, S, Ty) && "Invalid cast!"), function Create, file /Users/matt/src/llvm/llvm/lib/IR/Instructions.cpp, line 3042.

...

7  libsystem_c.dylib        0x00007fff6ec09ac6 err + 0
8  clang-14                 0x000000010acf104c llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) + 124
9  clang-14                 0x000000010beb140a llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) + 234
10 clang-14                 0x000000010bebdec2 llvm::IRBuilderBase::CreateZExt(llvm::Value*, llvm::Type*, llvm::Twine const&) + 50
11 clang-14                 0x000000010cab50aa clang::CodeGen::CodeGenFunction::EmitCall(clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::CGCallee const&, clang::CodeGen::ReturnValueSlot, clang::CodeGen::CallArgList const&, llvm::CallBase**, bool, clang::SourceLocation) + 8442
12 clang-14                 0x000000010ceadeb8 clang::CodeGen::CodeGenFunction::EmitCall(clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::CGCallee const&, clang::CodeGen::ReturnValueSlot, clang::CodeGen::CallArgList const&, llvm::CallBase**, bool) + 216
13 clang-14                 0x000000010cc76fe3 clang::CodeGen::CodeGenFunction::generateObjCGetterBody(clang::ObjCImplementationDecl const*, clang::ObjCPropertyImplDecl const*, clang::ObjCMethodDecl const*, llvm::Constant*) + 2595
14 clang-14                 0x000000010cc75387 clang::CodeGen::CodeGenFunction::GenerateObjCGetter(clang::ObjCImplementationDecl*, clang::ObjCPropertyImplDecl const*) + 343
15 clang-14                 0x000000010cf1c4c0 clang::CodeGen::CodeGenModule::EmitObjCPropertyImplementations(clang::ObjCImplementationDecl const*) + 336
16 clang-14                 0x000000010cf17799 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 2009
17 clang-14                 0x000000010d114bf2 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 146
18 clang-14                 0x000000010cec0014 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 228
19 clang-14                 0x0000000110436425 clang::ParseAST(clang::Sema&, bool, bool) + 533

Diff Detail

Unit TestsFailed

TimeTest
470 msx64 debian > Clang.CodeGen/avr::objc-property.m
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -triple avr -emit-llvm -fobjc-runtime=macosx /var/lib/buildkite-agent/builds/llvm-project/clang/test/CodeGen/avr/objc-property.m -o /dev/null

Event Timeline

mhjacobson created this revision.Oct 18 2021, 7:28 PM
mhjacobson requested review of this revision.Oct 18 2021, 7:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2021, 7:28 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

The test is failing for a different reason (that I'd forgotten I worked around locally). I'll look into fixing that first. Sorry for noise.