这是一个错误的GCC或者是我的code错了吗? [英] Is this a bug in GCC or is my code wrong?

查看:233
本文介绍了这是一个错误的GCC或者是我的code错了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个C code:

I have this C code:

int test(signed char anim_col)
{
    if (anim_col >= 31) {
        return 1;
    } else if (anim_col <= -15) {
        return -2;
    }
    return 0;
}

这编译成以下拇指code。与-Os -mthumb采用Android NDK R4B:

That compiles to the following thumb code with -Os -mthumb using Android NDK r4b:

test:
    mov r3, #1
    cmp r0, #30
    bgt .L3
    mov r3, #0
    add r0, r0, #14
    bge .L3
    mov r3, #2
    neg r3, r3
.L3:
    mov r0, r3
    bx  lr

但随着最新的的Andr​​oid NDK R5 该编译为这破code:

But with the latest Android NDK r5 it compiles to this broken code:

test:
    mov r3, #1
    cmp r0, #30
    bgt .L3
    lsl r0, r0, #24
    lsr r0, r0, #24
    mov r3, #0
    cmp r0, #127    @@ WTF?! should be <= -15 @@
    bls .L3
    mov r3, #2
    neg r3, r3
.L3:
    mov r0, r3
    bx  lr

这看起来......奇怪。如果anim_col小于0则返回-2代替仅返回-2时小于或等于-15。完整的命令行重现,这是如下:

This seems... strange. If anim_col is less than 0 it will return -2 instead of only returning -2 when less than or equal to -15. The complete command line to reproduce this is as follows:

Android的NDK-R4B /建设/ prebuilt / Linux的的x86 / ARM-EABI-4.4.0 /斌/ ARM-EABI-GCC -c -o test.o -Os test.c的--save -temps -mthumb

android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc -c -o test.o -Os test.c --save-temps -mthumb

android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/$p$pbuilt/linux-x86/bin/arm-linux-androideabi-gcc -c -o test.o -Os test.c的--save-临时工-mthumb

android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -c -o test.o -Os test.c --save-temps -mthumb

这是一个已知的GCC错误?我觉得很难相信,这并不发生在现实生活!当然,我的code是错的?!

Is this a known GCC bug? I find it hard to believe, that doesn't happen in real life! Surely my code is wrong?!

推荐答案

这是一个GCC的bug!

由于 NDK R5B ,这个bug已经修复。

As of NDK r5b, this bug has been fixed.

在NDK的此版本不
  包括相对于任何新功能
  R5。该R5B版本解决了
  在R5版本存在以下问题:

This release of the NDK does not include any new features compared to r5. The r5b release addresses the following problems in the r5 release:


      
  • 修正了一个编译器缺陷
      在arm-linux的-androideabi-4.4.3工具链。
      产生无效的previous二进制
      当拇指指令序列
      对付签署字符。

  •   

这篇关于这是一个错误的GCC或者是我的code错了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆