Skip to content

Conversation

@AnthonyLatsis
Copy link
Collaborator

No description provided.

Comment on lines 4210 to 4223
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is probably the only change that I feel needs a review. @Xazax-hun Could you take a look?

See swiftlang/llvm-project#10723.

Copy link
Contributor

Choose a reason for hiding this comment

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

Took a look, apart from a nit looks good to me. But just to double check, is this helper function that we used to use gone without any replacement? Although now at least we have a diagnostic for the failure case, which is great.

Copy link
Collaborator Author

@AnthonyLatsis AnthonyLatsis Jun 16, 2025

Choose a reason for hiding this comment

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

Yeah, it was refactored to accept an array of pairs. The splitting for compatibility with the old option is now done inline in the driver.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

Comment on lines 4210 to 4223
Copy link
Contributor

Choose a reason for hiding this comment

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

Took a look, apart from a nit looks good to me. But just to double check, is this helper function that we used to use gone without any replacement? Although now at least we have a diagnostic for the failure case, which is great.

Comment on lines 4210 to 4211
Copy link
Contributor

@bnbarham bnbarham Jun 17, 2025

Choose a reason for hiding this comment

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

Can we find this out rather than add a fixme? Or add an issue and point to that instead. Otherwise this will just sit here forever more 😅 CC @benlangmuir

@AnthonyLatsis AnthonyLatsis merged commit 5e22a5b into swiftlang:rebranch Jun 17, 2025
@AnthonyLatsis AnthonyLatsis deleted the rebranch branch June 17, 2025 11:20
drodriguez added a commit to drodriguez/swift that referenced this pull request Nov 11, 2025
…r rebranch

Upstream LLVM in llvm/llvm-project#139584 changed `DiagnosticOptions`
from being a referenced counted object to just be a reference, not owned
by the `clang::DiagnosticEngine`.

In 0981b71 (part of swiftlang#82243), the usages
of the Swift repository were adapted to the new memory model, but it
introduced at least one use-after-free and a potential one around the
usage of Clang in the Clang Importer.

This commit tries to fix the use-after-free in both cases, by returning
a `unique_ptr` to the `clang::DiagnosticOptions`, which makes the
lifetime of the `DiagnosticOptions` match the lifetime of the variable
that uses it (normally a `CompilerInvocation`).

Other cases in 0981b71 should be safe
because the lifetime of the `DiagnosticOptions` do not seem to propagate beyond
the scope of the functions where they live (but I am not fully sure
about the one in `IDETool/CompilerInvocation.cpp` completely).

This was causing compiler crashes during the test
`Interop/Cxx/stdlib/unsupported-stdlib.swift` which eventually uses
`createClangDriver` and tries to emit a diagnostic, which in some cases
was reading the memory from `DiagnosticOptions` when it was already out
of scope.
drodriguez added a commit that referenced this pull request Nov 12, 2025
…r rebranch (#85445)

Upstream LLVM in llvm/llvm-project#139584 changed `DiagnosticOptions`
from being a referenced counted object to just be a reference, not owned
by the `clang::DiagnosticEngine`.

In 0981b71 (part of #82243), the usages
of the Swift repository were adapted to the new memory model, but it
introduced at least one use-after-free and a potential one around the
usage of Clang in the Clang Importer.

This commit tries to fix the use-after-free in both cases, by returning
a `unique_ptr` to the `clang::DiagnosticOptions`, which makes the
lifetime of the `DiagnosticOptions` match the lifetime of the variable
that uses it (normally a `CompilerInvocation`).

Other cases in 0981b71 should be safe
because the lifetime of the `DiagnosticOptions` do not seem to propagate
beyond the scope of the functions where they live (but I am not fully
sure about the one in `IDETool/CompilerInvocation.cpp` completely).

This was causing compiler crashes during the test
`Interop/Cxx/stdlib/unsupported-stdlib.swift` which eventually uses
`createClangDriver` and tries to emit a diagnostic, which in some cases
was reading the memory from `DiagnosticOptions` when it was already out
of scope.
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.

3 participants