This is an archive of the discontinued LLVM Phabricator instance.

[NFC][Clang] Fix static analyzer concern about null pointer dereference
ClosedPublic

Authored by eandrews on Aug 9 2023, 3:38 PM.

Details

Summary

Param->getTypeConstraint() can return nullptr, and was dereferenced without a check.

I followed the logic for invalid constraints and set Status as concepts::ExprRequirement::SS_ExprSubstitutionFailure if getTypeConstraint() returns null unexpectedly. I am not a 100% certain about this change since I am unfamiliar with concepts.

Diff Detail

Event Timeline

eandrews created this revision.Aug 9 2023, 3:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 3:38 PM
eandrews requested review of this revision.Aug 9 2023, 3:38 PM
aaron.ballman added a subscriber: erichkeane.

This feels a bit more like a functional change than a non-functional change because it seems like we should be able to test this case (whereas, if we think TC can never be null in reality, we could add an assert for it and not add test coverage). That said, I'm not certain how to induce a failure here. Adding @erichkeane in case he has ideas.

This feels a bit more like a functional change than a non-functional change because it seems like we should be able to test this case (whereas, if we think TC can never be null in reality, we could add an assert for it and not add test coverage). That said, I'm not certain how to induce a failure here. Adding @erichkeane in case he has ideas.

Yea I agree. I see that this is inside ReturnTypeRequirement.isTypeConstraint() so maybe Param should always have a type constraint? I'm just naively guessing here though

This feels a bit more like a functional change than a non-functional change because it seems like we should be able to test this case (whereas, if we think TC can never be null in reality, we could add an assert for it and not add test coverage). That said, I'm not certain how to induce a failure here. Adding @erichkeane in case he has ideas.

Yea I agree. I see that this is inside ReturnTypeRequirement.isTypeConstraint() so maybe Param should always have a type constraint? I'm just naively guessing here though

As I read the code, I think an assert is sufficient -- if the param is a type constraint, I believe we expect a non-null type constraint and a null one is a sign of a bug.

This feels a bit more like a functional change than a non-functional change because it seems like we should be able to test this case (whereas, if we think TC can never be null in reality, we could add an assert for it and not add test coverage). That said, I'm not certain how to induce a failure here. Adding @erichkeane in case he has ideas.

Yea I agree. I see that this is inside ReturnTypeRequirement.isTypeConstraint() so maybe Param should always have a type constraint? I'm just naively guessing here though

As I read the code, I think an assert is sufficient -- if the param is a type constraint, I believe we expect a non-null type constraint and a null one is a sign of a bug.

Alright. I'll make the change then. Thanks!

eandrews updated this revision to Diff 549960.Aug 14 2023, 8:33 AM

Applied review comments

tahonermann accepted this revision.Aug 14 2023, 8:49 AM

Looks good to me!

This revision is now accepted and ready to land.Aug 14 2023, 8:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2023, 12:21 PM

Thanks for the reviews!