This is an archive of the discontinued LLVM Phabricator instance.

[clang][NFC] In parts of Objective-C Sema use Obj-C-specific types instead of `Decl`.
ClosedPublic

Authored by vsapsai on Apr 22 2022, 11:29 AM.

Diff Detail

Event Timeline

vsapsai created this revision.Apr 22 2022, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 11:29 AM
Herald added a subscriber: ributzka. · View Herald Transcript
vsapsai requested review of this revision.Apr 22 2022, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 11:29 AM
jansvoboda11 accepted this revision.Apr 26 2022, 4:39 AM

LGTM with two minor questions.

clang/include/clang/Sema/Sema.h
3288

Why the change in return type?

clang/lib/Sema/SemaDecl.cpp
17094

Why the cast? We should be able to compare/assign ObjCContainerDecl * to DeclContext *.

This revision is now accepted and ready to land.Apr 26 2022, 4:39 AM
vsapsai marked an inline comment as done.Apr 26 2022, 4:24 PM
vsapsai added inline comments.
clang/include/clang/Sema/Sema.h
3288

Initially I've changed the type to catch various return ActOnObjCContainerStartDefinition.. Now it's not really required.

What type do you think it should be? We can do both Decl * and ObjCContainerDecl * though none of those is particularly useful. I've decided to keep void because we don't use the returned value anyway.

I was also considering

template <typename ObjCDeclTy>
ObjCDeclTy *ActOnObjCContainerStartDefinition(ObjCDeclTy *IDecl);

but I feel like the introduced complexity isn't worth it.

clang/lib/Sema/SemaDecl.cpp
17094

I believe you are right and the cast is not required. Though we cannot compare ObjCCtx and CurContext, we need to compare DeclContext *DC.

Also dropped a similar cast in ActOnObjCContainerStartDefinition.

vsapsai updated this revision to Diff 425334.Apr 26 2022, 4:24 PM
vsapsai marked an inline comment as done.

Drop unnecessary cast<>.

jansvoboda11 added inline comments.Apr 28 2022, 2:10 AM
clang/include/clang/Sema/Sema.h
3288

I see. I'm fine with having void here, what caught my attention was changing return ActOnObjCContainerStartDefinition(X); into ActOnObjCContainerStartDefinition(X); return X; that's perfectly fine though.

clang/lib/Sema/SemaDecl.cpp
17094

Interesting, I would expect that ObjCCtx == CurContext would have implicit upcast of ObjCCtx to DeclContext *. Same for the assignment.

vsapsai added inline comments.Apr 28 2022, 1:10 PM
clang/lib/Sema/SemaDecl.cpp
17094

D'oh, relying on values in debugger isn't always correct. You are right, according to [expr.eq]p2 both operands are brought to their composite pointer type and [conv.ptr]p3 allows upcasting, so we don't need to have variables of the same time for comparison.

vsapsai updated this revision to Diff 425891.Apr 28 2022, 1:10 PM

Simplify pointer comparison.

This revision was landed with ongoing or failed builds.May 5 2022, 7:20 PM
This revision was automatically updated to reflect the committed changes.