Skip to content

Commit 098df72

Browse files
authored
Merge pull request #7490 from hughbe/attribute-cleanup
Various cleanups to definitions in the runtime
2 parents 493a7ce + 52a3622 commit 098df72

File tree

6 files changed

+63
-12
lines changed

6 files changed

+63
-12
lines changed

include/swift/Runtime/Config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
/// Does the current Swift platform use LLVM's intrinsic "swiftcall"
3636
/// calling convention for Swift functions?
3737
#ifndef SWIFT_USE_SWIFTCALL
38-
#ifdef __s390x__
38+
#if __has_attribute(swiftcall) || defined(__linux__)
3939
#define SWIFT_USE_SWIFTCALL 1
4040
#else
41-
#define SWIFT_USE_SWIFTCALL 1
41+
#define SWIFT_USE_SWIFTCALL 0
4242
#endif
4343
#endif
4444

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ __swift_size_t _swift_stdlib_fwrite_stdout(const void *ptr, __swift_size_t size,
6060
__swift_size_t nitems);
6161

6262
// String handling <string.h>
63-
__attribute__((__pure__)) SWIFT_RUNTIME_STDLIB_INTERFACE __swift_size_t
63+
SWIFT_READONLY SWIFT_RUNTIME_STDLIB_INTERFACE __swift_size_t
6464
_swift_stdlib_strlen(const char *s);
6565

66-
__attribute__((__pure__)) SWIFT_RUNTIME_STDLIB_INTERFACE __swift_size_t
66+
SWIFT_READONLY SWIFT_RUNTIME_STDLIB_INTERFACE __swift_size_t
6767
_swift_stdlib_strlen_unsigned(const unsigned char *s);
6868

69-
__attribute__((__pure__))
69+
SWIFT_READONLY
7070
SWIFT_RUNTIME_STDLIB_INTERFACE
7171
int _swift_stdlib_memcmp(const void *s1, const void *s2, __swift_size_t n);
7272

@@ -80,7 +80,7 @@ SWIFT_RUNTIME_STDLIB_INTERFACE
8080
int _swift_stdlib_close(int fd);
8181

8282
// Non-standard extensions
83-
__attribute__((__const__)) SWIFT_RUNTIME_STDLIB_INTERFACE __swift_size_t
83+
SWIFT_READNONE SWIFT_RUNTIME_STDLIB_INTERFACE __swift_size_t
8484
_swift_stdlib_malloc_size(const void *ptr);
8585

8686
// Random number <random>

stdlib/public/SwiftShims/SwiftStddef.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@
1313
#ifndef SWIFT_STDLIB_SHIMS_SWIFT_STDDEF_H
1414
#define SWIFT_STDLIB_SHIMS_SWIFT_STDDEF_H
1515

16+
// stddef.h is provided by Clang, but it dispatches to libc's stddef.h. As a
17+
// result, using stddef.h here would pull in Darwin module (which includes
18+
// libc). This creates a dependency cycle, so we can't use stddef.h in
19+
// SwiftShims.
20+
// On Linux, the story is different. We get the error message
21+
// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not
22+
// found"
23+
// This is a known Clang/Ubuntu bug.
24+
#if !defined(__APPLE__) && !defined(__linux__)
25+
#include <stddef.h>
26+
typedef size_t __swift_size_t;
27+
#else
1628
typedef __SIZE_TYPE__ __swift_size_t;
29+
#endif
1730

1831
#endif // SWIFT_STDLIB_SHIMS_SWIFT_STDDEF_H
19-

stdlib/public/SwiftShims/SwiftStdint.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,28 @@
1515

1616
// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a
1717
// result, using stdint.h here would pull in Darwin module (which includes
18-
// libc). This creates a dependency cycle, so we can't use stdint.h in
18+
// libc). This creates a dependency cycle, so we can't use stdint.h in
1919
// SwiftShims.
20+
// On Linux, the story is different. We get the error message
21+
// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not
22+
// found"
23+
// This is a known Clang/Ubuntu bug.
2024

2125
// Clang has been defining __INTxx_TYPE__ macros for a long time.
2226
// __UINTxx_TYPE__ are defined only since Clang 3.5.
23-
27+
#if !defined(__APPLE__) && !defined(__linux__)
28+
#include <stdint.h>
29+
typedef int64_t __swift_int64_t;
30+
typedef uint64_t __swift_uint64_t;
31+
typedef int32_t __swift_int32_t;
32+
typedef uint32_t __swift_uint32_t;
33+
typedef int16_t __swift_int16_t;
34+
typedef uint16_t __swift_uint16_t;
35+
typedef int8_t __swift_int8_t;
36+
typedef uint8_t __swift_uint8_t;
37+
typedef intptr_t __swift_intptr_t;
38+
typedef uintptr_t __swift_uintptr_t;
39+
#else
2440
typedef __INT64_TYPE__ __swift_int64_t;
2541
#ifdef __UINT64_TYPE__
2642
typedef __UINT64_TYPE__ __swift_uint64_t;
@@ -56,6 +72,6 @@ typedef unsigned __INT8_TYPE__ __swift_uint8_t;
5672

5773
typedef __swift_intn_t(__INTPTR_WIDTH__) __swift_intptr_t;
5874
typedef __swift_uintn_t(__INTPTR_WIDTH__) __swift_uintptr_t;
75+
#endif
5976

6077
#endif // SWIFT_STDLIB_SHIMS_SWIFT_STDINT_H
61-

stdlib/public/SwiftShims/Visibility.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
#define SWIFT_STDLIB_SHIMS_VISIBILITY_H
2020

2121
#if !defined(__has_feature)
22-
#define __has_feature(x) false
22+
#define __has_feature(x) 0
23+
#endif
24+
25+
#if !defined(__has_attribute)
26+
#define __has_attribute(x) 0
2327
#endif
2428

2529
#if __has_feature(nullability)
@@ -40,6 +44,18 @@
4044
# define SWIFT_END_NULLABILITY_ANNOTATIONS
4145
#endif
4246

47+
#if __has_attribute(pure)
48+
#define SWIFT_READONLY __attribute__((__pure__))
49+
#else
50+
#define SWIFT_READONLY
51+
#endif
52+
53+
#if __has_attribute(const)
54+
#define SWIFT_READNONE __attribute__((__const__))
55+
#else
56+
#define SWIFT_READNONE
57+
#endif
58+
4359
// TODO: support using shims headers in overlays by parameterizing
4460
// SWIFT_RUNTIME_EXPORT on the library it's exported from, then setting
4561
// protected vs. default based on the current value of __SWIFT_CURRENT_DYLIB.

stdlib/public/stubs/Stubs.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static long double swift_strtold_l(const char *nptr,
6565
#endif
6666
#include <limits>
6767
#include "llvm/ADT/StringExtras.h"
68+
#include "llvm/Support/Compiler.h"
6869
#include "swift/Runtime/Debug.h"
6970
#include "swift/Basic/Lazy.h"
7071

@@ -394,7 +395,13 @@ __muloti4(ti_int a, ti_int b, int* overflow)
394395
// some other lower-level architecture issue that I'm
395396
// missing. Perhaps relevant bug report:
396397
// FIXME: https://llvm.org/bugs/show_bug.cgi?id=14469
397-
typedef int di_int __attribute__((__mode__(DI)));
398+
#if __has_attribute(__mode__(DI))
399+
#define SWIFT_MODE_DI __attribute__((__mode__(DI)))
400+
#else
401+
#define SWIFT_MODE_DI
402+
#endif
403+
404+
typedef int di_int SWIFT_MODE_DI;
398405
SWIFT_RUNTIME_STDLIB_INTERFACE
399406
di_int
400407
__mulodi4(di_int a, di_int b, int* overflow)

0 commit comments

Comments
 (0)