RE: Need some clarification about optimization flags, what "exactly" does -O1 do?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andrzej Giniewicz,

> interesting, seems like something similar, any hints how to start tracking real issue?

Well, if that IS the real issue, I'd start looking for enum abuse.

For example, in some old code I had to maintain, there was this situation (simplified):

enum Bar { uno, dos, tres };
int Foo(enum Bar bar)
{
  int value = bar;
  switch(value)
  {
  case uno: return 100;
  case dos: return 200;
  case tres: return 300;
  case 4: return 400;
  case -1: return 0;
  default: return -1;
  }
}

The last three cases could happen in the code, due to sledgehammer casting.  That's undefined behavior.  The int value = bar; did not fix the undefined behavior.

Ultimately, the code was fixed to not have undefined behavior.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux