Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug with __int128_t in Clang?

Tags:

c

gcc

clang

int128

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).

like image 200
Douglas B. Staple Avatar asked May 08 '13 18:05

Douglas B. Staple


1 Answers

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.

like image 151
Douglas B. Staple Avatar answered Oct 10 '22 05:10

Douglas B. Staple