NO

Author Topic: [FIXED] 'Access violation' at 0x004a8b9c (optimizer thinks too much?)  (Read 2339 times)

iZzz32

  • Guest
I know the code is weird :-) It works when you do -DUSE_VAR or remove -O2.
Code: [Select]
#include <string.h>
#include <stdio.h>

static char foo[1024];

int main(int argc, char * argv[])
{
  size_t            n;
  char *            x;

  if (argc < 2)
    return -1;

  n = strlen(argv[1]);
  strcpy(foo, argv[1]);
 
#ifdef USE_VAR
  x = (n >= 4 && strcmp(&foo[n - 4], ".bar") == 0) ? &foo[n - 4] : &foo[n];
  strcpy(x, ".baz");
#else
  strcpy((n >= 4 && strcmp(&foo[n - 4], ".bar") == 0) ? &foo[n - 4] : &foo[n], ".baz");
#endif

  printf("Result: %s\n", foo);
  return 0;
}

Quote from: pocc -c -O2 test.c

test.c(21): warning #2242: Call to 'strcmp' removed.   <-- WHY???
test.c(9): warning #2114: Local 'x' is not referenced.
test.c(6): fatal error: Internal error: 'Access violation' at 0x004a8b9c.

It is Pelles ISO C Compiler, Version 7.00.9 from the latest 7.0 RC3.
« Last Edit: June 22, 2012, 02:22:19 PM by iZzz32 »

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: 'Access violation' at 0x004a8b9c (optimizer thinks too much?)
« Reply #1 on: June 03, 2012, 05:05:23 PM »
Yes, yuck about the code -- but at least I can reproduce the problem...
/Pelle