Bug with __int128_t in Clang?

2019-04-26 11:27发布

问题:

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.



标签: c gcc clang int128