Skip to content

Partial fix for verification of where pointer conversions can appear. #17972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2018
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
17 changes: 15 additions & 2 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -1469,7 +1469,9 @@ class Verifier : public ASTWalker {
}
};

// These outer entities will be interleaved in multi-level optionals.
// FIXME: This doesn't seem like a particularly robust
// approach to tracking whether pointer conversions
// always appear as call arguments.
while (true) {
// Look through optional evaluations.
if (auto *optionalEval = dyn_cast<OptionalEvaluationExpr>(subExpr)) {
Expand All @@ -1484,6 +1486,17 @@ class Verifier : public ASTWalker {
continue;
}

// FIXME: This is only handling the value conversion, not
// the key conversion. What this verifier check
// should probably do is just track whether we're
// currently visiting arguments of an apply when we
// find these conversions.
if (auto *upcast =
dyn_cast<CollectionUpcastConversionExpr>(subExpr)) {
subExpr = upcast->getValueConversion().Conversion;
continue;
}

break;
}

Expand Down
5 changes: 5 additions & 0 deletions test/Constraints/valid_pointer_conversions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %target-typecheck-verify-swift

func foo(_ a: [[UInt8]], _ p: [UnsafeRawPointer]) {
foo(a, a) // expect-warning {{all paths through this function will call itself}}
}