Skip to content

Commit 311ff73

Browse files
committed
runtime: Silence a -Wglobal-constructors error than appears with upstream clang on Windows
Landing this on main to minimize rebranch-specific changes.
1 parent ec38c6e commit 311ff73

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

stdlib/public/runtime/Errors.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include "ImageInspection.h"
3838
#include "swift/Demangling/Demangle.h"
3939
#include "swift/Runtime/Atomic.h"
40+
#if defined(_WIN32)
41+
#include "swift/Runtime/Config.h"
42+
#endif
4043
#include "swift/Runtime/Debug.h"
4144
#include "swift/Runtime/Portability.h"
4245
#include "swift/Runtime/Win32.h"
@@ -544,6 +547,7 @@ void swift::swift_abortDisabledUnicodeSupport() {
544547
}
545548

546549
#if defined(_WIN32)
550+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
547551
// On Windows, exceptions may be swallowed in some cases and the
548552
// process may not terminate as expected on crashes. For example,
549553
// illegal instructions used by llvm.trap. Disable the exception
@@ -555,5 +559,5 @@ static void ConfigureExceptionPolicy() {
555559
UOI_TIMERPROC_EXCEPTION_SUPPRESSION,
556560
&Suppress, sizeof(Suppress));
557561
}
558-
562+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
559563
#endif

stdlib/public/stubs/LibcShims.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@
2525
#include <stdio.h>
2626
#include <stdlib.h>
2727

28+
#if defined(_WIN32)
29+
#include "swift/Runtime/Config.h"
30+
#endif
2831
#include "swift/shims/LibcShims.h"
2932

3033
#if defined(_WIN32)
34+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
3135
static void __attribute__((__constructor__))
3236
_swift_stdlib_configure_console_mode(void) {
3337
static UINT uiPrevConsoleCP = GetConsoleOutputCP();
3438
atexit([]() { SetConsoleOutputCP(uiPrevConsoleCP); });
3539
SetConsoleOutputCP(CP_UTF8);
3640
}
41+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
3742
#endif
3843

3944
SWIFT_RUNTIME_STDLIB_INTERNAL

0 commit comments

Comments
 (0)