Skip to content

Commit da54c15

Browse files
authored
Merge pull request #330 from correctcomputation/fail_gracefully
Fix for issue 283 (round 2)
2 parents f184449 + afffadf commit da54c15

File tree

181 files changed

+4045
-3258
lines changed

Some content is hidden

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

181 files changed

+4045
-3258
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ For more information on Checked C and pointers to example code, see our
5656

5757
## 3C: Semi-automated conversion of C code to Checked C
5858

59-
This repository includes a tool called 3C that partially automates the
60-
conversion of C code to Checked C. Here is [general information about the 3C
61-
software](clang/docs/checkedc/3C/README.md), including development status and
62-
how to contribute. Here are the [usage instructions for the `3c` command-line
63-
tool](clang/tools/3c/README.md).
59+
This repository includes a tool called 3C that partially automates the conversion of C code to Checked C. Here is [general information about the 3C software](clang/docs/checkedc/3C/README.md), including development status and how to contribute. Here are the [usage instructions for the `3c` command-line tool](clang/tools/3c/README.md).
6460

6561
## More information
6662

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands) {
4848
}
4949

5050
bool Is3CCommand(const ExecuteCommandParams &Params) {
51-
return (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) ||
52-
(Params.command.rfind(Command::_3C_APPLY_FOR_ALL, 0) == 0);
51+
return (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) ||
52+
(Params.command.rfind(Command::_3C_APPLY_FOR_ALL, 0) == 0);
5353
}
5454

5555
bool Execute3CCommand(const ExecuteCommandParams &Params,
56-
std::string &ReplyMessage, _3CInterface &CcInterface) {
56+
std::string &ReplyMessage,
57+
_3CInterface &CcInterface) {
5758
ReplyMessage = "Checked C Pointer Modified.";
5859
if (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) {
5960
int PtrId = Params._3CManualFix->ptrID;
@@ -67,6 +68,6 @@ bool Execute3CCommand(const ExecuteCommandParams &Params,
6768
}
6869
return false;
6970
}
70-
} // namespace clangd
71-
} // namespace clang
71+
}
72+
}
7273
#endif

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717

1818
namespace clang {
1919
namespace clangd {
20-
// Convert the provided Diagnostic into Commands.
21-
void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands);
22-
// Check if the execute command request from the client is a 3C command.
23-
bool Is3CCommand(const ExecuteCommandParams &Params);
20+
// Convert the provided Diagnostic into Commands
21+
void As3CCommands(const Diagnostic &D, std::vector<Command> &OutCommands);
22+
// Check if the execute command request from the client is a 3C command.
23+
bool Is3CCommand(const ExecuteCommandParams &Params);
2424

25-
// Interpret the provided execute command request as 3C command
26-
// and execute them.
27-
bool Execute3CCommand(const ExecuteCommandParams &Params,
28-
std::string &ReplyMessage, _3CInterface &CcInterface);
29-
} // namespace clangd
30-
} // namespace clang
31-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CCOMMANDS_H
25+
// Interpret the provided execute command request as 3C command
26+
// and execute them.
27+
bool Execute3CCommand(const ExecuteCommandParams &Params,
28+
std::string &ReplyMessage,
29+
_3CInterface &CcInterface);
30+
}
31+
}
32+
#endif //LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CCOMMANDS_H
3233
#endif

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ static bool IsValidSourceFile(ConstraintsInfo &CCRes, std::string &FilePath) {
2525
return CCRes.ValidSourceFiles.find(FilePath) != CCRes.ValidSourceFiles.end();
2626
}
2727

28+
2829
bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
2930
std::lock_guard<std::mutex> Lock(DiagMutex);
3031
std::set<ConstraintKey> ProcessedCKeys;
3132
ProcessedCKeys.clear();
32-
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS,
33-
uint32_t ColNoE) -> Range {
33+
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS, uint32_t ColNoE) -> Range {
3434
Range nRange;
3535
Line--;
3636
nRange.start.line = Line;
@@ -60,8 +60,8 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
6060
NewDiag.Source = Diag::_3CMain;
6161
NewDiag.Severity = DiagnosticsEngine::Level::Error;
6262
NewDiag.code = std::to_string(WReason.first);
63-
NewDiag.Message =
64-
"Pointer is wild because of:" + WReason.second.getWildPtrReason();
63+
NewDiag.Message = "Pointer is wild because of:" +
64+
WReason.second.getWildPtrReason();
6565

6666
// Create notes for the information about root cause.
6767
PersistentSourceLoc SL = WReason.second.getLocation();
@@ -110,11 +110,11 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
110110
PsInfo = Line.AtomSourceMap[tC];
111111
FilePath = PsInfo->getFileName();
112112
DiagNote.AbsFile = FilePath;
113-
DiagNote.Range = GetLocRange(
114-
PsInfo->getLineNo(), PsInfo->getColSNo(), PsInfo->getColENo());
113+
DiagNote.Range =
114+
GetLocRange(PsInfo->getLineNo(), PsInfo->getColSNo(),
115+
PsInfo->getColENo());
115116
MaxPtrReasons--;
116-
DiagNote.Message =
117-
Line.RootWildAtomsWithReason[tC].getWildPtrReason();
117+
DiagNote.Message = Line.RootWildAtomsWithReason[tC].getWildPtrReason();
118118
if (MaxPtrReasons <= 1)
119119
DiagNote.Message += " (others)";
120120
NewDiag.Notes.push_back(DiagNote);
@@ -127,9 +127,10 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
127127
}
128128
}
129129

130+
130131
return true;
131132
}
132133

133-
} // namespace clangd
134-
} // namespace clang
134+
}
135+
}
135136
#endif

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CDIAGNOSTICS_H
1313
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CDIAGNOSTICS_H
1414

15+
#include <set>
1516
#include "Diagnostics.h"
1617
#include "clang/3C/3C.h"
17-
#include <set>
1818

1919
namespace clang {
2020
namespace clangd {
@@ -33,12 +33,13 @@ class _3CDiagnostics {
3333
std::map<std::string, std::vector<Diag>> &GetAllFilesDiagnostics() {
3434
return AllFileDiagnostics;
3535
}
36-
3736
private:
3837
// Diagnostics of all files.
3938
std::map<std::string, std::vector<Diag>> AllFileDiagnostics;
39+
40+
4041
};
41-
} // namespace clangd
42-
} // namespace clang
43-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_
42+
}
43+
}
44+
#endif //LLVM_CLANG_TOOLS_EXTRA_CLANGD_
4445
#endif

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
398398
llvm::json::Object{
399399
{"textDocumentSync", (int)TextDocumentSyncKind::Incremental},
400400
{"codeActionProvider", true},
401-
{"codeLensProvider", llvm::json::Object{{"resolveProvider", true}}},
401+
{"codeLensProvider", llvm::json::Object{
402+
{"resolveProvider", true}}},
402403
{"executeCommandProvider",
403404
llvm::json::Object{
404405
{"commands",
@@ -528,35 +529,40 @@ void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
528529
}
529530

530531
#ifdef INTERACTIVE3C
531-
void ClangdLSPServer::_3CResultsReady(std::string FileName, bool ClearDiags) {
532+
void ClangdLSPServer::_3CResultsReady(std::string FileName,
533+
bool ClearDiags) {
532534
// Get the diagnostics and update the client.
533535
std::vector<Diag> Diagnostics;
534536
Diagnostics.clear();
535537
if (!ClearDiags) {
536538
std::lock_guard<std::mutex> lock(Server->_3CDiagInfo.DiagMutex);
537539
auto &allDiags = Server->_3CDiagInfo.GetAllFilesDiagnostics();
538-
if (allDiags.find(FileName) != allDiags.end()) {
539-
Diagnostics.insert(Diagnostics.begin(), allDiags[FileName].begin(),
540-
allDiags[FileName].end());
540+
if (allDiags.find(FileName) !=
541+
allDiags.end()) {
542+
Diagnostics.insert(
543+
Diagnostics.begin(),
544+
allDiags[FileName].begin(),
545+
allDiags[FileName].end());
541546
}
542547
}
543548
this->onDiagnosticsReady(FileName, Diagnostics);
544549
}
545550

546551
void ClangdLSPServer::send3CMessage(std::string MsgStr) {
547-
// Send message as info to the client.
548-
notify("window/showMessage", llvm::json::Object{
549-
// Info message.
550-
{"type", 3},
551-
{"message", std::move(MsgStr)},
552-
});
552+
// Send message as info to the client.
553+
notify("window/showMessage",
554+
llvm::json::Object{
555+
// Info message.
556+
{"type", 3},
557+
{"message", std::move(MsgStr)},
558+
});
553559
}
554560
#endif
555561
void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
556562
Callback<llvm::json::Value> Reply) {
557563
#ifdef INTERACTIVE3C
558564
// In this mode, we support only 3C commands.
559-
if (Is3CCommand(Params)) {
565+
if(Is3CCommand(Params)) {
560566
Server->execute3CCommand(Params, this);
561567
Reply("3C Background work scheduled.");
562568
} else {
@@ -1143,6 +1149,7 @@ ClangdLSPServer::ClangdLSPServer(
11431149
MsgHandler->bind("textDocument/didOpen", &ClangdLSPServer::onDocumentDidOpen);
11441150
MsgHandler->bind("textDocument/didClose", &ClangdLSPServer::onDocumentDidClose);
11451151
MsgHandler->bind("textDocument/didChange", &ClangdLSPServer::onDocumentDidChange);
1152+
// clang-format on
11461153
#else
11471154
MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize);
11481155
MsgHandler->bind("shutdown", &ClangdLSPServer::onShutdown);
@@ -1172,7 +1179,6 @@ ClangdLSPServer::ClangdLSPServer(
11721179
MsgHandler->bind("textDocument/typeHierarchy", &ClangdLSPServer::onTypeHierarchy);
11731180
MsgHandler->bind("typeHierarchy/resolve", &ClangdLSPServer::onResolveTypeHierarchy);
11741181
#endif
1175-
// clang-format on
11761182
}
11771183

11781184
ClangdLSPServer::~ClangdLSPServer() = default;

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include "refactor/Rename.h"
2525
#include "refactor/Tweak.h"
2626
#ifdef INTERACTIVE3C
27-
#include "3CCommands.h"
2827
#include "clang/3C/3C.h"
28+
#include "3CCommands.h"
2929
#endif
3030
#include "clang/Format/Format.h"
3131
#include "clang/Frontend/CompilerInstance.h"
@@ -122,10 +122,9 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
122122
DynamicIdx.get(), DiagConsumer, Opts.SemanticHighlighting),
123123
Opts.UpdateDebounce, Opts.RetentionPolicy)
124124
#ifdef INTERACTIVE3C
125-
,
126-
_3CInter(_3CInterface)
125+
, _3CInter(_3CInterface)
127126
#endif
128-
{
127+
{
129128
// Adds an index to the stack, at higher priority than existing indexes.
130129
auto AddIndex = [&](SymbolIndex *Idx) {
131130
if (this->Index != nullptr) {
@@ -187,8 +186,8 @@ void ClangdServer::clear3CDiagsForAllFiles(ConstraintsInfo &CcInfo,
187186
}
188187
}
189188

190-
void ClangdServer::_3CCollectAndBuildInitialConstraints(
191-
_3CLSPCallBack *ConvCB) {
189+
void
190+
ClangdServer::_3CCollectAndBuildInitialConstraints(_3CLSPCallBack *ConvCB) {
192191
auto Task = [=]() {
193192
_3CDiagInfo.ClearAllDiags();
194193
ConvCB->send3CMessage("Running 3C for first time.");
@@ -213,7 +212,8 @@ void ClangdServer::execute3CCommand(ExecuteCommandParams Params,
213212
std::string RplMsg;
214213
auto &WildPtrsInfo = _3CInter.GetWILDPtrsInfo();
215214
auto &PtrSourceMap = WildPtrsInfo.AtomSourceMap;
216-
if (PtrSourceMap.find(Params._3CManualFix->ptrID) != PtrSourceMap.end()) {
215+
if (PtrSourceMap.find(Params._3CManualFix->ptrID) !=
216+
PtrSourceMap.end()) {
217217
std::string PtrFileName =
218218
PtrSourceMap[Params._3CManualFix->ptrID]->getFileName();
219219
log("3C: File of the pointer {0}\n", PtrFileName);
@@ -242,8 +242,7 @@ void ClangdServer::_3CCloseDocument(std::string FileName) {
242242
log("3C: Finished writing back file: {0}\n", FileName);
243243
} else {
244244
log("3C: File not included during constraint solving phase. "
245-
"Rewriting failed: {0}\n",
246-
FileName);
245+
"Rewriting failed: {0}\n", FileName);
247246
}
248247
};
249248
WorkScheduler.run("3C: Writing back file.", Task);

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ class ClangdServer {
310310
// collect and build initial set of constraints on the source
311311
// files.
312312

313-
void execute3CCommand(ExecuteCommandParams Params, _3CLSPCallBack *ConvCB);
313+
void execute3CCommand(ExecuteCommandParams Params,
314+
_3CLSPCallBack *ConvCB);
314315

315316
void _3CCollectAndBuildInitialConstraints(_3CLSPCallBack *ConvCB);
316317

@@ -327,8 +328,7 @@ class ClangdServer {
327328
ArrayRef<tooling::Range> Ranges);
328329

329330
#ifdef INTERACTIVE3C
330-
void report3CDiagsForAllFiles(ConstraintsInfo &CcInfo,
331-
_3CLSPCallBack *ConvCB);
331+
void report3CDiagsForAllFiles(ConstraintsInfo &CcInfo, _3CLSPCallBack *ConvCB);
332332
void clear3CDiagsForAllFiles(ConstraintsInfo &CcInfo, _3CLSPCallBack *ConvCB);
333333
#endif
334334

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ bool fromJSON(const llvm::json::Value &Params, ExecuteCommandParams &R) {
560560
#ifdef INTERACTIVE3C
561561
if (R.command == ExecuteCommandParams::_3C_APPLY_ONLY_FOR_THIS ||
562562
R.command == ExecuteCommandParams::_3C_APPLY_FOR_ALL) {
563-
return Args && Args->size() == 1 && fromJSON(Args->front(), R._3CManualFix);
563+
return Args && Args->size() == 1 &&
564+
fromJSON(Args->front(), R._3CManualFix);
564565
}
565566
#endif
566567
return false; // Unrecognized command.

clang-tools-extra/clangd/Protocol.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,25 +817,23 @@ llvm::json::Value toJSON(const CodeAction &);
817817
// A code lens represents a command that should be shown along with
818818
// source text, like the number of references, a way to run tests, etc.
819819
//
820-
// A code lens is _unresolved_ when no command is associated to it. For
821-
// performance reasons the creation of a code lens and resolving should be done
822-
// in two stages.
820+
// A code lens is _unresolved_ when no command is associated to it. For performance
821+
// reasons the creation of a code lens and resolving should be done in two stages.
823822
//
824823
struct CodeLens {
825-
/// The range in which this code lens is valid, should only span a single
826-
/// line.
824+
/// The range in which this code lens is valid, should only span a single line.
827825
Range range;
828826

829827
/**
830828
* The command this code lens represents.
831-
*/
829+
*/
832830
llvm::Optional<Command> command;
833831

834832
/**
835833
* A data entry field that is preserved on a code lens item between
836834
* a code lens and a code lens resolve request.
837835
*/
838-
// data?: any
836+
//data?: any
839837
};
840838

841839
llvm::json::Value toJSON(const CodeLens &);

0 commit comments

Comments
 (0)