Skip to content

Commit f7b0b99

Browse files
committed
[clang][NFC] Further improvements to const-correctness
1 parent 2c2e050 commit f7b0b99

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ class ASTWriter : public ASTDeserializationListener,
565565

566566
void GenerateNameLookupTable(const DeclContext *DC,
567567
llvm::SmallVectorImpl<char> &LookupTable);
568-
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
568+
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context,
569+
const DeclContext *DC);
569570
uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC);
570571
void WriteTypeDeclOffsets();
571572
void WriteFileDeclIDsMap();

clang/lib/Basic/SourceManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,14 @@ void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo,
276276
std::pair<FileID, unsigned> LocInfo = getDecomposedExpansionLoc(Loc);
277277

278278
bool Invalid = false;
279-
const SLocEntry &Entry = getSLocEntry(LocInfo.first, &Invalid);
279+
SLocEntry &Entry = getSLocEntry(LocInfo.first, &Invalid);
280280
if (!Entry.isFile() || Invalid)
281281
return;
282282

283-
const SrcMgr::FileInfo &FileInfo = Entry.getFile();
283+
SrcMgr::FileInfo &FileInfo = Entry.getFile();
284284

285285
// Remember that this file has #line directives now if it doesn't already.
286-
const_cast<SrcMgr::FileInfo&>(FileInfo).setHasLineDirectives();
286+
FileInfo.setHasLineDirectives();
287287

288288
(void) getLineTable();
289289

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,7 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags,
411411
SourceMgr.overrideFileContents(FromFile, RB.second->getMemBufferRef());
412412
else
413413
SourceMgr.overrideFileContents(
414-
FromFile, std::unique_ptr<llvm::MemoryBuffer>(
415-
const_cast<llvm::MemoryBuffer *>(RB.second)));
414+
FromFile, std::unique_ptr<llvm::MemoryBuffer>(RB.second));
416415
}
417416

418417
// Remap files in the source manager (with other files).

clang/lib/Serialization/ASTReader.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
16491649
FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
16501650
FileID FID = SourceMgr.createFileID(*File, IncludeLoc, FileCharacter, ID,
16511651
BaseOffset + Record[0]);
1652-
SrcMgr::FileInfo &FileInfo =
1653-
const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile());
1652+
SrcMgr::FileInfo &FileInfo = SourceMgr.getSLocEntry(FID).getFile();
16541653
FileInfo.NumCreatedFIDs = Record[5];
16551654
if (Record[3])
16561655
FileInfo.setHasLineDirectives();
@@ -1693,8 +1692,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
16931692
FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
16941693
BaseOffset + Offset, IncludeLoc);
16951694
if (Record[3]) {
1696-
auto &FileInfo =
1697-
const_cast<SrcMgr::FileInfo &>(SourceMgr.getSLocEntry(FID).getFile());
1695+
auto &FileInfo = SourceMgr.getSLocEntry(FID).getFile();
16981696
FileInfo.setHasLineDirectives();
16991697
}
17001698
break;

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,7 +3304,7 @@ static bool IsInternalDeclFromFileContext(const Decl *D) {
33043304
/// \returns the offset of the DECL_CONTEXT_LEXICAL block within the
33053305
/// bitstream, or 0 if no block was written.
33063306
uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
3307-
DeclContext *DC) {
3307+
const DeclContext *DC) {
33083308
if (DC->decls_empty())
33093309
return 0;
33103310

@@ -5698,8 +5698,8 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
56985698
break;
56995699

57005700
case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT:
5701-
Record.AddStmt(const_cast<Expr *>(
5702-
cast<ParmVarDecl>(Update.getDecl())->getDefaultArg()));
5701+
Record.writeStmtRef(
5702+
cast<ParmVarDecl>(Update.getDecl())->getDefaultArg());
57035703
break;
57045704

57055705
case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER:
@@ -5713,8 +5713,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
57135713
Record.push_back(RD->isParamDestroyedInCallee());
57145714
Record.push_back(llvm::to_underlying(RD->getArgPassingRestrictions()));
57155715
Record.AddCXXDefinitionData(RD);
5716-
Record.AddOffset(WriteDeclContextLexicalBlock(
5717-
*Context, const_cast<CXXRecordDecl *>(RD)));
5716+
Record.AddOffset(WriteDeclContextLexicalBlock(*Context, RD));
57185717

57195718
// This state is sometimes updated by template instantiation, when we
57205719
// switch from the specialization referring to the template declaration
@@ -6357,7 +6356,7 @@ void ASTRecordWriter::AddTemplateParameterList(
63576356
AddDeclRef(P);
63586357
if (const Expr *RequiresClause = TemplateParams->getRequiresClause()) {
63596358
Record->push_back(true);
6360-
AddStmt(const_cast<Expr*>(RequiresClause));
6359+
writeStmtRef(RequiresClause);
63616360
} else {
63626361
Record->push_back(false);
63636362
}
@@ -7814,15 +7813,15 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
78147813
case OpenACCClauseKind::If: {
78157814
const auto *IC = cast<OpenACCIfClause>(C);
78167815
writeSourceLocation(IC->getLParenLoc());
7817-
AddStmt(const_cast<Expr *>(IC->getConditionExpr()));
7816+
writeStmtRef(IC->getConditionExpr());
78187817
return;
78197818
}
78207819
case OpenACCClauseKind::Self: {
78217820
const auto *SC = cast<OpenACCSelfClause>(C);
78227821
writeSourceLocation(SC->getLParenLoc());
78237822
writeBool(SC->hasConditionExpr());
78247823
if (SC->hasConditionExpr())
7825-
AddStmt(const_cast<Expr *>(SC->getConditionExpr()));
7824+
writeStmtRef(SC->getConditionExpr());
78267825
return;
78277826
}
78287827
case OpenACCClauseKind::NumGangs: {
@@ -7836,13 +7835,13 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
78367835
case OpenACCClauseKind::NumWorkers: {
78377836
const auto *NWC = cast<OpenACCNumWorkersClause>(C);
78387837
writeSourceLocation(NWC->getLParenLoc());
7839-
AddStmt(const_cast<Expr *>(NWC->getIntExpr()));
7838+
writeStmtRef(NWC->getIntExpr());
78407839
return;
78417840
}
78427841
case OpenACCClauseKind::VectorLength: {
78437842
const auto *NWC = cast<OpenACCVectorLengthClause>(C);
78447843
writeSourceLocation(NWC->getLParenLoc());
7845-
AddStmt(const_cast<Expr *>(NWC->getIntExpr()));
7844+
writeStmtRef(NWC->getIntExpr());
78467845
return;
78477846
}
78487847
case OpenACCClauseKind::Private: {
@@ -7921,15 +7920,15 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
79217920
writeSourceLocation(AC->getLParenLoc());
79227921
writeBool(AC->hasIntExpr());
79237922
if (AC->hasIntExpr())
7924-
AddStmt(const_cast<Expr *>(AC->getIntExpr()));
7923+
writeStmtRef(AC->getIntExpr());
79257924
return;
79267925
}
79277926
case OpenACCClauseKind::Wait: {
79287927
const auto *WC = cast<OpenACCWaitClause>(C);
79297928
writeSourceLocation(WC->getLParenLoc());
79307929
writeBool(WC->getDevNumExpr());
79317930
if (const Expr *DNE = WC->getDevNumExpr())
7932-
AddStmt(const_cast<Expr *>(DNE));
7931+
writeStmtRef(DNE);
79337932
writeSourceLocation(WC->getQueuesLoc());
79347933

79357934
writeOpenACCIntExprList(WC->getQueueIdExprs());

clang/lib/Serialization/ASTWriterStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ addConstraintSatisfaction(ASTRecordWriter &Record,
473473
if (!Satisfaction.IsSatisfied) {
474474
Record.push_back(Satisfaction.NumRecords);
475475
for (const auto &DetailRecord : Satisfaction) {
476-
Record.AddStmt(const_cast<Expr *>(DetailRecord.first));
476+
Record.writeStmtRef(DetailRecord.first);
477477
auto *E = DetailRecord.second.dyn_cast<Expr *>();
478478
Record.push_back(E == nullptr);
479479
if (E)

0 commit comments

Comments
 (0)