Skip to content

Commit 94cd56c

Browse files
More command line options clean up (#732)
This is a follow up PR from #692 that moves all command line options into the _3COptions structure, moves all of 3C's command line options into the same category so that all options are shown by -help (fixes #393), and reformats some of the code around creating command line options. It also removes the the option -enable-itypeprop which was not referenced anywhere in the code.
1 parent 359b6a4 commit 94cd56c

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;
@@ -586,7 +580,7 @@ bool _3CInterface::solveConstraints() {
586580
GlobalProgramInfo.getABoundsInfo().addConstantArrayBounds(
587581
GlobalProgramInfo);
588582

589-
if (DebugArrSolver)
583+
if (_3COpts.DebugArrSolver)
590584
GlobalProgramInfo.getABoundsInfo().dumpAVarGraph(
591585
"arr_bounds_initial.dot");
592586

@@ -670,7 +664,7 @@ bool _3CInterface::writeAllConvertedFilesToDisk() {
670664
}
671665

672666
bool _3CInterface::dumpStats() {
673-
if (_3COpts.AllTypes && DebugArrSolver) {
667+
if (_3COpts.AllTypes && _3COpts.DebugArrSolver) {
674668
GlobalProgramInfo.getABoundsInfo().dumpAVarGraph("arr_bounds_final.dot");
675669
}
676670

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 = " ";
@@ -1734,7 +1722,7 @@ static void createAtomGeq(Constraints &CS, Atom *L, Atom *R,
17341722
}
17351723
break;
17361724
case Wild_to_Safe:
1737-
if (!DisableRDs) {
1725+
if (!_3COpts.DisableRDs) {
17381726
// Note: reversal.
17391727
CS.addConstraint(CS.createGeq(R, L, Rsn, true));
17401728
} else {
@@ -1763,7 +1751,7 @@ static void createAtomGeq(Constraints &CS, Atom *L, Atom *R,
17631751
CS.addConstraint(CS.createGeq(R, L, Rsn, true));
17641752
break;
17651753
case Wild_to_Safe:
1766-
if (!DisableRDs) {
1754+
if (!_3COpts.DisableRDs) {
17671755
// Note: reversal.
17681756
CS.addConstraint(CS.createGeq(R, L, Rsn, true));
17691757
} else {
@@ -2313,8 +2301,8 @@ void FVComponentVariable::linkInternalExternal(ProgramInfo &I,
23132301
// level. This is because CheckedC does not allow assignment from e.g.
23142302
// a function return of type `int ** : itype(_Ptr<_Ptr<int>>)` to a
23152303
// variable with type `int **`.
2316-
if (DisableFunctionEdges || DisableRDs || EquateChecked ||
2317-
(ExternalConstraint->getName() == RETVAR && J > 0))
2304+
if (_3COpts.DisableFunctionEdges || _3COpts.DisableRDs ||
2305+
EquateChecked || (ExternalConstraint->getName() == RETVAR && J > 0))
23182306
CS.addConstraint(CS.createGeq(ExternalA, InternalA,
23192307
LinkReason, true));
23202308
}

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)