Fix stack-use-after-scope issue by making LangOptions parameter non temporary (#5586)

The parameter is kept by reference.
Added a test that accesses `LangOptions` and crashes without this fix.

Part of #5176.
This commit is contained in:
Boaz Brickner
2025-06-02 14:28:36 +00:00
committed by GitHub
parent e3738eb196
commit 464ee76b9b
2 changed files with 78 additions and 4 deletions
+4 -4
View File
@@ -84,11 +84,11 @@ class CarbonClangDiagnosticConsumer : public clang::DiagnosticConsumer {
info.FormatDiagnostic(message);
RawStringOstream diagnostics_stream;
// TODO: Consider allowing setting `LangOptions` or use
// `ASTContext::getLangOptions()`.
clang::LangOptions lang_options;
clang::TextDiagnostic text_diagnostic(
diagnostics_stream,
// TODO: Consider allowing setting `LangOptions` or use
// `ASTContext::getLangOptions()`.
clang::LangOptions(),
diagnostics_stream, lang_options,
// TODO: Consider allowing setting `DiagnosticOptions` or use
// `ASTUnit::getDiagnostics().::getLangOptions().getDiagnosticOptions()`.
new clang::DiagnosticOptions());