bugTiny C Compiler - Bugs: bug #58155, Parameter passing bug, broken...

 
 

bug #58155: Parameter passing bug, broken argument stack

Submitter:  Tyge <tylo>
Submitted:  Fri 10 Apr 2020 11:03:09 AM UTC
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       No canned response available

 

Fri 10 Apr 2020 09:01:49 PM UTC, comment #2: 

I just realized that this bug is not present in the mob branch, only the official 0.9.27 release

Tyge <tylo>
Fri 10 Apr 2020 02:10:57 PM UTC, comment #1: 

/*
// Output of this demonstates a serious bug in tcc version 0.9.27 (x86_64 Windows):
// The bug does not seem to be related to the use float vs double type, but rather the
// float literal's f-suffix. Note that 'test 5' seems to work, which may be due to
// the '-' prefix in the float literal, but there is never bug when using double float
// literals - i.e. no 'f' suffix.

x: 2  y: 20
Parameters given: -1 1 -10 10

Test 1: FAILED!: -1 -10 -10 10
Test 2: FAILED!: 10 10 10 10
Test 3: FAILED!: 1 1 10 10
Test 4: FAILED!: -1 -10 -10 10
Test 5: PASSED!: -1 1 -10 10
Test 6: PASSED!: -1 1 -10 10
*/

#include <stdio.h>

typedef float Real;
typedef Real vec4[4];

void
glm_frustum(Real left,    Real right,
            Real bottom,  Real top) {
  fprintf(stdout, "%g %g %g %g\n", left, right, bottom, top);
}

void test(void)
{
  Real x = 2.0f, y = 20.0f;

  printf("x: %g  y: %g\n", x, y);
  printf("Parameters given: %g %g %g %g\n\n", -x * 0.5f, x * 0.5f, -y * 0.5f, y * 0.5f);

  printf("Test 1: FAILED!: ");
  glm_frustum(-x * 0.5f,
               x * 0.5f,
              -y * 0.5f,
               y * 0.5f);

  printf("Test 2: FAILED!: ");
  glm_frustum(x * 0.5f,
              x * 0.5f,
              y * 0.5f,
              y * 0.5f);

  printf("Test 3: FAILED!: ");
  glm_frustum(0.5f * -x,
              0.5f *  x,
              0.5f * -y,
              0.5f *  y);

  printf("Test 4: FAILED!: ");
  glm_frustum(-x * 0.5f,
               x * 0.5f,
              -y * 0.5f,
               y * 0.5f);

  printf("Test 5: PASSED!: "); // due to '-' prefix?
  glm_frustum(-0.5f * x,
               0.5f * x,
              -0.5f * y,
               0.5f * y);

  printf("Test 6: PASSED!: "); // due to no 'f' suffixes!
  glm_frustum(-x * 0.5,
               x * 0.5,
              -y * 0.5,
               y * 0.5);
}

Tyge <tylo>
Fri 10 Apr 2020 11:03:09 AM UTC, original submission:  

A seemingly nasty bug found when running the test suite of https://github.com/recp/cglm

11 tests fails, some I think are math precision errors but should be looked into. One failed test is strange though:

test\src\cam.c (camera_decomp)

float sizes[4] = ...;
glm_vec4_print(sizes, stderr); // I added this

glm_frustum(-sizes[0] * 0.5f,
             sizes[0] * 0.5f,
            -sizes[1] * 0.5f,
             sizes[1] * 0.5f,
             ...);

Vector (float4):
        |0.0729 0.0932  72.9040 93.2276|
Inside glm_frustum:
-0.036452 -0.0466138 -0.0466138 0.0466138  // WRONG!
  assert fail in src/test_cam.c on line 54 :  ASSERTIFY(test_assert_mat4_eq(proj, proj2))

Inside glm_frustum, the first four parameters are passed wrongly - they seem mixed up, different fail when removing the minuses. Strangely, if I pass the parameter like below, problem is gone:

glm_frustum(-0.5f * sizes[0],
             0.5f * sizes[0],
            -0.5f * sizes[1],
             0.5f * sizes[1],
             ...);

sizes: Vector (float4):
        |0.0729 0.0932  72.9040 93.2276|
Inside glm_frustum:
-0.036452 0.036452 -0.0466138 0.0466138    // CORRECT!

Note that this library does not allocate any memory, so this looks like a pure argument stack problem.

To build the tests: cd cglm\test & tcc -I../include runner.c src\*.c ..\src\*.c, and execute runner.exe

NOTE: I had to patch <math.h> to enable float variants of math functions, only double variants available by default. I submitted the path into the mob branch.

Tyge <tylo>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #48804:  tcc_bug.c added by tylo (2KiB - text/plain - Short single file demo of the bug.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tylo (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-04-10 tylo Attached File- Added tcc_bug.c, #48804

    Back to the top


    Powered by Savane 3.9