Bug with __int128_t in Clang?

99封情书 提交于 2019-12-04 00:59:31

问题


This little code compiles with both GCC and Clang, but gives different results:

#include <stdio.h>

int main(){

  __int128_t test=10;
  while(test>0){
    int myTest=(int)test;
    printf("? %d\n", myTest);
    test--;
  }

}

With GCC this counts from 10 down to 1, the intended behaviour, while for Clang it keeps on counting into negative numbers. With Clang, if I replace test-- with test-=1 then it gives the expected behaviour as well.

__int128_t is a GCC extension, so the above results only apply to non-standard C, so maybe __int128_t is "use at your own risk" in Clang.

Is this a bug in Clang, or did I make some mistake I'm not seeing?

EDIT: I'm using gcc (MacPorts gcc48 4.8-20130411_0) 4.8.1 20130411 (prerelease) and Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn).


回答1:


This was a bug in Clang, which was resolved somewhere between Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn) and Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn), see the comments -- thanks Carl and H2CO3.



来源:https://stackoverflow.com/questions/16447808/bug-with-int128-t-in-clang

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!