args.c 853 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <u.h>
  2. #include <libc.h>
  3. /*
  4. * The whole regression test I am after here is to call regress/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. if(((uintptr_t)&p & 15) != 0){
  21. fprint(2, "%p not 16-aligned\n", &p);
  22. print("FAIL\n");
  23. exits("FAIL");
  24. }
  25. sum = 0.0;
  26. for(i = 0; i < argc; i++){
  27. p = argv[i];
  28. sum += strtod(p, nil);
  29. }
  30. fprint(2, "&sum %p\n", &sum);
  31. fprint(2, "sum %f\n", sum);
  32. print("PASS\n");
  33. exits("PASS");
  34. }