[PATCH] D57747: [Sema] SequenceChecker: Fix handling of operator ||, && and ?:
Bruno Ricci via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 5 05:26:05 PST 2019
riccibruno created this revision.
riccibruno added reviewers: aaron.ballman, rsmith.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.
The current handling of the operators `||`, `&&` and `?:` has a number of false positive and false negative. The issues for operator `||` and `&&` are:
1. We need to add sequencing regions for the LHS and RHS as is done for the comma operator. Not doing so causes false positives in expressions like `((a++, false) || (a++, false));` (from PR39779, see PR22197 for another example).
2. In the current implementation when the evaluation of the LHS fails, the RHS is added to a worklist to be processed later. This results in false negatives in expressions like `(a && a++) + a`.
Fix these issues by introducing sequencing regions for the LHS and RHS, and by not deferring the visitation of the RHS.
The issues with the ternary operator `?:` are similar, with the added twist that we should not warn on expressions like `(x ? y += 1 : y += 2)` since exactly one of the 2nd and 3rd expression is going to be evaluated, but we should still warn on expressions like `(x ? y += 1 : y += 2) = y`.
Repository:
rC Clang
https://reviews.llvm.org/D57747
Files:
lib/Sema/SemaChecking.cpp
test/Sema/warn-unsequenced.c
test/SemaCXX/warn-unsequenced.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57747.185284.patch
Type: text/x-patch
Size: 13264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190205/fba1ccd0/attachment-0001.bin>
More information about the cfe-commits
mailing list