This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Add ParmVarDecls to FunctionDecls that are created to generate ObjC property getter/setter functions
ClosedPublic

Authored by ahatanak on Jun 24 2021, 4:29 PM.

Details

Summary

This is needed to prevent clang from crashing when we make the changes proposed in https://reviews.llvm.org/D98799.

Diff Detail

Event Timeline

ahatanak created this revision.Jun 24 2021, 4:29 PM
ahatanak requested review of this revision.Jun 24 2021, 4:29 PM

clang crashes if I remove the fake FunctionDecls as I did in https://reviews.llvm.org/D104082.

aprantl accepted this revision.Jun 24 2021, 4:58 PM

If args.push_back(Params[1] = SrcDecl); doesn't trigger a warning, this seems reasonable.

clang/lib/CodeGen/CGObjC.cpp
3706

Does this compile without warnings?

This revision is now accepted and ready to land.Jun 24 2021, 4:58 PM

Ah - this is an alternative to D104082? OK. Yeah, looks like it'd address the thing we were discussing in D98799. But do you have some more details on why D104082 wasn't the right direction? I thought we found other places that used a default-constructed/null GlobalDecl() for StartFunction` correctly, so I'm wondering why this would be a problem in this particular case(s)?

I see assert(DC && "This decl is not contained in a translation unit!"); fail in Decl::getTranslationUnitDecl when DeclRefExpr is constructed. That's because the ImplicitParamDecl passed to DeclRefExpr's constructor doesn't have a decl context if I delete FD. So it looks like FD is needed in these cases.

clang/lib/CodeGen/CGObjC.cpp
3706

Yes, clang compiles this without any warnings. I don't know whether other compilers warn.

I see assert(DC && "This decl is not contained in a translation unit!"); fail in Decl::getTranslationUnitDecl when DeclRefExpr is constructed. That's because the ImplicitParamDecl passed to DeclRefExpr's constructor doesn't have a decl context if I delete FD. So it looks like FD is needed in these cases.

Hmm, OK - I think I'm following enough. I'll leave the rest to you & @aprantl - appreciate the work!

I'll wait a day or two in case someone else has feedback.