-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect the alignment attribute of functions (#186)
Respect the alignment attribute of functions. This is necessary to support calls to function pointer calls to member functions (which need to be aligned to 2, and the generated code crashes if this happens to be not the case) MSVC doesn't support adding alignment to functions, so create a separate #define for this, which is a no-op on MSVC Given that this occurs in several tests, and the MSVC tests have error-on-warning, this is a comment rather than a #warning
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef _MSC_VER | ||
// Suppress "dereferencing type-punned pointer will break strict-aliasing rules" | ||
// gcc_extra_args: -Wno-strict-aliasing | ||
struct A { | ||
int a; | ||
int b; | ||
int f1(int i) { return 1 + i; } | ||
int f2(int i) { return 1 + i; } | ||
typedef int (A::*Function)(int); | ||
int function_wrapper(Function f, int i) __attribute__((noinline)) { | ||
return (this->*f)(i); | ||
} | ||
}; | ||
|
||
int main() { | ||
A a{}; | ||
if (a.function_wrapper(&A::f1, 1) != 2) | ||
return 0; | ||
if (a.function_wrapper(&A::f2, 1) != 2) | ||
return 0; | ||
return 6; | ||
} | ||
|
||
#else | ||
|
||
/* MSVC doesn't support adding alignment to functions, treat it as an expected | ||
* failure */ | ||
|
||
int main() { return 25; } | ||
|
||
#endif |