-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Do not crash while generating a diagnostic for un-instantiatable template #63063
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
@swift-ci please smoke test |
lib/ClangImporter/ClangImporter.cpp
Outdated
// TODO: Use the location of the apply here. | ||
// TODO: This error message should not reference implementation details. | ||
// See: https://github.com/apple/swift/pull/33053#discussion_r477003350 | ||
ctx.Diags.diagnose(SourceLoc(), | ||
diag::unable_to_convert_generic_swift_types.ID, | ||
{func->getName(), StringRef(failedTypesStr)}); | ||
{StringRef(funcName), StringRef(failedTypesStr)}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .diagnose
going to copy when it constructs an in-flight diagnostic? Otherwise, is this going to be a dangling pointer?
I guess we do this with failedTypesStr
too, so it's probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, we can actually avoid the creation of StringRef
s here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature for unable_to_convert_generic_swift_types
takes two StringRef
s so are we just doing an implicit conversion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be safe (depending on when the diagnostic is emitted/if it's stored anywhere), I really don't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you're right. On a closer look, StringRef
s in diagnostic parameters are either emitted in the destructor of InFlightDiagnostic
or copied in DiagnosticEngine::onTentativeDiagnosticFlush
, so this is safe.
…ntiatable template Swift was previously crashing while emitting an error ("could not generate C++ types from the generic Swift types provided") for C++ decls that do not have a name, such as constructors: `func->getName()` triggered an assertion.
2844fe8
to
65f319a
Compare
@swift-ci please smoke test |
Swift was previously crashing while emitting an error ("could not generate C++ types from the generic Swift types provided") for C++ decls that do not have a name, such as constructors:
func->getName()
triggered an assertion.