TrustInSoft / tis-interpreter

An interpreter for finding subtle bugs in programs written in standard C
565 stars 28 forks source link

GCC Builtins #144

Open mrigger opened 6 years ago

mrigger commented 6 years ago

We are currently studying the usage of GCC builtins by GitHub projects and how well various tools support them. To that end, we are also developing a test suite for the most frequently used machine-independent GCC builtins (available at https://github.com/gcc-builtins/tests/tree/master/test-cases). We'd be glad to contribute the test suite (or parts of it) to the project, if you are interested.

While evaluating the builtin support in Frama-C, I was advised to use the -machdep gcc_x86_32 flag to enable support for compiler extensions. When turning on this flag for the tis-interpreter, it successfully executed 88 out of 100 builtin test cases. Surprisingly (to me at least), it correctly executed the __sync builtin test cases and the __builtin_object_size test case which seem to be a problem for Frama-C.

In terms of failing test cases, 11 tests failed since the NAN and INFINITY macros were not implemented, which is not related to builtin support itself (they are also not supported by Frama-C). However, 10 of these test cases also failed because the builtins were not recognized; these builtins provided operations to compare floating point numbers (__builtin_isinf, __builtin_islessgreater, __builtin_isless, __builtin_copysign, __builtin_islessequal, __builtin_isgreaterequal, __builtin_isnan, __builtin_signbit, __builtin_isunordered, __builtin_isgreater). Furthermore, __builtin_memchr was not supported. The test case below results in the warning warning: Calling undeclared function __builtin_memchr. Old style K&R code?:

#include <assert.h>
#include <string.h>

char* str = "hello test!";

int main() {
  char needle = '!';
  assert(__builtin_memchr(str, needle, strlen(str)) == &str[10]);
}

Note: I realized that the latest binary snapshop is from 2016. I will try to test with a newer version.