Skip to content

Commit ba3e197

Browse files
committed
Diagnose the combination of -Ounchecked with strict memory safety
Aligns with the current proposal and fixes rdar://127128995
1 parent 1230045 commit ba3e197

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,5 +589,9 @@ ERROR(experimental_not_supported_in_production,none,
589589
"experimental feature '%0' cannot be enabled in production compiler",
590590
(StringRef))
591591

592+
GROUPED_WARNING(Ounchecked_with_strict_safety,Unsafe,none,
593+
"'-Ounchecked' is not memory-safe and should not be combined with "
594+
"strict memory safety checking", ())
595+
592596
#define UNDEFINE_DIAGNOSTIC_MACROS
593597
#include "DefineDiagnosticMacros.h"

lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,6 +3834,13 @@ bool CompilerInvocation::parseArgs(
38343834
}
38353835
}
38363836

3837+
if (LangOpts.hasFeature(Feature::WarnUnsafe)) {
3838+
if (SILOpts.RemoveRuntimeAsserts ||
3839+
SILOpts.AssertConfig == SILOptions::Unchecked) {
3840+
Diags.diagnose(SourceLoc(), diag::Ounchecked_with_strict_safety);
3841+
}
3842+
}
3843+
38373844
SILOpts.UseAggressiveReg2MemForCodeSize =
38383845
ParsedArgs.hasFlag(OPT_enable_aggressive_reg2mem,
38393846
OPT_disable_aggressive_reg2mem,

test/Unsafe/unsafe_Ounchecked.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature WarnUnsafe -Ounchecked %s 2>&1 | %FileCheck %s
2+
3+
// REQUIRES: swift_feature_WarnUnsafe
4+
5+
// CHECK: warning: '-Ounchecked' is not memory-safe

0 commit comments

Comments
 (0)