TrustInSoft / tis-interpreter

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

No warnings: preprocessor -- sources of indeterminacy, dependancy on a compiler etc. #109

Open ch3root opened 8 years ago

ch3root commented 8 years ago

Source code:

#include <stdio.h>

int main()
{
  printf("%s\n", __DATE__);
  printf("%s\n", __TIME__);
  printf("%s\n", __FILE__);
  printf("%d\n", __LINE__);

#if __clang__
  volatile int *p = 0;
  return *p;
#endif
}

tis-interpreter (095c3a888e4af1d29f733688f2d47f0cc881cebd) output:

[value] Analyzing a complete application starting at main
[value] Computing initial state
[value] Initial state computed

Jun 15 2016

14:02:48

test.c

8

[value] done for function main

gcc (GCC) 7.0.0 20160614 (experimental):

$ gcc -std=c11 -pedantic -Wall -Wextra -O3 -fsanitize=undefined test.c && ./a.out
Jun 15 2016
14:02:48
test.c
8

clang version 3.9.0 (trunk 271312):

$ clang -std=c11 -Weverything -O3 -fsanitize=undefined test.c && ./a.out
test.c:5:18: warning: expansion of date or time macro is not reproducible [-Wdate-time]
  printf("%s\n", __DATE__);
                 ^
test.c:6:18: warning: expansion of date or time macro is not reproducible [-Wdate-time]
  printf("%s\n", __TIME__);
                 ^
2 warnings generated.
test.c:12:10: runtime error: load of null pointer of type 'volatile int'
Segmentation fault
pascal-cuoq commented 8 years ago

Related to https://github.com/TrustInSoft/tis-interpreter/issues/87 and should be considered at the same time. tis-interpreter really works on pre-processed files. All this sanitation work can be done separately and implemented in any convenient programming language and compilation framework. Everything done by Clang should be used instead of re-implemented, and the fact that it's already warning about non-reproducible builds means that it may be the right place to continue.