Skip to content

Commit 36e262a

Browse files
Merge branch 'main' of github.com:correctcomputation/checkedc-clang into inline-struct-fixes
2 parents eea9b94 + 94cd56c commit 36e262a

File tree

8 files changed

+169
-185
lines changed

8 files changed

+169
-185
lines changed

clang/include/clang/3C/3CGlobalOptions.h

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,40 @@
2121
// NOLINTNEXTLINE(readability-identifier-naming)
2222
struct _3COptions {
2323
bool DumpIntermediate;
24-
2524
bool Verbose;
26-
2725
std::string OutputPostfix;
2826
std::string OutputDir;
29-
3027
std::string ConstraintOutputJson;
31-
3228
bool DumpStats;
33-
3429
std::string StatsOutputJson;
35-
3630
std::string WildPtrInfoJson;
37-
3831
std::string PerWildPtrInfoJson;
39-
4032
std::vector<std::string> AllocatorFunctions;
41-
4233
bool HandleVARARGS;
43-
44-
bool EnablePropThruIType;
45-
4634
std::string BaseDir;
4735
bool AllowSourcesOutsideBaseDir;
48-
4936
bool AllTypes;
50-
5137
bool AddCheckedRegions;
52-
5338
bool EnableCCTypeChecker;
54-
5539
bool WarnRootCause;
56-
5740
bool WarnAllRootCause;
58-
59-
#ifdef FIVE_C
60-
bool RemoveItypes;
61-
bool ForceItypes;
62-
#endif
63-
6441
bool DumpUnwritableChanges;
6542
bool AllowUnwritableChanges;
66-
6743
bool AllowRewriteFailures;
68-
6944
bool ItypesForExtern;
70-
7145
bool InferTypesForUndefs;
46+
bool DebugSolver;
47+
bool OnlyGreatestSol;
48+
bool OnlyLeastSol;
49+
bool DisableRDs;
50+
bool DisableFunctionEdges;
51+
bool DisableInfDecls;
52+
bool DisableArrH;
53+
bool DebugArrSolver;
54+
#ifdef FIVE_C
55+
bool RemoveItypes;
56+
bool ForceItypes;
57+
#endif
7258
};
7359

7460
// NOLINTNEXTLINE(readability-identifier-naming)

clang/lib/3C/3C.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ using namespace llvm;
3232
#define BEFORE_SOLVING_SUFFIX "_before_solving_"
3333
#define AFTER_SUBTYPING_SUFFIX "_after_subtyping_"
3434

35-
cl::OptionCategory ArrBoundsInferCat("Array bounds inference options");
36-
static cl::opt<bool>
37-
DebugArrSolver("debug-arr-solver",
38-
cl::desc("Dump array bounds inference graph"),
39-
cl::init(false), cl::cat(ArrBoundsInferCat));
40-
4135
std::set<std::string> FilePaths;
4236

4337
struct _3COptions _3COpts;
@@ -598,7 +592,7 @@ bool _3CInterface::solveConstraints() {
598592
GlobalProgramInfo.getABoundsInfo().addConstantArrayBounds(
599593
GlobalProgramInfo);
600594

601-
if (DebugArrSolver)
595+
if (_3COpts.DebugArrSolver)
602596
GlobalProgramInfo.getABoundsInfo().dumpAVarGraph(
603597
"arr_bounds_initial.dot");
604598

@@ -682,7 +676,7 @@ bool _3CInterface::writeAllConvertedFilesToDisk() {
682676
}
683677

684678
bool _3CInterface::dumpStats() {
685-
if (_3COpts.AllTypes && DebugArrSolver) {
679+
if (_3COpts.AllTypes && _3COpts.DebugArrSolver) {
686680
GlobalProgramInfo.getABoundsInfo().dumpAVarGraph("arr_bounds_final.dot");
687681
}
688682

clang/lib/3C/AVarBoundsInfo.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,12 @@
1313
#include "clang/3C/AVarBoundsInfo.h"
1414
#include "clang/3C/ConstraintResolver.h"
1515
#include "clang/3C/ProgramInfo.h"
16+
#include "clang/3C/3CGlobalOptions.h"
1617
#include <sstream>
1718

1819
std::vector<BoundsPriority> AVarBoundsInfo::PrioList{Declared, Allocator,
1920
FlowInferred, Heuristics};
2021

21-
extern cl::OptionCategory ArrBoundsInferCat;
22-
static cl::opt<bool> DisableInfDecls("disable-arr-missd",
23-
cl::desc("Disable ignoring of missed "
24-
"bounds from declarations."),
25-
cl::init(false),
26-
cl::cat(ArrBoundsInferCat));
27-
2822
void AVarBoundsStats::print(llvm::raw_ostream &O,
2923
const std::set<BoundsKey> *InSrcArrs,
3024
bool JsonFormat) const {
@@ -412,7 +406,7 @@ bool AvarBoundsInference::predictBounds(BoundsKey K,
412406
} else {
413407
bool IsDeclaredB = areDeclaredBounds(NBK, NKBChoice);
414408

415-
if (!IsDeclaredB || DisableInfDecls) {
409+
if (!IsDeclaredB || _3COpts.DisableInfDecls) {
416410
// Oh, there are bounds for neighbour NBK but no bounds
417411
// can be inferred for K from it.
418412
InferredNBnds.clear();

clang/lib/3C/ConstraintVariables.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,12 @@
1414
#include "clang/3C/ProgramInfo.h"
1515
#include "clang/Lex/Lexer.h"
1616
#include "llvm/ADT/StringSwitch.h"
17-
#include "llvm/Support/CommandLine.h"
1817
#include <sstream>
1918

2019
using namespace clang;
2120
// Macro for boolean implication.
2221
#define IMPLIES(a, b) ((a) ? (b) : true)
2322

24-
static llvm::cl::OptionCategory OptimizationCategory("Optimization category");
25-
static llvm::cl::opt<bool>
26-
DisableRDs("disable-rds",
27-
llvm::cl::desc("Disable reverse edges for Checked Constraints."),
28-
llvm::cl::init(false), llvm::cl::cat(OptimizationCategory));
29-
30-
static llvm::cl::opt<bool> DisableFunctionEdges(
31-
"disable-fnedgs",
32-
llvm::cl::desc("Disable reverse edges for external functions."),
33-
llvm::cl::init(false), llvm::cl::cat(OptimizationCategory));
34-
3523
std::string ConstraintVariable::getRewritableOriginalTy() const {
3624
std::string OrigTyString = getOriginalTy();
3725
std::string SpaceStr = " ";
@@ -1739,7 +1727,7 @@ static void createAtomGeq(Constraints &CS, Atom *L, Atom *R,
17391727
}
17401728
break;
17411729
case Wild_to_Safe:
1742-
if (!DisableRDs) {
1730+
if (!_3COpts.DisableRDs) {
17431731
// Note: reversal.
17441732
CS.addConstraint(CS.createGeq(R, L, Rsn, true));
17451733
} else {
@@ -1768,7 +1756,7 @@ static void createAtomGeq(Constraints &CS, Atom *L, Atom *R,
17681756
CS.addConstraint(CS.createGeq(R, L, Rsn, true));
17691757
break;
17701758
case Wild_to_Safe:
1771-
if (!DisableRDs) {
1759+
if (!_3COpts.DisableRDs) {
17721760
// Note: reversal.
17731761
CS.addConstraint(CS.createGeq(R, L, Rsn, true));
17741762
} else {
@@ -2318,8 +2306,8 @@ void FVComponentVariable::linkInternalExternal(ProgramInfo &I,
23182306
// level. This is because CheckedC does not allow assignment from e.g.
23192307
// a function return of type `int ** : itype(_Ptr<_Ptr<int>>)` to a
23202308
// variable with type `int **`.
2321-
if (DisableFunctionEdges || DisableRDs || EquateChecked ||
2322-
(ExternalConstraint->getName() == RETVAR && J > 0))
2309+
if (_3COpts.DisableFunctionEdges || _3COpts.DisableRDs ||
2310+
EquateChecked || (ExternalConstraint->getName() == RETVAR && J > 0))
23232311
CS.addConstraint(CS.createGeq(ExternalA, InternalA,
23242312
LinkReason, true));
23252313
}

clang/lib/3C/Constraints.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,11 @@
1313
#include "clang/3C/3CGlobalOptions.h"
1414
#include "clang/3C/ConstraintVariables.h"
1515
#include "clang/3C/ConstraintsGraph.h"
16-
#include "llvm/Support/CommandLine.h"
1716
#include <iostream>
1817
#include <set>
1918

2019
using namespace llvm;
2120

22-
static cl::OptionCategory SolverCategory("solver options");
23-
static cl::opt<bool> DebugSolver("debug-solver",
24-
cl::desc("Dump intermediate solver state"),
25-
cl::init(false), cl::cat(SolverCategory));
26-
static cl::opt<bool> OnlyGreatestSol(
27-
"only-g-sol",
28-
cl::desc("Perform only greatest solution for Pty Constrains."),
29-
cl::init(false), cl::cat(SolverCategory));
30-
31-
static cl::opt<bool>
32-
OnlyLeastSol("only-l-sol",
33-
cl::desc("Perform only least solution for Pty Constrains."),
34-
cl::init(false), cl::cat(SolverCategory));
35-
3621
// Remove the constraint from the global constraint set.
3722
bool Constraints::removeConstraint(Constraint *C) {
3823
bool RetVal = false;
@@ -339,7 +324,7 @@ bool Constraints::graphBasedSolve() {
339324
}
340325
}
341326

342-
if (DebugSolver)
327+
if (_3COpts.DebugSolver)
343328
GraphVizOutputGraph::dumpConstraintGraphs("initial_constraints_graph.dot",
344329
SolChkCG, SolPtrTypCG);
345330

@@ -351,9 +336,9 @@ bool Constraints::graphBasedSolve() {
351336
// Now solve PtrType constraints
352337
if (Res && _3COpts.AllTypes) {
353338
Env.doCheckedSolve(false);
354-
bool RegularSolve = !(OnlyGreatestSol || OnlyLeastSol);
339+
bool RegularSolve = !(_3COpts.OnlyGreatestSol || _3COpts.OnlyLeastSol);
355340

356-
if (OnlyLeastSol) {
341+
if (_3COpts.OnlyLeastSol) {
357342
// Do only least solution.
358343
// First reset ptr solution to NTArr.
359344
Env.resetSolution(
@@ -363,7 +348,7 @@ bool Constraints::graphBasedSolve() {
363348
},
364349
getNTArr());
365350
Res = doSolve(SolPtrTypCG, Env, this, true, nullptr, Conflicts);
366-
} else if (OnlyGreatestSol) {
351+
} else if (_3COpts.OnlyGreatestSol) {
367352
// Do only greatest solution
368353
Res = doSolve(SolPtrTypCG, Env, this, false, nullptr, Conflicts);
369354
} else {
@@ -481,13 +466,13 @@ bool Constraints::graphBasedSolve() {
481466
// an empty. If the system could not be solved, the constraints in conflict
482467
// are returned in the first position.
483468
void Constraints::solve() {
484-
if (DebugSolver) {
469+
if (_3COpts.DebugSolver) {
485470
errs() << "constraints beginning solve\n";
486471
dump();
487472
}
488473
graphBasedSolve();
489474

490-
if (DebugSolver) {
475+
if (_3COpts.DebugSolver) {
491476
errs() << "solution, when done solving\n";
492477
Environment.dump();
493478
}

clang/lib/3C/IntermediateToolHook.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,16 @@
1010

1111
#include "clang/3C/IntermediateToolHook.h"
1212
#include "clang/3C/ArrayBoundsInferenceConsumer.h"
13+
#include "clang/3C/3CGlobalOptions.h"
1314
#include "clang/AST/RecursiveASTVisitor.h"
1415

1516
using namespace llvm;
1617
using namespace clang;
1718

18-
extern cl::OptionCategory ArrBoundsInferCat;
19-
static cl::opt<bool>
20-
DisableArrH("disable-arr-hu",
21-
cl::desc("Disable Array Bounds Inference Heuristics."),
22-
cl::init(false), cl::cat(ArrBoundsInferCat));
23-
2419
void IntermediateToolHook::HandleTranslationUnit(ASTContext &Context) {
2520
Info.enterCompilationUnit(Context);
2621
Info.getPerfStats().startArrayBoundsInferenceTime();
27-
handleArrayVariablesBoundsDetection(&Context, Info, !DisableArrH);
22+
handleArrayVariablesBoundsDetection(&Context, Info, !_3COpts.DisableArrH);
2823
Info.getPerfStats().endArrayBoundsInferenceTime();
2924
Info.exitCompilationUnit();
3025
}

clang/lib/3C/ProgramInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ void ProgramInfo::printAggregateStats(const std::set<std::string> &F,
237237
void ProgramInfo::printStats(const std::set<std::string> &F, raw_ostream &O,
238238
bool OnlySummary, bool JsonFormat) {
239239
if (!OnlySummary && !JsonFormat) {
240-
O << "Enable itype propagation:" << _3COpts.EnablePropThruIType << "\n";
241240
O << "Sound handling of var args functions:" << _3COpts.HandleVARARGS
242241
<< "\n";
243242
}

0 commit comments

Comments
 (0)