Skip to content

Commit 0ca43d4

Browse files
author
Krzysztof Parzyszek
committed
DebugInfoMetadata: convert Optional to std::optional
1 parent fcf4e36 commit 0ca43d4

38 files changed

+249
-201
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/Support/Error.h"
3838
#include "llvm/Support/VersionTuple.h"
3939
#include <cassert>
40+
#include <optional>
4041
#include <string>
4142
#include <vector>
4243

@@ -1654,7 +1655,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,
16541655
///
16551656
/// \returns Otherwise return None and no conversion will be emitted in the
16561657
/// DWARF.
1657-
virtual Optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace) const {
1658+
virtual std::optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace)
1659+
const {
16581660
return std::nullopt;
16591661
}
16601662

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/Triple.h"
2121
#include "llvm/Support/Compiler.h"
2222
#include "llvm/Support/TargetParser.h"
23+
#include <optional>
2324

2425
namespace clang {
2526
namespace targets {
@@ -393,7 +394,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
393394
///
394395
/// \returns Otherwise return None and no conversion will be emitted in the
395396
/// DWARF.
396-
Optional<unsigned>
397+
std::optional<unsigned>
397398
getDWARFAddressSpace(unsigned AddressSpace) const override {
398399
const unsigned DWARF_Private = 1;
399400
const unsigned DWARF_Local = 2;

clang/lib/Basic/Targets/NVPTX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/TargetOptions.h"
1919
#include "llvm/ADT/Triple.h"
2020
#include "llvm/Support/Compiler.h"
21+
#include <optional>
2122

2223
namespace clang {
2324
namespace targets {
@@ -158,7 +159,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
158159
///
159160
/// \returns Otherwise return None and no conversion will be emitted in the
160161
/// DWARF.
161-
Optional<unsigned>
162+
std::optional<unsigned>
162163
getDWARFAddressSpace(unsigned AddressSpace) const override {
163164
if (AddressSpace >= std::size(NVPTXDWARFAddrSpaceMap) ||
164165
NVPTXDWARFAddrSpaceMap[AddressSpace] < 0)

clang/lib/Basic/Targets/SPIR.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Basic/TargetOptions.h"
1818
#include "llvm/ADT/Triple.h"
1919
#include "llvm/Support/Compiler.h"
20+
#include <optional>
2021

2122
namespace clang {
2223
namespace targets {
@@ -127,7 +128,7 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public TargetInfo {
127128
return TargetInfo::VoidPtrBuiltinVaList;
128129
}
129130

130-
Optional<unsigned>
131+
std::optional<unsigned>
131132
getDWARFAddressSpace(unsigned AddressSpace) const override {
132133
return AddressSpace;
133134
}

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "llvm/Support/SHA1.h"
5252
#include "llvm/Support/SHA256.h"
5353
#include "llvm/Support/TimeProfiler.h"
54+
#include <optional>
5455
using namespace clang;
5556
using namespace clang::CodeGen;
5657

@@ -345,7 +346,7 @@ StringRef CGDebugInfo::getClassName(const RecordDecl *RD) {
345346
return StringRef();
346347
}
347348

348-
Optional<llvm::DIFile::ChecksumKind>
349+
std::optional<llvm::DIFile::ChecksumKind>
349350
CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum) const {
350351
Checksum.clear();
351352

@@ -373,8 +374,8 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum) const {
373374
llvm_unreachable("Unhandled DebugSrcHashKind enum");
374375
}
375376

376-
Optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
377-
FileID FID) {
377+
std::optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
378+
FileID FID) {
378379
if (!CGM.getCodeGenOpts().EmbedSource)
379380
return std::nullopt;
380381

@@ -419,17 +420,18 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
419420

420421
SmallString<64> Checksum;
421422

422-
Optional<llvm::DIFile::ChecksumKind> CSKind = computeChecksum(FID, Checksum);
423-
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
423+
std::optional<llvm::DIFile::ChecksumKind> CSKind =
424+
computeChecksum(FID, Checksum);
425+
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
424426
if (CSKind)
425427
CSInfo.emplace(*CSKind, Checksum);
426428
return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
427429
}
428430

429-
llvm::DIFile *
430-
CGDebugInfo::createFile(StringRef FileName,
431-
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
432-
Optional<StringRef> Source) {
431+
llvm::DIFile *CGDebugInfo::createFile(
432+
StringRef FileName,
433+
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
434+
std::optional<StringRef> Source) {
433435
StringRef Dir;
434436
StringRef File;
435437
std::string RemappedFile = remapDIPath(FileName);
@@ -512,8 +514,8 @@ StringRef CGDebugInfo::getCurrentDirname() {
512514

513515
void CGDebugInfo::CreateCompileUnit() {
514516
SmallString<64> Checksum;
515-
Optional<llvm::DIFile::ChecksumKind> CSKind;
516-
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
517+
std::optional<llvm::DIFile::ChecksumKind> CSKind;
518+
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
517519

518520
// Should we be asking the SourceManager for the main file name, instead of
519521
// accepting it as an argument? This just causes the main file name to
@@ -1148,8 +1150,9 @@ llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
11481150
// Size is always the size of a pointer.
11491151
uint64_t Size = CGM.getContext().getTypeSize(Ty);
11501152
auto Align = getTypeAlignIfRequired(Ty, CGM.getContext());
1151-
Optional<unsigned> DWARFAddressSpace = CGM.getTarget().getDWARFAddressSpace(
1152-
CGM.getTypes().getTargetAddressSpace(PointeeTy));
1153+
std::optional<unsigned> DWARFAddressSpace =
1154+
CGM.getTarget().getDWARFAddressSpace(
1155+
CGM.getTypes().getTargetAddressSpace(PointeeTy));
11531156

11541157
SmallVector<llvm::Metadata *, 4> Annots;
11551158
auto *BTFAttrTy = dyn_cast<BTFTagAttributedType>(PointeeTy);
@@ -2201,7 +2204,7 @@ llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
22012204
llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
22022205
unsigned Size = Context.getTypeSize(Context.VoidPtrTy);
22032206
unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2204-
Optional<unsigned> DWARFAddressSpace =
2207+
std::optional<unsigned> DWARFAddressSpace =
22052208
CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
22062209

22072210
llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
@@ -2298,7 +2301,7 @@ void CGDebugInfo::CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile *Unit,
22982301
VFTLayout.vtable_components().size() - CGM.getLangOpts().RTTIData;
22992302
unsigned VTableWidth = PtrWidth * VSlotCount;
23002303
unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2301-
Optional<unsigned> DWARFAddressSpace =
2304+
std::optional<unsigned> DWARFAddressSpace =
23022305
CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
23032306

23042307
// Create a very wide void* type and insert it directly in the element list.
@@ -4284,7 +4287,7 @@ void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) {
42844287

42854288
void CGDebugInfo::AppendAddressSpaceXDeref(
42864289
unsigned AddressSpace, SmallVectorImpl<uint64_t> &Expr) const {
4287-
Optional<unsigned> DWARFAddressSpace =
4290+
std::optional<unsigned> DWARFAddressSpace =
42884291
CGM.getTarget().getDWARFAddressSpace(AddressSpace);
42894292
if (!DWARFAddressSpace)
42904293
return;

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/IR/DebugInfo.h"
3131
#include "llvm/IR/ValueHandle.h"
3232
#include "llvm/Support/Allocator.h"
33+
#include <optional>
3334

3435
namespace llvm {
3536
class MDNode;
@@ -630,11 +631,11 @@ class CGDebugInfo {
630631
void CreateCompileUnit();
631632

632633
/// Compute the file checksum debug info for input file ID.
633-
Optional<llvm::DIFile::ChecksumKind>
634+
std::optional<llvm::DIFile::ChecksumKind>
634635
computeChecksum(FileID FID, SmallString<64> &Checksum) const;
635636

636637
/// Get the source of the given file ID.
637-
Optional<StringRef> getSource(const SourceManager &SM, FileID FID);
638+
std::optional<StringRef> getSource(const SourceManager &SM, FileID FID);
638639

639640
/// Convenience function to get the file debug info descriptor for the input
640641
/// location.
@@ -643,8 +644,8 @@ class CGDebugInfo {
643644
/// Create a file debug info descriptor for a source file.
644645
llvm::DIFile *
645646
createFile(StringRef FileName,
646-
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
647-
Optional<StringRef> Source);
647+
std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
648+
std::optional<StringRef> Source);
648649

649650
/// Get the type from the cache or create a new type if necessary.
650651
llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "llvm/ADT/ArrayRef.h"
1818
#include "llvm/ADT/DenseMap.h"
1919
#include "llvm/ADT/MapVector.h"
20-
#include "llvm/ADT/Optional.h"
2120
#include "llvm/ADT/SetVector.h"
2221
#include "llvm/ADT/SmallVector.h"
2322
#include "llvm/ADT/StringRef.h"
@@ -27,6 +26,7 @@
2726
#include "llvm/Support/Casting.h"
2827
#include <algorithm>
2928
#include <cstdint>
29+
#include <optional>
3030

3131
namespace llvm {
3232

@@ -175,8 +175,8 @@ namespace llvm {
175175
/// \param Source Optional source text.
176176
DIFile *createFile(
177177
StringRef Filename, StringRef Directory,
178-
Optional<DIFile::ChecksumInfo<StringRef>> Checksum = std::nullopt,
179-
Optional<StringRef> Source = std::nullopt);
178+
std::optional<DIFile::ChecksumInfo<StringRef>> Checksum = std::nullopt,
179+
std::optional<StringRef> Source = std::nullopt);
180180

181181
/// Create debugging information entry for a macro.
182182
/// \param Parent Macro parent (could be nullptr).
@@ -256,7 +256,7 @@ namespace llvm {
256256
DIDerivedType *
257257
createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
258258
uint32_t AlignInBits = 0,
259-
Optional<unsigned> DWARFAddressSpace = std::nullopt,
259+
std::optional<unsigned> DWARFAddressSpace = std::nullopt,
260260
StringRef Name = "", DINodeArray Annotations = nullptr);
261261

262262
/// Create debugging information entry for a pointer to member.
@@ -271,10 +271,10 @@ namespace llvm {
271271

272272
/// Create debugging information entry for a c++
273273
/// style reference or rvalue reference type.
274-
DIDerivedType *
275-
createReferenceType(unsigned Tag, DIType *RTy, uint64_t SizeInBits = 0,
276-
uint32_t AlignInBits = 0,
277-
Optional<unsigned> DWARFAddressSpace = std::nullopt);
274+
DIDerivedType *createReferenceType(
275+
unsigned Tag, DIType *RTy, uint64_t SizeInBits = 0,
276+
uint32_t AlignInBits = 0,
277+
std::optional<unsigned> DWARFAddressSpace = std::nullopt);
278278

279279
/// Create debugging information entry for a typedef.
280280
/// \param Ty Original type.

0 commit comments

Comments
 (0)