Bug 236014 - [JSC] Remove compiler warning in TrailingArray.h
Summary: [JSC] Remove compiler warning in TrailingArray.h
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-02 06:42 PST by Xan Lopez
Modified: 2022-02-02 13:40 PST (History)
7 users (show)

See Also:


Attachments
v1 (1.73 KB, patch)
2022-02-02 06:44 PST, Xan Lopez
ysuzuki: review+
Details | Formatted Diff | Diff
v2 (1.82 KB, patch)
2022-02-02 11:29 PST, Xan Lopez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xan Lopez 2022-02-02 06:42:36 PST
std::distance returns 'int' here, and we are comparing it with an unsigned int size. I believe we just care about the absolute value in the comparison, so use std::abs.

Warning:

WTF/Headers/wtf/TrailingArray.h: In instantiation of 'WTF::TrailingArray<Derived, T>::TrailingArray(unsigned int, InputIterator, InputIterator) [with InputIterator = const JSC::RegisterAtOffset*; Derived = WTF::EmbeddedFixedVector<JSC::RegisterAtOffset>; T = JSC::RegisterAtOffset]':
WTF/Headers/wtf/EmbeddedFixedVector.h:99:33:   required from 'WTF::EmbeddedFixedVector<T>::EmbeddedFixedVector(unsigned int, InputIterator, InputIterator) [with InputIterator = const JSC::RegisterAtOffset*; T = JSC::RegisterAtOffset]'
WTF/Headers/wtf/EmbeddedFixedVector.h:52:29:   required from 'static WTF::UniqueRef<WTF::EmbeddedFixedVector<T> > WTF::EmbeddedFixedVector<T>::create(InputIterator, InputIterator) [with InputIterator = const JSC::RegisterAtOffset*; T = JSC::RegisterAtOffset]'
WTF/Headers/wtf/EmbeddedFixedVector.h:72:22:   required from 'WTF::UniqueRef<WTF::EmbeddedFixedVector<T> > WTF::EmbeddedFixedVector<T>::clone() const [with T = JSC::RegisterAtOffset]'
WTF/Headers/wtf/FixedVector.h:43:61:   required from 'WTF::FixedVector< <template-parameter-1-1> >::FixedVector(const WTF::FixedVector< <template-parameter-1-1> >&) [with T = JSC::RegisterAtOffset]'
WTF/Headers/wtf/FixedVector.h:59:21:   required from 'WTF::FixedVector< <template-parameter-1-1> >& WTF::FixedVector< <template-parameter-1-1> >::operator=(const WTF::FixedVector< <template-parameter-1-1> >&) [with T = JSC::RegisterAtOffset]'
../../Source/JavaScriptCore/jit/RegisterAtOffsetList.h:37:7:   required from here
WTF/Headers/wtf/TrailingArray.h:69:43: warning: comparison of integer expressions of different signedness: 'std::iterator_traits<const JSC::RegisterAtOffset*>::difference_type' {aka 'int'} and 'unsigned int' [-Wsign-compare]
   69 |         ASSERT(std::distance(first, last) == size);
WTF/Headers/wtf/Assertions.h:356:11: note: in definition of macro 'ASSERT'
  356 |     if (!(assertion)) { \
Comment 1 Xan Lopez 2022-02-02 06:44:51 PST
Created attachment 450642 [details]
v1

Remove compiler warning.
Comment 2 Yusuke Suzuki 2022-02-02 11:04:04 PST
Comment on attachment 450642 [details]
v1

View in context: https://bugs.webkit.org/attachment.cgi?id=450642&action=review

> Source/WTF/wtf/TrailingArray.h:69
> +        ASSERT(std::abs(std::distance(first, last)) == size);

I think `static_cast<size_t>(std::distance(first, last))` is better.
Comment 3 Xan Lopez 2022-02-02 11:29:04 PST
Created attachment 450678 [details]
v2

Fix compiler warning with static_cast
Comment 4 EWS 2022-02-02 13:39:15 PST
Committed r288993 (246712@main): <https://commits.webkit.org/246712@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 450678 [details].
Comment 5 Radar WebKit Bug Importer 2022-02-02 13:40:17 PST
<rdar://problem/88399028>