Skip to content

Commit eb94a0a

Browse files
committed
[Preprocessor] Refactor offsetof
1 parent 11d464e commit eb94a0a

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,10 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
761761
// Compiler version introspection macros.
762762
Builder.defineMacro("__llvm__"); // LLVM Backend
763763
Builder.defineMacro("__clang__"); // Clang Frontend
764-
Builder.defineMacro("__llvmmsvc__"); // llvmmsvc Frontend
764+
Builder.defineMacro("__llvmmsvc__"); // LLVM-MSVC Frontend
765765
Builder.defineMacro("_LLVM_MSC_VER"); // LLVM-MSVC Frontend
766+
Builder.defineMacro("__llvmmsvc__private"); // LLVM-MSVC private Frontend
767+
Builder.defineMacro("_LLVM_MSC_PRIVATE_VER"); // LLVM-MSVC private Frontend
766768
#define TOSTR2(X) #X
767769
#define TOSTR(X) TOSTR2(X)
768770
Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
@@ -1339,16 +1341,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
13391341

13401342
#ifdef _WIN32
13411343
// #define offsetof
1342-
Builder.append("#ifndef offsetof");
1343-
Builder.append("#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF");
1344-
Builder.append(" #ifdef __cplusplus");
1345-
Builder.append(" #define offsetof(s,m) ((::size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m)))");
1346-
Builder.append(" #else");
1347-
Builder.append(" #define offsetof(s,m) ((size_t)&(((s*)0)->m))");
1348-
Builder.append(" #endif");
1349-
Builder.append("#else");
1350-
Builder.append(" #define offsetof(s,m) __builtin_offsetof(s,m)");
1351-
Builder.append("#endif");
1344+
Builder.append("#if !defined(offsetof) || __has_feature(modules)");
1345+
Builder.append("#define offsetof(t, d) __builtin_offsetof(t, d)");
13521346
Builder.append("#endif");
13531347
#endif
13541348
}

clang/lib/Headers/stddef.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@
9090
#undef __need_max_align_t
9191
#endif /* defined(__need_max_align_t) */
9292

93-
#if defined(__need_offsetof)
94-
#include <__stddef_offsetof.h>
95-
#undef __need_offsetof
96-
#endif /* defined(__need_offsetof) */
93+
//#if defined(__need_offsetof)
94+
//#include <__stddef_offsetof.h>
95+
//#undef __need_offsetof
96+
//#endif /* defined(__need_offsetof) */
9797

9898
/* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
9999
__WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */

0 commit comments

Comments
 (0)