Bug 107227 - Fix WTF::copyLCharsFromUCharSource() to compile with -Wshorten-64-to-32
Summary: Fix WTF::copyLCharsFromUCharSource() to compile with -Wshorten-64-to-32
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords:
Depends on:
Blocks: 107093
  Show dependency treegraph
 
Reported: 2013-01-17 22:14 PST by David Kilzer (:ddkilzer)
Modified: 2013-01-18 15:49 PST (History)
3 users (show)

See Also:


Attachments
Patch (2.00 KB, patch)
2013-01-17 22:14 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v2 (2.02 KB, patch)
2013-01-17 22:25 PST, David Kilzer (:ddkilzer)
benjamin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2013-01-17 22:14:15 PST
<http://webkit.org/b/000000>

Reviewed by NOBODY (OOPS!).

Fixes the following build error:

ASCIIFastPath.h:117:59: error: implicit conversion loses integer precision: 'unsigned long' to 'const unsigned int' [-Werror,-Wshorten-64-to-32]
const unsigned endLength = length - ucharsPerLoop + 1;
~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~^~~
1 error generated.

* wtf/text/ASCIIFastPath.h:
(WTF::copyLCharsFromUCharSource): Change local variables from
unsigned to size_t.
---
 2 files changed, 20 insertions(+), 2 deletions(-)
Comment 1 David Kilzer (:ddkilzer) 2013-01-17 22:14:16 PST
Created attachment 183374 [details]
Patch
Comment 2 David Kilzer (:ddkilzer) 2013-01-17 22:22:06 PST
Comment on attachment 183374 [details]
Patch

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

> Source/WTF/ChangeLog:4
> +        Fix WTF::copyLCharsFromUCharSource() to compile with -Wshorten-64-to-32
> +        <107227>

Oops!  Trying to make webkit-patch replace bug ID placeholders in my patches.
My re.sub() fu is weak!
Comment 3 David Kilzer (:ddkilzer) 2013-01-17 22:25:18 PST
Created attachment 183376 [details]
Patch v2
Comment 4 Benjamin Poulain 2013-01-17 22:30:14 PST
Comment on attachment 183376 [details]
Patch v2

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

> Source/WTF/wtf/text/ASCIIFastPath.h:115
>      const uintptr_t sourceLoadSize = 32; // Process 32 bytes (16 UChars) each iteration
> -    const unsigned ucharsPerLoop = sourceLoadSize / sizeof(UChar);
> +    const size_t ucharsPerLoop = sourceLoadSize / sizeof(UChar);

You may want to change sourceLoadSize to size_t for the case where sizeof(size_t) < sizeof(void*)
Comment 5 David Kilzer (:ddkilzer) 2013-01-17 22:38:09 PST
(In reply to comment #4)
> (From update of attachment 183376 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=183376&action=review
> 
> > Source/WTF/wtf/text/ASCIIFastPath.h:115
> >      const uintptr_t sourceLoadSize = 32; // Process 32 bytes (16 UChars) each iteration
> > -    const unsigned ucharsPerLoop = sourceLoadSize / sizeof(UChar);
> > +    const size_t ucharsPerLoop = sourceLoadSize / sizeof(UChar);
> 
> You may want to change sourceLoadSize to size_t for the case where sizeof(size_t) < sizeof(void*)

On what systems would the size of size_t be smaller than the size of a pointer?  I can't think of any off the top of my head, but it's late and I haven't worked with any "interesting" systems recently.  :)

This code is also inside this macro:

#if OS(DARWIN) && (CPU(X86) || CPU(X86_64))

So I doubt uintptr_t and size_t are going to change sizes in those configurations.

Looking at the code, though, I guess it would be a good idea to use size_t just to match the other local variables.  Any reason why uintptr_t was chosen here to begin with?
Comment 6 Benjamin Poulain 2013-01-17 22:58:38 PST
> On what systems would the size of size_t be smaller than the size of a pointer?  I can't think of any off the top of my head, but it's late and I haven't worked with any "interesting" systems recently.  :)

I can just be wrong, but I am thinking about mixed ABI like x32.

Although, I guess it is the other way around then and sizeof(size_t) > sizeof(void*).

> This code is also inside this macro:
> 
> #if OS(DARWIN) && (CPU(X86) || CPU(X86_64))
>
> So I doubt uintptr_t and size_t are going to change sizes in those configurations.

Right! I missed that. Yep, that does not matter in this case.

> Looking at the code, though, I guess it would be a good idea to use size_t just to match the other local variables.  Any reason why uintptr_t was chosen here to begin with?

I think it was just to have a type semantically correct to explain the "/ size(...)" later.
Comment 7 David Kilzer (:ddkilzer) 2013-01-18 08:14:27 PST
(In reply to comment #6)
> > Looking at the code, though, I guess it would be a good idea to use size_t just to match the other local variables.  Any reason why uintptr_t was chosen here to begin with?
> 
> I think it was just to have a type semantically correct to explain the "/ size(...)" later.

On second thought, I think I'll leave it unchanged for now.  It can always be fixed later if it's an issue.

Thanks!
Comment 8 David Kilzer (:ddkilzer) 2013-01-18 09:27:33 PST
Committed r140162: <http://trac.webkit.org/changeset/140162>
Comment 9 Darin Adler 2013-01-18 15:49:36 PST
Comment on attachment 183376 [details]
Patch v2

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

>>> Source/WTF/wtf/text/ASCIIFastPath.h:115
>>> +    const size_t ucharsPerLoop = sourceLoadSize / sizeof(UChar);
>> 
>> You may want to change sourceLoadSize to size_t for the case where sizeof(size_t) < sizeof(void*)
> 
> On what systems would the size of size_t be smaller than the size of a pointer?  I can't think of any off the top of my head, but it's late and I haven't worked with any "interesting" systems recently.  :)
> 
> This code is also inside this macro:
> 
> #if OS(DARWIN) && (CPU(X86) || CPU(X86_64))
> 
> So I doubt uintptr_t and size_t are going to change sizes in those configurations.
> 
> Looking at the code, though, I guess it would be a good idea to use size_t just to match the other local variables.  Any reason why uintptr_t was chosen here to begin with?

Agreed that it should be size_t just for consistency. But not sure that it earns its keep as a named variable, really, since it’s just used in the line below. I think that comment would be clearer if it was on a line by itself and the “32” could just be in the line below; the comment is a great one for the ucharsPerLoop initialization.