[clang] 53e5cd4 - llvm::Optional::value => operator*/operator->
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 16 22:38:05 PST 2022
Author: Fangrui Song
Date: 2022-12-17T06:37:59Z
New Revision: 53e5cd4d3e39dad47312a48d4c6c71318bb2c283
URL: https://github.com/llvm/llvm-project/commit/53e5cd4d3e39dad47312a48d4c6c71318bb2c283
DIFF: https://github.com/llvm/llvm-project/commit/53e5cd4d3e39dad47312a48d4c6c71318bb2c283.diff
LOG: 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.
Added:
Modified:
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/Basic/DirectoryEntry.h
clang/include/clang/Basic/FileEntry.h
clang/include/clang/Lex/HeaderMap.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
clang/lib/AST/AttrImpl.cpp
clang/lib/Analysis/BodyFarm.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/lib/Analysis/PathDiagnostic.cpp
clang/lib/Analysis/UninitializedValues.cpp
clang/lib/Basic/Sarif.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Lex/MacroInfo.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/PreprocessingRecord.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
llvm/include/llvm/ADT/STLForwardCompat.h
polly/lib/Transform/ManualOptimizer.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td
index 474b49b0cd006..6c7f6928305e8 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -521,15 +521,15 @@ let Class = PropertyTypeCase<APValue, "LValue"> 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<Expr>(stmt.value()),
- callIndex.value(), version.value());
+ base = APValue::LValueBase(cast<Expr>(*stmt),
+ *callIndex, *version);
elemTy = base.get<const Expr *>()->getType();
} else {
- base = APValue::LValueBase(cast<ValueDecl>(decl.value()),
- callIndex.value(), version.value());
+ base = APValue::LValueBase(cast<ValueDecl>(*decl),
+ *callIndex, *version);
elemTy = base.get<const ValueDecl *>()->getType();
}
}
diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h
index c8e10fb88b963..1a318264717f4 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -289,7 +289,7 @@ class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr
/// DirectoryEntry::getName have been deleted, delete this class and replace
/// instances with Optional<DirectoryEntryRef>
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 3a2b9ffab0355..9f00cfaeec2a7 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -332,7 +332,7 @@ class OptionalFileEntryRefDegradesToFileEntryPtr
/// FileEntry::getName have been deleted, delete this class and replace
/// instances with Optional<FileEntryRef>
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 222776d88c54a..2a4af28eaef0c 100644
--- a/clang/include/clang/Lex/HeaderMap.h
+++ b/clang/include/clang/Lex/HeaderMap.h
@@ -47,11 +47,9 @@ class HeaderMapImpl {
for (unsigned Bucket = 0; Bucket < NumBuckets; ++Bucket) {
HMapBucket B = getBucket(Bucket);
- if (B.Key != HMAP_EmptyBucketKey) {
- Optional<StringRef> Key = getString(B.Key);
- if (Key)
- Callback(Key.value());
- }
+ if (B.Key != HMAP_EmptyBucketKey)
+ if (Optional<StringRef> 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 ca6d7849d6210..92df266115243 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -53,10 +53,10 @@ class ConditionTruthVal {
}
/// 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 2f88732a4c8b6..38d77b845e846 100644
--- a/clang/lib/AST/AttrImpl.cpp
+++ b/clang/lib/AST/AttrImpl.cpp
@@ -169,7 +169,7 @@ llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy>
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(const ValueDecl *VD) {
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
if (ActiveAttr)
- return ActiveAttr.value()->getMapType();
+ return (*ActiveAttr)->getMapType();
return std::nullopt;
}
@@ -177,7 +177,7 @@ llvm::Optional<OMPDeclareTargetDeclAttr::DevTypeTy>
OMPDeclareTargetDeclAttr::getDeviceType(const ValueDecl *VD) {
llvm::Optional<OMPDeclareTargetDeclAttr *> ActiveAttr = getActiveAttr(VD);
if (ActiveAttr)
- return ActiveAttr.value()->getDevType();
+ return (*ActiveAttr)->getDevType();
return std::nullopt;
}
@@ -185,7 +185,7 @@ llvm::Optional<SourceLocation>
OMPDeclareTargetDeclAttr::getLocation(const ValueDecl *VD) {
llvm::Optional<OMPDeclareTargetDeclAttr *> 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 b242008865cc4..cf9c22fafe258 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<Stmt *> &Val = Bodies[D];
if (Val)
- return Val.value();
+ return *Val;
Val = nullptr;
@@ -874,7 +874,7 @@ Stmt *BodyFarm::getBody(const ObjCMethodDecl *D) {
Optional<Stmt *> &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 e221a8bba22ad..5c885680207d7 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -51,7 +51,7 @@ class StmtToEnvMapImpl : public StmtToEnvMap {
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 f16835999bcfe..e2a20a0f85151 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -316,11 +316,9 @@ static Optional<bool> 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<bool> 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<bool> 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<bool> 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 98d4dde111b4d..e2f1f6e897d46 100644
--- a/clang/lib/Analysis/UninitializedValues.cpp
+++ b/clang/lib/Analysis/UninitializedValues.cpp
@@ -147,9 +147,8 @@ class CFGBlockValues {
Value getValue(const CFGBlock *block, const CFGBlock *dstBlock,
const VarDecl *vd) {
- const Optional<unsigned> &idx = declToIndex.getValueIndex(vd);
- assert(idx);
- return getValueVector(block)[idx.value()];
+ Optional<unsigned> idx = declToIndex.getValueIndex(vd);
+ return getValueVector(block)[*idx];
}
};
@@ -208,9 +207,7 @@ void CFGBlockValues::resetScratch() {
}
ValueVector::reference CFGBlockValues::operator[](const VarDecl *vd) {
- const Optional<unsigned> &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 a2f0faf2e38fa..2c1eebc128700 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<int64_t>(A.Location.Index.value());
+ Loc["index"] = static_cast<int64_t>(*A.Location.Index);
}
json::Object Artifact;
Artifact["location"] = std::move(Loc);
if (A.Length.has_value())
- Artifact["length"] = static_cast<int64_t>(A.Length.value());
+ Artifact["length"] = static_cast<int64_t>(*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 fd139a0ac6985..bf3b0c3d74825 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<SanitizeDtorFieldRange>(
- NormalAndEHCleanup, DD, StartIndex.value(), FieldIndex);
+ EHStack.pushCleanup<SanitizeDtorFieldRange>(NormalAndEHCleanup, DD,
+ *StartIndex, FieldIndex);
StartIndex = std::nullopt;
}
}
void End() {
if (StartIndex)
EHStack.pushCleanup<SanitizeDtorFieldRange>(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 9122d491b873c..5c7ab654c05c9 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<Object> 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> 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 b3ec8e48be828..acb3cb85314dd 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<TargetOptions>();
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 a709847a83892..183be4f5dc7ee 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<StringRef> 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 eb69e8eaab778..bfac365c9d7dc 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 10329229f71e7..f5a7f5102d13c 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1215,8 +1215,8 @@ void ModuleMap::resolveHeaderDirectives(
Module *Mod, llvm::Optional<const FileEntry *> File) const {
bool NeedsFramework = false;
SmallVector<Module::UnresolvedHeaderDirective, 1> 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 d1aca2d2120f4..c33c9d13bd7f9 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1345,10 +1345,10 @@ static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream& OS,
// 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 2146a7c042179..35f9e4dbfe3ff 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<bool> IsInFile =
- ExternalSource->isPreprocessedEntityInFileID(LoadedIndex, FID);
- if (IsInFile)
- return IsInFile.value();
+ if (Optional<bool> 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 fd0fc309a2834..680cae705fcce 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<OpenMPDeviceType>(DevTypeData.value().Type)) {
+ switch (static_cast<OpenMPDeviceType>(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<DefaultKind>(Val.value().Type) == OMP_DEFAULT_private ||
- static_cast<DefaultKind>(Val.value().Type) ==
+ (static_cast<DefaultKind>(Val->Type) == OMP_DEFAULT_private ||
+ static_cast<DefaultKind>(Val->Type) ==
OMP_DEFAULT_firstprivate)) {
- Diag(Val.value().LOpen, diag::err_omp_invalid_dsa)
- << getOpenMPClauseName(static_cast<DefaultKind>(Val.value().Type) ==
+ Diag(Val->LOpen, diag::err_omp_invalid_dsa)
+ << getOpenMPClauseName(static_cast<DefaultKind>(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 5dd7df2c8350a..c995c7e65f4b7 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 e8dd4c98fe995..01349f41e84cb 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 86f1c3c42598a..68ae9896554bd 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<CXXNewExpr>(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 6e5c026167230..0d2cd02d10293 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<AllocAlignAttr>()) {
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 36aa97ed3a2fc..49f401dfff690 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -848,7 +848,7 @@ class DSAStackTy {
std::pair<const Expr *, OMPOrderedClause *> 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 @@ class DSAStackTy {
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<Expr *, Expr *> 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<ValueDecl>(ND);
llvm::Optional<OMPDeclareTargetDeclAttr *> 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<OMPDeclareTargetDeclAttr *> 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 5aaa0c36ea671..a05eceac73988 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<DeclRefExpr>(E->IgnoreParenImpCasts())) {
if (auto *VariantFD = dyn_cast<FunctionDecl>(VariantDRE->getDecl())) {
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 6eefbd7c83b79..9f8017266bb93 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<ProgramStateRef> 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 fb6afd0fdabcd..fd47e19cb786c 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<Loc>(DV.value()));
+ assert(!HasRefTypeParam || isa<Loc>(*DV));
// Process the case when the argument is not a location.
- if (ExpectedToBeNonNull && !isa<Loc>(DV.value())) {
+ if (ExpectedToBeNonNull && !isa<Loc>(*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 2e3c0415903d6..f8e32b6769cfb 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 469ac61563f3a..eecf04941e429 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<PathDiagnosticEventPiece>(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 e0bb4a56da5c3..d6968db31de9a 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<bool> 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 d35646bfba910..56f441ec2c8f2 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) << "<key>name</key>";
- EmitString(o, MacroName.value()) << '\n';
+ EmitString(o, *MacroName) << '\n';
// Output what it expands into.
Indent(o, indent) << "<key>expansion</key>";
- 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 0ab4bd2b12a52..51748c7c0ea28 100644
--- a/llvm/include/llvm/ADT/STLForwardCompat.h
+++ b/llvm/include/llvm/ADT/STLForwardCompat.h
@@ -65,9 +65,9 @@ auto transformOptional(std::optional<T> &&O, const Function &F)
// complete.
template <typename T, typename Function>
auto transformOptional(const Optional<T> &O, const Function &F)
- -> Optional<decltype(F(O.value()))> {
+ -> Optional<decltype(F(*O))> {
if (O)
- return F(O.value());
+ return F(*O);
return std::nullopt;
}
@@ -75,9 +75,9 @@ auto transformOptional(const Optional<T> &O, const Function &F)
// complete.
template <typename T, typename Function>
auto transformOptional(Optional<T> &&O, const Function &F)
- -> Optional<decltype(F(std::move(O).value()))> {
+ -> Optional<decltype(F(*std::move(O)))> {
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 382bcd6374150..f6d0ef2aa8571 100644
--- a/polly/lib/Transform/ManualOptimizer.cpp
+++ b/polly/lib/Transform/ManualOptimizer.cpp
@@ -43,7 +43,7 @@ static TransformationMode hasUnrollTransformation(MDNode *LoopID) {
Optional<int> 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;
More information about the cfe-commits
mailing list