Skip to content

Commit 8013451

Browse files
authored
Merge pull request #1393 from swiftwasm/master
[pull] swiftwasm from master
2 parents 5e687ec + 74f2878 commit 8013451

File tree

9 files changed

+382
-244
lines changed

9 files changed

+382
-244
lines changed

cmake/modules/DarwinSDKs.cmake

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ set(SUPPORTED_WATCHOS_ARCHS "armv7k")
1616
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386;arm64")
1717
set(SUPPORTED_OSX_ARCHS "x86_64;arm64;arm64e")
1818

19-
# Get the SDK version from SDKSettings.
20-
execute_process(
21-
COMMAND "defaults" "read" "${CMAKE_OSX_SYSROOT}/SDKSettings.plist" "Version"
22-
OUTPUT_VARIABLE SWIFT_OSX_SDK_VERSION
23-
OUTPUT_STRIP_TRAILING_WHITESPACE)
24-
25-
# Remove the last component, if any. e.g. 10.15.26 -> 10.15
26-
string(REGEX REPLACE "\([0-9]*[.][0-9]*\)[.][0-9]*" "\\1"
27-
SWIFT_OSX_SDK_VERSION "${SWIFT_OSX_SDK_VERSION}")
28-
29-
if (${SWIFT_OSX_SDK_VERSION} STREQUAL "10.14" OR
30-
${SWIFT_OSX_SDK_VERSION} STREQUAL "10.15")
31-
set(SUPPORTED_OSX_ARCHS "x86_64")
32-
else()
33-
set(SUPPORTED_OSX_ARCHS "x86_64;arm64e")
34-
endif()
35-
3619
is_sdk_requested(OSX swift_build_osx)
3720
if(swift_build_osx)
3821
configure_sdk_darwin(

include/swift/AST/DiagnosticsSema.def

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,10 +3095,16 @@ ERROR(derivative_attr_class_member_dynamic_self_result_unsupported,none,
30953095
ERROR(derivative_attr_nonfinal_class_init_unsupported,none,
30963096
"cannot register derivative for 'init' in a non-final class; consider "
30973097
"making %0 final", (Type))
3098+
ERROR(derivative_attr_unsupported_accessor_kind,none,
3099+
"cannot register derivative for %0", (/*accessorKind*/ DescriptiveDeclKind))
30983100
// TODO(SR-13096): Remove this temporary diagnostic.
30993101
ERROR(derivative_attr_class_setter_unsupported,none,
31003102
"cannot yet register derivative for class property or subscript setters",
31013103
())
3104+
// TODO(TF-982): Remove this temporary diagnostic.
3105+
NOTE(derivative_attr_protocol_requirement_unsupported,none,
3106+
"cannot yet register derivative default implementation for protocol "
3107+
"requirements", ())
31023108
ERROR(derivative_attr_original_already_has_derivative,none,
31033109
"a derivative already exists for %0", (DeclName))
31043110
NOTE(derivative_attr_duplicate_note,none,
@@ -3134,15 +3140,25 @@ NOTE(transpose_attr_wrt_self_self_type_mismatch_note,none,
31343140
"%1", (Type, Type))
31353141

31363142
// Automatic differentiation attributes
3137-
ERROR(autodiff_attr_original_decl_invalid_kind,none,
3138-
"%0 is not a 'func', 'init', 'subscript', or 'var' computed property "
3139-
"declaration", (DeclNameRef))
3140-
ERROR(autodiff_attr_accessor_not_found,none,
3141-
"%0 does not have a '%1' accessor", (DeclNameRef, StringRef))
3142-
ERROR(autodiff_attr_original_decl_none_valid_found,none,
3143-
"could not find function %0 with expected type %1", (DeclNameRef, Type))
3144-
ERROR(autodiff_attr_original_decl_not_same_type_context,none,
3145-
"%0 is not defined in the current type context", (DeclNameRef))
3143+
ERROR(autodiff_attr_original_decl_ambiguous,none,
3144+
"referenced declaration %0 is ambiguous", (DeclNameRef))
3145+
NOTE(autodiff_attr_original_decl_ambiguous_candidate,none,
3146+
"candidate %0 found here", (DescriptiveDeclKind))
3147+
ERROR(autodiff_attr_original_decl_none_valid,none,
3148+
"referenced declaration %0 could not be resolved", (DeclNameRef))
3149+
NOTE(autodiff_attr_original_decl_invalid_kind,none,
3150+
"candidate %0 is not a 'func', 'init', 'subscript', or 'var' computed "
3151+
"property declaration", (DescriptiveDeclKind))
3152+
NOTE(autodiff_attr_original_decl_missing_accessor,none,
3153+
"candidate %0 does not have a %1",
3154+
(DescriptiveDeclKind, /*accessorDeclKind*/ DescriptiveDeclKind))
3155+
NOTE(autodiff_attr_original_decl_type_mismatch,none,
3156+
"candidate %0 does not have "
3157+
"%select{expected type|type equal to or less constrained than}2 %1",
3158+
(DescriptiveDeclKind, Type, /*hasGenericSignature*/ bool))
3159+
NOTE(autodiff_attr_original_decl_not_same_type_context,none,
3160+
"candidate %0 is not defined in the current type context",
3161+
(DescriptiveDeclKind))
31463162
ERROR(autodiff_attr_original_void_result,none,
31473163
"cannot differentiate void function %0", (DeclName))
31483164
ERROR(autodiff_attr_original_multiple_semantic_results,none,

lib/Demangling/Punycode.cpp

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "swift/Demangling/Punycode.h"
1414
#include "swift/Demangling/ManglingUtils.h"
15+
#include <limits>
1516
#include <vector>
1617
#include <cstdint>
1718

@@ -49,7 +50,7 @@ static int digit_index(char value) {
4950
static bool isValidUnicodeScalar(uint32_t S) {
5051
// Also accept the range of 0xD800 - 0xD880, which is used for non-symbol
5152
// ASCII characters.
52-
return (S < 0xD880) || (S >= 0xE000 && S <= 0x1FFFFF);
53+
return (S < 0xD880) || (S >= 0xE000 && S <= 0x10FFFF);
5354
}
5455

5556
// Section 6.1: Bias adaptation function
@@ -88,7 +89,7 @@ bool Punycode::decodePunycode(StringRef InputPunycode,
8889
for (char c : InputPunycode.slice(0, lastDelimiter)) {
8990
// fail on any non-basic code point
9091
if (static_cast<unsigned char>(c) > 0x7f)
91-
return true;
92+
return false;
9293
OutCodePoints.push_back(c);
9394
}
9495
// if more than zero code points were consumed then consume one more
@@ -103,28 +104,37 @@ bool Punycode::decodePunycode(StringRef InputPunycode,
103104
for (int k = base; ; k += base) {
104105
// consume a code point, or fail if there was none to consume
105106
if (InputPunycode.empty())
106-
return true;
107+
return false;
107108
char codePoint = InputPunycode.front();
108109
InputPunycode = InputPunycode.slice(1, InputPunycode.size());
109110
// let digit = the code point's digit-value, fail if it has none
110111
int digit = digit_index(codePoint);
111112
if (digit < 0)
112-
return true;
113+
return false;
113114

115+
// Fail if i + (digit * w) would overflow
116+
if (digit > (std::numeric_limits<int>::max() - i) / w)
117+
return false;
114118
i = i + digit * w;
115119
int t = k <= bias ? tmin
116120
: k >= bias + tmax ? tmax
117121
: k - bias;
118122
if (digit < t)
119123
break;
124+
// Fail if w * (base - t) would overflow
125+
if (w > std::numeric_limits<int>::max() / (base - t))
126+
return false;
120127
w = w * (base - t);
121128
}
122129
bias = adapt(i - oldi, OutCodePoints.size() + 1, oldi == 0);
130+
// Fail if n + i / (OutCodePoints.size() + 1) would overflow
131+
if (i / (OutCodePoints.size() + 1) > std::numeric_limits<int>::max() - n)
132+
return false;
123133
n = n + i / (OutCodePoints.size() + 1);
124134
i = i % (OutCodePoints.size() + 1);
125135
// if n is a basic code point then fail
126136
if (n < 0x80)
127-
return true;
137+
return false;
128138
// insert n into output at position i
129139
OutCodePoints.insert(OutCodePoints.begin() + i, n);
130140
++i;
@@ -168,11 +178,17 @@ bool Punycode::encodePunycode(const std::vector<uint32_t> &InputCodePoints,
168178
if (codePoint >= n && codePoint < m)
169179
m = codePoint;
170180
}
171-
181+
182+
if ((m - n) > (std::numeric_limits<int>::max() - delta) / (h + 1))
183+
return false;
172184
delta = delta + (m - n) * (h + 1);
173185
n = m;
174186
for (auto c : InputCodePoints) {
175-
if (c < n) ++delta;
187+
if (c < n) {
188+
if (delta == std::numeric_limits<int>::max())
189+
return false;
190+
++delta;
191+
}
176192
if (c == n) {
177193
int q = delta;
178194
for (int k = base; ; k += base) {
@@ -285,11 +301,12 @@ static bool convertUTF8toUTF32(llvm::StringRef InputUTF8,
285301
auto end = InputUTF8.end();
286302
while (ptr < end) {
287303
uint8_t first = *ptr++;
304+
uint32_t code_point = 0;
288305
if (first < 0x80) {
289306
if (Mangle::isValidSymbolChar(first) || !mapNonSymbolChars) {
290-
OutUTF32.push_back(first);
307+
code_point = first;
291308
} else {
292-
OutUTF32.push_back((uint32_t)first + 0xD800);
309+
code_point = (uint32_t)first + 0xD800;
293310
}
294311
} else if (first < 0xC0) {
295312
// Invalid continuation byte.
@@ -301,7 +318,7 @@ static bool convertUTF8toUTF32(llvm::StringRef InputUTF8,
301318
uint8_t second = *ptr++;
302319
if (!isContinuationByte(second))
303320
return false;
304-
OutUTF32.push_back(((first & 0x1F) << 6) | (second & 0x3F));
321+
code_point = ((first & 0x1F) << 6) | (second & 0x3F);
305322
} else if (first < 0xF0) {
306323
// Three-byte sequence.
307324
if (end - ptr < 2)
@@ -310,8 +327,9 @@ static bool convertUTF8toUTF32(llvm::StringRef InputUTF8,
310327
uint8_t third = *ptr++;
311328
if (!isContinuationByte(second) || !isContinuationByte(third))
312329
return false;
313-
OutUTF32.push_back(((first & 0xF) << 12) | ((second & 0x3F) << 6)
314-
| ( third & 0x3F ));
330+
code_point = ((first & 0xF) << 12)
331+
| ((second & 0x3F) << 6)
332+
| ( third & 0x3F );
315333
} else if (first < 0xF8) {
316334
// Four-byte sequence.
317335
if (end - ptr < 3)
@@ -322,13 +340,17 @@ static bool convertUTF8toUTF32(llvm::StringRef InputUTF8,
322340
if (!isContinuationByte(second) || !isContinuationByte(third)
323341
|| !isContinuationByte(fourth))
324342
return false;
325-
OutUTF32.push_back(((first & 0x7) << 18) | ((second & 0x3F) << 12)
326-
| ((third & 0x3F) << 6)
327-
| ( fourth & 0x3F ));
343+
code_point = ((first & 0x7) << 18)
344+
| ((second & 0x3F) << 12)
345+
| ((third & 0x3F) << 6)
346+
| ( fourth & 0x3F );
328347
} else {
329348
// Unused sequence length.
330349
return false;
331350
}
351+
if (!isValidUnicodeScalar(code_point))
352+
return false;
353+
OutUTF32.push_back(code_point);
332354
}
333355
return true;
334356
}

lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,8 @@ bool TypeVarBindingProducer::computeNext() {
10341034

10351035
auto srcLocator = binding.getLocator();
10361036
if (srcLocator &&
1037-
srcLocator->isLastElement<LocatorPathElt::ApplyArgToParam>() &&
1037+
(srcLocator->isLastElement<LocatorPathElt::ApplyArgToParam>() ||
1038+
srcLocator->isLastElement<LocatorPathElt::AutoclosureResult>()) &&
10381039
!type->hasTypeVariable() && type->isKnownStdlibCollectionType()) {
10391040
// If the type binding comes from the argument conversion, let's
10401041
// instead of binding collection types directly, try to bind

0 commit comments

Comments
 (0)