Skip to content
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

load => loadUnaligned #6929

Merged
merged 1 commit into from Sep 20, 2023
Merged

load => loadUnaligned #6929

merged 1 commit into from Sep 20, 2023

Conversation

neonichu
Copy link
Member

This is the potential source of a crash on x86_64 using the rebranch branch of Swift.

rdar://115675736

Copy link
Contributor

@abertelrud abertelrud left a comment

Choose a reason for hiding this comment

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

Fix looks good but it surprises me that this shows up on x86_64, which is usually lenient about unaligned loads, and not on arm64, which is much stricter.

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

Fix looks good but it surprises me that this shows up on x86_64, which is usually lenient about unaligned loads, and not on arm64, which is much stricter.

The Swift stdlib has internal checks for this stuff too. This failure is the stdlib precondition check; https://github.com/apple/swift/blob/e1c6a4b5391538f5f290bee79a843c3a55f3f159/stdlib/public/core/UnsafeRawPointer.swift#L421C5-L423

Do we need this on both load functions, or just the one? There's a withUnsafeBytes load in DefaultPluginScriptRunner.swift too:

let length = header.withUnsafeBytes{ $0.load(as: UInt64.self).littleEndian }

@abertelrud
Copy link
Contributor

Fix looks good but it surprises me that this shows up on x86_64, which is usually lenient about unaligned loads, and not on arm64, which is much stricter.

The Swift stdlib has internal checks for this stuff too. This failure is the stdlib precondition check; https://github.com/apple/swift/blob/e1c6a4b5391538f5f290bee79a843c3a55f3f159/stdlib/public/core/UnsafeRawPointer.swift#L421C5-L423

Oh I see, that explains it.

Do we need this on both load functions, or just the one? There's a withUnsafeBytes load in DefaultPluginScriptRunner.swift too:

let length = header.withUnsafeBytes{ $0.load(as: UInt64.self).littleEndian }

Good point — that was actually the one I found first, and didn't notice that Boris fixed the other one. Thanks for catching that!

Ideally this code would be shared between the plugin library and the plugin host... it's a small amount of code and hasn't changed for a long time, but for cases like this... :)

@MaxDesiatov
Copy link
Member

@swift-ci test

This is the potential source of a crash on x86_64 using the rebranch branch of Swift.

rdar://115675736
@neonichu
Copy link
Member Author

@swift-ci please test

@neonichu
Copy link
Member Author

Looks like the cross-repo test got past SwiftPM, so this should be good to merge.

@neonichu
Copy link
Member Author

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift-tools-support-core\Sources\TSCBasic\CStringArray.swift:11:8: error: module compiled with Swift 5.10 cannot be imported by the Swift 5.11 compiler: T:\7\swift\TSCLibc.swiftmodule
import TSCLibc
       ^
ninja: build stopped: subcommand failed.

I think this is a sporadic issue on the Windows CI.

@neonichu
Copy link
Member Author

@swift-ci please test windows

@etcwilde
Copy link
Member

apple/swift#68641
@swift-ci please test windows

@neonichu neonichu merged commit b08e801 into main Sep 20, 2023
5 checks passed
@neonichu neonichu deleted the load-unaligned branch September 20, 2023 01:44
MaxDesiatov pushed a commit that referenced this pull request Sep 28, 2023
This is the potential source of a crash on x86_64 using the rebranch branch of Swift.

rdar://115675736
MaxDesiatov pushed a commit that referenced this pull request Sep 28, 2023
This is the potential source of a crash on x86_64 using the rebranch branch of Swift.

rdar://115675736
neonichu added a commit to apple/swift-syntax that referenced this pull request Oct 25, 2023
Same fix as apple/swift-package-manager#6929 since the code in swift-syntax is based on what is in SwiftPM.
ahoppen pushed a commit to ahoppen/swift-syntax that referenced this pull request Oct 31, 2023
Same fix as apple/swift-package-manager#6929 since the code in swift-syntax is based on what is in SwiftPM.
art-divin added a commit to art-divin/swift-syntax that referenced this pull request Nov 2, 2023
commit ebd7026
Merge: e5962c4 efbfbab
Author: Ben Barham <b.n.barham@gmail.com>
Date:   Fri Oct 27 16:04:15 2023 -0700

    Merge pull request apple#2313 from bnbarham/literal-expr-parsing

    Skip parsing trailing closures after literals

commit efbfbab
Author: Ben Barham <ben_barham@apple.com>
Date:   Wed Oct 25 14:08:57 2023 -0700

    Skip parsing trailing closures after literals

    Postfix parsing should skip trailing closure if the base expression is
    a literal (which is not callable).

commit e5962c4
Merge: 18c5bce 8fb1309
Author: Sophia Poirier <2997196+sophiapoirier@users.noreply.github.com>
Date:   Thu Oct 26 15:15:30 2023 -0700

    Merge pull request apple#2306 from sophiapoirier/globals_strict_concurrency_opt_out_nonisolated_unsafe

    nonisolated(unsafe) to opt out of strict concurrency static checking for global variables

commit 18c5bce
Merge: 598e191 dbb04e5
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Thu Oct 26 11:05:54 2023 -0700

    Merge pull request apple#2311 from ahoppen/ahoppen/511-version-indicator

    Add a `SwiftSyntax511` version indicator module

commit 598e191
Merge: bcd4772 a5315ff
Author: Boris Bügling <bbuegling@apple.com>
Date:   Wed Oct 25 14:06:20 2023 -0700

    Merge pull request apple#2312 from apple/load-unaligned

    load => loadUnaligned

commit a5315ff
Author: Boris Buegling <bbuegling@apple.com>
Date:   Wed Oct 25 11:29:53 2023 -0700

    load => loadUnaligned

    Same fix as apple/swift-package-manager#6929 since the code in swift-syntax is based on what is in SwiftPM.

commit bcd4772
Merge: 48c2705 12993b0
Author: Ben Barham <b.n.barham@gmail.com>
Date:   Wed Oct 25 10:10:33 2023 -0700

    Merge pull request apple#2265 from bnbarham/cast-sometimes-fails

    Casts to children of `SyntaxProtocol` are not always invalid

commit 48c2705
Merge: 0f808e7 1dc4c16
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Tue Oct 24 19:25:43 2023 -0700

    Merge pull request apple#2308 from art-divin/function-compilation-optimization

    Optimized Type Checker performance in UnicodeScalarExtensions and SyntaxText

commit dbb04e5
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Tue Oct 24 18:41:32 2023 -0700

    Add a `SwiftSyntax511` version indicator module

commit 0f808e7
Merge: 8d5fab7 636556c
Author: Alex Hoppen <alex@alexhoppen.de>
Date:   Tue Oct 24 17:17:45 2023 -0700

    Merge pull request apple#2238 from Matejkob/annotat-source-lines-with-notes-preperations

commit 12993b0
Author: Ben Barham <ben_barham@apple.com>
Date:   Mon Oct 23 17:29:51 2023 -0700

    Casts to children of SyntaxProtocol are not always invalid

    Update these overrides so they don't always fail.

commit 1dc4c16
Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
Date:   Mon Oct 23 22:35:34 2023 +0400

    Squashed commit of the following:

    commit 4cd9756
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Mon Oct 23 22:17:28 2023 +0400

        applied swift-format

    commit dc59e96
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Mon Oct 23 22:02:35 2023 +0400

        removed redundant variable

    commit ff95302
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Mon Oct 23 22:00:23 2023 +0400

        refactored optimization in isValidIdentifierContinuationCodePoint

    commit 5b94ec9
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Mon Oct 23 21:51:48 2023 +0400

        fixed a typo; renamed variables

    commit 7e1f23d
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Mon Oct 23 21:38:08 2023 +0400

        renamed variables in slice(of:)

    commit 3b9c1f8
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Sat Oct 21 19:45:34 2023 +0400

        removed redundant newline

    commit 83ad08c
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Sat Oct 21 19:02:13 2023 +0400

        optimized isSlice(of other: SyntaxText) -> Bool

    commit f5d0a3a
    Author: Ruslan Alikhamov <r.alikhamov@gmail.com>
    Date:   Sat Oct 21 19:02:03 2023 +0400

        optimized isValidIdentifierContinuationCodePoint

commit 8d5fab7
Merge: f8be751 46c39ad
Author: Ben Barham <b.n.barham@gmail.com>
Date:   Mon Oct 23 09:18:42 2023 -0700

    Merge pull request apple#2309 from icanzilb/marin_todorov/command-help-typo-fix

    Fixes a typo in the cli abstract string

commit 46c39ad
Author: Marin Todorov <marin@underplot.com>
Date:   Sun Oct 22 11:16:36 2023 +0200

    fixes typo in a help string

commit 636556c
Author: Mateusz Bąk <bakmatthew@icloud.com>
Date:   Mon Sep 25 16:42:37 2023 +0200

    Add diagnostic testing utils for enhanced diagnostics testing

    Introduces `DiagnosticTestingUtils.swift`, a utility suite designed to aid in writing unit tests for `DiagnosticsFormatter` and `GroupedDiagnostics`. Highlights include:

    1. `LocationMarker` Typealias:
      - Enhances readability and precision in location identification within AST.

    2. `DiagnosticDescriptor` and `NoteDescriptor` Structs:
      - Offers a robust mechanism to construct and describe diagnostics and notes for testing.

    3. Simple Implementations for Protocols:
      - `SimpleNoteMessage` and `SimpleDiagnosticMessage` for streamlined testing.

    4. `assertAnnotated` Function:
      - Asserts that annotated source generated from diagnostics aligns with the expected output.

    This addition significantly bolsters the testing utilities, providing a comprehensive framework for ensuring accurate and effective diagnostics.

commit 6954167
Author: Mateusz Bąk <bakmatthew@icloud.com>
Date:   Mon Sep 25 16:39:16 2023 +0200

    Introduce diagnostic decorator

    This commit introduces three significant components:

    1. `DiagnosticDecorator` Protocol:
      - Defines a standard interface for decorating diagnostic output in source code.
      - Design to be used by entities like `DiagnosticsFormatter` and `GroupedDiagnostics`.

    2. `ANSIDiagnosticDecorator` Struct:
      - Implements the `DiagnosticDecorator` protocol.
      - Adds severity-based prefixes to diagnostic messages.
      - Supports ANSI colorization to enhance visibility and interpretation.

    3. `BasicDiagnosticDecorator` Struct:
      - Implements the `DiagnosticDecorator` protocol.
      - Adds severity-based prefixes to diagnostic messages.

    Also includes:
    - Unit tests for `ANSIDiagnosticDecorator` in `ANSIDiagnosticDecoratorTests` and `BasicDiagnosticDecorator` in `BasicDiagnosticDecoratorTests`.

    This feature enriches the diagnostic capabilities, offering customizable and visually informative feedback.

commit 953bab2
Author: Mateusz Bąk <bakmatthew@icloud.com>
Date:   Mon Sep 18 09:53:24 2023 +0200

    Rename DiagnosticsFormatterTests to ParserDiagnosticsFormatterIntegrationTests

commit 8fb1309
Author: Sophia Poirier <spoirier@apple.com>
Date:   Fri Oct 20 10:30:46 2023 -0700

    nonisolated(unsafe) to opt out of strict concurrency static checking for global variables

commit f8be751
Merge: 2223e4c e111f3a
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Fri Oct 20 10:05:52 2023 -0700

    Merge pull request apple#2305 from Matejkob/new-extension-macro-example

    Add extension macro example

commit e111f3a
Author: Mateusz Bąk <bakmatthew@icloud.com>
Date:   Wed Oct 18 22:27:54 2023 +0200

    Add extension macro example

    This commit introduces a new macro, `DefaultFatalErrorImplementationMacro`, to provide default implementations for protocol methods. The macro automatically generates extension code blocks with the default implementations for any protocol it's attached to.

commit 2223e4c
Merge: 3fd8f49 45e92e8
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Thu Oct 19 17:07:39 2023 -0700

    Merge pull request apple#2272 from divalue/syntax_tree_with_lookahead_struct

    Add IncrementalParseResult

commit 3fd8f49
Merge: 83e12ff 9a0f0ff
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Thu Oct 19 14:16:54 2023 -0700

    Merge pull request apple#2278 from Matejkob/modifi-nodes-with-variable-setters

    Refactor syntax node manipulation to use variable setters

commit 9a0f0ff
Author: Mateusz Bąk <bakmatthew@icloud.com>
Date:   Thu Oct 12 09:11:56 2023 +0200

    Refactor syntax node manipulation to use variable setters

    This commit replaces the use of 'with' method for syntax node manipulation in SwiftSyntax examples with direct variable setters for better clarity and readability.

commit 83e12ff
Merge: f6868a7 d5400cb
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Wed Oct 18 15:18:32 2023 -0700

    Merge pull request apple#2304 from ahoppen/ahoppen/trivia-comment

    Improve comment of leading and trailing trivia on `SyntaxProtocol`

commit d5400cb
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Wed Oct 18 13:19:30 2023 -0700

    Improve comment of leading and trailing trivia on `SyntaxProtocol`

commit f6868a7
Merge: 02a1330 b5c9937
Author: Kim de Vos <kimdevos12@hotmail.com>
Date:   Wed Oct 18 12:40:46 2023 +0200

    Merge pull request apple#2286 from kimdv/kimdv/2273-bad-diagnostic-for-generic-parameter-list-on-enum-case

    Handle generic parameter on enum case

commit b5c9937
Author: Kim de Vos <kimdevos12@hotmail.com>
Date:   Sun Oct 15 20:18:58 2023 +0200

    Handle generic parameter on enum case

commit 02a1330
Merge: 106183a 33c4b08
Author: Kim de Vos <kimdevos12@hotmail.com>
Date:   Tue Oct 17 23:26:49 2023 +0200

    Merge pull request apple#2226 from kimdv/kimdv/rewrite-fit-it-applier

    Rewrite FixItApplier to be string based

commit 106183a
Merge: e8659bb aa33736
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Tue Oct 17 12:41:23 2023 -0700

    Merge pull request apple#2292 from ahoppen/ahoppen/case-iterable

    Remove `SyntaxKind` conformance to `CaseIterable`

commit 33c4b08
Author: Kim de Vos <kimdevos12@hotmail.com>
Date:   Tue Oct 17 08:32:46 2023 +0200

    Rewrite FixItApplier to be string based

commit e8659bb
Author: Rauhul Varma <rauhul@users.noreply.github.com>
Date:   Tue Oct 17 11:31:12 2023 -0700

    Fix missing space in LabeledExprSyntax init (apple#2291)

    Updates LabeledExprSyntax convenience initializer to include a trailing
    space trivia after the colon if an argument label is specified. This
    ensures the rendered description is 'arg: value' instead of 'arg:value'.

commit aa33736
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Mon Oct 16 12:46:21 2023 -0700

    Remove `IntegerLiteralExprSyntax.Radix` conformance to `CaseIterable`

    There’s no good reason why you would want to iterate over all radix kinds.

commit a318593
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Tue Oct 17 09:41:05 2023 -0700

    Remove `SyntaxKind` conformance to `CaseIterable`

    There’s no good reason to iterate over all cases in `SyntaxKind` and if `SyntaxKind` conforms to `CaseIterable`, we can’t mark members of it as deprecated (https://github.com/apple/swift-syntax/pull/2237/files#r1359917461)

commit 1fa18e5
Merge: 975ac26 d8c8695
Author: Rintaro Ishizaki <rishizaki@apple.com>
Date:   Mon Oct 16 19:07:47 2023 -0700

    Merge pull request apple#2296 from rintaro/cmake-nocache

    [CMake] Remove set(CACHE) line for SWIFT_MODULE_ABI_NAME_PREFIX

commit 975ac26
Merge: 8decbe4 e4e6a95
Author: Rintaro Ishizaki <rishizaki@apple.com>
Date:   Mon Oct 16 17:35:51 2023 -0700

    Merge pull request apple#2268 from rintaro/macro-resolveerror-rdar115571427

    [Macros] Granular diagnostics when macro type is not found in a plugin

commit 8decbe4
Merge: 72565a4 947e6f3
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Mon Oct 16 17:34:09 2023 -0700

    Merge pull request apple#2290 from ahoppen/ahoppen/interpolation-failure-message

    Update the interpolation failure message

commit d8c8695
Author: Rintaro Ishizaki <rishizaki@apple.com>
Date:   Mon Oct 16 13:50:05 2023 -0700

    [CMake] Remove set(CACHE) line for SWIFT_MODULE_ABI_NAME_PREFIX

    Due to https://cmake.org/cmake/help/latest/policy/CMP0126.html
    set(CACHE) overwrites the existing value if the cache has not been set
    to any value. Since we don't need any default value, just remove it.

commit 72565a4
Merge: ccab07f 7a3df8c
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Mon Oct 16 13:18:52 2023 -0700

    Merge pull request apple#2285 from pointfreeco/add-missing-dependency

    Add missing dependency to SwiftSyntaxMacroExpansion.

commit 45e92e8
Author: Dmitrii Valuev <dima.vap2013@gmail.com>
Date:   Sun Oct 8 22:44:23 2023 +0300

    Add IncrementalParseResult type

    Added IncrementalParseResult type and changed parseIncrementally return type

    Fix spacing in 510 rn

commit 947e6f3
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Mon Oct 16 11:32:38 2023 -0700

    Update the interpolation failure message

    When a user is getting the interpolation `os_log` failure message but actually supports parsing invalid source code, offer them an alternative parses the source code without checking for errors.

commit e4e6a95
Author: Rintaro Ishizaki <rishizaki@apple.com>
Date:   Fri Oct 13 15:53:50 2023 -0700

    [CompilerPlugin] remove _resolveMacro

    That was only just a thunk for testing. Use @_spi(Testing) instead.

commit ccab07f
Merge: df6600d 093b895
Author: Rintaro Ishizaki <rishizaki@apple.com>
Date:   Mon Oct 16 09:03:30 2023 -0700

    Merge pull request apple#2282 from rintaro/cmake-abi-name-rdar116951101

    [CMake] Add option to specify '-module-abi-name'

commit df6600d
Merge: e695b37 43c0388
Author: Kim de Vos <kimdevos12@hotmail.com>
Date:   Sun Oct 15 19:42:52 2023 +0200

    Merge pull request apple#2264 from kimdv/kimdv/2261-rename-notemessagefixitid-to-noteid

    Rename `NoteMessage.fixItID` to `noteID`

commit 43c0388
Author: Kim de Vos <kimdevos12@hotmail.com>
Date:   Thu Oct 5 21:23:24 2023 +0200

    Rename `NoteMessage.fixItID` to `noteID`

commit 7a3df8c
Author: Brandon Williams <mbrandonw@hey.com>
Date:   Sat Oct 14 20:38:18 2023 -0400

    Add missing dependency to SwiftSyntaxMacroExpansion.

commit e695b37
Merge: 27db137 657f2e1
Author: Alex Hoppen <alex@alexhoppen.de>
Date:   Sat Oct 14 17:22:05 2023 -0700

    Merge pull request apple#2063 from StevenWong12/move_swift_parser_cli

commit 27db137
Merge: 71afbc1 9a561e6
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Sat Oct 14 09:07:54 2023 -0700

    Merge pull request apple#2283 from Matejkob/add-SwiftSyntax510

commit 9a561e6
Author: Mateusz Bąk <bakmatthew@icloud.com>
Date:   Sat Oct 14 10:43:43 2023 +0200

    Create `SwiftSyntax510` module for version indication

commit 093b895
Author: Rintaro Ishizaki <rishizaki@apple.com>
Date:   Sat Oct 14 06:17:40 2023 +0000

    [CMake] Add option to specify '-module-abi-name'

    Add 'SWIFT_MODULE_ABI_NAME_PREFIX' CMake variable. This can be used from
    compiler's CMake so its swift-syntax libraries can have unique names.
    That avoids symbol name conflicts when compiler libraries (e.g.
    sourcekitdInProc) is used from binaries linking with swift-syntax (e.g.
    via SwiftPM)

    apple/swift#68812
    rdar://116951101

commit f413c51
Author: Rintaro Ishizaki <rishizaki@apple.com>
Date:   Wed Sep 20 14:53:11 2023 -0700

    [Macros] Granular diagnostics when macro type is not found in a plugin

    rdar://115571427

commit 71afbc1
Merge: fc58fc8 c5cb386
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Thu Oct 12 17:40:07 2023 -0700

    Merge pull request apple#2277 from ahoppen/ahoppen/editor-extension-deployment-target

    Remove deployment target setting from editor extension

commit c5cb386
Author: Alex Hoppen <ahoppen@apple.com>
Date:   Thu Oct 12 09:13:48 2023 -0700

    Remove deployment target setting from editor extension

    This fixes a warning when building the Xcode project.

commit fc58fc8
Merge: 1f3618d acdbf3d
Author: Harlan Haskins <harlan@apple.com>
Date:   Wed Oct 11 22:42:19 2023 -0600

    Merge pull request apple#2275 from apple/harlan/vintage-conformances

    Add support for '@retroactive' conformances in SwiftSyntaxParser

commit acdbf3d
Author: Harlan Haskins <harlan@apple.com>
Date:   Wed Oct 11 15:47:47 2023 -0600

    Update Types.swift

    Fixes a format error

commit 657f2e1
Author: Ziyang Huang <stevenhuang12@outlook.com>
Date:   Tue Oct 10 22:57:45 2023 +0800

    Run `swift-format` to format codes

commit cbd5764
Author: Harlan Haskins <harlan@apple.com>
Date:   Mon Oct 9 16:25:40 2023 -0600

    Add support for '@retroactive' conformances in SwiftSyntaxParser

commit 280fc3e
Author: Ziyang Huang <stevenhuang12@outlook.com>
Date:   Sun Oct 8 21:26:48 2023 +0800

    Rename `_InstructionCounter` in `SwiftParserCLI` to `InstructionCounter`

commit 264f676
Author: Ziyang Huang <stevenhuang12@outlook.com>
Date:   Tue Aug 22 22:10:28 2023 +0800

    Make CI build `SwiftParserCLI`

commit bdca1a4
Author: Ziyang Huang <stevenhuang12@outlook.com>
Date:   Sun Oct 8 21:23:04 2023 +0800

    Move `swift-parser-cli` to its own package
ahoppen pushed a commit to ahoppen/swift-syntax that referenced this pull request Mar 7, 2024
Same fix as apple/swift-package-manager#6929 since the code in swift-syntax is based on what is in SwiftPM.
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.

None yet

4 participants