This is an archive of the discontinued LLVM Phabricator instance.

[ASTStructuralEquivalence] Add support for comparing ObjCCategoryDecl.
ClosedPublic

Authored by vsapsai on Mar 7 2022, 5:15 PM.

Details

Summary

Will post shortly another patch that relies on comparing ObjCCategoryDecl.

Diff Detail

Event Timeline

vsapsai created this revision.Mar 7 2022, 5:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 5:15 PM
vsapsai requested review of this revision.Mar 7 2022, 5:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 5:15 PM
shafik added a comment.Mar 7 2022, 6:12 PM

This make sense to me at a first pass, please make sure you run check-lldb as well.

clang/lib/AST/ASTStructuralEquivalence.cpp
1979

I am curious what case are we catching here? Does NumArgs ever have the value 1?

Hi Volodymyr,
Unfortunately, I'm not familiar with Objective-C and its frontend but I have a question.

clang/lib/AST/ASTStructuralEquivalence.cpp
1997

Should we check if the parameter count is different?

Thanks for the reviews! I'm going to address the comments, check-lldb, check tests failing on Debian.

clang/lib/AST/ASTStructuralEquivalence.cpp
1979

Here I'm trying to handle the case with argument-less methods. For example, -(void)test; has 0 arguments but we still want to compare the first slot. At the moment I don't know how to clarify the code to make the intention clearer. Can add a comment explaining the intention (though there is a test that should catch breaking code accidentally).

And to answer your question, NumArgs can have value 1.

1997

Mismatch in the number of parameters should be caught by NumArgs != Selector2.getNumArgs() earlier. But I think it makes sense to add an assertion verifying param_size is equal at this point.

vsapsai added inline comments.Mar 8 2022, 7:43 PM
clang/lib/AST/ASTStructuralEquivalence.cpp
1248

By the way, the alternative to introducing parameter Owner2Type was to use ...Owner2 = cast<TypeDecl>(...). But that would work only for ObjCInterfaceDecl and would require making ObjCInterfaceDecl TypeDecl. Conceptually, it makes sense for ObjCInterfaceDecl to be TypeDecl as @interface does represent a type. But I've decided that such invasive change is not justified.

vsapsai updated this revision to Diff 414244.Mar 9 2022, 4:59 PM

Add a comment and an assertion.

vsapsai marked 2 inline comments as done.Mar 9 2022, 5:03 PM

check-lldb has the following tests failing

lldb-shell :: Expr/TestIRMemoryMap.test
lldb-shell :: Process/TestEnvironment.test
lldb-shell :: Register/x86-64-gp-read.test
lldb-shell :: Register/x86-64-read.test
lldb-shell :: Register/x86-64-ymm-read.test
lldb-shell :: Register/x86-multithread-read.test
lldb-shell :: Register/x86-multithread-write.test

All of them look irrelevant as they are failing with various "file not found" errors, e.g., cstdlib, cstdint, cinttypes. I guess my local toolchain configuration differs from LLDB expectations.

clang/lib/AST/ASTStructuralEquivalence.cpp
1979

Added a comment.

1997

Added an assertion for param_size (not triggered during running the test suite).

Basically, this looks good to me. But my confidence with ObjC is low, so, I'd like @shafik as well to approve.
Besides, seems like the pre-merge check fails with the new tests on Debian, could you please address that?

vsapsai updated this revision to Diff 414565.Mar 10 2022, 7:34 PM

Fix tests on Debian by using -fobjc-nonfragile-abi explicitly as declaring ivars in extensions is supported only with non-fragile ABI.

vsapsai updated this revision to Diff 414724.Mar 11 2022, 12:08 PM

Fix clang-format error.

Basically, this looks good to me. But my confidence with ObjC is low, so, I'd like @shafik as well to approve.
Besides, seems like the pre-merge check fails with the new tests on Debian, could you please address that?

Thanks for the review! My confidence with the structural equivalence is low and I appreciate your expertise in this area.

Fixed the tests by using non-fragile ABI explicitly. The only remaining failing test is Clang :: Driver/clang_f_opts.c which is failing for unrelated reasons.

@shafik, can you please check the patch? Or maybe recommend somebody who worked both on ASTStructuralEquivalence and Objective-C part of clang?

martong accepted this revision.Apr 21 2022, 4:30 AM

Ok, still looks good to me, thanks!

This revision is now accepted and ready to land.Apr 21 2022, 4:30 AM

Thanks for the review, Gabor! Now I'll work on rebasing the patch and testing one final time.

vsapsai updated this revision to Diff 424561.Apr 22 2022, 12:04 PM

Rebase and trigger pre-commit tests.