Skip to content

Commit

Permalink
Merged main:bbe40b9e0a24605e0526475e643312839772294f into amd-gfx:c16…
Browse files Browse the repository at this point in the history
…9650cd441

Local branch amd-gfx c169650 Merged main:b27eb0ae8280675fc8fb249d39f1ccafa3ee2187 into amd-gfx:ea66a9b7b6c7
Remote branch main bbe40b9 [MCAsmStreamer] Do not crash on switching to sections of unknown types (llvm#92380)
  • Loading branch information
SC llvm team authored and SC llvm team committed May 17, 2024
2 parents c169650 + bbe40b9 commit 79e3e42
Show file tree
Hide file tree
Showing 47 changed files with 2,720 additions and 2,071 deletions.
44 changes: 41 additions & 3 deletions clang/include/clang/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ class SLocEntry {
bool isFile() const { return !isExpansion(); }

const FileInfo &getFile() const {
return const_cast<SLocEntry *>(this)->getFile();
}

FileInfo &getFile() {
assert(isFile() && "Not a file SLocEntry!");
return File;
}
Expand Down Expand Up @@ -1120,12 +1124,12 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// Set the number of FileIDs (files and macros) that were created
/// during preprocessing of \p FID, including it.
void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs,
bool Force = false) const {
bool Force = false) {
auto *Entry = getSLocEntryForFile(FID);
if (!Entry)
return;
assert((Force || Entry->getFile().NumCreatedFIDs == 0) && "Already set!");
const_cast<SrcMgr::FileInfo &>(Entry->getFile()).NumCreatedFIDs = NumFIDs;
Entry->getFile().NumCreatedFIDs = NumFIDs;
}

//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -1730,6 +1734,11 @@ class SourceManager : public RefCountedBase<SourceManager> {

/// Get a local SLocEntry. This is exposed for indexing.
const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index) const {
return const_cast<SourceManager *>(this)->getLocalSLocEntry(Index);
}

/// Get a local SLocEntry. This is exposed for indexing.
SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index) {
assert(Index < LocalSLocEntryTable.size() && "Invalid index");
return LocalSLocEntryTable[Index];
}
Expand All @@ -1740,6 +1749,13 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// Get a loaded SLocEntry. This is exposed for indexing.
const SrcMgr::SLocEntry &getLoadedSLocEntry(unsigned Index,
bool *Invalid = nullptr) const {
return const_cast<SourceManager *>(this)->getLoadedSLocEntry(Index,
Invalid);
}

/// Get a loaded SLocEntry. This is exposed for indexing.
SrcMgr::SLocEntry &getLoadedSLocEntry(unsigned Index,
bool *Invalid = nullptr) {
assert(Index < LoadedSLocEntryTable.size() && "Invalid index");
if (SLocEntryLoaded[Index])
return LoadedSLocEntryTable[Index];
Expand All @@ -1748,6 +1764,10 @@ class SourceManager : public RefCountedBase<SourceManager> {

const SrcMgr::SLocEntry &getSLocEntry(FileID FID,
bool *Invalid = nullptr) const {
return const_cast<SourceManager *>(this)->getSLocEntry(FID, Invalid);
}

SrcMgr::SLocEntry &getSLocEntry(FileID FID, bool *Invalid = nullptr) {
if (FID.ID == 0 || FID.ID == -1) {
if (Invalid) *Invalid = true;
return LocalSLocEntryTable[0];
Expand Down Expand Up @@ -1821,14 +1841,23 @@ class SourceManager : public RefCountedBase<SourceManager> {
SrcMgr::ContentCache &getFakeContentCacheForRecovery() const;

const SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid) const;
SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid);

const SrcMgr::SLocEntry *getSLocEntryOrNull(FileID FID) const {
return const_cast<SourceManager *>(this)->getSLocEntryOrNull(FID);
}

SrcMgr::SLocEntry *getSLocEntryOrNull(FileID FID) {
bool Invalid = false;
const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
return Invalid ? nullptr : &Entry;
}

const SrcMgr::SLocEntry *getSLocEntryForFile(FileID FID) const {
return const_cast<SourceManager *>(this)->getSLocEntryForFile(FID);
}

SrcMgr::SLocEntry *getSLocEntryForFile(FileID FID) {
if (auto *Entry = getSLocEntryOrNull(FID))
if (Entry->isFile())
return Entry;
Expand All @@ -1839,6 +1868,10 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// Invalid will not be modified for Local IDs.
const SrcMgr::SLocEntry &getSLocEntryByID(int ID,
bool *Invalid = nullptr) const {
return const_cast<SourceManager *>(this)->getSLocEntryByID(ID, Invalid);
}

SrcMgr::SLocEntry &getSLocEntryByID(int ID, bool *Invalid = nullptr) {
assert(ID != -1 && "Using FileID sentinel value");
if (ID < 0)
return getLoadedSLocEntryByID(ID, Invalid);
Expand All @@ -1847,6 +1880,11 @@ class SourceManager : public RefCountedBase<SourceManager> {

const SrcMgr::SLocEntry &
getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) const {
return const_cast<SourceManager *>(this)->getLoadedSLocEntryByID(ID,
Invalid);
}

SrcMgr::SLocEntry &getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) {
return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
}

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ ContentCache &SourceManager::createMemBufferContentCache(

const SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index,
bool *Invalid) const {
return const_cast<SourceManager *>(this)->loadSLocEntry(Index, Invalid);
}

SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index, bool *Invalid) {
assert(!SLocEntryLoaded[Index]);
if (ExternalSLocEntries->ReadSLocEntry(-(static_cast<int>(Index) + 2))) {
if (Invalid)
Expand Down
Loading

0 comments on commit 79e3e42

Please sign in to comment.