drmortalwombat / oscar64

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

Variable increment ignored in for loop #108

Closed AGPX closed 1 month ago

AGPX commented 1 month ago

In the following code x is 0 and doesn't change, probably because the optimizer recognize that the for loop does nothing, expect increasing the variable x:

#include "common.h"
double
foo (void)
{
  return 0.0;
}

void
do_sibcall (void)
{
  (void) foo ();
}

int
main (void)
{
   double x;

   for (x = 0; x < 20; x++)
      do_sibcall ();

   if (!(x >= 10))
      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.