Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Sema/TypeCheckEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4309,7 +4309,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
Ctx.Diags.diagnose(S->getForLoc(), diag::for_unsafe_without_unsafe)
.fixItInsert(insertionLoc, "unsafe ");
}
} else if (S->getUnsafeLoc().isValid()) {
} else if (S->getUnsafeLoc().isValid() &&
Ctx.LangOpts.hasFeature(Feature::StrictMemorySafety)) {
// Extraneous "unsafe" on the sequence.
Ctx.Diags.diagnose(S->getUnsafeLoc(), diag::no_unsafe_in_unsafe_for)
.fixItRemove(S->getUnsafeLoc());
Expand Down Expand Up @@ -4343,6 +4344,9 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
}

void diagnoseRedundantUnsafe(UnsafeExpr *E) const {
if (!Ctx.LangOpts.hasFeature(Feature::StrictMemorySafety))
return;

if (auto *SVE = SingleValueStmtExpr::tryDigOutSingleValueStmtExpr(E)) {
// For an if/switch expression, produce a tailored warning.
Ctx.Diags.diagnose(E->getUnsafeLoc(),
Expand All @@ -4351,6 +4355,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
.highlight(E->getUnsafeLoc());
return;
}

Ctx.Diags.diagnose(E->getUnsafeLoc(), diag::no_unsafe_in_unsafe);
}

Expand Down
18 changes: 18 additions & 0 deletions test/Unsafe/unsafe_nonstrict.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %target-typecheck-verify-swift -print-diagnostic-groups

@unsafe func unsafeFunc() { }

@unsafe
struct UnsafeType { }

protocol P { }

struct X: @unsafe P { }

func acceptP<T: P>(_: T) { }

func testItAll(ut: UnsafeType, x: X, i: Int) {
_ = unsafe ut
unsafe acceptP(x)
_ = unsafe i
}