diff mbox

[5/5] target-arm: Fix warn about implicit conversion

Message ID 20160809190229.27871-5-bobby.prani@gmail.com
State New
Headers show

Commit Message

Pranith Kumar Aug. 9, 2016, 7:02 p.m. UTC
Clang warns about an implicit conversion as follows:

/mnt/devops/code/qemu/target-arm/neon_helper.c:1075:1: warning: implicit conversion from 'int' to 'int8_t' (aka 'signed char') changes value from 128 to -128 [-Wconstant-conversion]
NEON_VOP_ENV(qrshl_s8, neon_s8, 4)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/mnt/devops/code/qemu/target-arm/neon_helper.c:116:83: note: expanded from macro 'NEON_VOP_ENV'
uint32_t HELPER(glue(neon_,name))(CPUARMState *env, uint32_t arg1, uint32_t arg2) \
                                                                                  ^
/mnt/devops/code/qemu/target-arm/neon_helper.c:106:5: note: expanded from macro '\
NEON_VOP_BODY'
    NEON_DO##n; \
    ^~~~~~~~~~
<scratch space>:21:1: note: expanded from here
NEON_DO4
^~~~~~~~
/mnt/devops/code/qemu/target-arm/neon_helper.c:93:5: note: expanded from macro 'NEON_DO4'
    NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1); \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/mnt/devops/code/qemu/target-arm/neon_helper.c:1054:23: note: expanded from macro 'NEON_FN'
            dest = (1 << (sizeof(src1) * 8 - 1)); \
                 ~  ~~^~~~~~~~~~~~~~~~~~~~~~~~~

Fix it by casting to appropriate type.

Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
 target-arm/neon_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peter Maydell Aug. 11, 2016, 10:50 a.m. UTC | #1
On 9 August 2016 at 20:02, Pranith Kumar <bobby.prani@gmail.com> wrote:
> Clang warns about an implicit conversion as follows:
>
> /mnt/devops/code/qemu/target-arm/neon_helper.c:1075:1: warning: implicit conversion from 'int' to 'int8_t' (aka 'signed char') changes value from 128 to -128 [-Wconstant-conversion]
> NEON_VOP_ENV(qrshl_s8, neon_s8, 4)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /mnt/devops/code/qemu/target-arm/neon_helper.c:116:83: note: expanded from macro 'NEON_VOP_ENV'
> uint32_t HELPER(glue(neon_,name))(CPUARMState *env, uint32_t arg1, uint32_t arg2) \
>                                                                                   ^
> /mnt/devops/code/qemu/target-arm/neon_helper.c:106:5: note: expanded from macro '\
> NEON_VOP_BODY'
>     NEON_DO##n; \
>     ^~~~~~~~~~
> <scratch space>:21:1: note: expanded from here
> NEON_DO4
> ^~~~~~~~
> /mnt/devops/code/qemu/target-arm/neon_helper.c:93:5: note: expanded from macro 'NEON_DO4'
>     NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1); \
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /mnt/devops/code/qemu/target-arm/neon_helper.c:1054:23: note: expanded from macro 'NEON_FN'
>             dest = (1 << (sizeof(src1) * 8 - 1)); \
>                  ~  ~~^~~~~~~~~~~~~~~~~~~~~~~~~
>
> Fix it by casting to appropriate type.
>
> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
> ---
>  target-arm/neon_helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target-arm/neon_helper.c b/target-arm/neon_helper.c
> index 1f1844f..ebdf7c9 100644
> --- a/target-arm/neon_helper.c
> +++ b/target-arm/neon_helper.c
> @@ -1051,7 +1051,7 @@ uint64_t HELPER(neon_qrshl_u64)(CPUARMState *env, uint64_t val, uint64_t shiftop
>      if (tmp >= (ssize_t)sizeof(src1) * 8) { \
>          if (src1) { \
>              SET_QC(); \
> -            dest = (1 << (sizeof(src1) * 8 - 1)); \
> +            dest = (typeof(dest))(1 << (sizeof(src1) * 8 - 1)); \
>              if (src1 > 0) { \
>                  dest--; \
>              } \

A bit ugly but I guess it works. (The code is
deliberately setting dest to "most negative integer
that fits into src1 type".)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Peter Maydell Aug. 12, 2016, 12:20 p.m. UTC | #2
On 11 August 2016 at 11:50, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 9 August 2016 at 20:02, Pranith Kumar <bobby.prani@gmail.com> wrote:
>> Clang warns about an implicit conversion as follows:
>>
>> /mnt/devops/code/qemu/target-arm/neon_helper.c:1075:1: warning: implicit conversion from 'int' to 'int8_t' (aka 'signed char') changes value from 128 to -128 [-Wconstant-conversion]
>> NEON_VOP_ENV(qrshl_s8, neon_s8, 4)
>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> /mnt/devops/code/qemu/target-arm/neon_helper.c:116:83: note: expanded from macro 'NEON_VOP_ENV'
>> uint32_t HELPER(glue(neon_,name))(CPUARMState *env, uint32_t arg1, uint32_t arg2) \
>>                                                                                   ^
>> /mnt/devops/code/qemu/target-arm/neon_helper.c:106:5: note: expanded from macro '\
>> NEON_VOP_BODY'
>>     NEON_DO##n; \
>>     ^~~~~~~~~~
>> <scratch space>:21:1: note: expanded from here
>> NEON_DO4
>> ^~~~~~~~
>> /mnt/devops/code/qemu/target-arm/neon_helper.c:93:5: note: expanded from macro 'NEON_DO4'
>>     NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1); \
>>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> /mnt/devops/code/qemu/target-arm/neon_helper.c:1054:23: note: expanded from macro 'NEON_FN'
>>             dest = (1 << (sizeof(src1) * 8 - 1)); \
>>                  ~  ~~^~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> Fix it by casting to appropriate type.
>>
>> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
>> ---
>>  target-arm/neon_helper.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/target-arm/neon_helper.c b/target-arm/neon_helper.c
>> index 1f1844f..ebdf7c9 100644
>> --- a/target-arm/neon_helper.c
>> +++ b/target-arm/neon_helper.c
>> @@ -1051,7 +1051,7 @@ uint64_t HELPER(neon_qrshl_u64)(CPUARMState *env, uint64_t val, uint64_t shiftop
>>      if (tmp >= (ssize_t)sizeof(src1) * 8) { \
>>          if (src1) { \
>>              SET_QC(); \
>> -            dest = (1 << (sizeof(src1) * 8 - 1)); \
>> +            dest = (typeof(dest))(1 << (sizeof(src1) * 8 - 1)); \
>>              if (src1 > 0) { \
>>                  dest--; \
>>              } \
>
> A bit ugly but I guess it works. (The code is
> deliberately setting dest to "most negative integer
> that fits into src1 type".)
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

Applied to master, thanks.

-- PMM
diff mbox

Patch

diff --git a/target-arm/neon_helper.c b/target-arm/neon_helper.c
index 1f1844f..ebdf7c9 100644
--- a/target-arm/neon_helper.c
+++ b/target-arm/neon_helper.c
@@ -1051,7 +1051,7 @@  uint64_t HELPER(neon_qrshl_u64)(CPUARMState *env, uint64_t val, uint64_t shiftop
     if (tmp >= (ssize_t)sizeof(src1) * 8) { \
         if (src1) { \
             SET_QC(); \
-            dest = (1 << (sizeof(src1) * 8 - 1)); \
+            dest = (typeof(dest))(1 << (sizeof(src1) * 8 - 1)); \
             if (src1 > 0) { \
                 dest--; \
             } \