Skip to content

Commit 50c6824

Browse files
authored
Merge pull request #81935 from eeckstein/min-pointer-value-option
IRGen: add an option `-min-valid-pointer-value` to override the target's LeastValidPointerValue
2 parents b189b8a + c02bc2d commit 50c6824

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ ERROR(objc_with_embedded,none,
603603
"Objective-C interoperability cannot be enabled with embedded Swift.", ())
604604
ERROR(no_allocations_without_embedded,none,
605605
"-no-allocations is only applicable with embedded Swift.", ())
606+
ERROR(min_ptr_value_without_embedded,none,
607+
"-min-valid-pointer-value is only applicable with embedded Swift.", ())
606608
ERROR(no_swift_sources_with_embedded,none,
607609
"embedded swift cannot be enabled in a compiler built without Swift sources", ())
608610

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ class IRGenOptions {
566566
/// Pointer authentication.
567567
PointerAuthOptions PointerAuth;
568568

569+
// If not 0, this overrides the value defined by the target.
570+
uint64_t CustomLeastValidPointerValue = 0;
571+
569572
/// The different modes for dumping IRGen type info.
570573
enum class TypeInfoDumpFilter {
571574
All,

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,10 @@ def enable_cond_fail_message_annotation : Flag<["-"], "enable-cond-fail-message-
11871187
def disable_cond_fail_message_annotation : Flag<["-"], "dissable-cond-fail-message-annotation">,
11881188
HelpText<"Disable cond_fail message annotation.">;
11891189

1190+
def min_valid_pointer_value : Joined<["-"], "min-valid-pointer-value=">,
1191+
MetaVarName<"<value>">,
1192+
HelpText<"Overrides the target's least valid pointer value.'">;
1193+
11901194
let Flags = [FrontendOption, NoDriverOption, HelpHidden, ModuleInterfaceOptionIgnorable] in {
11911195
def enable_pack_metadata_stack_promotion :
11921196
Joined<["-"], "enable-pack-metadata-stack-promotion=">,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,6 +3506,21 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
35063506

35073507
Opts.DebugInfoForProfiling |= Args.hasArg(OPT_debug_info_for_profiling);
35083508

3509+
3510+
if (const Arg *A = Args.getLastArg(OPT_min_valid_pointer_value)) {
3511+
// The LeastValidPointerValue is hard-coded in the runtime. Therefore it
3512+
// can only safely customized in embedded swift - which doesn't have a runtime.
3513+
if (!LangOpts.hasFeature(Feature::Embedded)) {
3514+
Diags.diagnose(SourceLoc(), diag::min_ptr_value_without_embedded);
3515+
return true;
3516+
}
3517+
if (StringRef(A->getValue()).getAsInteger(0, Opts.CustomLeastValidPointerValue)) {
3518+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
3519+
A->getAsString(Args), A->getValue());
3520+
return true;
3521+
}
3522+
}
3523+
35093524
Opts.PrintInlineTree |= Args.hasArg(OPT_print_llvm_inline_tree);
35103525
// Always producing all outputs when caching is enabled.
35113526
Opts.AlwaysCompile |= Args.hasArg(OPT_always_compile_output_files) ||

lib/IRGen/SwiftTargetInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ SwiftTargetInfo SwiftTargetInfo::get(IRGenModule &IGM) {
263263
break;
264264
}
265265

266+
if (IGM.getOptions().CustomLeastValidPointerValue != 0)
267+
target.LeastValidPointerValue = IGM.getOptions().CustomLeastValidPointerValue;
268+
266269
return target;
267270
}
268271

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// RUN: %target-swift-emit-ir %s -module-name main -parse-as-library -enable-experimental-feature Embedded -O -min-valid-pointer-value=0x200 | %FileCheck %s
3+
4+
// REQUIRES: OS=macosx || OS=linux-gnu
5+
// REQUIRES: swift_feature_Embedded
6+
7+
public func testit(_ s: S?) -> Bool {
8+
return s != nil
9+
}
10+
11+
class C {}
12+
13+
public struct S {
14+
var a = InlineArray<57, UInt8>(repeating: 0)
15+
var b = C()
16+
var c = InlineArray<49, UInt8>(repeating: 0)
17+
}
18+
19+
// CHECK-LABEL: define {{.*}} @"$e4main1SVSgWOg"(ptr %0)
20+
// CHECK: icmp {{.*}}, 511
21+
// CHECK-LABEL: }

0 commit comments

Comments
 (0)