drmortalwombat / oscar64

Optimizing Small memory C Compiler Assembler and Runtime for C64
GNU General Public License v3.0
273 stars 24 forks source link

Wrong number of iterations #115

Closed AGPX closed 1 month ago

AGPX commented 1 month ago

In the following test the for loop inside the f function, misteriously, iterates 240 times instead of 16:

#include "common.h"
/* "i" overflows in f().  Check that x[i] is not treated as a giv.  */
#include <limits.h>

void f (unsigned int *x)
{
  unsigned char i;
  int j;

  i = 0x10;
  for (j = 0; j < 0x10; j++)
    {
      i += 0xe8;
      x[i] = 0;
      i -= 0xe7;
    }
}

int main ()
{
  unsigned int x[256];
  int i;

  for (i = 0; i < 256; i++)
    x[i] = 1;
  f (x);
  for (i = 0; i < 256; i++)
    if (x[i] != (i >= 0x08 && i < 0xf8))
      abort ();
  exit (0);
}

with common.h:

#pragma once

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

#define register

#define double float

#define __attribute__(x)

#define __complex__

#define NULL (void *)0

static void abort()
{
    printf("** TEST FAILED **!\n");
}

static void abort2(const char *msg)
{
    printf("%s\n", msg);
    printf("** TEST FAILED **!\n");
}
drmortalwombat commented 1 month ago

Fixed

AGPX commented 1 month ago

Test passed.