Skip to content

Commit 3a96ded

Browse files
committed
Don't use certain attributes in shims or stubs if the attribute doesn't exist
1 parent bddebc5 commit 3a96ded

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

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/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)