-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clang] Predefine _CRT_USE_BUILTIN_OFFSETOF
in MS-compatible modes
#127568
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
Merged
frederick-vs-ja
merged 9 commits into
llvm:main
from
frederick-vs-ja:__builtin_offsetof-with-ucrt
Mar 13, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2c9e6e4
[clang] Predefine `_CRT_USE_BUILTIN_OFFSETOF` in MS-compatible modes
frederick-vs-ja 8febf53
Merge branch 'main' into __builtin_offsetof-with-ucrt
frederick-vs-ja 4dc9bed
Address @AaronBallman's review comments
frederick-vs-ja 9bf9005
Merge branch 'main' into __builtin_offsetof-with-ucrt
frederick-vs-ja d974358
Release notes for `_CRT_USE_BUILTIN_OFFSETOF`
frederick-vs-ja fafe581
Merge branch 'main' into __builtin_offsetof-with-ucrt
frederick-vs-ja 246fba4
Merge branch 'main' into __builtin_offsetof-with-ucrt
frederick-vs-ja 9c12679
Merge branch 'main' into __builtin_offsetof-with-ucrt
frederick-vs-ja 1d3fb8b
Revert changes for another PR
frederick-vs-ja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify -fms-compatibility | ||
// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify | ||
// expected-no-diagnostics | ||
|
||
typedef __typeof__(sizeof(0)) size_t; | ||
|
||
#ifdef _MSC_VER | ||
#ifndef _CRT_USE_BUILTIN_OFFSETOF | ||
#error _CRT_USE_BUILTIN_OFFSETOF should be predefined in MSVC-compatible modes. | ||
#endif | ||
#else | ||
#ifdef _CRT_USE_BUILTIN_OFFSETOF | ||
#error _CRT_USE_BUILTIN_OFFSETOF should not be predefined in non-MSVC-compatible modes. | ||
#endif | ||
#endif | ||
|
||
#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF | ||
frederick-vs-ja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#ifdef __cplusplus | ||
#define offsetof(s,m) ((::size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m))) | ||
#else | ||
#define offsetof(s,m) ((size_t)&(((s*)0)->m)) | ||
#endif | ||
#else | ||
#define offsetof(s,m) __builtin_offsetof(s,m) | ||
#endif | ||
|
||
struct S { int a; }; | ||
_Static_assert(offsetof(struct S, a) == 0, ""); |
This file contains hidden or 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,28 @@ | ||
// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify -fms-compatibility | ||
// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify | ||
// expected-no-diagnostics | ||
|
||
typedef __typeof__(sizeof(0)) size_t; | ||
|
||
#ifdef _MSC_VER | ||
#ifndef _CRT_USE_BUILTIN_OFFSETOF | ||
#error _CRT_USE_BUILTIN_OFFSETOF should be predefined in MSVC-compatible modes. | ||
#endif | ||
#else | ||
#ifdef _CRT_USE_BUILTIN_OFFSETOF | ||
#error _CRT_USE_BUILTIN_OFFSETOF should not be predefined in non-MSVC-compatible modes. | ||
#endif | ||
#endif | ||
|
||
#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF | ||
#ifdef __cplusplus | ||
#define offsetof(s,m) ((::size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m))) | ||
#else | ||
#define offsetof(s,m) ((size_t)&(((s*)0)->m)) | ||
#endif | ||
#else | ||
#define offsetof(s,m) __builtin_offsetof(s,m) | ||
#endif | ||
|
||
struct S { int a; }; | ||
_Static_assert(offsetof(S, a) == 0, ""); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.