1
0

args.c 741 B

1234567891011121314151617181920212223242526272829303132
  1. #include <u.h>
  2. #include <lib9.h>
  3. /*
  4. * The whole regression test I am after here is to call qa/kern/args with
  5. * arguments of various lengths, in order to trigger different stack alignments
  6. * due to varying amounts of stuff in args.
  7. *
  8. * It turned out that gcc compiles fprintf into something that uses
  9. * fpu instructions which require the stack to be 16-aligned, so in
  10. * fact the fprint for sum here would suicide the process if the stack
  11. * it got happened to be not 16-aligned.
  12. *
  13. */
  14. void
  15. main(int argc, char *argv[])
  16. {
  17. char *p;
  18. int i;
  19. double sum;
  20. sum = 0.0;
  21. for(i = 0; i < argc; i++){
  22. p = argv[i];
  23. sum += strtod(p, nil);
  24. }
  25. fprint(2, "&sum %p\n", &sum);
  26. fprint(2, "sum %f\n", sum);
  27. print("PASS\n");
  28. exits("PASS");
  29. }