Bug 163058

Summary: Invalid executable. Mangled struct arguments to function
Product: [Fedora] Fedora Reporter: Brian McGurk <mcgurk>
Component: gcc4Assignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact:
Severity: high Docs Contact:
Priority: medium    
Version: 4   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: 4.0.1-3.fc4 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-07-21 21:00:14 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Brian McGurk 2005-07-12 17:37:17 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050524 Fedora/1.0.4-4 Firefox/1.0.4

Description of problem:
The output from the compiler is broken with '-O2' optimisation turned on. After two levels of function calls, the arguments to the final function are the same when they should be different.

Here is a simple program that reproduces the problem:

struct number {
        int value;
        int only_here_to_cause_a_bug_1;
        int only_here_to_cause_a_bug_2;
};

int different(struct number a, struct number b);
int still_different(struct number a, struct number b);

int main(int argc, char **argv)
{
        struct number three, seven;

        three.value = 3;
        seven.value = 7;

        return ! different(three, seven);
}

int different(struct number a, struct number b)
{
        return still_different(b, a);
}

int still_different(struct number a, struct number b) {
        return (a.value != b.value);
}

Version-Release number of selected component (if applicable):
gcc-4.0.0-8

How reproducible:
Always

Steps to Reproduce:
1.Save the above program in a file try.c
2.Run '/usr/bin/gcc -O2 try.c'
3.Run './a.out'
  

Actual Results:  The program exits with an error status

Expected Results:  It should exit without an error status.

Additional info:

Removing the unused fields from the structure removes the problem.

Reducing the optimisation removes the problem.

Reversing the order of the arguments in the call to the function "still_different"   
 removes the problem.

Comment 2 Jakub Jelinek 2005-07-21 21:00:14 UTC
Should be fixed in gcc-4.0.1-4 (rawhide) and gcc-4.0.1-3.fc4 (FC4 testing
update).