Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Issue 2526783002: [base] Define CHECK comparison for signed vs. unsigned (Closed)

Created:
4 years ago by Clemens Hammacher
Modified:
4 years ago
Reviewers:
Igor Sheludko, titzer
CC:
ahaas, Benedikt Meurer, v8-reviews_googlegroups.com
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

[base] Define CHECK comparison for signed vs. unsigned The current CHECK/DCHECK implementation fails statically if a signed value is compared against an unsigned value. The common solution is to cast on each caller, which is tedious and error-prone (might hide bugs). This CL implements signed vs. unsigned comparisons by executing up to two comparisons. For example, if i is int32_t and u is uint_32_t, a DCHECK_LE(i, u) would create the check i <= 0 || static_cast<uint32_t>(i) <= u. For checks against constants, at least one of the checks can be removed by compiler optimizations. The tradeoff we have to make is to sometimes silently execute an additional comparison. And we increase code complexity of course, even though the usage is just as easy (or even easier) as before. The compile time impact seems to be minimal: I ran 3 full compilations for Optdebug on my local machine, one time on the current ToT, one time with this CL plus http://crrev.com/2524093002. Before: 143.72 +- 1.21 seconds Now: 144.18 +- 0.67 seconds In order to check that the new comparisons are working, I refactored some DCHECKs in wasm to use the new magic, and added unit test cases. R=ishell@chromium.org, titzer@chromium.org CC=ahaas@chromium.org, bmeurer@chromium.org Committed: https://crrev.com/5925074a9dab5a8577766545b91b62f2c531d3dc Committed: https://crrev.com/db0c86fa5f03794838ee6d1d301ca34d41f20fca Cr-Original-Commit-Position: refs/heads/master@{#41275} Cr-Commit-Position: refs/heads/master@{#41411}

Patch Set 1 #

Patch Set 2 : Rebase & refactor for windows #

Total comments: 4

Patch Set 3 : Address Ben's comments #

Patch Set 4 : Fix comment #

Total comments: 2

Patch Set 5 : Add missing undefs #

Patch Set 6 : Extend test case #

Total comments: 2

Patch Set 7 : Include cstdint #

Patch Set 8 : Extend test case #

Patch Set 9 : Rebase #

Unified diffs Side-by-side diffs Delta from patch set Stats (+132 lines, -38 lines) Patch
M src/base/logging.h View 1 2 3 4 5 1 chunk +59 lines, -3 lines 0 comments Download
M src/log-utils.h View 1 chunk +2 lines, -2 lines 0 comments Download
M src/wasm/ast-decoder.cc View 1 2 3 4 5 6 7 8 3 chunks +3 lines, -3 lines 0 comments Download
M src/wasm/wasm-interpreter.cc View 1 2 3 4 5 6 7 8 4 chunks +6 lines, -6 lines 0 comments Download
M src/wasm/wasm-module.h View 1 2 3 4 5 6 7 8 2 chunks +2 lines, -2 lines 0 comments Download
M src/wasm/wasm-module.cc View 1 2 3 4 5 6 7 8 3 chunks +4 lines, -4 lines 0 comments Download
M src/wasm/wasm-objects.cc View 1 2 3 4 5 6 7 8 5 chunks +7 lines, -9 lines 0 comments Download
M src/wasm/wasm-text.cc View 1 2 3 4 5 6 7 8 1 chunk +1 line, -1 line 0 comments Download
M test/unittests/base/logging-unittest.cc View 1 2 3 4 5 6 7 8 1 chunk +48 lines, -8 lines 0 comments Download

Depends on Patchset:

Messages

Total messages: 74 (58 generated)
Clemens Hammacher
4 years ago (2016-11-24 11:33:04 UTC) #13
Clemens Hammacher
+ishell I heard you have fun reviewing C++ template magic :)
4 years ago (2016-11-24 12:22:00 UTC) #17
titzer
https://codereview.chromium.org/2526783002/diff/20001/src/base/logging.h File src/base/logging.h (right): https://codereview.chromium.org/2526783002/diff/20001/src/base/logging.h#newcode118 src/base/logging.h:118: template <typename Lhs, typename Rhs> This is a nasty ...
4 years ago (2016-11-24 12:57:31 UTC) #18
Clemens Hammacher
https://codereview.chromium.org/2526783002/diff/20001/src/base/logging.h File src/base/logging.h (right): https://codereview.chromium.org/2526783002/diff/20001/src/base/logging.h#newcode118 src/base/logging.h:118: template <typename Lhs, typename Rhs> On 2016/11/24 at 12:57:31, ...
4 years ago (2016-11-24 13:46:08 UTC) #23
Igor Sheludko
Thanks for adding more comments. lgtm with a nit https://codereview.chromium.org/2526783002/diff/60001/src/base/logging.h File src/base/logging.h (right): https://codereview.chromium.org/2526783002/diff/60001/src/base/logging.h#newcode156 src/base/logging.h:156: ...
4 years ago (2016-11-24 15:37:12 UTC) #26
titzer
lgtm
4 years ago (2016-11-24 15:53:41 UTC) #27
Clemens Hammacher
https://codereview.chromium.org/2526783002/diff/60001/src/base/logging.h File src/base/logging.h (right): https://codereview.chromium.org/2526783002/diff/60001/src/base/logging.h#newcode156 src/base/logging.h:156: DEFINE_SIGNED_MISMATCH_COMP(is_unsigned_vs_signed, GE, CmpLEImpl(rhs, lhs)) On 2016/11/24 at 15:37:12, Igor ...
4 years ago (2016-11-24 17:06:31 UTC) #30
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2526783002/80001
4 years ago (2016-11-24 17:51:52 UTC) #35
commit-bot: I haz the power
Committed patchset #5 (id:80001)
4 years ago (2016-11-24 17:53:31 UTC) #37
commit-bot: I haz the power
Patchset 5 (id:??) landed as https://crrev.com/5925074a9dab5a8577766545b91b62f2c531d3dc Cr-Commit-Position: refs/heads/master@{#41275}
4 years ago (2016-11-24 17:53:47 UTC) #39
Clemens Hammacher
A revert of this CL (patchset #5 id:80001) has been created in https://codereview.chromium.org/2531533003/ by clemensh@chromium.org. ...
4 years ago (2016-11-24 19:14:54 UTC) #40
Igor Sheludko
lgtm https://codereview.chromium.org/2526783002/diff/100001/test/unittests/base/logging-unittest.cc File test/unittests/base/logging-unittest.cc (right): https://codereview.chromium.org/2526783002/diff/100001/test/unittests/base/logging-unittest.cc#newcode33 test/unittests/base/logging-unittest.cc:33: CHECK_SUCCEED(EQ, -0.0, -0.0) Maybe also test a case ...
4 years ago (2016-11-29 14:12:04 UTC) #53
Clemens Hammacher
Thanks! Will land tomorrow morning then. https://codereview.chromium.org/2526783002/diff/100001/test/unittests/base/logging-unittest.cc File test/unittests/base/logging-unittest.cc (right): https://codereview.chromium.org/2526783002/diff/100001/test/unittests/base/logging-unittest.cc#newcode33 test/unittests/base/logging-unittest.cc:33: CHECK_SUCCEED(EQ, -0.0, -0.0) ...
4 years ago (2016-11-29 17:18:43 UTC) #58
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2526783002/160001
4 years ago (2016-12-01 08:50:58 UTC) #70
commit-bot: I haz the power
Committed patchset #9 (id:160001)
4 years ago (2016-12-01 08:52:37 UTC) #72
commit-bot: I haz the power
4 years ago (2016-12-01 08:53:13 UTC) #74
Message was sent while issue was closed.
Patchset 9 (id:??) landed as
https://crrev.com/db0c86fa5f03794838ee6d1d301ca34d41f20fca
Cr-Commit-Position: refs/heads/master@{#41411}

Powered by Google App Engine
This is Rietveld 408576698