Bug 24737 - const bool& optimization error
Summary: const bool& optimization error
Status: RESOLVED DUPLICATE of bug 23326
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.1
: P3 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-11-08 16:39 UTC by Fredrik Littmarck
Modified: 2005-11-08 16:46 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test Case (2.75 KB, application/zip)
2005-11-08 16:45 UTC, Fredrik Littmarck
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fredrik Littmarck 2005-11-08 16:39:45 UTC
When using gcc 4.0.0 or 4.0.1 on MacOS, the following code fails when optimizations (-O1 - -O3) is turned on:

--- snip ---

bool TestFoo(const bool& trueBool) {
	CFoo foo;

//	bool falseBool = trueBool ? false: true;	// This works!
	bool falseBool = !trueBool;					// This does not work!
	if (falseBool != foo.GetFalse()) {
		if (!falseBool) {						// Should never be executed!
			foo.DoSomething(1);
			return true;
		}
	}

	return false;
}

int main (int /*argc*/, char * const /*argv[]*/) {
	bool trueBool = true;
	if (TestFoo(trueBool)) {
		return -1;				// Error!
	}

    return 0;
}

--- snip ---

The code works as intended when optimizations are turned off.
It seems to be the ! operator not working with const bool&, but modifying the code in other ways may also solve the problem. (Try putting the CFoo class in the same module, or remove the inner if statement in TestFoo.)
Comment 1 Andrew Pinski 2005-11-08 16:43:46 UTC
I Think this has already been fixed in 4.0.2 by the patch for PR 23326.
Comment 2 Andrew Pinski 2005-11-08 16:44:18 UTC
Actually on second thought, this is a dup of bug 23326.

*** This bug has been marked as a duplicate of 23326 ***
Comment 3 Fredrik Littmarck 2005-11-08 16:45:02 UTC
Created attachment 10175 [details]
Test Case
Comment 4 Andrew Pinski 2005-11-08 16:46:53 UTC
Note also you are using Apple's compiler and should report this to them.