Skip to content

Commit 5f4d71c

Browse files
committed
merge with master
2 parents 923b34f + 74d2913 commit 5f4d71c

File tree

255 files changed

+6887
-6029
lines changed

Some content is hidden

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

255 files changed

+6887
-6029
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 578 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ manual is
5454
For more information on Checked C and pointers to example code, see our
5555
[Wiki](https://github.com/Microsoft/checkedc/wiki).
5656

57+
## 3C: Semi-automated conversion of C code to Checked C
58+
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).
64+
5765
## More information
5866

5967
For more information on the Checked C clang compiler, see the [Checked C clang

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

Lines changed: 17 additions & 18 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 AsCCCommands(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,27 +47,26 @@ void AsCCCommands(const Diagnostic &D, std::vector<Command> &OutCommands) {
4747
}
4848
}
4949

50-
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);
50+
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);
5353
}
5454

55-
bool ExecuteCCCommand(const ExecuteCommandParams &Params,
56-
std::string &ReplyMessage,
57-
_3CInterface &CcInterface) {
55+
bool execute3CCommand(const ExecuteCommandParams &Params,
56+
std::string &ReplyMessage, _3CInterface &CcInterface) {
5857
ReplyMessage = "Checked C Pointer Modified.";
5958
if (Params.command.rfind(Command::_3C_APPLY_ONLY_FOR_THIS, 0) == 0) {
60-
int PtrId = Params._3CManualFix->ptrID;
61-
CcInterface.MakeSinglePtrNonWild(PtrId);
59+
int PtrId = Params.The3CManualFix->PtrId;
60+
CcInterface.makeSinglePtrNonWild(PtrId);
6261
return true;
6362
}
6463
if (Params.command.rfind(Command::_3C_APPLY_FOR_ALL, 0) == 0) {
65-
int PtrId = Params._3CManualFix->ptrID;
66-
CcInterface.InvalidateWildReasonGlobally(PtrId);
64+
int PtrId = Params.The3CManualFix->PtrId;
65+
CcInterface.invalidateWildReasonGlobally(PtrId);
6766
return true;
6867
}
6968
return false;
7069
}
71-
}
72-
}
73-
#endif
70+
} // namespace clangd
71+
} // namespace clang
72+
#endif

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

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

1818
namespace clang {
1919
namespace clangd {
20-
// Convert the provided Diagnostic into Commands
21-
void AsCCCommands(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 ExecuteCCCommand(const ExecuteCommandParams &Params,
28-
std::string &ReplyMessage,
29-
_3CInterface &CcInterface);
30-
}
31-
}
32-
#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, _3CInterface &CcInterface);
29+
} // namespace clangd
30+
} // namespace clang
31+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_3CCOMMANDS_H
3332
#endif

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

Lines changed: 34 additions & 30 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-
29-
bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
28+
bool _3CDiagnostics::populateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
3029
std::lock_guard<std::mutex> Lock(DiagMutex);
3130
std::set<ConstraintKey> ProcessedCKeys;
3231
ProcessedCKeys.clear();
33-
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS, uint32_t ColNoE) -> Range {
34-
Range nRange;
32+
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS,
33+
uint32_t ColNoE) -> Range {
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,9 +59,9 @@ 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);
63-
NewDiag.Message = "Pointer is wild because of:" +
64-
WReason.second.getWildPtrReason();
62+
NewDiag.Code = std::to_string(WReason.first);
63+
NewDiag.Message =
64+
"Pointer is wild because of:" + WReason.second.getWildPtrReason();
6565

6666
// Create notes for the information about root cause.
6767
PersistentSourceLoc SL = WReason.second.getLocation();
@@ -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;
113-
DiagNote.Range =
114-
GetLocRange(PsInfo->getLineNo(), PsInfo->getColSNo(),
115-
PsInfo->getColENo());
113+
DiagNote.Range = GetLocRange(
114+
PsInfo->getLineNo(), PsInfo->getColSNo(), PsInfo->getColENo());
116115
MaxPtrReasons--;
117-
DiagNote.Message = Line.RootWildAtomsWithReason[tC].getWildPtrReason();
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.
121+
DiagNote.Message =
122+
Line.RootWildAtomsWithReason.at(TC).getWildPtrReason();
118123
if (MaxPtrReasons <= 1)
119124
DiagNote.Message += " (others)";
120125
NewDiag.Notes.push_back(DiagNote);
@@ -127,10 +132,9 @@ bool _3CDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
127132
}
128133
}
129134

130-
131135
return true;
132136
}
133137

134-
}
135-
}
136-
#endif
138+
} // namespace clangd
139+
} // namespace clang
140+
#endif

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

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

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

1919
namespace clang {
2020
namespace clangd {
2121

2222
// Class that represents diagnostics messages specific to 3C.
23+
//
24+
// See clang/docs/checkedc/3C/clang-tidy.md#_3c-name-prefix
25+
// NOLINTNEXTLINE(readability-identifier-naming)
2326
class _3CDiagnostics {
2427
public:
2528
std::mutex DiagMutex;
2629

2730
// GUARDED by DiagMutex
2831
// Populate diagnostics from the given disjoint set.
29-
bool PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line);
32+
bool populateDiagsFromConstraintsInfo(ConstraintsInfo &Line);
3033
// GUARDED by DiagMutex
3134
// Clear diagnostics of all files.
32-
void ClearAllDiags();
33-
std::map<std::string, std::vector<Diag>> &GetAllFilesDiagnostics() {
35+
void clearAllDiags();
36+
std::map<std::string, std::vector<Diag>> &getAllFilesDiagnostics() {
3437
return AllFileDiagnostics;
3538
}
39+
3640
private:
3741
// Diagnostics of all files.
3842
std::map<std::string, std::vector<Diag>> AllFileDiagnostics;
39-
40-
4143
};
42-
}
43-
}
44-
#endif //LLVM_CLANG_TOOLS_EXTRA_CLANGD_
44+
} // namespace clangd
45+
} // namespace clang
46+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_
4547
#endif

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ add_clang_library(3cClangDaemon
209209
refactor/Tweak.cpp
210210

211211
LINK_LIBS
212-
3C
212+
clang3C
213213
clangAST
214214
clangASTMatchers
215215
clangBasic

0 commit comments

Comments
 (0)