From 1e6adbadc77517037cb0723df26510fb7a8457ec Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 17 Dec 2022 08:10:45 +0000 Subject: [PATCH] [clang] llvm::Optional::value => operator*/operator-> std::optional::value() has undesired exception checking semantics and is unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The call sites block std::optional migration. This makes `ninja check-clang` work in the absence of llvm::Optional::value. --- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp | 2 +- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp | 2 +- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp | 2 +- clang/tools/libclang/CIndex.cpp | 8 ++++---- clang/unittests/Lex/HeaderSearchTest.cpp | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp index b112059..2bdb1cd 100644 --- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp +++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp @@ -36,7 +36,7 @@ buildStmtToBasicBlockMap(const CFG &Cfg) { if (!Stmt) continue; - StmtToBlock[Stmt.value().getStmt()] = Block; + StmtToBlock[Stmt->getStmt()] = Block; } if (const Stmt *TerminatorStmt = Block->getTerminatorStmt()) StmtToBlock[TerminatorStmt] = Block; diff --git a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp index 1e3ecf4..d4886f15 100644 --- a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp +++ b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp @@ -185,7 +185,7 @@ Constraints auto StatusString = clang::dataflow::debugString(Result.getStatus()); auto Solution = Result.getSolution(); - auto SolutionString = Solution ? "\n" + debugString(Solution.value()) : ""; + auto SolutionString = Solution ? "\n" + debugString(*Solution) : ""; return formatv( Template, diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp index 5c88568..ced016f 100644 --- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp +++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp @@ -262,7 +262,7 @@ computeBlockInputState(const CFGBlock &Block, AnalysisContext &AC) { if (!MaybePredState) continue; - TypeErasedDataflowAnalysisState PredState = MaybePredState.value(); + TypeErasedDataflowAnalysisState PredState = *MaybePredState; if (BuiltinTransferOpts) { if (const Stmt *PredTerminatorStmt = Pred->getTerminatorStmt()) { const StmtToEnvMapImpl StmtToEnv(AC.CFCtx, AC.BlockStates); diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index f99275e..9958671 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -538,7 +538,7 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) { const Optional V = handleDeclForVisitation(*TL); if (!V) continue; - return V.value(); + return *V; } } else if (VisitDeclContext( CXXUnit->getASTContext().getTranslationUnitDecl())) @@ -643,7 +643,7 @@ bool CursorVisitor::VisitDeclContext(DeclContext *DC) { const Optional V = handleDeclForVisitation(D); if (!V) continue; - return V.value(); + return *V; } return false; } @@ -677,7 +677,7 @@ Optional CursorVisitor::handleDeclForVisitation(const Decl *D) { const Optional V = shouldVisitCursor(Cursor); if (!V) return std::nullopt; - if (!V.value()) + if (!*V) return false; if (Visit(Cursor, true)) return true; @@ -1076,7 +1076,7 @@ bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) { const Optional &V = shouldVisitCursor(Cursor); if (!V) continue; - if (!V.value()) + if (!*V) return false; if (Visit(Cursor, true)) return true; diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index e67445f..b0f4221 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -214,7 +214,7 @@ TEST_F(HeaderSearchTest, HeaderFrameworkLookup) { EXPECT_TRUE(FoundFile.has_value()); EXPECT_TRUE(IsFrameworkFound); - auto &FE = FoundFile.value(); + auto &FE = *FoundFile; auto FI = Search.getExistingFileInfo(FE); EXPECT_TRUE(FI); EXPECT_TRUE(FI->IsValid); @@ -284,7 +284,7 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) { EXPECT_TRUE(FoundFile.has_value()); EXPECT_TRUE(IsMapped); - auto &FE = FoundFile.value(); + auto &FE = *FoundFile; auto FI = Search.getExistingFileInfo(FE); EXPECT_TRUE(FI); EXPECT_TRUE(FI->IsValid); -- 2.7.4