Skip to content

Commit 3fa1d1f

Browse files
committed
runtime: ingest LLVMSupport into the runtime
This adds a new copy of LLVMSupport into the runtime. This is the final step before changing the inline namespace for the runtime support. This will allow us to avoid the ODR violations from the header definitions of LLVMSupport. LLVMSupport forked at: 22492eead218ec91d349c8c50439880fbeacf2b7 Changes made to LLVMSupport from that revision: process.inc forward declares `_beginthreadex` due to compilation issues due to custom flag handling API changes required that we alter the `Deallocate` routine to account for the alignment. This is a temporary state, meant to simplify the process. We do not use the entire LLVMSupport library and there is no value in keeping the entire library. Subsequent commits will prune the library to the needs for the runtime.
1 parent 01dcc29 commit 3fa1d1f

File tree

172 files changed

+73732
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+73732
-93
lines changed

include/swift/Basic/STLExtras.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct function_traits<R (T::*)(Args...) const> {
7171

7272
} // end namespace swift
7373

74+
#if !defined(swiftCore_EXPORTS)
7475
namespace llvm {
7576

7677
/// @{
@@ -109,6 +110,7 @@ inline void interleave(const Container &c, UnaryFunctor each_fn,
109110
/// @}
110111

111112
} // end namespace llvm
113+
#endif
112114

113115
namespace swift {
114116

include/swift/Runtime/Concurrent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class ConcurrentMapBase<EntryTy, false, Allocator> : protected Allocator {
203203

204204
// Deallocate the node. The static_cast here is required
205205
// because LLVM's allocator API is insane.
206-
this->Deallocate(static_cast<void*>(node), allocSize);
206+
this->Deallocate(static_cast<void*>(node), allocSize, alignof(Node));
207207
}
208208
};
209209

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ function(_add_swift_target_library_single target name)
849849
${SWIFTLIB_SINGLE_EXTERNAL_SOURCES}
850850
${INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
851851
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES})
852+
# NOTE: always inject the LLVMSupport directory before anything else. We want
853+
# to ensure that the runtime is built with our local copy of LLVMSupport
854+
target_include_directories(${target} BEFORE PRIVATE
855+
${SWIFT_SOURCE_DIR}/stdlib/include)
852856
if(("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
853857
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF") AND
854858
SWIFTLIB_SINGLE_TARGET_LIBRARY)

stdlib/include/llvm-c/DataTypes.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*===-- include/llvm-c/DataTypes.h - Define fixed size types ------*- C -*-===*\
2+
|* *|
3+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4+
|* Exceptions. *|
5+
|* See https://llvm.org/LICENSE.txt for license information. *|
6+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7+
|* *|
8+
|*===----------------------------------------------------------------------===*|
9+
|* *|
10+
|* This file contains definitions to figure out the size of _HOST_ data types.*|
11+
|* This file is important because different host OS's define different macros,*|
12+
|* which makes portability tough. This file exports the following *|
13+
|* definitions: *|
14+
|* *|
15+
|* [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*|
16+
|* [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values. *|
17+
|* *|
18+
|* No library is required when using these functions. *|
19+
|* *|
20+
|*===----------------------------------------------------------------------===*/
21+
22+
/* Please leave this file C-compatible. */
23+
24+
#ifndef LLVM_C_DATATYPES_H
25+
#define LLVM_C_DATATYPES_H
26+
27+
#include <inttypes.h>
28+
#include <stdint.h>
29+
30+
#ifndef _MSC_VER
31+
32+
#if !defined(UINT32_MAX)
33+
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
34+
"__STDC_LIMIT_MACROS before #including llvm-c/DataTypes.h"
35+
#endif
36+
37+
#if !defined(UINT32_C)
38+
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
39+
"__STDC_CONSTANT_MACROS before #including llvm-c/DataTypes.h"
40+
#endif
41+
42+
/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
43+
#include <sys/types.h>
44+
45+
#ifdef _AIX
46+
// GCC is strict about defining large constants: they must have LL modifier.
47+
#undef INT64_MAX
48+
#undef INT64_MIN
49+
#endif
50+
51+
#else /* _MSC_VER */
52+
#ifdef __cplusplus
53+
#include <cstddef>
54+
#include <cstdlib>
55+
#else
56+
#include <stddef.h>
57+
#include <stdlib.h>
58+
#endif
59+
#include <sys/types.h>
60+
61+
#if defined(_WIN64)
62+
typedef signed __int64 ssize_t;
63+
#else
64+
typedef signed int ssize_t;
65+
#endif /* _WIN64 */
66+
67+
#endif /* _MSC_VER */
68+
69+
/* Set defaults for constants which we cannot find. */
70+
#if !defined(INT64_MAX)
71+
# define INT64_MAX 9223372036854775807LL
72+
#endif
73+
#if !defined(INT64_MIN)
74+
# define INT64_MIN ((-INT64_MAX)-1)
75+
#endif
76+
#if !defined(UINT64_MAX)
77+
# define UINT64_MAX 0xffffffffffffffffULL
78+
#endif
79+
80+
#ifndef HUGE_VALF
81+
#define HUGE_VALF (float)HUGE_VAL
82+
#endif
83+
84+
#endif /* LLVM_C_DATATYPES_H */

stdlib/include/llvm-c/Error.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*===------- llvm-c/Error.h - llvm::Error class C Interface -------*- C -*-===*\
2+
|* *|
3+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4+
|* Exceptions. *|
5+
|* See https://llvm.org/LICENSE.txt for license information. *|
6+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7+
|* *|
8+
|*===----------------------------------------------------------------------===*|
9+
|* *|
10+
|* This file defines the C interface to LLVM's Error class. *|
11+
|* *|
12+
\*===----------------------------------------------------------------------===*/
13+
14+
#ifndef LLVM_C_ERROR_H
15+
#define LLVM_C_ERROR_H
16+
17+
#include "llvm-c/ExternC.h"
18+
19+
LLVM_C_EXTERN_C_BEGIN
20+
21+
#define LLVMErrorSuccess 0
22+
23+
/**
24+
* Opaque reference to an error instance. Null serves as the 'success' value.
25+
*/
26+
typedef struct LLVMOpaqueError *LLVMErrorRef;
27+
28+
/**
29+
* Error type identifier.
30+
*/
31+
typedef const void *LLVMErrorTypeId;
32+
33+
/**
34+
* Returns the type id for the given error instance, which must be a failure
35+
* value (i.e. non-null).
36+
*/
37+
LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err);
38+
39+
/**
40+
* Dispose of the given error without handling it. This operation consumes the
41+
* error, and the given LLVMErrorRef value is not usable once this call returns.
42+
* Note: This method *only* needs to be called if the error is not being passed
43+
* to some other consuming operation, e.g. LLVMGetErrorMessage.
44+
*/
45+
void LLVMConsumeError(LLVMErrorRef Err);
46+
47+
/**
48+
* Returns the given string's error message. This operation consumes the error,
49+
* and the given LLVMErrorRef value is not usable once this call returns.
50+
* The caller is responsible for disposing of the string by calling
51+
* LLVMDisposeErrorMessage.
52+
*/
53+
char *LLVMGetErrorMessage(LLVMErrorRef Err);
54+
55+
/**
56+
* Dispose of the given error message.
57+
*/
58+
void LLVMDisposeErrorMessage(char *ErrMsg);
59+
60+
/**
61+
* Returns the type id for llvm StringError.
62+
*/
63+
LLVMErrorTypeId LLVMGetStringErrorTypeId(void);
64+
65+
LLVM_C_EXTERN_C_END
66+
67+
#endif

stdlib/include/llvm-c/ErrorHandling.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*===-- llvm-c/ErrorHandling.h - Error Handling C Interface -------*- C -*-===*\
2+
|* *|
3+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4+
|* Exceptions. *|
5+
|* See https://llvm.org/LICENSE.txt for license information. *|
6+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7+
|* *|
8+
|*===----------------------------------------------------------------------===*|
9+
|* *|
10+
|* This file defines the C interface to LLVM's error handling mechanism. *|
11+
|* *|
12+
\*===----------------------------------------------------------------------===*/
13+
14+
#ifndef LLVM_C_ERROR_HANDLING_H
15+
#define LLVM_C_ERROR_HANDLING_H
16+
17+
#include "llvm-c/ExternC.h"
18+
19+
LLVM_C_EXTERN_C_BEGIN
20+
21+
typedef void (*LLVMFatalErrorHandler)(const char *Reason);
22+
23+
/**
24+
* Install a fatal error handler. By default, if LLVM detects a fatal error, it
25+
* will call exit(1). This may not be appropriate in many contexts. For example,
26+
* doing exit(1) will bypass many crash reporting/tracing system tools. This
27+
* function allows you to install a callback that will be invoked prior to the
28+
* call to exit(1).
29+
*/
30+
void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
31+
32+
/**
33+
* Reset the fatal error handler. This resets LLVM's fatal error handling
34+
* behavior to the default.
35+
*/
36+
void LLVMResetFatalErrorHandler(void);
37+
38+
/**
39+
* Enable LLVM's built-in stack trace code. This intercepts the OS's crash
40+
* signals and prints which component of LLVM you were in at the time if the
41+
* crash.
42+
*/
43+
void LLVMEnablePrettyStackTrace(void);
44+
45+
LLVM_C_EXTERN_C_END
46+
47+
#endif

stdlib/include/llvm-c/ExternC.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*===- llvm-c/ExternC.h - Wrapper for 'extern "C"' ----------------*- C -*-===*\
2+
|* *|
3+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4+
|* Exceptions. *|
5+
|* See https://llvm.org/LICENSE.txt for license information. *|
6+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7+
|* *|
8+
|*===----------------------------------------------------------------------===*|
9+
|* *|
10+
|* This file defines an 'extern "C"' wrapper *|
11+
|* *|
12+
\*===----------------------------------------------------------------------===*/
13+
14+
#ifndef LLVM_C_EXTERN_C_H
15+
#define LLVM_C_EXTERN_C_H
16+
17+
#ifdef __clang__
18+
#define LLVM_C_STRICT_PROTOTYPES_BEGIN \
19+
_Pragma("clang diagnostic push") \
20+
_Pragma("clang diagnostic error \"-Wstrict-prototypes\"")
21+
#define LLVM_C_STRICT_PROTOTYPES_END _Pragma("clang diagnostic pop")
22+
#else
23+
#define LLVM_C_STRICT_PROTOTYPES_BEGIN
24+
#define LLVM_C_STRICT_PROTOTYPES_END
25+
#endif
26+
27+
#ifdef __cplusplus
28+
#define LLVM_C_EXTERN_C_BEGIN \
29+
extern "C" { \
30+
LLVM_C_STRICT_PROTOTYPES_BEGIN
31+
#define LLVM_C_EXTERN_C_END \
32+
LLVM_C_STRICT_PROTOTYPES_END \
33+
}
34+
#else
35+
#define LLVM_C_EXTERN_C_BEGIN LLVM_C_STRICT_PROTOTYPES_BEGIN
36+
#define LLVM_C_EXTERN_C_END LLVM_C_STRICT_PROTOTYPES_END
37+
#endif
38+
39+
#endif

0 commit comments

Comments
 (0)