From 53e5cd4d3e39dad47312a48d4c6c71318bb2c283 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 17 Dec 2022 06:37:59 +0000 Subject: [PATCH] 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 clang` work in the absence of llvm::Optional::value. --- clang/include/clang/AST/PropertiesBase.td | 10 ++-- clang/include/clang/Basic/DirectoryEntry.h | 2 +- clang/include/clang/Basic/FileEntry.h | 2 +- clang/include/clang/Lex/HeaderMap.h | 8 +-- .../Core/PathSensitive/ConstraintManager.h | 4 +- clang/lib/AST/AttrImpl.cpp | 6 +- clang/lib/Analysis/BodyFarm.cpp | 4 +- .../FlowSensitive/TypeErasedDataflowAnalysis.cpp | 6 +- clang/lib/Analysis/PathDiagnostic.cpp | 12 ++-- clang/lib/Analysis/UninitializedValues.cpp | 9 +-- clang/lib/Basic/Sarif.cpp | 6 +- clang/lib/CodeGen/CGClass.cpp | 6 +- .../Serialization/SymbolGraphSerializer.cpp | 4 +- clang/lib/Frontend/CompilerInstance.cpp | 4 +- clang/lib/Lex/DependencyDirectivesScanner.cpp | 2 +- clang/lib/Lex/MacroInfo.cpp | 2 +- clang/lib/Lex/ModuleMap.cpp | 4 +- clang/lib/Lex/PPMacroExpansion.cpp | 4 +- clang/lib/Lex/PreprocessingRecord.cpp | 7 +-- clang/lib/Parse/ParseOpenMP.cpp | 18 +++--- clang/lib/Sema/Scope.cpp | 2 +- clang/lib/Sema/SemaCUDA.cpp | 12 ++-- clang/lib/Sema/SemaChecking.cpp | 4 +- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/lib/Sema/SemaOpenMP.cpp | 65 +++++++++++----------- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 +- .../lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 2 +- .../Checkers/NonNullParamChecker.cpp | 4 +- clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 6 +- .../StaticAnalyzer/Core/BugReporterVisitors.cpp | 2 +- .../Core/ExprEngineCallAndReturn.cpp | 2 +- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp | 4 +- llvm/include/llvm/ADT/STLForwardCompat.h | 8 +-- polly/lib/Transform/ManualOptimizer.cpp | 2 +- 34 files changed, 114 insertions(+), 125 deletions(-) diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td index 474b49b..6c7f692 100644 --- a/clang/include/clang/AST/PropertiesBase.td +++ b/clang/include/clang/AST/PropertiesBase.td @@ -521,15 +521,15 @@ let Class = PropertyTypeCase in { if (hasBase) { if (isTypeInfo) { base = APValue::LValueBase::getTypeInfo( - TypeInfoLValue(typeInfo.value().getTypePtr()), type.value()); + TypeInfoLValue(typeInfo->getTypePtr()), *type); elemTy = base.getTypeInfoType(); } else if (isExpr) { - base = APValue::LValueBase(cast(stmt.value()), - callIndex.value(), version.value()); + base = APValue::LValueBase(cast(*stmt), + *callIndex, *version); elemTy = base.get()->getType(); } else { - base = APValue::LValueBase(cast(decl.value()), - callIndex.value(), version.value()); + base = APValue::LValueBase(cast(*decl), + *callIndex, *version); elemTy = base.get()->getType(); } } diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h index c8e10fb..1a31826 100644 --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -289,7 +289,7 @@ public: /// DirectoryEntry::getName have been deleted, delete this class and replace /// instances with Optional operator const DirectoryEntry *() const { - return has_value() ? &value().getDirEntry() : nullptr; + return has_value() ? &(*this)->getDirEntry() : nullptr; } }; diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 3a2b9ff..9f00cfa 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -332,7 +332,7 @@ public: /// FileEntry::getName have been deleted, delete this class and replace /// instances with Optional operator const FileEntry *() const { - return has_value() ? &value().getFileEntry() : nullptr; + return has_value() ? &(*this)->getFileEntry() : nullptr; } }; diff --git a/clang/include/clang/Lex/HeaderMap.h b/clang/include/clang/Lex/HeaderMap.h index 222776d..2a4af28 100644 --- a/clang/include/clang/Lex/HeaderMap.h +++ b/clang/include/clang/Lex/HeaderMap.h @@ -47,11 +47,9 @@ public: for (unsigned Bucket = 0; Bucket < NumBuckets; ++Bucket) { HMapBucket B = getBucket(Bucket); - if (B.Key != HMAP_EmptyBucketKey) { - Optional Key = getString(B.Key); - if (Key) - Callback(Key.value()); - } + if (B.Key != HMAP_EmptyBucketKey) + if (Optional Key = getString(B.Key)) + Callback(*Key); } } diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h index ca6d784..92df266 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h @@ -53,10 +53,10 @@ public: } /// Return true if the constraint is perfectly constrained to 'true'. - bool isConstrainedTrue() const { return Val && Val.value(); } + bool isConstrainedTrue() const { return Val && *Val; } /// Return true if the constraint is perfectly constrained to 'false'. - bool isConstrainedFalse() const { return Val && !Val.value(); } + bool isConstrainedFalse() const { return Val && !*Val; } /// Return true if the constrained is perfectly constrained. bool isConstrained() const { return Val.has_value(); } diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp index 2f88732..38d77b8 100644 --- a/clang/lib/AST/AttrImpl.cpp +++ b/clang/lib/AST/AttrImpl.cpp @@ -169,7 +169,7 @@ llvm::Optional OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(const ValueDecl *VD) { llvm::Optional ActiveAttr = getActiveAttr(VD); if (ActiveAttr) - return ActiveAttr.value()->getMapType(); + return (*ActiveAttr)->getMapType(); return std::nullopt; } @@ -177,7 +177,7 @@ llvm::Optional OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) { llvm::Optional ActiveAttr = getActiveAttr(VD); if (ActiveAttr) - return ActiveAttr.value()->getDevType(); + return (*ActiveAttr)->getDevType(); return std::nullopt; } @@ -185,7 +185,7 @@ llvm::Optional OMPDeclareTargetDeclAttr::getLocation(const ValueDecl *VD) { llvm::Optional ActiveAttr = getActiveAttr(VD); if (ActiveAttr) - return ActiveAttr.value()->getRange().getBegin(); + return (*ActiveAttr)->getRange().getBegin(); return std::nullopt; } diff --git a/clang/lib/Analysis/BodyFarm.cpp b/clang/lib/Analysis/BodyFarm.cpp index b242008..cf9c22f 100644 --- a/clang/lib/Analysis/BodyFarm.cpp +++ b/clang/lib/Analysis/BodyFarm.cpp @@ -699,7 +699,7 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D) Stmt *BodyFarm::getBody(const FunctionDecl *D) { Optional &Val = Bodies[D]; if (Val) - return Val.value(); + return *Val; Val = nullptr; @@ -874,7 +874,7 @@ Stmt *BodyFarm::getBody(const ObjCMethodDecl *D) { Optional &Val = Bodies[D]; if (Val) - return Val.value(); + return *Val; Val = nullptr; // For now, we only synthesize getters. diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp index e221a8b..5c88568 100644 --- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp +++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp @@ -51,7 +51,7 @@ public: assert(BlockIt != CFCtx.getStmtToBlock().end()); const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()]; assert(State); - return &State.value().Env; + return &State->Env; } private: @@ -450,7 +450,7 @@ runTypeErasedDataflowAnalysis( if (OldBlockState) { if (isLoopHead(*Block)) { LatticeJoinEffect Effect1 = Analysis.widenTypeErased( - NewBlockState.Lattice, OldBlockState.value().Lattice); + NewBlockState.Lattice, OldBlockState->Lattice); LatticeJoinEffect Effect2 = NewBlockState.Env.widen(OldBlockState->Env, Analysis); if (Effect1 == LatticeJoinEffect::Unchanged && @@ -458,7 +458,7 @@ runTypeErasedDataflowAnalysis( // The state of `Block` didn't change from widening so there's no need // to revisit its successors. continue; - } else if (Analysis.isEqualTypeErased(OldBlockState.value().Lattice, + } else if (Analysis.isEqualTypeErased(OldBlockState->Lattice, NewBlockState.Lattice) && OldBlockState->Env.equivalentTo(NewBlockState.Env, Analysis)) { // The state of `Block` didn't change after transfer so there's no need diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp index f168359..e2a20a0 100644 --- a/clang/lib/Analysis/PathDiagnostic.cpp +++ b/clang/lib/Analysis/PathDiagnostic.cpp @@ -316,11 +316,9 @@ static Optional comparePath(const PathPieces &X, const PathPieces &Y) { PathPieces::const_iterator X_I = X.begin(), X_end = X.end(); PathPieces::const_iterator Y_I = Y.begin(), Y_end = Y.end(); - for ( ; X_I != X_end && Y_I != Y_end; ++X_I, ++Y_I) { - Optional b = comparePiece(**X_I, **Y_I); - if (b) - return b.value(); - } + for (; X_I != X_end && Y_I != Y_end; ++X_I, ++Y_I) + if (Optional b = comparePiece(**X_I, **Y_I)) + return *b; return std::nullopt; } @@ -394,9 +392,7 @@ static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y) { if (*XI != *YI) return (*XI) < (*YI); } - Optional b = comparePath(X.path, Y.path); - assert(b); - return b.value(); + return *comparePath(X.path, Y.path); } void PathDiagnosticConsumer::FlushDiagnostics( diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp index 98d4dde..e2f1f6e8 100644 --- a/clang/lib/Analysis/UninitializedValues.cpp +++ b/clang/lib/Analysis/UninitializedValues.cpp @@ -147,9 +147,8 @@ public: Value getValue(const CFGBlock *block, const CFGBlock *dstBlock, const VarDecl *vd) { - const Optional &idx = declToIndex.getValueIndex(vd); - assert(idx); - return getValueVector(block)[idx.value()]; + Optional idx = declToIndex.getValueIndex(vd); + return getValueVector(block)[*idx]; } }; @@ -208,9 +207,7 @@ void CFGBlockValues::resetScratch() { } ValueVector::reference CFGBlockValues::operator[](const VarDecl *vd) { - const Optional &idx = declToIndex.getValueIndex(vd); - assert(idx); - return scratch[idx.value()]; + return scratch[*declToIndex.getValueIndex(vd)]; } //------------------------------------------------------------------------====// diff --git a/clang/lib/Basic/Sarif.cpp b/clang/lib/Basic/Sarif.cpp index a2f0faf..2c1eebc 100644 --- a/clang/lib/Basic/Sarif.cpp +++ b/clang/lib/Basic/Sarif.cpp @@ -237,7 +237,7 @@ SarifDocumentWriter::createPhysicalLocation(const CharSourceRange &R) { const SarifArtifactLocation &Location = I->second.Location; json::Object ArtifactLocationObject{{"uri", Location.URI}}; if (Location.Index.has_value()) - ArtifactLocationObject["index"] = Location.Index.value(); + ArtifactLocationObject["index"] = *Location.Index; return json::Object{{{"artifactLocation", std::move(ArtifactLocationObject)}, {"region", createTextRegion(SourceMgr, R)}}}; } @@ -296,12 +296,12 @@ void SarifDocumentWriter::endRun() { const SarifArtifact &A = Pair.getValue(); json::Object Loc{{"uri", A.Location.URI}}; if (A.Location.Index.has_value()) { - Loc["index"] = static_cast(A.Location.Index.value()); + Loc["index"] = static_cast(*A.Location.Index); } json::Object Artifact; Artifact["location"] = std::move(Loc); if (A.Length.has_value()) - Artifact["length"] = static_cast(A.Length.value()); + Artifact["length"] = static_cast(*A.Length); if (!A.Roles.empty()) Artifact["roles"] = json::Array(A.Roles); if (!A.MimeType.empty()) diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index fd139a0..bf3b0c3 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1822,15 +1822,15 @@ namespace { if (!StartIndex) StartIndex = FieldIndex; } else if (StartIndex) { - EHStack.pushCleanup( - NormalAndEHCleanup, DD, StartIndex.value(), FieldIndex); + EHStack.pushCleanup(NormalAndEHCleanup, DD, + *StartIndex, FieldIndex); StartIndex = std::nullopt; } } void End() { if (StartIndex) EHStack.pushCleanup(NormalAndEHCleanup, DD, - StartIndex.value(), -1); + *StartIndex, -1); } }; } // end anonymous namespace diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp index 9122d49..5c7ab65 100644 --- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp +++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp @@ -39,14 +39,14 @@ namespace { /// at position \p Key. void serializeObject(Object &Paren, StringRef Key, Optional Obj) { if (Obj) - Paren[Key] = std::move(Obj.value()); + Paren[Key] = std::move(*Obj); } /// Helper function to inject a JSON array \p Array into object \p Paren at /// position \p Key. void serializeArray(Object &Paren, StringRef Key, Optional Array) { if (Array) - Paren[Key] = std::move(Array.value()); + Paren[Key] = std::move(*Array); } /// Serialize a \c VersionTuple \p V with the Symbol Graph semantic version diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index b3ec8e4..acb3cb8 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -119,9 +119,9 @@ bool CompilerInstance::createTarget() { auto TO = std::make_shared(); TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple); if (getFrontendOpts().AuxTargetCPU) - TO->CPU = getFrontendOpts().AuxTargetCPU.value(); + TO->CPU = *getFrontendOpts().AuxTargetCPU; if (getFrontendOpts().AuxTargetFeatures) - TO->FeaturesAsWritten = getFrontendOpts().AuxTargetFeatures.value(); + TO->FeaturesAsWritten = *getFrontendOpts().AuxTargetFeatures; TO->HostTriple = getTarget().getTriple().str(); setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO)); } diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp index a709847..183be4f 100644 --- a/clang/lib/Lex/DependencyDirectivesScanner.cpp +++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -557,7 +557,7 @@ Scanner::tryLexIdentifierOrSkipLine(const char *&First, const char *const End) { StringRef Scanner::lexIdentifier(const char *&First, const char *const End) { Optional Id = tryLexIdentifierOrSkipLine(First, End); assert(Id && "expected identifier token"); - return Id.value(); + return *Id; } bool Scanner::isNextIdentifierOrSkipLine(StringRef Id, const char *&First, diff --git a/clang/lib/Lex/MacroInfo.cpp b/clang/lib/Lex/MacroInfo.cpp index eb69e8e..bfac365 100644 --- a/clang/lib/Lex/MacroInfo.cpp +++ b/clang/lib/Lex/MacroInfo.cpp @@ -213,7 +213,7 @@ MacroDirective::DefInfo MacroDirective::getDefinition() { isPublic = VisMD->isPublic(); } - return DefInfo(nullptr, UndefLoc, !isPublic || isPublic.value()); + return DefInfo(nullptr, UndefLoc, !isPublic || *isPublic); } const MacroDirective::DefInfo diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 1032922..f5a7f51 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1215,8 +1215,8 @@ void ModuleMap::resolveHeaderDirectives( Module *Mod, llvm::Optional File) const { bool NeedsFramework = false; SmallVector NewHeaders; - const auto Size = File ? File.value()->getSize() : 0; - const auto ModTime = File ? File.value()->getModificationTime() : 0; + const auto Size = File ? (*File)->getSize() : 0; + const auto ModTime = File ? (*File)->getModificationTime() : 0; for (auto &Header : Mod->UnresolvedHeaders) { if (File && ((Header.ModTime && Header.ModTime != ModTime) || diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index d1aca2d..c33c9d1 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1345,10 +1345,10 @@ already_lexed: // The last ')' has been reached; return the value if one found or // a diagnostic and a dummy value. if (Result) { - OS << Result.value(); + OS << *Result; // For strict conformance to __has_cpp_attribute rules, use 'L' // suffix for dated literals. - if (Result.value() > 1) + if (*Result > 1) OS << 'L'; } else { OS << 0; diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index 2146a7c..35f9e4d 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -112,10 +112,9 @@ bool PreprocessingRecord::isEntityInFileID(iterator PPEI, FileID FID) { // See if the external source can see if the entity is in the file without // deserializing it. - Optional IsInFile = - ExternalSource->isPreprocessedEntityInFileID(LoadedIndex, FID); - if (IsInFile) - return IsInFile.value(); + if (Optional IsInFile = + ExternalSource->isPreprocessedEntityInFileID(LoadedIndex, FID)) + return *IsInFile; // The external source did not provide a definite answer, go and deserialize // the entity to check it. diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index fd0fc30..680cae7 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -1881,11 +1881,11 @@ void Parser::ParseOMPDeclareTargetClauses( if (DevTypeData) { if (DeviceTypeLoc.isValid()) { // We already saw another device_type clause, diagnose it. - Diag(DevTypeData.value().Loc, + Diag(DevTypeData->Loc, diag::warn_omp_more_one_device_type_clause); break; } - switch (static_cast(DevTypeData.value().Type)) { + switch (static_cast(DevTypeData->Type)) { case OMPC_DEVICE_TYPE_any: DTCI.DT = OMPDeclareTargetDeclAttr::DT_Any; break; @@ -3697,20 +3697,20 @@ OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind, if (!Val || ParseOnly) return nullptr; if (getLangOpts().OpenMP < 51 && Kind == OMPC_default && - (static_cast(Val.value().Type) == OMP_DEFAULT_private || - static_cast(Val.value().Type) == + (static_cast(Val->Type) == OMP_DEFAULT_private || + static_cast(Val->Type) == OMP_DEFAULT_firstprivate)) { - Diag(Val.value().LOpen, diag::err_omp_invalid_dsa) - << getOpenMPClauseName(static_cast(Val.value().Type) == + Diag(Val->LOpen, diag::err_omp_invalid_dsa) + << getOpenMPClauseName(static_cast(Val->Type) == OMP_DEFAULT_private ? OMPC_private : OMPC_firstprivate) << getOpenMPClauseName(OMPC_default) << "5.1"; return nullptr; } - return Actions.ActOnOpenMPSimpleClause(Kind, Val.value().Type, - Val.value().TypeLoc, Val.value().LOpen, - Val.value().Loc, Val.value().RLoc); + return Actions.ActOnOpenMPSimpleClause(Kind, Val->Type, + Val->TypeLoc, Val->LOpen, + Val->Loc, Val->RLoc); } /// Parsing of OpenMP clauses like 'ordered'. diff --git a/clang/lib/Sema/Scope.cpp b/clang/lib/Sema/Scope.cpp index 5dd7df2..c995c7e 100644 --- a/clang/lib/Sema/Scope.cpp +++ b/clang/lib/Sema/Scope.cpp @@ -163,7 +163,7 @@ void Scope::applyNRVO() { return; if (*NRVO && isDeclScope(*NRVO)) - NRVO.value()->setNRVOVariable(true); + (*NRVO)->setNRVOVariable(true); // It's necessary to propagate NRVO candidate to the parent scope for cases // when the parent scope doesn't contain a return statement. diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index e8dd4c9..01349f41 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -381,12 +381,12 @@ bool Sema::inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, InferredTarget = BaseMethodTarget; } else { bool ResolutionError = resolveCalleeCUDATargetConflict( - InferredTarget.value(), BaseMethodTarget, &*InferredTarget); + *InferredTarget, BaseMethodTarget, &*InferredTarget); if (ResolutionError) { if (Diagnose) { Diag(ClassDecl->getLocation(), diag::note_implicit_member_target_infer_collision) - << (unsigned)CSM << InferredTarget.value() << BaseMethodTarget; + << (unsigned)CSM << *InferredTarget << BaseMethodTarget; } MemberDecl->addAttr(CUDAInvalidTargetAttr::CreateImplicit(Context)); return true; @@ -424,12 +424,12 @@ bool Sema::inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, InferredTarget = FieldMethodTarget; } else { bool ResolutionError = resolveCalleeCUDATargetConflict( - InferredTarget.value(), FieldMethodTarget, &*InferredTarget); + *InferredTarget, FieldMethodTarget, &*InferredTarget); if (ResolutionError) { if (Diagnose) { Diag(ClassDecl->getLocation(), diag::note_implicit_member_target_infer_collision) - << (unsigned)CSM << InferredTarget.value() << FieldMethodTarget; + << (unsigned)CSM << *InferredTarget << FieldMethodTarget; } MemberDecl->addAttr(CUDAInvalidTargetAttr::CreateImplicit(Context)); return true; @@ -442,9 +442,9 @@ bool Sema::inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, // it's the least restrictive option that can be invoked from any target. bool NeedsH = true, NeedsD = true; if (InferredTarget) { - if (InferredTarget.value() == CFT_Device) + if (*InferredTarget == CFT_Device) NeedsH = false; - else if (InferredTarget.value() == CFT_Host) + else if (*InferredTarget == CFT_Host) NeedsD = false; } diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 86f1c3c..68ae989 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1918,7 +1918,7 @@ static ExprResult SemaBuiltinLaunder(Sema &S, CallExpr *TheCall) { }(); if (DiagSelect) { S.Diag(TheCall->getBeginLoc(), diag::err_builtin_launder_invalid_arg) - << DiagSelect.value() << TheCall->getSourceRange(); + << *DiagSelect << TheCall->getSourceRange(); return ExprError(); } @@ -14748,7 +14748,7 @@ void Sema::CheckForIntOverflow (Expr *E) { else if (auto New = dyn_cast(E)) { if (New->isArray()) if (auto ArraySize = New->getArraySize()) - Exprs.push_back(ArraySize.value()); + Exprs.push_back(*ArraySize); } } while (!Exprs.empty()); } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6e5c026..0d2cd02 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -15867,7 +15867,7 @@ void Sema::AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( // specified by the value of this argument. if (AlignmentParam && !FD->hasAttr()) { FD->addAttr(AllocAlignAttr::CreateImplicit( - Context, ParamIdx(AlignmentParam.value(), FD), FD->getLocation())); + Context, ParamIdx(*AlignmentParam, FD), FD->getLocation())); } // FIXME: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 36aa97e..49f401d 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -848,7 +848,7 @@ public: std::pair getOrderedRegionParam() const { if (const SharingMapTy *Top = getTopOfStackOrNull()) if (Top->OrderedRegion) - return Top->OrderedRegion.value(); + return *Top->OrderedRegion; return std::make_pair(nullptr, nullptr); } /// Returns true, if parent region is ordered (has associated @@ -863,7 +863,7 @@ public: getParentOrderedRegionParam() const { if (const SharingMapTy *Parent = getSecondOnStackOrNull()) if (Parent->OrderedRegion) - return Parent->OrderedRegion.value(); + return *Parent->OrderedRegion; return std::make_pair(nullptr, nullptr); } /// Marks current region as having an 'order' clause. @@ -7985,19 +7985,18 @@ bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) { // != with increment is treated as <; != with decrement is treated as > if (!TestIsLessOp) TestIsLessOp = IsConstPos || (IsUnsigned && !Subtract); - if (UB && - (IsConstZero || - (TestIsLessOp.value() ? (IsConstNeg || (IsUnsigned && Subtract)) - : (IsConstPos || (IsUnsigned && !Subtract))))) { + if (UB && (IsConstZero || + (*TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) + : (IsConstPos || (IsUnsigned && !Subtract))))) { SemaRef.Diag(NewStep->getExprLoc(), diag::err_omp_loop_incr_not_compatible) - << LCDecl << TestIsLessOp.value() << NewStep->getSourceRange(); + << LCDecl << *TestIsLessOp << NewStep->getSourceRange(); SemaRef.Diag(ConditionLoc, diag::note_omp_loop_cond_requres_compatible_incr) - << TestIsLessOp.value() << ConditionSrcRange; + << *TestIsLessOp << ConditionSrcRange; return true; } - if (TestIsLessOp.value() == Subtract) { + if (*TestIsLessOp == Subtract) { NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) .get(); @@ -8752,8 +8751,8 @@ Expr *OpenMPIterationSpaceChecker::buildNumIterations( UBVal = MinUB.get(); } } - Expr *UBExpr = TestIsLessOp.value() ? UBVal : LBVal; - Expr *LBExpr = TestIsLessOp.value() ? LBVal : UBVal; + Expr *UBExpr = *TestIsLessOp ? UBVal : LBVal; + Expr *LBExpr = *TestIsLessOp ? LBVal : UBVal; Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); if (!Upper || !Lower) @@ -8816,12 +8815,12 @@ std::pair OpenMPIterationSpaceChecker::buildMinMaxValues( // init value. Expr *MinExpr = nullptr; Expr *MaxExpr = nullptr; - Expr *LBExpr = TestIsLessOp.value() ? LB : UB; - Expr *UBExpr = TestIsLessOp.value() ? UB : LB; - bool LBNonRect = TestIsLessOp.value() ? InitDependOnLC.has_value() - : CondDependOnLC.has_value(); - bool UBNonRect = TestIsLessOp.value() ? CondDependOnLC.has_value() - : InitDependOnLC.has_value(); + Expr *LBExpr = *TestIsLessOp ? LB : UB; + Expr *UBExpr = *TestIsLessOp ? UB : LB; + bool LBNonRect = + *TestIsLessOp ? InitDependOnLC.has_value() : CondDependOnLC.has_value(); + bool UBNonRect = + *TestIsLessOp ? CondDependOnLC.has_value() : InitDependOnLC.has_value(); Expr *Lower = LBNonRect ? LBExpr : tryBuildCapture(SemaRef, LBExpr, Captures).get(); Expr *Upper = @@ -8943,11 +8942,11 @@ Expr *OpenMPIterationSpaceChecker::buildPreCond( if (!NewLB.isUsable() || !NewUB.isUsable()) return nullptr; - ExprResult CondExpr = SemaRef.BuildBinOp( - S, DefaultLoc, - TestIsLessOp.value() ? (TestIsStrictOp ? BO_LT : BO_LE) - : (TestIsStrictOp ? BO_GT : BO_GE), - NewLB.get(), NewUB.get()); + ExprResult CondExpr = + SemaRef.BuildBinOp(S, DefaultLoc, + *TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) + : (TestIsStrictOp ? BO_GT : BO_GE), + NewLB.get(), NewUB.get()); if (CondExpr.isUsable()) { if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), SemaRef.Context.BoolTy)) @@ -9023,9 +9022,9 @@ Expr *OpenMPIterationSpaceChecker::buildOrderedLoopData( return nullptr; // Upper - Lower Expr *Upper = - TestIsLessOp.value() ? Cnt : tryBuildCapture(SemaRef, LB, Captures).get(); + *TestIsLessOp ? Cnt : tryBuildCapture(SemaRef, LB, Captures).get(); Expr *Lower = - TestIsLessOp.value() ? tryBuildCapture(SemaRef, LB, Captures).get() : Cnt; + *TestIsLessOp ? tryBuildCapture(SemaRef, LB, Captures).get() : Cnt; if (!Upper || !Lower) return nullptr; @@ -22811,27 +22810,27 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, auto *VD = cast(ND); llvm::Optional ActiveAttr = OMPDeclareTargetDeclAttr::getActiveAttr(VD); - if (ActiveAttr && ActiveAttr.value()->getDevType() != DTCI.DT && - ActiveAttr.value()->getLevel() == Level) { + if (ActiveAttr && (*ActiveAttr)->getDevType() != DTCI.DT && + (*ActiveAttr)->getLevel() == Level) { Diag(Loc, diag::err_omp_device_type_mismatch) << OMPDeclareTargetDeclAttr::ConvertDevTypeTyToStr(DTCI.DT) << OMPDeclareTargetDeclAttr::ConvertDevTypeTyToStr( - ActiveAttr.value()->getDevType()); + (*ActiveAttr)->getDevType()); return; } - if (ActiveAttr && ActiveAttr.value()->getMapType() != MT && - ActiveAttr.value()->getLevel() == Level) { + if (ActiveAttr && (*ActiveAttr)->getMapType() != MT && + (*ActiveAttr)->getLevel() == Level) { Diag(Loc, diag::err_omp_declare_target_to_and_link) << ND; return; } - if (ActiveAttr && ActiveAttr.value()->getLevel() == Level) + if (ActiveAttr && (*ActiveAttr)->getLevel() == Level) return; Expr *IndirectE = nullptr; bool IsIndirect = false; if (DTCI.Indirect) { - IndirectE = DTCI.Indirect.value(); + IndirectE = *DTCI.Indirect; if (!IndirectE) IsIndirect = true; } @@ -22926,13 +22925,13 @@ void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, llvm::Optional ActiveAttr = OMPDeclareTargetDeclAttr::getActiveAttr(VD); unsigned Level = DeclareTargetNesting.size(); - if (ActiveAttr && ActiveAttr.value()->getLevel() >= Level) + if (ActiveAttr && (*ActiveAttr)->getLevel() >= Level) return; DeclareTargetContextInfo &DTCI = DeclareTargetNesting.back(); Expr *IndirectE = nullptr; bool IsIndirect = false; if (DTCI.Indirect) { - IndirectE = DTCI.Indirect.value(); + IndirectE = *DTCI.Indirect; if (!IndirectE) IsIndirect = true; } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 5aaa0c3..a05ecea 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -469,8 +469,8 @@ static void instantiateOMPDeclareVariantAttr( if (!DeclVarData) return; - E = DeclVarData.value().second; - FD = DeclVarData.value().first; + E = DeclVarData->second; + FD = DeclVarData->first; if (auto *VariantDRE = dyn_cast(E->IgnoreParenImpCasts())) { if (auto *VariantFD = dyn_cast(VariantDRE->getDecl())) { diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 6eefbd7..9f80172 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1224,7 +1224,7 @@ void MallocChecker::checkKernelMalloc(const CallEvent &Call, llvm::Optional MaybeState = performKernelMalloc(Call, C, State); if (MaybeState) - State = MaybeState.value(); + State = *MaybeState; else State = MallocMemAux(C, Call, Call.getArgExpr(0), UndefinedVal(), State, AF_Malloc); diff --git a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp index fb6afd0..fd47e19 100644 --- a/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp @@ -136,10 +136,10 @@ void NonNullParamChecker::checkPreCall(const CallEvent &Call, if (!DV) continue; - assert(!HasRefTypeParam || isa(DV.value())); + assert(!HasRefTypeParam || isa(*DV)); // Process the case when the argument is not a location. - if (ExpectedToBeNonNull && !isa(DV.value())) { + if (ExpectedToBeNonNull && !isa(*DV)) { // If the argument is a union type, we want to handle a potential // transparent_union GCC extension. if (!ArgE) diff --git a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 2e3c041..f8e32b6 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -77,7 +77,7 @@ AnalyzerOptions::getExplorationStrategy() const { ExplorationStrategyKind::BFSBlockDFSContents) .Default(std::nullopt); assert(K && "User mode is invalid."); - return K.value(); + return *K; } CTUPhase1InliningKind AnalyzerOptions::getCTUPhase1Inlining() const { @@ -88,7 +88,7 @@ CTUPhase1InliningKind AnalyzerOptions::getCTUPhase1Inlining() const { .Case("all", CTUPhase1InliningKind::All) .Default(std::nullopt); assert(K && "CTU inlining mode is invalid."); - return K.value(); + return *K; } IPAKind AnalyzerOptions::getIPAMode() const { @@ -101,7 +101,7 @@ IPAKind AnalyzerOptions::getIPAMode() const { .Default(std::nullopt); assert(K && "IPA Mode is invalid."); - return K.value(); + return *K; } bool diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 469ac61..eecf049 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -3121,7 +3121,7 @@ PathDiagnosticPieceRef ConditionBRVisitor::VisitTrueTest( PathDiagnosticLocation Loc(Cond, SM, LCtx); auto event = std::make_shared(Loc, Message); if (shouldPrune) - event->setPrunable(shouldPrune.value()); + event->setPrunable(*shouldPrune); return event; } diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp index e0bb4a5..d6968db 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp @@ -1092,7 +1092,7 @@ bool ExprEngine::shouldInlineCall(const CallEvent &Call, const Decl *D, // Check if this function has been marked as non-inlinable. Optional MayInline = Engine.FunctionSummaries->mayInline(D); if (MayInline) { - if (!MayInline.value()) + if (!*MayInline) return false; } else { diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp index d35646b..56f441e 100644 --- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -407,11 +407,11 @@ void PlistPrinter::ReportMacroExpansions(raw_ostream &o, unsigned indent) { // Output the macro name. Indent(o, indent) << "name"; - EmitString(o, MacroName.value()) << '\n'; + EmitString(o, *MacroName) << '\n'; // Output what it expands into. Indent(o, indent) << "expansion"; - EmitString(o, ExpansionText.value()) << '\n'; + EmitString(o, *ExpansionText) << '\n'; // Finish up. --indent; diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h index 0ab4bd2..51748c7 100644 --- a/llvm/include/llvm/ADT/STLForwardCompat.h +++ b/llvm/include/llvm/ADT/STLForwardCompat.h @@ -65,9 +65,9 @@ auto transformOptional(std::optional &&O, const Function &F) // complete. template auto transformOptional(const Optional &O, const Function &F) - -> Optional { + -> Optional { if (O) - return F(O.value()); + return F(*O); return std::nullopt; } @@ -75,9 +75,9 @@ auto transformOptional(const Optional &O, const Function &F) // complete. template auto transformOptional(Optional &&O, const Function &F) - -> Optional { + -> Optional { if (O) - return F(std::move(O).value()); + return F(*std::move(O)); return std::nullopt; } diff --git a/polly/lib/Transform/ManualOptimizer.cpp b/polly/lib/Transform/ManualOptimizer.cpp index 382bcd6..f6d0ef2 100644 --- a/polly/lib/Transform/ManualOptimizer.cpp +++ b/polly/lib/Transform/ManualOptimizer.cpp @@ -43,7 +43,7 @@ static TransformationMode hasUnrollTransformation(MDNode *LoopID) { Optional Count = getOptionalIntLoopAttribute(LoopID, "llvm.loop.unroll.count"); if (Count) - return Count.value() == 1 ? TM_SuppressedByUser : TM_ForcedByUser; + return *Count == 1 ? TM_SuppressedByUser : TM_ForcedByUser; if (getBooleanLoopAttribute(LoopID, "llvm.loop.unroll.enable")) return TM_ForcedByUser; -- 2.7.4