-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect
#pragma pack(...)
and make pack(n)
where n > 1
opaque
This is a bandaid for #537. It does *not* fix the underlying issue, which requires `#[repr(packed = "N")]` support in Rust. However, it does make sure that we don't generate type definitions with the wrong layout, or fail our generated layout tests.
- Loading branch information
Showing
7 changed files
with
109 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// This should not be opaque; we can see the attributes and can pack the | ||
/// struct. | ||
struct AlignedToOne { | ||
int i; | ||
} __attribute__ ((packed,aligned(1))); | ||
|
||
/// This should be opaque because although we can see the attributes, Rust | ||
/// doesn't have `#[repr(packed = "N")]` yet. | ||
struct AlignedToTwo { | ||
int i; | ||
} __attribute__ ((packed,aligned(2))); | ||
|
||
#pragma pack(1) | ||
|
||
/// This should not be opaque because although `libclang` doesn't give us the | ||
/// `#pragma pack(1)`, we can detect that alignment is 1 and add | ||
/// `#[repr(packed)]` to the struct ourselves. | ||
struct PackedToOne { | ||
int x; | ||
int y; | ||
}; | ||
|
||
#pragma pack() | ||
|
||
#pragma pack(2) | ||
|
||
/// In this case, even if we can detect the weird alignment triggered by | ||
/// `#pragma pack(2)`, we can't do anything about it because Rust doesn't have | ||
/// `#[repr(packed = "N")]`. Therefore, we must make it opaque. | ||
struct PackedToTwo { | ||
int x; | ||
int y; | ||
}; | ||
|
||
#pragma pack() |