Skip to content

Commit 3c571f4

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 2531895 + ea1edad commit 3c571f4

File tree

423 files changed

+43928
-6110
lines changed

Some content is hidden

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

423 files changed

+43928
-6110
lines changed

clang-tools-extra/clangd/CConvertDiagnostics.cpp

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,42 @@ void CConvertDiagnostics::ClearAllDiags() {
2121
AllFileDiagnostics.clear();
2222
}
2323

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

2828

29-
bool CConvertDiagnostics::PopulateDiagsFromDisjointSet(DisjointSet &CCRes) {
29+
bool CConvertDiagnostics::PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line) {
3030
std::lock_guard<std::mutex> Lock(DiagMutex);
3131
std::set<ConstraintKey> ProcessedCKeys;
3232
ProcessedCKeys.clear();
33-
auto GetLocRange = [](uint32_t Line, uint32_t ColNo) -> Range {
33+
auto GetLocRange = [](uint32_t Line, uint32_t ColNoS, uint32_t ColNoE) -> Range {
3434
Range nRange;
3535
Line--;
3636
nRange.start.line = Line;
3737
nRange.end.line = Line;
38-
nRange.start.character = ColNo;
39-
nRange.end.character = ColNo + DEFAULT_PTRSIZE;
38+
nRange.start.character = ColNoS;
39+
if (ColNoE > 0) {
40+
nRange.end.character = ColNoE;
41+
} else {
42+
nRange.end.character = ColNoS + DEFAULT_PTRSIZE;
43+
}
4044
return nRange;
4145
};
4246

43-
for (auto &WReason : CCRes.RealWildPtrsWithReasons) {
44-
if (CCRes.PtrSourceMap.find(WReason.first) != CCRes.PtrSourceMap.end()) {
45-
auto *PsInfo = CCRes.PtrSourceMap[WReason.first];
47+
for (auto &WReason : Line.RealWildPtrsWithReasons) {
48+
if (Line.PtrSourceMap.find(WReason.first) != Line.PtrSourceMap.end()) {
49+
auto *PsInfo = Line.PtrSourceMap[WReason.first];
4650
std::string FilePath = PsInfo->getFileName();
4751
// If this is not a file in a project? Then ignore.
48-
if (!IsValidSourceFile(CCRes, FilePath))
52+
if (!IsValidSourceFile(Line, FilePath))
4953
continue;
5054

5155
ProcessedCKeys.insert(WReason.first);
5256

5357
Diag NewDiag;
54-
NewDiag.Range = GetLocRange(PsInfo->getLineNo(), PsInfo->getColNo());
58+
NewDiag.Range = GetLocRange(PsInfo->getLineNo(), PsInfo->getColSNo(),
59+
PsInfo->getColENo());
5560
NewDiag.Source = Diag::CConvMain;
5661
NewDiag.Severity = DiagnosticsEngine::Level::Error;
5762
NewDiag.code = std::to_string(WReason.first);
@@ -63,7 +68,8 @@ bool CConvertDiagnostics::PopulateDiagsFromDisjointSet(DisjointSet &CCRes) {
6368
Note DiagNote;
6469
DiagNote.AbsFile = WReason.second.SourceFileName;
6570
DiagNote.Range =
66-
GetLocRange(WReason.second.LineNo, WReason.second.ColStart);
71+
GetLocRange(WReason.second.LineNo, WReason.second.ColStartS,
72+
WReason.second.ColStartE);
6773
DiagNote.Message = "Go here to know the root cause for this.";
6874
NewDiag.Notes.push_back(DiagNote);
6975
}
@@ -72,19 +78,20 @@ bool CConvertDiagnostics::PopulateDiagsFromDisjointSet(DisjointSet &CCRes) {
7278
}
7379

7480
// For non-direct wild pointers..update the reason and diag information.
75-
for (auto NonWildCk : CCRes.TotalNonDirectWildPointers) {
81+
for (auto NonWildCk : Line.TotalNonDirectWildPointers) {
7682
if (ProcessedCKeys.find(NonWildCk) == ProcessedCKeys.end()) {
7783
ProcessedCKeys.insert(NonWildCk);
78-
if (CCRes.PtrSourceMap.find(NonWildCk) != CCRes.PtrSourceMap.end()) {
79-
auto *PsInfo = CCRes.PtrSourceMap[NonWildCk];
84+
if (Line.PtrSourceMap.find(NonWildCk) != Line.PtrSourceMap.end()) {
85+
auto *PsInfo = Line.PtrSourceMap[NonWildCk];
8086
std::string FilePath = PsInfo->getFileName();
8187
// If this is not a file in a project? Then ignore.
82-
if (!IsValidSourceFile(CCRes, FilePath))
88+
if (!IsValidSourceFile(Line, FilePath))
8389
continue;
8490

8591
ProcessedCKeys.insert(NonWildCk);
8692
Diag NewDiag;
87-
NewDiag.Range = GetLocRange(PsInfo->getLineNo(), PsInfo->getColNo());
93+
NewDiag.Range = GetLocRange(PsInfo->getLineNo(), PsInfo->getColSNo(),
94+
PsInfo->getColENo());
8895

8996
NewDiag.code = std::to_string(NonWildCk);
9097
NewDiag.Source = Diag::CConvSec;
@@ -93,29 +100,21 @@ bool CConvertDiagnostics::PopulateDiagsFromDisjointSet(DisjointSet &CCRes) {
93100
"depends on other pointer(s)";
94101

95102
// find the pointer group
96-
auto DirectWildPtrKey = CCRes.GetLeader(NonWildCk);
97-
auto &PtrGroup = CCRes.GetGroup(DirectWildPtrKey);
98-
CVars DirectWildPtrs;
99-
DirectWildPtrs.clear();
100-
std::set_intersection(
101-
PtrGroup.begin(), PtrGroup.end(),
102-
CCRes.AllWildPtrs.begin(),
103-
CCRes.AllWildPtrs.end(),
104-
std::inserter(DirectWildPtrs,
105-
DirectWildPtrs.begin()));
103+
CVars &DirectWildPtrs = Line.GetRCVars(NonWildCk);
106104

107105
unsigned MaxPtrReasons = 4;
108106
for (auto tC : DirectWildPtrs) {
109107
Note DiagNote;
110108

111-
if (CCRes.PtrSourceMap.find(tC) != CCRes.PtrSourceMap.end()) {
112-
PsInfo = CCRes.PtrSourceMap[tC];
109+
if (Line.PtrSourceMap.find(tC) != Line.PtrSourceMap.end()) {
110+
PsInfo = Line.PtrSourceMap[tC];
113111
FilePath = PsInfo->getFileName();
114112
DiagNote.AbsFile = FilePath;
115113
DiagNote.Range =
116-
GetLocRange(PsInfo->getLineNo(), PsInfo->getColNo());
114+
GetLocRange(PsInfo->getLineNo(), PsInfo->getColSNo(),
115+
PsInfo->getColENo());
117116
MaxPtrReasons--;
118-
DiagNote.Message = CCRes.RealWildPtrsWithReasons[tC].WildPtrReason;
117+
DiagNote.Message = Line.RealWildPtrsWithReasons[tC].WildPtrReason;
119118
if (MaxPtrReasons <= 1)
120119
DiagNote.Message += " (others)";
121120
NewDiag.Notes.push_back(DiagNote);

clang-tools-extra/clangd/CConvertDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CConvertDiagnostics {
2626

2727
// GUARDED by DiagMutex
2828
// Populate diagnostics from the given disjoint set.
29-
bool PopulateDiagsFromDisjointSet(DisjointSet &Line);
29+
bool PopulateDiagsFromConstraintsInfo(ConstraintsInfo &Line);
3030
// GUARDED by DiagMutex
3131
// Clear diagnostics of all files.
3232
void ClearAllDiags();

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ add_clang_library(clangDaemon
140140
${CLANGD_ATOMIC_LIB}
141141
)
142142

143-
144143
add_clang_library(cconvClangDaemon
145144
AST.cpp
146145
CConvertCommands.cpp
@@ -246,9 +245,9 @@ add_clang_library(cconvClangDaemon
246245
clangToolingSyntax
247246
${LLVM_PTHREAD_LIB}
248247
${CLANGD_ATOMIC_LIB}
249-
)
248+
)
250249

251-
target_compile_definitions(obj.cconvClangDaemon PRIVATE INTERACTIVECCCONV=1)
250+
target_compile_definitions(obj.cconvClangDaemon PRIVATE INTERACTIVECCCONV=1)
252251

253252
add_subdirectory(refactor/tweaks)
254253
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
170170
}
171171

172172
#ifdef INTERACTIVECCCONV
173-
void ClangdServer::reportCConvDiagsForAllFiles(DisjointSet &CcInfo,
173+
void ClangdServer::reportCConvDiagsForAllFiles(ConstraintsInfo &CcInfo,
174174
CConvLSPCallBack *ConvCB) {
175175
// Update the diag information for all the valid files.
176176
for (auto &SrcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
177177
ConvCB->ccConvResultsReady(SrcFileDiags.first);
178178
}
179179
}
180180

181-
void ClangdServer::clearCConvDiagsForAllFiles(DisjointSet &CcInfo,
181+
void ClangdServer::clearCConvDiagsForAllFiles(ConstraintsInfo &CcInfo,
182182
CConvLSPCallBack *ConvCB) {
183183
for (auto &SrcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
184184
// Clear diags for all files.
@@ -192,12 +192,12 @@ ClangdServer::cconvCollectAndBuildInitialConstraints(CConvLSPCallBack *ConvCB) {
192192
CConvDiagInfo.ClearAllDiags();
193193
ConvCB->sendCConvMessage("Running CConv for first time.");
194194
CConvInter.BuildInitialConstraints();
195-
CConvInter.SolveConstraints();
195+
CConvInter.SolveConstraints(true);
196196
ConvCB->sendCConvMessage("Finished running CConv.");
197197
log("CConv: Built initial constraints successfully.\n");
198198
auto &WildPtrsInfo = CConvInter.GetWILDPtrsInfo();
199199
log("CConv: Got WILD Ptrs Info.\n");
200-
CConvDiagInfo.PopulateDiagsFromDisjointSet(WildPtrsInfo);
200+
CConvDiagInfo.PopulateDiagsFromConstraintsInfo(WildPtrsInfo);
201201
log("CConv: Populated Diags from Disjoint Sets.\n");
202202
reportCConvDiagsForAllFiles(WildPtrsInfo, ConvCB);
203203
ConvCB->sendCConvMessage("CConv: Finished updating problems.");
@@ -223,7 +223,7 @@ void ClangdServer::executeCConvCommand(ExecuteCommandParams Params,
223223
this->CConvDiagInfo.ClearAllDiags();
224224
ConvCB->sendCConvMessage("CConv Updating new issues "
225225
"after editing constraints.");
226-
this->CConvDiagInfo.PopulateDiagsFromDisjointSet(WildPtrsInfo);
226+
this->CConvDiagInfo.PopulateDiagsFromConstraintsInfo(WildPtrsInfo);
227227
log("CConv calling call-back\n");
228228
// ConvCB->ccConvResultsReady(ptrFileName);
229229
ConvCB->sendCConvMessage("CConv Updated new issues.");

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ class ClangdServer {
328328
ArrayRef<tooling::Range> Ranges);
329329

330330
#ifdef INTERACTIVECCCONV
331-
void reportCConvDiagsForAllFiles(DisjointSet &CcInfo, CConvLSPCallBack *ConvCB);
332-
void clearCConvDiagsForAllFiles(DisjointSet &CcInfo, CConvLSPCallBack *ConvCB);
331+
void reportCConvDiagsForAllFiles(ConstraintsInfo &CcInfo, CConvLSPCallBack *ConvCB);
332+
void clearCConvDiagsForAllFiles(ConstraintsInfo &CcInfo, CConvLSPCallBack *ConvCB);
333333
#endif
334334

335335
const FileSystemProvider &FSProvider;

clang-tools-extra/clangd/tool/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ add_clang_tool(clangd
66
$<TARGET_OBJECTS:obj.clangDaemonTweaks>
77
)
88

9-
add_clang_tool(icconv
10-
ClangdMain.cpp
11-
$<TARGET_OBJECTS:obj.clangDaemonTweaks>
12-
)
13-
149
set(LLVM_LINK_COMPONENTS
1510
support
1611
)
@@ -35,6 +30,11 @@ target_link_libraries(clangd
3530
${CLANGD_XPC_LIBS}
3631
)
3732

33+
add_clang_tool(icconv
34+
ClangdMain.cpp
35+
$<TARGET_OBJECTS:obj.clangDaemonTweaks>
36+
)
37+
3838
target_link_libraries(icconv
3939
PRIVATE
4040
clangAST

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,6 @@ static llvm::cl::opt<bool> Verbose("verbose",
299299
llvm::cl::init(false),
300300
llvm::cl::cat(ConvertCategory));
301301

302-
static llvm::cl::opt<bool>
303-
SeperateMultipleFuncDecls("seperatefds",
304-
llvm::cl::desc("Do not merge multiple "
305-
"declarations of functions."),
306-
llvm::cl::init(false),
307-
llvm::cl::cat(ConvertCategory));
308-
309302
static llvm::cl::opt<std::string>
310303
OutputPostfix("output-postfix",
311304
llvm::cl::desc("Postfix to add to the names of "
@@ -325,6 +318,26 @@ static llvm::cl::opt<bool> DumpStats("dump-stats",
325318
llvm::cl::init(false),
326319
llvm::cl::cat(ConvertCategory));
327320

321+
static llvm::cl::opt<std::string>
322+
OptStatsOutputJson("stats-output",
323+
llvm::cl::desc("Path to the file where all the stats "
324+
"will be dumped as json"),
325+
llvm::cl::init("TotalConstraintStats.json"),
326+
llvm::cl::cat(ConvertCategory));
327+
328+
static llvm::cl::opt<std::string>
329+
OptWildPtrInfoJson("wildptrstats-output",
330+
llvm::cl::desc("Path to the file where all the info "
331+
"related to WILD ptr will be dumped as json"),
332+
llvm::cl::init("WildPtrStats.json"),
333+
llvm::cl::cat(ConvertCategory));
334+
335+
static llvm::cl::opt<bool>
336+
OptDiableCCTypeChecker("disccty",
337+
llvm::cl::desc("Do not disable checked c type checker."),
338+
llvm::cl::init(false),
339+
llvm::cl::cat(ConvertCategory));
340+
328341
static llvm::cl::opt<bool>
329342
HandleVARARGS("handle-varargs",
330343
llvm::cl::desc("Enable handling of varargs "
@@ -341,12 +354,7 @@ static llvm::cl::opt<bool>
341354
llvm::cl::init(false),
342355
llvm::cl::cat(ConvertCategory));
343356

344-
static llvm::cl::opt<bool>
345-
ConsiderAllocUnsafe("alloc-unsafe",
346-
llvm::cl::desc("Consider the allocators "
347-
"(i.e., malloc/calloc) as unsafe."),
348-
llvm::cl::init(false),
349-
llvm::cl::cat(ConvertCategory));
357+
350358
static llvm::cl::opt<bool>
351359
AllTypes("alltypes",
352360
llvm::cl::desc("Consider all Checked C types for "
@@ -434,6 +442,7 @@ int main(int argc, char *argv[]) {
434442
OS << clang::getClangToolFullVersion("clangd") << "\n";
435443
});
436444

445+
437446
#ifdef INTERACTIVECCCONV
438447
tooling::CommonOptionsParser OptionsParser(argc,
439448
(const char**)(argv),
@@ -442,17 +451,18 @@ int main(int argc, char *argv[]) {
442451
// Setup options.
443452
struct CConvertOptions CcOptions;
444453
CcOptions.BaseDir = BaseDir.getValue();
445-
CcOptions.ConsiderAllocUnsafe = ConsiderAllocUnsafe;
446454
CcOptions.EnablePropThruIType = EnablePropThruIType;
447455
CcOptions.HandleVARARGS = HandleVARARGS;
448456
CcOptions.DumpStats = DumpStats;
449457
CcOptions.OutputPostfix = OutputPostfix.getValue();
450458
CcOptions.Verbose = Verbose;
451459
CcOptions.DumpIntermediate = DumpIntermediate;
452460
CcOptions.ConstraintOutputJson = ConstraintOutputJson.getValue();
453-
CcOptions.SeperateMultipleFuncDecls = SeperateMultipleFuncDecls;
461+
CcOptions.WildPtrInfoJson = OptWildPtrInfoJson.getValue();
462+
CcOptions.StatsOutputJson = OptStatsOutputJson.getValue();
454463
CcOptions.AddCheckedRegions = AddCheckedRegions;
455464
CcOptions.EnableAllTypes = AllTypes;
465+
CcOptions.DisableCCTypeChecker = OptDiableCCTypeChecker;
456466

457467
CConvInterface CCInterface(CcOptions,
458468
OptionsParser.getSourcePathList(),

0 commit comments

Comments
 (0)