Launchpad has imported 6 comments from the remote bug at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36235.
If you reply to an imported comment from within Launchpad, your comment will be sent to the remote bug automatically. Read more about Launchpad's inter-bugtracker facilities at https://documentation.ubuntu.com/launchpad/user/reference/bugs/multi-project-bugs/about-multi-project-bugs/#bugs-in-external-trackers. ------------------------------------------------------------------------ On 2008-05-14T16:51:36+00:00 Cxl-s wrote: g++ (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Used flags: -ggdb -g2 -fexceptions -O3 -x c++ Code (has to be in 4 files to keep inlining constelation): ----------------- CGGBug.h #include <stdio.h> #include <string.h> #include <stdlib.h> #include <new> template <class T> inline const T& my_max(const T& a, const T& b) { return a > b ? a : b; } template <class T> inline const T& my_min(const T& a, const T& b) { return a < b ? a : b; } template <class T> inline T minmax(T x, T _min, T _max) { return my_min(my_max(x, _min), _max); } void *MemoryAllocSz(size_t& sz); void MemoryFree(void *); template <class T> class Vector { T *vector; int items; int alloc; static void RawFree(T *ptr) { if(ptr) MemoryFree(ptr); } static T *RawAlloc(int& n); void RawInsert(int q, int count); public: void InsertN(int q, int count); const T& First() { return vector[0]; } int GetCount() const { return items; } Vector() { vector = NULL; items = alloc = 0; } }; template <class T> T * Vector<T>::RawAlloc(int& n) { size_t sz0 = n * sizeof(T); size_t sz = sz0; void *q = MemoryAllocSz(sz); n += (int)((sz - sz0) / sizeof(T)); return (T *)q; } template <class T> void Vector<T>::RawInsert(int q, int count) { if(!count) return; if(items + count > alloc) { T *newvector = RawAlloc(alloc = alloc + my_max(alloc, count)); if(vector) { memcpy(newvector, vector, q * sizeof(T)); memcpy(newvector + q + count, vector + q, (items - q) * sizeof(T)); RawFree(vector); } vector = newvector; } else { memmove(vector + q + count, vector + q, (items - q) * sizeof(T)); } items += count; } template <class T> void Vector<T>::InsertN(int q, int count) { RawInsert(q, count); } void *MemoryAllocSz(size_t& sz); void MemoryFree(void *); struct Item { char h[32]; }; struct Bar { Vector<Item> li; void DoTest(int i, int count); }; ------- GCCBug1.cpp: #include "GCCBug.h" char array[256]; void *MemoryAllocSz(size_t& sz) { printf("%d\n", sz); return array; } void MemoryFree(void *) {} --------- GCCBug2.cpp: #include "GCCBug.h" void Bar::DoTest(int i, int count) { li.InsertN(minmax(i, 0, li.GetCount()), my_max(count, 0)); } -------- GCCBug.cpp: #include "GCCBug.h" int main(int argc, char argv[]) { Bar b; b.DoTest(0, 1); return 0; } --------------- This code should print "32" (== sizeof(T)) and it does when compiled -Os, but compiled -O3 it prints "0". In assembly there seems a bug at the beginning of inlined "RawAlloc" method around the shift to perform "n * sizeof(T)" multiply. Note that changing sizeof(T) to something else than power of two makes the code work as expected. AMD64 compiler seems to be affected as well. Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-4.2/+bug/230682/comments/0 ------------------------------------------------------------------------ On 2008-05-14T16:52:44+00:00 Cxl-s wrote: (fixed compiler version) Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-4.2/+bug/230682/comments/1 ------------------------------------------------------------------------ On 2008-05-14T16:54:50+00:00 Pinskia wrote: Can you try 4.3.0? Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-4.2/+bug/230682/comments/2 ------------------------------------------------------------------------ On 2008-05-15T08:51:27+00:00 Rguenth wrote: Confirmed. It fails with -O -finline-functions -fstrict-aliasing. Works with 4.3.0. I suppose this is a dup of one of the known alias bugs with 4.2. Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-4.2/+bug/230682/comments/3 ------------------------------------------------------------------------ On 2008-05-19T20:25:22+00:00 Jsm28 wrote: 4.2.4 is being released, changing milestones to 4.2.5. Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-4.2/+bug/230682/comments/5 ------------------------------------------------------------------------ On 2009-03-31T15:38:26+00:00 Jsm28 wrote: Closing 4.2 branch, fixed in 4.3. Reply at: https://bugs.launchpad.net/ubuntu/+source/gcc-4.2/+bug/230682/comments/7 -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/230682 Title: [PR36235] C++ is broken with -O3 To manage notifications about this bug go to: https://bugs.launchpad.net/gcc/+bug/230682/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
