This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Always constant-evaluate operands of comparisons to nullptr
ClosedPublic

Authored by cor3ntin on Aug 23 2023, 5:26 AM.

Details

Summary

even if we know what the result is going to be.
There may be side effects we ought not to ignore,

Fixes #64923

Diff Detail

Event Timeline

cor3ntin created this revision.Aug 23 2023, 5:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2023, 5:26 AM
cor3ntin requested review of this revision.Aug 23 2023, 5:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2023, 5:26 AM
tbaeder added inline comments.
clang/lib/AST/ExprConstant.cpp
13316

I kinda expected the fix for this bug to simply remove a special case... does just falling through to the DoAfter() call not work?

cor3ntin added inline comments.Aug 23 2023, 6:14 AM
clang/lib/AST/ExprConstant.cpp
13316

Nope, EvaluateComparisonBinaryOperator does compute the result of the comparison. DoAfter only adjust the result.
Removing that block of codes lead to a whole bunch of test failures

tbaeder added inline comments.Aug 23 2023, 7:04 AM
clang/lib/AST/ExprConstant.cpp
13316

Shame, but ok.

ChuanqiXu accepted this revision.Aug 23 2023, 6:37 PM

LGTM. Thanks.

This revision is now accepted and ready to land.Aug 23 2023, 6:37 PM

@ChuanqiXu Thanks. Do you think this needs to be backported for coroutine support?

@ChuanqiXu Thanks. Do you think this needs to be backported for coroutine support?

For coroutine support, I don't think it is needed. It is a pretty corner case and Tobias had mentioned there are too many back ports now (https://discourse.llvm.org/t/llvm-17-0-0-rc3-released/72946). Although he doesn't throw any requirement to us, I think it may better to lift our bar for backporting patches now.

Gotcha. Given there are other stuffs I need to backport, this will have to wait clang 18! I don't want to give undue work to tobias and testers.

shafik added a subscriber: shafik.Aug 25 2023, 8:26 PM

It might have been nice to add a test where nullptr_t comparison succeeds as well.