aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Serebrennikov <serebrennikov.vladislav@gmail.com>2024-05-18 12:10:06 +0300
committerVlad Serebrennikov <serebrennikov.vladislav@gmail.com>2024-05-18 12:10:39 +0300
commitf7b0b99c52ee36ed6ca8abcce74a752e483768d6 (patch)
treeca478538482715db9b1faf9bbb023c4ac3945b31
parent2c2e0507e92bdb77a01828f899ff59e44492b537 (diff)
downloadllvm-f7b0b99c52ee36ed6ca8abcce74a752e483768d6.zip
llvm-f7b0b99c52ee36ed6ca8abcce74a752e483768d6.tar.gz
llvm-f7b0b99c52ee36ed6ca8abcce74a752e483768d6.tar.bz2
[clang][NFC] Further improvements to const-correctness
-rw-r--r--clang/include/clang/Serialization/ASTWriter.h3
-rw-r--r--clang/lib/Basic/SourceManager.cpp6
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp3
-rw-r--r--clang/lib/Serialization/ASTReader.cpp6
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp23
-rw-r--r--clang/lib/Serialization/ASTWriterStmt.cpp2
6 files changed, 20 insertions, 23 deletions
diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h
index 7bb0e81..6aa2796 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -565,7 +565,8 @@ private:
void GenerateNameLookupTable(const DeclContext *DC,
llvm::SmallVectorImpl<char> &LookupTable);
- uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
+ uint64_t WriteDeclContextLexicalBlock(ASTContext &Context,
+ const DeclContext *DC);
uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
void WriteTypeDeclOffsets();
void WriteFileDeclIDsMap();
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index afdb5b0..753601e 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -276,14 +276,14 @@ void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo,
std::pair<FileID, unsigned> LocInfo = getDecomposedExpansionLoc(Loc);
bool Invalid = false;
- const SLocEntry &Entry = getSLocEntry(LocInfo.first, &Invalid);
+ SLocEntry &Entry = getSLocEntry(LocInfo.first, &Invalid);
if (!Entry.isFile() || Invalid)
return;
- const SrcMgr::FileInfo &FileInfo = Entry.getFile();
+ SrcMgr::FileInfo &FileInfo = Entry.getFile();
// Remember that this file has #line directives now if it doesn't already.
- const_cast<SrcMgr::FileInfo&>(FileInfo).setHasLineDirectives();
+ FileInfo.setHasLineDirectives();
(void) getLineTable();
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 66a45b8..6242b5a 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -411,8 +411,7 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags,
SourceMgr.overrideFileContents(FromFile, RB.second->getMemBufferRef());
else
SourceMgr.overrideFileContents(
- FromFile, std::unique_ptr<llvm::MemoryBuffer>(
- const_cast<llvm::MemoryBuffer *>(RB.second)));
+ FromFile, std::unique_ptr<llvm::MemoryBuffer>(RB.second));
}
// Remap files in the source manager (with other files).
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 510f61d..f50f956 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1649,8 +1649,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
FileID FID = SourceMgr.createFileID(*File, IncludeLoc, FileCharacter, ID,
BaseOffset + Record[0]);
- SrcMgr::FileInfo &FileInfo =
- const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile());
+ SrcMgr::FileInfo &FileInfo = SourceMgr.getSLocEntry(FID).getFile();
FileInfo.NumCreatedFIDs = Record[5];
if (Record[3])
FileInfo.setHasLineDirectives();
@@ -1693,8 +1692,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
BaseOffset + Offset, IncludeLoc);
if (Record[3]) {
- auto &FileInfo =
- const_cast<SrcMgr::FileInfo &>(SourceMgr.getSLocEntry(FID).getFile());
+ auto &FileInfo = SourceMgr.getSLocEntry(FID).getFile();
FileInfo.setHasLineDirectives();
}
break;
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index dd5d65b..2a107e4 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3304,7 +3304,7 @@ static bool IsInternalDeclFromFileContext(const Decl *D) {
/// \returns the offset of the DECL_CONTEXT_LEXICAL block within the
/// bitstream, or 0 if no block was written.
uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
- DeclContext *DC) {
+ const DeclContext *DC) {
if (DC->decls_empty())
return 0;
@@ -5698,8 +5698,8 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
break;
case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT:
- Record.AddStmt(const_cast<Expr *>(
- cast<ParmVarDecl>(Update.getDecl())->getDefaultArg()));
+ Record.writeStmtRef(
+ cast<ParmVarDecl>(Update.getDecl())->getDefaultArg());
break;
case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER:
@@ -5713,8 +5713,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
Record.push_back(RD->isParamDestroyedInCallee());
Record.push_back(llvm::to_underlying(RD->getArgPassingRestrictions()));
Record.AddCXXDefinitionData(RD);
- Record.AddOffset(WriteDeclContextLexicalBlock(
- *Context, const_cast<CXXRecordDecl *>(RD)));
+ Record.AddOffset(WriteDeclContextLexicalBlock(*Context, RD));
// This state is sometimes updated by template instantiation, when we
// switch from the specialization referring to the template declaration
@@ -6357,7 +6356,7 @@ void ASTRecordWriter::AddTemplateParameterList(
AddDeclRef(P);
if (const Expr *RequiresClause = TemplateParams->getRequiresClause()) {
Record->push_back(true);
- AddStmt(const_cast<Expr*>(RequiresClause));
+ writeStmtRef(RequiresClause);
} else {
Record->push_back(false);
}
@@ -7814,7 +7813,7 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
case OpenACCClauseKind::If: {
const auto *IC = cast<OpenACCIfClause>(C);
writeSourceLocation(IC->getLParenLoc());
- AddStmt(const_cast<Expr *>(IC->getConditionExpr()));
+ writeStmtRef(IC->getConditionExpr());
return;
}
case OpenACCClauseKind::Self: {
@@ -7822,7 +7821,7 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeSourceLocation(SC->getLParenLoc());
writeBool(SC->hasConditionExpr());
if (SC->hasConditionExpr())
- AddStmt(const_cast<Expr *>(SC->getConditionExpr()));
+ writeStmtRef(SC->getConditionExpr());
return;
}
case OpenACCClauseKind::NumGangs: {
@@ -7836,13 +7835,13 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
case OpenACCClauseKind::NumWorkers: {
const auto *NWC = cast<OpenACCNumWorkersClause>(C);
writeSourceLocation(NWC->getLParenLoc());
- AddStmt(const_cast<Expr *>(NWC->getIntExpr()));
+ writeStmtRef(NWC->getIntExpr());
return;
}
case OpenACCClauseKind::VectorLength: {
const auto *NWC = cast<OpenACCVectorLengthClause>(C);
writeSourceLocation(NWC->getLParenLoc());
- AddStmt(const_cast<Expr *>(NWC->getIntExpr()));
+ writeStmtRef(NWC->getIntExpr());
return;
}
case OpenACCClauseKind::Private: {
@@ -7921,7 +7920,7 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeSourceLocation(AC->getLParenLoc());
writeBool(AC->hasIntExpr());
if (AC->hasIntExpr())
- AddStmt(const_cast<Expr *>(AC->getIntExpr()));
+ writeStmtRef(AC->getIntExpr());
return;
}
case OpenACCClauseKind::Wait: {
@@ -7929,7 +7928,7 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeSourceLocation(WC->getLParenLoc());
writeBool(WC->getDevNumExpr());
if (const Expr *DNE = WC->getDevNumExpr())
- AddStmt(const_cast<Expr *>(DNE));
+ writeStmtRef(DNE);
writeSourceLocation(WC->getQueuesLoc());
writeOpenACCIntExprList(WC->getQueueIdExprs());
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 39aec31..6f7c368 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -473,7 +473,7 @@ addConstraintSatisfaction(ASTRecordWriter &Record,
if (!Satisfaction.IsSatisfied) {
Record.push_back(Satisfaction.NumRecords);
for (const auto &DetailRecord : Satisfaction) {
- Record.AddStmt(const_cast<Expr *>(DetailRecord.first));
+ Record.writeStmtRef(DetailRecord.first);
auto *E = DetailRecord.second.dyn_cast<Expr *>();
Record.push_back(E == nullptr);
if (E)