Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-gcc] CFE does not lay out structures correctly when funny darwin rules apply #975

Closed
lattner opened this issue Jul 22, 2005 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla llvm-tools All llvm tools that do not have corresponding tag miscompilation

Comments

@lattner
Copy link
Collaborator

lattner commented Jul 22, 2005

Bugzilla Link 603
Resolution FIXED
Resolved on Feb 22, 2010 12:41
Version 1.0
OS MacOS X
Blocks #821

Extended Description

llvm-gcc is currently miscompiling the following code:


typedef union {
int A; long long L;
} X;
typedef struct {
X x;
int B;
} Y;
Y* foo(Y *l) { return l+1; }

In this case, the X union should have 8-byte alignment due to funny darwin rules (even though long
long's are normally only 4-byte aligned). When X is the first element of a struct, that increases its
alignment requirements to 8-bytes, which increases the size of Y from 12 to 16 bytes.

llvm-gcc currently compiles this to:


    %struct.Y = type { %union.X, int }
    %union.X = type { long }

%struct.Y* %_Z3fooP1Y(%struct.Y* %l) {
%tmp.2 = getelementptr %struct.Y* %l, int 1 ; <%struct.Y*> [#uses=1]
ret %struct.Y* %tmp.2
}

... which is incorrect: Y is only 12 bytes in size. This causes us to emit the following PPC code:

__Z3fooP1Y:
addi r3, r3, 12
blr

... instead of the correct code:

__Z3fooP1Y:
addi r3, r3, 16
blr

This problem was reduced from Bug 449.

-Chris

@lattner
Copy link
Collaborator Author

lattner commented Jul 22, 2005

assigned to @lattner

@lattner
Copy link
Collaborator Author

lattner commented Jul 22, 2005

geeze, here's another simpler case:

typedef struct {
double X;
int B;
} Y;
Y* foo(Y *l) { return l+1; }

Darwin only makes "Y" 8-byte aligned if the double is first in the struct.

-Chris

@lattner
Copy link
Collaborator Author

lattner commented Jul 26, 2005

Fixed. Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20050725/027198.html

Testcase here:
Regression/C++/ofstream_ctor.cpp

This also fixes #821 .

-Chris

@lattner
Copy link
Collaborator Author

lattner commented Jul 26, 2005

*** Bug #821 has been marked as a duplicate of this bug. ***

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm-tools All llvm tools that do not have corresponding tag miscompilation
Projects
None yet
Development

No branches or pull requests

1 participant