From edf41ceff63c0ba33afe3a41f67422b503049c49 Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Fri, 19 Sep 2025 11:39:55 -0700 Subject: [PATCH] [DiagnoseStaticExclusivity] Fix this assertion. This function is called in one place in an assertion. It asserts that the function in question is the stdlib's swap. In language mode 6, the called value may be wrapped in a `function_conversion_expr` for `@Sendable`. That's irrelevant for the purposes of this assertion, so look through such conversions. rdar://160692694 --- .../Mandatory/DiagnoseStaticExclusivity.cpp | 2 +- validation-test/SILOptimizer/rdar160692694.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 validation-test/SILOptimizer/rdar160692694.swift diff --git a/lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp b/lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp index 0913dd1cace1a..60388e39d7bc2 100644 --- a/lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp +++ b/lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp @@ -336,7 +336,7 @@ static StringRef extractExprText(const Expr *E, SourceManager &SM) { /// it is in the ifndef. #ifndef NDEBUG static bool isCallToStandardLibrarySwap(CallExpr *CE, ASTContext &Ctx) { - if (CE->getCalledValue() == Ctx.getSwap()) + if (CE->getCalledValue(/*skipFunctionConversions=*/true) == Ctx.getSwap()) return true; // Is the call module qualified, i.e. Swift.swap(&a[i], &[j)? diff --git a/validation-test/SILOptimizer/rdar160692694.swift b/validation-test/SILOptimizer/rdar160692694.swift new file mode 100644 index 0000000000000..44dd332fe2e1e --- /dev/null +++ b/validation-test/SILOptimizer/rdar160692694.swift @@ -0,0 +1,12 @@ +// RUN: %target-swift-frontend \ +// RUN: -c \ +// RUN: -verify \ +// RUN: -disable-availability-checking \ +// RUN: -swift-version 6 \ +// RUN: %s + +typealias A = InlineArray<2, UInt64> +func mix(_ a: inout A) { + swap(&a[0], &a[1]) // expected-error{{overlapping accesses}} + // expected-note@-1{{conflicting access}} +}