TrustInSoft / tis-interpreter

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

No warning: copying padding in long double #106

Open ch3root opened 8 years ago

ch3root commented 8 years ago

It seems a full implementation of long double is not really required to illustrated the issue with padding in it.

Source code:

#include <string.h>
#include <stdio.h>

int main()
{
  long double x, y;
  memset(&x, 0, sizeof x);
  memset(&y, -1, sizeof y);

  y = x;
  printf("%d\n", ((unsigned char *)&y)[10]);
}

tis-interpreter (72384b0a1f37636c879e6f499785fb4e1292ee91) output:

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

0

[value] done for function main

gcc (GCC) 7.0.0 20160608 (experimental):

$ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out
255

clang version 3.9.0 (trunk 271312):

$ clang -std=c11 -Weverything test.c && ./a.out
255
pascal-cuoq commented 8 years ago

It's not that long double is not fully implemented, it's that it is not supported, period. tis-interpreter does not require as pre-requisite a platform where 80-bit long doubles are available, and these would be a pain to emulate in software, so long double can not be used at all in interpreted programs. The examples showing how it is interesting because it's a scalar type with padding on x86-64 are not making a case for adding support for it.