This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Initialize pointer fields and remove a needless null check.
ClosedPublic

Authored by schittir on Jun 22 2023, 2:08 PM.

Diff Detail

Event Timeline

schittir created this revision.Jun 22 2023, 2:08 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald Transcript
schittir requested review of this revision.Jun 22 2023, 2:08 PM
erichkeane added inline comments.Jun 22 2023, 2:24 PM
clang/lib/Analysis/CFG.cpp
4156

I get that we're counting on the dereference on 4145 to have made this check irrelevant, but are we sure that we KNOW that "S" is non-null here otherwise? That is, is the bug actually 4145 doing 'alwaysAdd' without checking vs the unnecessary check here?

clang/lib/CodeGen/CGObjCGNU.cpp
58

I would suggest instead making these inline initialization rather than here (that is, CGM = nullptr on line 49, etc).

schittir marked an inline comment as done.Jun 22 2023, 2:49 PM
schittir added inline comments.
clang/lib/Analysis/CFG.cpp
4156

VisitCXXTypeidExpr is used only in one place - here https://github.com/llvm/llvm-project/blob/a89c9b35be08b665cc1a01d840bc20349ba1308f/clang/lib/Analysis/CFG.cpp#L2288 where S is not null. Null check for S already happens at the beginning of the method where VisitCXXTypeidExpr is called.

schittir updated this revision to Diff 533794.Jun 22 2023, 2:51 PM

Address comment- Use default member initialization instead of initializing in a constructor.

erichkeane added inline comments.Jun 22 2023, 2:54 PM
clang/lib/Analysis/CFG.cpp
4156

SG, an assert is perhaps not a bad idea, but LGTM. I don't know very much about the CFG stuff, so aaron might wish to take a final look.

clang/lib/CodeGen/CGObjCGNU.cpp
58
schittir updated this revision to Diff 533798.Jun 22 2023, 3:02 PM

Make the constructor default.

clang/lib/Analysis/CFG.cpp
4156

What is SG?

schittir added inline comments.Jun 22 2023, 3:03 PM
clang/lib/CodeGen/CGObjCGNU.cpp
58

The comment above needs to be updated?

erichkeane added inline comments.Jun 22 2023, 3:05 PM
clang/lib/Analysis/CFG.cpp
4156

"Sounds Good"

clang/lib/CodeGen/CGObjCGNU.cpp
58

I don't think so? It still leaves the class uninitialized.

schittir added inline comments.Jun 22 2023, 3:09 PM
clang/lib/Analysis/CFG.cpp
4156

Haha!
Thanks for the review.

clang/lib/CodeGen/CGObjCGNU.cpp
58

Right! Still valid.

schittir added inline comments.Jun 26 2023, 1:33 PM
clang/lib/Analysis/CFG.cpp
4156

SG, an assert is perhaps not a bad idea, but LGTM. I don't know very much about the CFG stuff, so aaron might wish to take a final look.

Hi @aaron.ballman, could you please comment on this? Thank you!

aaron.ballman added inline comments.Jun 27 2023, 10:21 AM
clang/lib/Analysis/CFG.cpp
4156

I don't think an assert is necessary; I think it's a predicate to pass non-null nodes to the Visit functions in general, and I don't think we get a whole lot out of asserting in each Visit method that its given node is nonnull.

clang/lib/CodeGen/CGObjCGNU.cpp
58

I think the comment is stale or imprecise -- the class certainly is initialized (it was being initialized previously as well, just not fully initialized). I think it may have meant "not initialized to useful values", so we could either repair it that way or remove the comment entirely.

schittir added inline comments.Jun 27 2023, 10:30 AM
clang/lib/Analysis/CFG.cpp
4156

Thanks for the comment.

clang/lib/CodeGen/CGObjCGNU.cpp
58

I prefer removing the comment entirely because constructor = default() is self-explanatory.

schittir updated this revision to Diff 535050.Jun 27 2023, 10:38 AM

Remove stale comment about default constructor not initializing members in a useful way.

erichkeane accepted this revision.Jun 28 2023, 7:42 AM
This revision is now accepted and ready to land.Jun 28 2023, 7:42 AM
tahonermann accepted this revision.Jul 6 2023, 8:48 AM

These changes look fine to me.

owenpan accepted this revision.Jul 6 2023, 7:59 PM

The clang-format part LGTM.

Thank you all for reviewing.

Can you mark this change as closed?
If you'd put "Differential Revision: https://reviews.llvm.org/D153589" in your commit message this would have happened automatically.

schittir closed this revision.Jul 12 2023, 10:46 AM

Can you mark this change as closed?
If you'd put "Differential Revision: https://reviews.llvm.org/D153589" in your commit message this would have happened automatically.

I put the link to the review but worded the commit message differently. Thanks, I will close this.