New issue
Advanced search Search tips

Issue 612995 link

Starred by 5 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug

Blocked on:
issue 554717

Blocking:
issue 761570



Sign in to add a comment

constexpr all of base/numerics

Project Member Reported by jsc...@chromium.org, May 18 2016

Issue description

Now that we have constexpr support, make all of the base/numerics APIs constexpr compliant.
 
Project Member

Comment 1 by bugdroid1@chromium.org, May 19 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/5ae3e261c39b24073806b31c1701865fa4134842

commit 5ae3e261c39b24073806b31c1701865fa4134842
Author: jschuh <jschuh@chromium.org>
Date: Thu May 19 05:07:25 2016

Cleanup some constexpr nits in base/numerics

Cleanup some unneeded inlines and make two trivial cases constexpr

BUG=612995

Review-Url: https://codereview.chromium.org/1995753003
Cr-Commit-Position: refs/heads/master@{#394680}

[modify] https://crrev.com/5ae3e261c39b24073806b31c1701865fa4134842/base/numerics/safe_conversions.h
[modify] https://crrev.com/5ae3e261c39b24073806b31c1701865fa4134842/base/numerics/safe_conversions_impl.h
[modify] https://crrev.com/5ae3e261c39b24073806b31c1701865fa4134842/base/numerics/safe_math_impl.h

Project Member

Comment 2 by bugdroid1@chromium.org, Nov 8 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb

commit 00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb
Author: jschuh <jschuh@chromium.org>
Date: Tue Nov 08 04:59:34 2016

Make checked_cast a constexpr

Wraps the CHECK in a handler. This makes the non-CHECK case a clean
constexpr, and has the nice effect of throwing a compile error if the
compile-time evaluation can determine that a runtime CHECK would hit.
Also had to fix a few incorrect uses of base::checked_cast (hence
the need for the NOPRESUBMIT to cover the media directory).

BUG=612995
NOPRESUBMIT=true
TBR=vabr@chromium.org,hubbe@chromium.org,dmurph@chromium.org

Review-Url: https://codereview.chromium.org/2481903002
Cr-Commit-Position: refs/heads/master@{#430519}

[modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/base/numerics/safe_conversions.h
[modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/base/numerics/safe_numerics_unittest.cc
[modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/components/autofill/core/common/save_password_progress_logger.cc
[modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/media/formats/mp2t/es_parser_h264.cc
[modify] https://crrev.com/00c1837ccba1c6da4cb1e9b26539a6c3801bb2fb/storage/browser/blob/blob_data_builder.cc

Project Member

Comment 3 by bugdroid1@chromium.org, Nov 22 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/3223ae27f45270fc80e247d473c9cb8c19e91aa8

commit 3223ae27f45270fc80e247d473c9cb8c19e91aa8
Author: jschuh <jschuh@chromium.org>
Date: Tue Nov 22 03:35:48 2016

Convert simple CheckedNumeric functions to constexpr

NOTRY=true
TBR=tsepez@chromium.org
BUG=612995

Review-Url: https://codereview.chromium.org/2522543002
Cr-Commit-Position: refs/heads/master@{#433775}

[modify] https://crrev.com/3223ae27f45270fc80e247d473c9cb8c19e91aa8/base/numerics/safe_math.h
[modify] https://crrev.com/3223ae27f45270fc80e247d473c9cb8c19e91aa8/base/numerics/safe_math_impl.h

Project Member

Comment 4 by bugdroid1@chromium.org, Jan 3 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/7308c7f7745c8bce834250d1a93e3c4501c65ca4

commit 7308c7f7745c8bce834250d1a93e3c4501c65ca4
Author: jschuh <jschuh@chromium.org>
Date: Tue Jan 03 23:09:34 2017

Convert remaining CheckedNumeric unary operators to constexpr

This swaps out some unnecessarily complex checked functions with simpler
wrappers that support constexpr.

BUG=612995

Review-Url: https://codereview.chromium.org/2612443002
Cr-Commit-Position: refs/heads/master@{#441239}

[modify] https://crrev.com/7308c7f7745c8bce834250d1a93e3c4501c65ca4/base/numerics/safe_math.h
[modify] https://crrev.com/7308c7f7745c8bce834250d1a93e3c4501c65ca4/base/numerics/safe_math_impl.h

Comment 5 by jsc...@chromium.org, Jul 26 2017

Blockedon: 554717

Comment 6 by jsc...@chromium.org, Jul 26 2017

Components: -Security Internals>BaseNumerics

Comment 7 by m...@chromium.org, Sep 2 2017

Blocking: 761570
Project Member

Comment 8 by bugdroid1@chromium.org, Oct 1 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/3725ec39917fea4cc350f0abb8dde4552e955054

commit 3725ec39917fea4cc350f0abb8dde4552e955054
Author: Justin Schuh <jschuh@chromium.org>
Date: Sun Oct 01 03:44:27 2017

Make ClampedNumeric and CheckedNumeric constexpr

Convert the remaining CheckedNumeric and ClampedNumeric methods to be
fully C++14 constexpr compliant. This also includes the following
dependent changes:
* The constexpr allowed some compile-time optimizations in ClampedAddOp
  and ClampedSubOp, which required restructuring the overflow handling
  to get correct saturation semantics. (New tests cover this.)
* The Clamped*FastAsmOp implementations included redundant saturation
  code, which was removed.

Bug: 612995
Change-Id: I0e0397968712ee06f8beff2f74c638cab01f34bb
Reviewed-on: https://chromium-review.googlesource.com/603127
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Justin Schuh <jschuh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505494}
[modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/checked_math.h
[modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/checked_math_impl.h
[modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/clamped_math.h
[modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/clamped_math_impl.h
[modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/safe_math_clang_gcc_impl.h
[modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/numerics/safe_math_shared_impl.h
[modify] https://crrev.com/3725ec39917fea4cc350f0abb8dde4552e955054/base/safe_numerics_unittest.cc

The commit above broke GCC builds (I've tested 6.3.0 and 7.2.1):

../../base/numerics/checked_math_impl.h: In instantiation of ‘static constexpr bool base::internal::CheckedSubOp<T, U, typename std::enable_if<(std::is_integral<_Tp>::value && std::is_integral<_Tp2>::value)>::type>::Do(T, U, V*) [with V = short unsigned int; T = short unsigned int; U = short unsigned int]’:
../../base/numerics/checked_math.h:245:29:   required from ‘constexpr base::internal::CheckedNumeric<T>& base::internal::CheckedNumeric<T>::MathOp(R) [with M = base::internal::CheckedSubOp; R = short unsigned int; T = short unsigned int]’
../../base/numerics/checked_math.h:340:1:   required from ‘constexpr base::internal::CheckedNumeric<T>& base::internal::CheckedNumeric<T>::operator-=(R) [with Src = short unsigned int; T = short unsigned int]’
../../base/metrics/histogram_samples.cc:145:20:   required from here
../../base/numerics/checked_math_impl.h:130:15: error: uninitialized variable ‘presult’ in ‘constexpr’ function
     Promotion presult;
               ^~~~~~~
Friendly ping

Sign in to add a comment