Skip to content

[4.2][Exclusivity] Teach separate-stored-property relaxation about TSan instrumentation #17178

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

Conversation

devincoughlin
Copy link
Contributor

The compile-time exclusivity diagnostics explicitly allow conflicting accesses
to a struct when it can prove that the two accesses are used to project addresses
for separate stored properties. Unfortunately, the logic that detects this special
case gets confused by Thread Sanitizer's SIL-level instrumentation. This causes
the exclusivity diagnostics to have false positives when TSan is enabled.

To fix this, teach the AccessSummaryAnalysis to ignore TSan builtins when
determining whether an access has a single projected subpath.

rdar://problem/40455335

Factor out common logic for detecting sanitizer instrumentation and put it in
SIL/InstructionUtils.
…strumentation

The compile-time exclusivity diagnostics explicitly allow conflicting accesses
to a struct when it can prove that the two accesses are used to project addresses
for separate stored properties. Unfortunately, the logic that detects this special
case gets confused by Thread Sanitizer's SIL-level instrumentation. This causes
the exclusivity diagnostics to have false positives when TSan is enabled.

To fix this, teach the AccessSummaryAnalysis to ignore TSan builtins when
determining whether an access has a single projected subpath.

rdar://problem/40455335
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@devincoughlin
Copy link
Contributor Author

@swift-ci Please test

@devincoughlin
Copy link
Contributor Author

@swift-ci please nominate

Explanation: There is a false positive in the compile-time exclusivity diagnostics that manifests only when Thread Sanitizer is enabled. The exclusivity logic that detects when it is safe to have overlapping accesses to two different stored properties of the same struct gets confused by TSan's SIL-level instrumentation. This manifests as code that compiles without errors normally and only fails to build under TSan. The bug dates from the introduction of the separate-stored property exclusivity relaxation. However, it is a much bigger problem now that we're diagnosing more exclusivity violations as errors rather than warnings.
Scope: This affects Swift developers who run TSan and have code that uses closures to simultaneously access different stored properties of the same struct. The idiom is not super common, but we saw it in several benchmarks.
Radar/SR Issue: rdar://problem/40455335
Risk: This is a low risk change. The behavior change only affects compiling code with TSan builtins.
Testing: I've added end-to-end TSan regression tests and SIL-level tests.
Reviewer: Andy Trick

@devincoughlin devincoughlin merged commit 73ae90b into swiftlang:swift-4.2-branch-06-11-2018 Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants