From 53243f2a296178b899dcc569475bdcc7e5f30d3b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 17 Dec 2022 03:12:04 +0000 Subject: [PATCH] std::optional::value => operator*/operator-> value() has undesired exception checking semantics and calls __throw_bad_optional_access in libc++. Moreover, the API is unavailable without _LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). This fixes check-clang-tools. --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 12 ++++++------ clang-tools-extra/clangd/ClangdLSPServer.cpp | 4 ++-- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp | 2 +- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 03c698c..37598c4 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -655,10 +655,10 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { if (I.DefLoc) { if (!CDCtx.RepositoryUrl) - Out.emplace_back(writeFileDefinition(I.DefLoc.value())); + Out.emplace_back(writeFileDefinition(*I.DefLoc)); else Out.emplace_back(writeFileDefinition( - I.DefLoc.value(), StringRef{CDCtx.RepositoryUrl.value()})); + *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; @@ -704,10 +704,10 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx, if (I.DefLoc) { if (!CDCtx.RepositoryUrl) - Out.emplace_back(writeFileDefinition(I.DefLoc.value())); + Out.emplace_back(writeFileDefinition(*I.DefLoc)); else Out.emplace_back(writeFileDefinition( - I.DefLoc.value(), StringRef{CDCtx.RepositoryUrl.value()})); + *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; @@ -771,10 +771,10 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx, if (I.DefLoc) { if (!CDCtx.RepositoryUrl) - Out.emplace_back(writeFileDefinition(I.DefLoc.value())); + Out.emplace_back(writeFileDefinition(*I.DefLoc)); else Out.emplace_back(writeFileDefinition( - I.DefLoc.value(), StringRef{CDCtx.RepositoryUrl.value()})); + *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 306ff3b..6259057 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -670,8 +670,8 @@ void ClangdLSPServer::onDocumentDidChange( const DidChangeTextDocumentParams &Params) { auto WantDiags = WantDiagnostics::Auto; if (Params.wantDiagnostics) - WantDiags = Params.wantDiagnostics.value() ? WantDiagnostics::Yes - : WantDiagnostics::No; + WantDiags = + *Params.wantDiagnostics ? WantDiagnostics::Yes : WantDiagnostics::No; PathRef File = Params.textDocument.uri.file(); auto Code = Server->getDraft(File); diff --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp index 72bec10..37d71dd 100644 --- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp @@ -103,7 +103,7 @@ TEST_F(WalkUsedTest, Basic) { auto PrivateFile = Header(AST.fileManager().getFile("private.h").get()); auto PublicFile = Header("\"path/public.h\""); auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID())); - auto VectorSTL = Header(tooling::stdlib::Header::named("").value()); + auto VectorSTL = Header(*tooling::stdlib::Header::named("")); EXPECT_THAT( offsetToProviders(AST, SM), UnorderedElementsAre( diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index e8c1b4a..f5c462e 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -9940,7 +9940,7 @@ private: const Function &Fn) { std::optional Cached = isCachedReachable(Fn); if (Cached) - return Cached.value(); + return *Cached; // The query was not cached, thus it is new. We need to request an update // explicitly to make sure this the information is properly run to a -- 2.7.4