Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Recent Ubuntu8.04 troubles confirmed to be the compiler bug
Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15892] Wed, 14 May 2008 13:14 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I was hunting this one for about 12 hours total, tracked the problem down, seen the broken assembly and prepared the isolated test.

This test should print "32", which is the sizeof(Item). But if you compile it with -O3 flag under

gcc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)

it prints 0.

Please check, maybe there is still something wrong with code, some undefined behaviour:

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));
}


GCCBug3.cpp
#include "GCCBug.h"

int main(int argc, char argv[])
{
	Bar b;
	b.DoTest(0, 1);
	return 0;
}


(Note, it is probably important to keep all this in 4 specific files to avoid specific inlining variants).

Compiled with flags:

-ggdb -g2 -fexceptions -O3 -x c++

Mirek
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15899 is a reply to message #15892] Thu, 15 May 2008 00:14 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
confirmed. After rebuild with gcc-4.1 all memory violations went away and theide become stable as used to be in ubuntu feisty.

Ciao

Max
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15902 is a reply to message #15892] Thu, 15 May 2008 10:54 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
So is this reported to GCC team or at least to Ubuntu so they can push upstream a bit?
I think this is quite critical, I will probably search trough launchpad (ubuntu bug+stuff system) today to see if it is reported and if not, I will report it.
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15904 is a reply to message #15902] Thu, 15 May 2008 13:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
GCC yes.

Ubuntu not. I would be glad if you would do it.

Mirek
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15905 is a reply to message #15892] Thu, 15 May 2008 13:16 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Can you post here some URL to GCC bug report, so it's easy for everyone from this forum to track it? Smile I'm really lazy today. Very Happy
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15906 is a reply to message #15905] Thu, 15 May 2008 13:47 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36235
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15907 is a reply to message #15892] Thu, 15 May 2008 14:28 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Reported to launchpad too, but I'm afraid they will not change the GCC version in 8.04.
https://bugs.launchpad.net/gcc/+bug/230682

Anyway, the 4.2 is already uploaded into Intrepid too (next Ubuntu 8.10 release), so I hope they will move to 4.3 ASAP at least there.
Although till it's release date there will be maybe yet another "current" version of gcc.

Let's see.
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15912 is a reply to message #15907] Thu, 15 May 2008 17:17 Go to previous messageGo to next message
bytefield is currently offline  bytefield
Messages: 210
Registered: December 2007
Experienced Member
Edit: (compiler confusion Confused )

cdabbd745f1234c2751ee1f932d1dd75

[Updated on: Thu, 15 May 2008 20:46]

Report message to a moderator

Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15992 is a reply to message #15892] Wed, 21 May 2008 22:30 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
I'am using debian testing with 2007.1. My g++ version is 4.2.3 and i have no problems with U++. Normal or not ?
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15994 is a reply to message #15992] Wed, 21 May 2008 23:47 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
cocob wrote on Wed, 21 May 2008 22:30

I'am using debian testing with 2007.1. My g++ version is 4.2.3 and i have no problems with U++. Normal or not ?


It depends... If you use 2007.1 binary, which is compiled against GCC 4.1 or earlier, you won't have problems RUNNING theide, but compiling against GCC 4.2.3 you've got a good chance to have problems with your compiled apps.
More, if you don't enable -O3 optimization (or, better said, -finlune-functions optimization, which is in -O3), you shouldn't have problems.

Ciao

Max
Re: Recent Ubuntu8.04 troubles confirmed to be the compiler bug [message #15997 is a reply to message #15892] Thu, 22 May 2008 09:37 Go to previous message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
From gcc bug: "4.2.4 is being released, changing milestones to 4.2.5."
Previous Topic: Another new ubuntu problem...
Next Topic: Ideas for an SVN addition to theide
Goto Forum:
  


Current Time: Thu Mar 28 19:08:39 CET 2024

Total time taken to generate the page: 0.01620 seconds