Re: Strange optimization results

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

 



I think there's a missed-optimization bug in GCC.

=========================== testcase1.cc ===========================
struct my_number
{
  unsigned number;
  my_number(unsigned i) : number(i) { }
};

const struct my_number n(1);

int main(void)
{
  unsigned i, result = 1;

  for (i = 0; i < 18; i++)
    result &= n.number;

  return result;
}
=========================== testcase2.cc ===========================
struct my_string
{
  char string[10];
  unsigned size;
  my_string(const char*);
};

inline my_string::my_string(const char* str)
{
  size = __builtin_strlen(str);
  __builtin_memcpy(string, str, size);
}

inline bool operator==(const my_string& str1, const my_string& str2)
{
  return str1.size == str2.size &&
         !__builtin_memcmp(str1.string, str2.string, str1.size);
}

const my_string s1("abcdef");
const my_string s2("abcdef");

int main(void)
{
  bool result = true;

  for (int i = 0; i < 18; i++)
    result &= s1 == s2;

  return result;
}
====================================================================

Should it be reported to Bugzilla?


[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