Skip to content

Commit 2916b99

Browse files
committed
[ADT] Alias llvm::Optional to std::optional
This avoids the continuous API churn when upgrading things to use std::optional and makes trivial string replace upgrades possible. I tested this with GCC 7.5, the oldest supported GCC I had around. Differential Revision: https://reviews.llvm.org/D140332
1 parent f361777 commit 2916b99

File tree

17 files changed

+24
-1301
lines changed

17 files changed

+24
-1301
lines changed

clang/include/clang/Basic/LLVM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace llvm {
3737
template<unsigned InternalLen> class SmallString;
3838
template<typename T, unsigned N> class SmallVector;
3939
template<typename T> class SmallVectorImpl;
40-
template <typename T> class Optional;
40+
template <typename T> using Optional = std::optional<T>;
4141
template <class T> class Expected;
4242

4343
template<typename T>

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ Optional<unsigned> ExprEngine::getPendingInitLoop(ProgramStateRef State,
481481
const CXXConstructExpr *E,
482482
const LocationContext *LCtx) {
483483
const unsigned *V = State->get<PendingInitLoop>({E, LCtx->getStackFrame()});
484-
return V ? Optional(*V) : std::nullopt;
484+
return V ? std::make_optional(*V) : std::nullopt;
485485
}
486486

487487
ProgramStateRef ExprEngine::removePendingInitLoop(ProgramStateRef State,
@@ -510,7 +510,7 @@ ExprEngine::getIndexOfElementToConstruct(ProgramStateRef State,
510510
const LocationContext *LCtx) {
511511
const unsigned *V =
512512
State->get<IndexOfElementToConstruct>({E, LCtx->getStackFrame()});
513-
return V ? Optional(*V) : std::nullopt;
513+
return V ? std::make_optional(*V) : std::nullopt;
514514
}
515515

516516
ProgramStateRef
@@ -530,7 +530,7 @@ ExprEngine::getPendingArrayDestruction(ProgramStateRef State,
530530

531531
const unsigned *V =
532532
State->get<PendingArrayDestruction>(LCtx->getStackFrame());
533-
return V ? Optional(*V) : std::nullopt;
533+
return V ? std::make_optional(*V) : std::nullopt;
534534
}
535535

536536
ProgramStateRef ExprEngine::setPendingArrayDestruction(
@@ -600,7 +600,7 @@ ExprEngine::getObjectUnderConstruction(ProgramStateRef State,
600600
const LocationContext *LC) {
601601
ConstructedObjectKey Key(Item, LC->getStackFrame());
602602
const SVal *V = State->get<ObjectsUnderConstruction>(Key);
603-
return V ? Optional(*V) : std::nullopt;
603+
return V ? std::make_optional(*V) : std::nullopt;
604604
}
605605

606606
ProgramStateRef

flang/include/flang/Lower/Runtime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#ifndef FORTRAN_LOWER_RUNTIME_H
1717
#define FORTRAN_LOWER_RUNTIME_H
1818

19+
#include <optional>
20+
1921
namespace llvm {
20-
template <typename T>
21-
class Optional;
22+
template <typename T> using Optional = std::optional<T>;
2223
}
2324

2425
namespace mlir {

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static FormSize g_form_sizes[] = {
190190
llvm::Optional<uint8_t>
191191
DWARFFormValue::GetFixedSize(dw_form_t form, const DWARFUnit *u) {
192192
if (form <= DW_FORM_ref_sig8 && g_form_sizes[form].valid)
193-
return g_form_sizes[form].size;
193+
return static_cast<uint8_t>(g_form_sizes[form].size);
194194
if (form == DW_FORM_addr && u)
195195
return u->GetAddressByteSize();
196196
return std::nullopt;

lldb/source/Symbol/Type.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Type *Type::GetEncodingType() {
343343

344344
llvm::Optional<uint64_t> Type::GetByteSize(ExecutionContextScope *exe_scope) {
345345
if (m_byte_size_has_value)
346-
return m_byte_size;
346+
return static_cast<uint64_t>(m_byte_size);
347347

348348
switch (m_encoding_uid_type) {
349349
case eEncodingInvalid:
@@ -360,14 +360,14 @@ llvm::Optional<uint64_t> Type::GetByteSize(ExecutionContextScope *exe_scope) {
360360
if (llvm::Optional<uint64_t> size = encoding_type->GetByteSize(exe_scope)) {
361361
m_byte_size = *size;
362362
m_byte_size_has_value = true;
363-
return m_byte_size;
363+
return static_cast<uint64_t>(m_byte_size);
364364
}
365365

366366
if (llvm::Optional<uint64_t> size =
367367
GetLayoutCompilerType().GetByteSize(exe_scope)) {
368368
m_byte_size = *size;
369369
m_byte_size_has_value = true;
370-
return m_byte_size;
370+
return static_cast<uint64_t>(m_byte_size);
371371
}
372372
} break;
373373

@@ -378,7 +378,7 @@ llvm::Optional<uint64_t> Type::GetByteSize(ExecutionContextScope *exe_scope) {
378378
if (ArchSpec arch = m_symbol_file->GetObjectFile()->GetArchitecture()) {
379379
m_byte_size = arch.GetAddressByteSize();
380380
m_byte_size_has_value = true;
381-
return m_byte_size;
381+
return static_cast<uint64_t>(m_byte_size);
382382
}
383383
} break;
384384
}

0 commit comments

Comments
 (0)