This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Diagnose undefined behavior in a constant expression while evaluating a compound assignment with remainder as operand
ClosedPublic

Authored by shafik on Dec 20 2022, 10:08 PM.

Details

Summary

Currently we don't diagnose overflow in a constant expression for the case of compound assignment with remainder as a operand.

In handleIntIntBinOp the arguments LHS and Result can be the same source but in the check for remainder in this function we assigned to Result before checking for overflow. In all the other operations the check is done before Result is assigned to.

Diff Detail

Event Timeline

shafik created this revision.Dec 20 2022, 10:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2022, 10:08 PM
shafik requested review of this revision.Dec 20 2022, 10:08 PM
aaron.ballman accepted this revision.Jan 9 2023, 12:23 PM

LGTM aside from some style nits. Can you also add a release note for the fix?

clang/lib/AST/ExprConstant.cpp
2754–2755
2772–2785
clang/test/CXX/expr/expr.const/p2-0x.cpp
304
This revision is now accepted and ready to land.Jan 9 2023, 12:23 PM
shafik updated this revision to Diff 488383.Jan 11 2023, 2:23 PM
shafik marked 3 inline comments as done.
  • Move HandleOverflowResult closer to where it is used.
  • move int after constexpr in function rem
  • Add release note
shafik updated this revision to Diff 488441.Jan 11 2023, 5:43 PM
  • Moving back HandleOverflowResult to before the switch statement to avoid "jump bypasses variable initialization" error.
This revision was landed with ongoing or failed builds.Jan 12 2023, 8:04 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 8:04 AM