Skip to content

Commit 1173e9f

Browse files
Finish applying clang-tidy to 3C (for now).
- Update clang/docs/checkedc/3C/clang-tidy.md with much more information about the process. Note that some warnings remain that we haven't yet decided what to do about. - Disable misc-no-recursion rule for now because it looks like we make significant intentional use of recursion. - Remove blank lines between #include lines so that the `llvm-include-order` check will sort all the lines. Minor tweaks to nearby formatting. - Run `clang-tidy --fix` multiple times, then `clang-format`, then fix up formatting mistakes from `llvm-else-after-return` as described in clang-tidy.md. - Manually rename some elements where we're not happy with what the default `readability-identifier-naming` fix did. - Get the clangd3c target to build and enable it again! After clang-tidy fixed some broken references without being asked, there was only one real error left, which was straightforward to fix. We still think clangd3c doesn't work, but as long as it builds, it will be easier for us to include it in bulk code edits like this one if we want to.
1 parent 0042db4 commit 1173e9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1528
-1417
lines changed

clang-tools-extra/clangd/3CCommands.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace clangd {
1616

1717
#define _3CSOURCE "3C_RealWild"
1818

19-
static bool GetPtrIDFromDiagMessage(const Diagnostic &DiagMsg,
19+
static bool getPtrIdFromDiagMessage(const Diagnostic &DiagMsg,
2020
unsigned long &PtrId) {
2121
if (DiagMsg.source.rfind(_3CSOURCE, 0) == 0) {
2222
PtrId = atoi(DiagMsg.code.c_str());
@@ -25,13 +25,13 @@ static bool GetPtrIDFromDiagMessage(const Diagnostic &DiagMsg,
2525
return false;
2626
}
2727

28-
void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands) {
28+
void as3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands) {
2929
unsigned long PtrId;
30-
if (GetPtrIDFromDiagMessage(D, PtrId)) {
30+
if (getPtrIdFromDiagMessage(D, PtrId)) {
3131
Command AllPtrsCmd;
3232
_3CManualFix PtrFix;
33-
PtrFix.ptrID = PtrId;
34-
AllPtrsCmd._3CManualFix = PtrFix;
33+
PtrFix.PtrId = PtrId;
34+
AllPtrsCmd.The3CManualFix = PtrFix;
3535
Command SinglePtrCmd = AllPtrsCmd;
3636

3737
AllPtrsCmd.command = Command::_3C_APPLY_FOR_ALL;
@@ -47,22 +47,22 @@ void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands) {
4747
}
4848
}
4949

50-
bool Is3CCommand(const ExecuteCommandParams &Params) {
50+
bool is3CCommand(const ExecuteCommandParams &Params) {
5151
return (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) ||
5252
(Params.command.rfind(Command::_3C_APPLY_FOR_ALL, 0) == 0);
5353
}
5454

55-
bool Execute3CCommand(const ExecuteCommandParams &Params,
55+
bool execute3CCommand(const ExecuteCommandParams &Params,
5656
std::string &ReplyMessage, _3CInterface &CcInterface) {
5757
ReplyMessage = "Checked C Pointer Modified.";
5858
if (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) {
59-
int PtrId = Params._3CManualFix->ptrID;
60-
CcInterface.MakeSinglePtrNonWild(PtrId);
59+
int PtrId = Params.The3CManualFix->PtrId;
60+
CcInterface.makeSinglePtrNonWild(PtrId);
6161
return true;
6262
}
6363
if (Params.command.rfind(Command::_3C_APPLY_FOR_ALL, 0) == 0) {
64-
int PtrId = Params._3CManualFix->ptrID;
65-
CcInterface.InvalidateWildReasonGlobally(PtrId);
64+
int PtrId = Params.The3CManualFix->PtrId;
65+
CcInterface.invalidateWildReasonGlobally(PtrId);
6666
return true;
6767
}
6868
return false;

clang-tools-extra/clangd/3CCommands.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
namespace clang {
1919
namespace clangd {
2020
// Convert the provided Diagnostic into Commands.
21-
void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands);
21+
void as3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands);
2222
// Check if the execute command request from the client is a 3C command.
23-
bool Is3CCommand(const ExecuteCommandParams &Params);
23+
bool is3CCommand(const ExecuteCommandParams &Params);
2424

2525
// Interpret the provided execute command request as 3C command
2626
// and execute them.
27-
bool Execute3CCommand(const ExecuteCommandParams &Params,
27+
bool execute3CCommand(const ExecuteCommandParams &Params,
2828
std::string &ReplyMessage, _3CInterface &CcInterface);
2929
} // namespace clangd
3030
} // namespace clang

clang-tools-extra/clangd/3CDiagnostics.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,40 @@ namespace clangd {
1616

1717
#define DEFAULT_PTRSIZE 4
1818

19-
void _3CDiagnostics::ClearAllDiags() {
19+
void _3CDiagnostics::clearAllDiags() {
2020
std::lock_guard<std::mutex> Lock(DiagMutex);
2121
AllFileDiagnostics.clear();
2222
}
2323

24-
static bool IsValidSourceFile(ConstraintsInfo &CCRes, std::string &FilePath) {
24+
static bool isValidSourceFile(ConstraintsInfo &CCRes, std::string &FilePath) {
2525
return CCRes.ValidSourceFiles.find(FilePath) != CCRes.ValidSourceFiles.end();
2626
}
2727

28-
bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
28+
bool _3CDiagnostics::populateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
2929
std::lock_guard<std::mutex> Lock(DiagMutex);
3030
std::set<ConstraintKey> ProcessedCKeys;
3131
ProcessedCKeys.clear();
3232
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS,
3333
uint32_t ColNoE) -> Range {
34-
Range nRange;
34+
Range NRange;
3535
Line--;
36-
nRange.start.line = Line;
37-
nRange.end.line = Line;
38-
nRange.start.character = ColNoS;
36+
NRange.start.line = Line;
37+
NRange.end.line = Line;
38+
NRange.start.character = ColNoS;
3939
if (ColNoE > 0) {
40-
nRange.end.character = ColNoE;
40+
NRange.end.character = ColNoE;
4141
} else {
42-
nRange.end.character = ColNoS + DEFAULT_PTRSIZE;
42+
NRange.end.character = ColNoS + DEFAULT_PTRSIZE;
4343
}
44-
return nRange;
44+
return NRange;
4545
};
4646

4747
for (auto &WReason : Line.RootWildAtomsWithReason) {
4848
if (Line.AtomSourceMap.find(WReason.first) != Line.AtomSourceMap.end()) {
4949
auto *PsInfo = Line.AtomSourceMap[WReason.first];
5050
std::string FilePath = PsInfo->getFileName();
5151
// If this is not a file in a project? Then ignore.
52-
if (!IsValidSourceFile(Line, FilePath))
52+
if (!isValidSourceFile(Line, FilePath))
5353
continue;
5454

5555
ProcessedCKeys.insert(WReason.first);
@@ -59,7 +59,7 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
5959
PsInfo->getColENo());
6060
NewDiag.Source = Diag::_3CMain;
6161
NewDiag.Severity = DiagnosticsEngine::Level::Error;
62-
NewDiag.code = std::to_string(WReason.first);
62+
NewDiag.Code = std::to_string(WReason.first);
6363
NewDiag.Message =
6464
"Pointer is wild because of:" + WReason.second.getWildPtrReason();
6565

@@ -85,36 +85,41 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
8585
auto *PsInfo = Line.AtomSourceMap[NonWildCk];
8686
std::string FilePath = PsInfo->getFileName();
8787
// If this is not a file in a project? Then ignore.
88-
if (!IsValidSourceFile(Line, FilePath))
88+
if (!isValidSourceFile(Line, FilePath))
8989
continue;
9090

9191
ProcessedCKeys.insert(NonWildCk);
9292
Diag NewDiag;
9393
NewDiag.Range = GetLocRange(PsInfo->getLineNo(), PsInfo->getColSNo(),
9494
PsInfo->getColENo());
9595

96-
NewDiag.code = std::to_string(NonWildCk);
96+
NewDiag.Code = std::to_string(NonWildCk);
9797
NewDiag.Source = Diag::_3CSec;
9898
NewDiag.Severity = DiagnosticsEngine::Level::Warning;
9999
NewDiag.Message = "Pointer is wild because it transitively "
100100
"depends on other pointer(s)";
101101

102102
// find the pointer group
103-
CVars &DirectWildPtrs = Line.GetRCVars(NonWildCk);
103+
CVars &DirectWildPtrs = Line.getRCVars(NonWildCk);
104104

105105
unsigned MaxPtrReasons = 4;
106-
for (auto tC : DirectWildPtrs) {
106+
for (auto TC : DirectWildPtrs) {
107107
Note DiagNote;
108108

109-
if (Line.AtomSourceMap.find(tC) != Line.AtomSourceMap.end()) {
110-
PsInfo = Line.AtomSourceMap[tC];
109+
if (Line.AtomSourceMap.find(TC) != Line.AtomSourceMap.end()) {
110+
PsInfo = Line.AtomSourceMap[TC];
111111
FilePath = PsInfo->getFileName();
112112
DiagNote.AbsFile = FilePath;
113113
DiagNote.Range = GetLocRange(
114114
PsInfo->getLineNo(), PsInfo->getColSNo(), PsInfo->getColENo());
115115
MaxPtrReasons--;
116+
// NOTE: Matt changed [] to `at` to fix a compile error after the
117+
// default constructor of WildPointerInferenceInfo was removed in
118+
// 3c3098c8724889a12eba383dec9088094bced99c. Right now, we don't
119+
// care because we're not running clangd3c at all, but if and when
120+
// we revive it, we should consider whether this assumption is safe.
116121
DiagNote.Message =
117-
Line.RootWildAtomsWithReason[tC].getWildPtrReason();
122+
Line.RootWildAtomsWithReason.at(TC).getWildPtrReason();
118123
if (MaxPtrReasons <= 1)
119124
DiagNote.Message += " (others)";
120125
NewDiag.Notes.push_back(DiagNote);

clang-tools-extra/clangd/3CDiagnostics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class _3CDiagnostics {
2929

3030
// GUARDED by DiagMutex
3131
// Populate diagnostics from the given disjoint set.
32-
bool PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line);
32+
bool populateDiagsFromConstraintsInfo(ConstraintsInfo &Line);
3333
// GUARDED by DiagMutex
3434
// Clear diagnostics of all files.
35-
void ClearAllDiags();
36-
std::map<std::string, std::vector<Diag>> &GetAllFilesDiagnostics() {
35+
void clearAllDiags();
36+
std::map<std::string, std::vector<Diag>> &getAllFilesDiagnostics() {
3737
return AllFileDiagnostics;
3838
}
3939

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
365365
ClangdServerOpts.ResourceDir);
366366
Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this),
367367
#ifdef INTERACTIVE3C
368-
ClangdServerOpts, _3CInterface);
368+
ClangdServerOpts, The3CInterface);
369369
#else
370370
ClangdServerOpts);
371371
#endif
@@ -462,7 +462,7 @@ void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
462462
#ifdef INTERACTIVE3C
463463
send3CMessage("Writing all CheckedC files back to disk");
464464
// Write all files back.
465-
auto &AllDiags = Server->_3CDiagInfo.GetAllFilesDiagnostics();
465+
auto &AllDiags = Server->_3CDiagInfo.getAllFilesDiagnostics();
466466
for (auto &CD : AllDiags) {
467467
Server->_3CCloseDocument(CD.first);
468468
}
@@ -533,11 +533,11 @@ void ClangdLSPServer::_3CResultsReady(std::string FileName, bool ClearDiags) {
533533
std::vector<Diag> Diagnostics;
534534
Diagnostics.clear();
535535
if (!ClearDiags) {
536-
std::lock_guard<std::mutex> lock(Server->_3CDiagInfo.DiagMutex);
537-
auto &allDiags = Server->_3CDiagInfo.GetAllFilesDiagnostics();
538-
if (allDiags.find(FileName) != allDiags.end()) {
539-
Diagnostics.insert(Diagnostics.begin(), allDiags[FileName].begin(),
540-
allDiags[FileName].end());
536+
std::lock_guard<std::mutex> Lock(Server->_3CDiagInfo.DiagMutex);
537+
auto &AllDiags = Server->_3CDiagInfo.getAllFilesDiagnostics();
538+
if (AllDiags.find(FileName) != AllDiags.end()) {
539+
Diagnostics.insert(Diagnostics.begin(), AllDiags[FileName].begin(),
540+
AllDiags[FileName].end());
541541
}
542542
}
543543
this->onDiagnosticsReady(FileName, Diagnostics);
@@ -556,7 +556,7 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
556556
Callback<llvm::json::Value> Reply) {
557557
#ifdef INTERACTIVE3C
558558
// In this mode, we support only 3C commands.
559-
if (Is3CCommand(Params)) {
559+
if (is3CCommand(Params)) {
560560
Server->execute3CCommand(Params, this);
561561
Reply("3C Background work scheduled.");
562562
} else {
@@ -811,7 +811,7 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
811811
std::vector<Command> Commands;
812812
// Convert the diagnostics into 3C commands.
813813
for (const Diagnostic &D : Params.context.diagnostics) {
814-
As3CCommands(D, Commands);
814+
as3CCommands(D, Commands);
815815
}
816816
Reply(llvm::json::Array(Commands));
817817
#else
@@ -914,14 +914,14 @@ void ClangdLSPServer::onCodeLens(const CodeLensParams &Params,
914914
// This is just a beacon to display for user.
915915
std::vector<CodeLens> AllCodeLens;
916916
CodeLens CcBecon;
917-
CcBecon.range.start.line = 15;
918-
CcBecon.range.end.line = 16;
919-
CcBecon.range.start.character = 13;
920-
CcBecon.range.end.character = 17;
917+
CcBecon.TheRange.start.line = 15;
918+
CcBecon.TheRange.end.line = 16;
919+
CcBecon.TheRange.start.character = 13;
920+
CcBecon.TheRange.end.character = 17;
921921
Command NewCmd;
922922
NewCmd.command = "3C Interactive Mode On";
923923
NewCmd.title = "3C Mode On";
924-
CcBecon.command = NewCmd;
924+
CcBecon.TheCommand = NewCmd;
925925
AllCodeLens.clear();
926926
AllCodeLens.push_back(CcBecon);
927927
Reply(llvm::json::Array(AllCodeLens));
@@ -930,7 +930,7 @@ void ClangdLSPServer::onCodeLens(const CodeLensParams &Params,
930930
void ClangdLSPServer::onCodeLensResolve(const CodeLens &Params,
931931
Callback<llvm::json::Value> Reply) {
932932
CodeLens CcBeaconResolve;
933-
CcBeaconResolve.range = Params.range;
933+
CcBeaconResolve.TheRange = Params.TheRange;
934934
Reply(clang::clangd::toJSON(CcBeaconResolve));
935935
}
936936
#endif
@@ -1126,7 +1126,7 @@ ClangdLSPServer::ClangdLSPServer(
11261126
UseDirBasedCDB(UseDirBasedCDB),
11271127
CompileCommandsDir(std::move(CompileCommandsDir)), ClangdServerOpts(Opts),
11281128
#ifdef INTERACTIVE3C
1129-
NegotiatedOffsetEncoding(ForcedOffsetEncoding), _3CInterface(Cinter) {
1129+
NegotiatedOffsetEncoding(ForcedOffsetEncoding), The3CInterface(Cinter) {
11301130
#else
11311131
NegotiatedOffsetEncoding(ForcedOffsetEncoding) {
11321132
#endif

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,7 @@ class ClangdLSPServer : private DiagnosticsConsumer {
203203
llvm::Optional<ClangdServer> Server;
204204
llvm::Optional<OffsetEncoding> NegotiatedOffsetEncoding;
205205
#ifdef INTERACTIVE3C
206-
// See clang/docs/checkedc/3C/clang-tidy.md#_3c-name-prefix
207-
// NOLINTNEXTLINE(readability-identifier-naming)
208-
_3CInterface &_3CInterface;
206+
_3CInterface &The3CInterface;
209207
#endif
210208
};
211209
} // namespace clangd

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
177177
void ClangdServer::report3CDiagsForAllFiles(ConstraintsInfo &CcInfo,
178178
_3CLSPCallBack *ConvCB) {
179179
// Update the diag information for all the valid files.
180-
for (auto &SrcFileDiags : _3CDiagInfo.GetAllFilesDiagnostics()) {
180+
for (auto &SrcFileDiags : _3CDiagInfo.getAllFilesDiagnostics()) {
181181
ConvCB->_3CResultsReady(SrcFileDiags.first);
182182
}
183183
}
184184

185185
void ClangdServer::clear3CDiagsForAllFiles(ConstraintsInfo &CcInfo,
186186
_3CLSPCallBack *ConvCB) {
187-
for (auto &SrcFileDiags : _3CDiagInfo.GetAllFilesDiagnostics()) {
187+
for (auto &SrcFileDiags : _3CDiagInfo.getAllFilesDiagnostics()) {
188188
// Clear diags for all files.
189189
ConvCB->_3CResultsReady(SrcFileDiags.first, true);
190190
}
@@ -193,15 +193,15 @@ void ClangdServer::clear3CDiagsForAllFiles(ConstraintsInfo &CcInfo,
193193
void ClangdServer::_3CCollectAndBuildInitialConstraints(
194194
_3CLSPCallBack *ConvCB) {
195195
auto Task = [=]() {
196-
_3CDiagInfo.ClearAllDiags();
196+
_3CDiagInfo.clearAllDiags();
197197
ConvCB->send3CMessage("Running 3C for first time.");
198-
_3CInter.BuildInitialConstraints();
199-
_3CInter.SolveConstraints(true);
198+
_3CInter.buildInitialConstraints();
199+
_3CInter.solveConstraints(true);
200200
ConvCB->send3CMessage("Finished running 3C.");
201201
log("3C: Built initial constraints successfully.\n");
202-
auto &WildPtrsInfo = _3CInter.GetWILDPtrsInfo();
202+
auto &WildPtrsInfo = _3CInter.getWildPtrsInfo();
203203
log("3C: Got WILD Ptrs Info.\n");
204-
_3CDiagInfo.PopulateDiagsFromConstraintsInfo(WildPtrsInfo);
204+
_3CDiagInfo.populateDiagsFromConstraintsInfo(WildPtrsInfo);
205205
log("3C: Populated Diags from Disjoint Sets.\n");
206206
report3CDiagsForAllFiles(WildPtrsInfo, ConvCB);
207207
ConvCB->send3CMessage("3C: Finished updating problems.");
@@ -214,19 +214,19 @@ void ClangdServer::execute3CCommand(ExecuteCommandParams Params,
214214
_3CLSPCallBack *ConvCB) {
215215
auto Task = [this, Params, ConvCB]() {
216216
std::string RplMsg;
217-
auto &WildPtrsInfo = _3CInter.GetWILDPtrsInfo();
217+
auto &WildPtrsInfo = _3CInter.getWildPtrsInfo();
218218
auto &PtrSourceMap = WildPtrsInfo.AtomSourceMap;
219-
if (PtrSourceMap.find(Params._3CManualFix->ptrID) != PtrSourceMap.end()) {
219+
if (PtrSourceMap.find(Params.The3CManualFix->PtrId) != PtrSourceMap.end()) {
220220
std::string PtrFileName =
221-
PtrSourceMap[Params._3CManualFix->ptrID]->getFileName();
221+
PtrSourceMap[Params.The3CManualFix->PtrId]->getFileName();
222222
log("3C: File of the pointer {0}\n", PtrFileName);
223223
clear3CDiagsForAllFiles(WildPtrsInfo, ConvCB);
224224
ConvCB->send3CMessage("3C modifying constraints.");
225-
Execute3CCommand(Params, RplMsg, _3CInter);
226-
this->_3CDiagInfo.ClearAllDiags();
225+
::clang::clangd::execute3CCommand(Params, RplMsg, _3CInter);
226+
this->_3CDiagInfo.clearAllDiags();
227227
ConvCB->send3CMessage("3C Updating new issues "
228228
"after editing constraints.");
229-
this->_3CDiagInfo.PopulateDiagsFromConstraintsInfo(WildPtrsInfo);
229+
this->_3CDiagInfo.populateDiagsFromConstraintsInfo(WildPtrsInfo);
230230
log("3C calling call-back\n");
231231
// ConvCB->_3CResultsReady(ptrFileName);
232232
ConvCB->send3CMessage("3C Updated new issues.");
@@ -241,7 +241,7 @@ void ClangdServer::execute3CCommand(ExecuteCommandParams Params,
241241
void ClangdServer::_3CCloseDocument(std::string FileName) {
242242
auto Task = [=]() {
243243
log("3C: Trying to write back file: {0}\n", FileName);
244-
if (_3CInter.WriteConvertedFileToDisk(FileName)) {
244+
if (_3CInter.writeConvertedFileToDisk(FileName)) {
245245
log("3C: Finished writing back file: {0}\n", FileName);
246246
} else {
247247
log("3C: File not included during constraint solving phase. "

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void toLSPDiags(
319319

320320
clangd::Diagnostic Main = FillBasicFields(D);
321321
#ifdef INTERACTIVE3C
322-
Main.code = D.code;
322+
Main.code = D.Code;
323323
#else
324324
Main.code = D.Name;
325325
#endif

clang-tools-extra/clangd/Diagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct DiagBase {
5858
// Absolute path to containing file, if available.
5959
llvm::Optional<std::string> AbsFile;
6060
#ifdef INTERACTIVE3C
61-
std::string code;
61+
std::string Code;
6262
#endif
6363
clangd::Range Range;
6464
DiagnosticsEngine::Level Severity = DiagnosticsEngine::Note;

0 commit comments

Comments
 (0)