Hi,
the following C++ program seems to yield a segmentation fault
in g++ 3.4 when compiled with any of the optimization options -O*,
e.g. with "g++ -O2 bug.cpp -o bug".
class TestClass {
public:
TestClass() {
c[0] = 1;
c[1] = 2;
}
int f(const unsigned int i) { // segfault during optimization
// int f(unsigned int i) { // works fine
return c[(i==1) ? 1 : 0];
}
int c[2];
};
int main()
{
TestClass c;
int x = c.f(1);
return 0;
}
I tested the code with g++ 3.4 under Debian, CentOS and SunOS, resulting
in a segmentation fault in each case. Can anyone confirm the bug?
First, the point seems to be that the argument of the method f is a
"const unsigned int". Changing the argument either into a "const int" or
an "unsigned int" indeed yields a compileable code.
Second point: if the return value is just (i==1) ? 1 : 0, the code also
compiles fine.
Best,
Thorsten Raasch 6 3963
Thorsten Raasch wrote: the following C++ program seems to yield a segmentation fault in g++ 3.4 when compiled with any of the optimization options -O*, e.g. with "g++ -O2 bug.cpp -o bug". [...] I tested the code with g++ 3.4 under Debian, CentOS and SunOS, resulting in a segmentation fault in each case. Can anyone confirm the bug?
Please post to one of gnu.g++.* newsgroups. Specific compiler behaviour
is off-topic here, especially if there is a newsgroup dedicated to that
compiler.
[...]
Victor Bazarov wrote: (...) Please post to one of gnu.g++.* newsgroups. Specific compiler behaviour is off-topic here, especially if there is a newsgroup dedicated to that compiler.
Sorry for being OT. Especially the gnu.g++.bug newsgroup is full of
spam, so I hesitated posting there. I did try now, hopefully someone can
help me there.
Thorsten Raasch wrote: Hi,
the following C++ program seems to yield a segmentation fault in g++ 3.4 when compiled with any of the optimization options -O*, e.g. with "g++ -O2 bug.cpp -o bug". class TestClass { public: TestClass() { c[0] = 1; c[1] = 2; }
int f(const unsigned int i) { // segfault during optimization // int f(unsigned int i) { // works fine return c[(i==1) ? 1 : 0]; }
int c[2]; };
int main() { TestClass c; int x = c.f(1);
return 0; } I tested the code with g++ 3.4 under Debian, CentOS and SunOS, resulting in a segmentation fault in each case. Can anyone confirm the bug? First, the point seems to be that the argument of the method f is a "const unsigned int". Changing the argument either into a "const int" or an "unsigned int" indeed yields a compileable code. Second point: if the return value is just (i==1) ? 1 : 0, the code also compiles fine. Best, Thorsten Raasch
I get no segfault with mingw/g++ 3.4.2 under Windows XP/msys.
I would post to the gcc-help mailing list if you're getting problems
with g++.
--John Ratliff
"John Ratliff" <us**@example.n et> wrote in message
news:GdS5f.4502 21$_o.205227@at tbi_s71... Thorsten Raasch wrote: Hi,
the following C++ program seems to yield a segmentation fault in g++ 3.4 when compiled with any of the optimization options -O*, e.g. with "g++ -O2 bug.cpp -o bug". class TestClass { public: TestClass() { c[0] = 1; c[1] = 2; }
int f(const unsigned int i) { // segfault during optimization // int f(unsigned int i) { // works fine return c[(i==1) ? 1 : 0]; }
int c[2]; };
int main() { TestClass c; int x = c.f(1);
return 0; }
I get no segfault with mingw/g++ 3.4.2 under Windows XP/msys.
You didn't get segfault because compiler just silently fails and
does not produce object file.
Greetings, Bane.
Branimir Maksimovic wrote: "John Ratliff" <us**@example.n et> wrote in message news:GdS5f.4502 21$_o.205227@at tbi_s71...
Thorsten Raasch wrote:
Hi,
the following C++ program seems to yield a segmentation fault in g++ 3.4 when compiled with any of the optimization options -O*, e.g. with "g++ -O2 bug.cpp -o bug". class TestClass { public: TestClass() { c[0] = 1; c[1] = 2; }
int f(const unsigned int i) { // segfault during optimization // int f(unsigned int i) { // works fine return c[(i==1) ? 1 : 0]; }
int c[2]; };
int main() { TestClass c; int x = c.f(1);
return 0; }
I get no segfault with mingw/g++ 3.4.2 under Windows XP/msys.
You didn't get segfault because compiler just silently fails and does not produce object file.
Greetings, Bane.
You're right. I didn't notice that. I compiled one without optimization
first, and that's what I was running later with optimization turned on.
--John Ratliff
John Ratliff wrote: Branimir Maksimovic wrote:
"John Ratliff" <us**@example.n et> wrote in message news:GdS5f.4502 21$_o.205227@at tbi_s71... (...) I get no segfault with mingw/g++ 3.4.2 under Windows XP/msys.
You didn't get segfault because compiler just silently fails and does not produce object file.
Greetings, Bane.
You're right. I didn't notice that. I compiled one without optimization first, and that's what I was running later with optimization turned on.
--John Ratliff
So can you both confirm the segfault? The exact compiler versions I
tested the code with were 3.4.3 (under CentOS) and 3.4.4 (under SunOS).
Under g++ 4.0.2, the code compiles fine.
I'm currently reporting the bug to bugzilla.
By the way, does anyone know whether the gnu.g++.bug and gnu.g++.help
newsgroups are working at all? I posted my problem there yesterday, but
the posts did not arrive so far.
Best,
Thorsten Raasch This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alex Vinokur |
last post by:
For instance, we need to measure performance
of assignment 'ch1 = ch2' where ch1 and ch2 are of char type.
We need to do that for different optimization levels of the same compiler.
Here is some test program.
Environment
-----------
|
by: Rune |
last post by:
Is it best to use double quotes and let PHP expand variables inside strings,
or is it faster to do the string manipulation yourself manually?
Which is quicker?
1)
$insert = 'To Be';
$sentence = "$insert or not $insert. That is the question.";
or
|
by: AC Slater |
last post by:
Whats the simplest way to change a single stored procedures query
optimization level?
In UDB8 that is.
/F
|
by: Eugene |
last post by:
I am trying to set query optimization class in a simple SQL UDF like
this:
CREATE FUNCTION udftest ( in_item_id INT )
SPECIFIC udftest
MODIFIES SQL DATA
RETURNS TABLE( location_id INT, period_id INT )
BEGIN ATOMIC
SET CURRENT QUERY OPTIMIZATION 1;
|
by: WantedToBeDBA |
last post by:
Hi all,
db2 => create table emp(empno int not null primary key, \
db2 (cont.) => sex char(1) not null constraint s_check check \
db2 (cont.) => (sex in ('m','f')) \
db2 (cont.) => not enforced \
db2 (cont.) => enable query optimization)
DB20000I The SQL command completed successfully.
db2 => insert into emp values(1,'m')
| |
by: Kunal |
last post by:
Hello,
I need help in removing if ..else conditions inside for loops. I have
used the following method but I am not sure whether it has actually
helped.
Below is an example to illustrate what I have used.
Original code :
c= 0 ;
for (i=0; i<999; i++)
|
by: mjbackues at yahoo |
last post by:
Hello.
I'm having a problem with the Visual Studio .net (2003) C++ speed
optimization, and hope someone can suggest a workaround.
My project includes many C++ files, most of which work fine with speed
optimization turned on. At least one does not however, though it does
work with size optimization turned on. I don't know specifically what
the optimizer is doing wrong, just that the output is incorrect. And I
know within about 10...
|
by: wkaras |
last post by:
I've compiled this code:
const int x0 = 10;
const int x1 = 20;
const int x2 = 30;
int x = { x2, x0, x1 };
struct Y
{
|
by: db2admin |
last post by:
hi,
I have query which runs great when optimization level is changed to 3
but does not run fine with default optimization level of 5. since this
is a query in java code, i do not know how can i change optimization
level of this one sql. also, developers are not comfortable with this.
i am thinking of writing stored procedure in which i can execute sql
with lower optimization level and return resultset to java code.
|
by: Ravikiran |
last post by:
Hi Friends,
I wanted know about whatt is ment by zero optimization and
sign optimization and its differences....
Thank you...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |