clang: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

16#include "llvm/ADT/SmallString.h"

17#include "llvm/ADT/StringSwitch.h"

18#include "llvm/ADT/StringRef.h"

19#include "llvm/ADT/Twine.h"

20#include "llvm/Support/ErrorHandling.h"

21#include "llvm/Support/FileSystem.h"

22#include "llvm/Support/FormattedStream.h"

23#include "llvm/Support/raw_ostream.h"

24#include

25#include

26#include

27#include

28#include

29

30using namespace clang;

31using namespace ento;

32using namespace llvm;

33

35 llvm::raw_ostream &Out,

36 std::pair<StringRef, StringRef> EntryDescPair,

37 size_t InitialPad, size_t EntryWidth, size_t MinLineWidth) {

38

39 llvm::formatted_raw_ostream FOut(Out);

40

41 const size_t PadForDesc = InitialPad + EntryWidth;

42

43 FOut.PadToColumn(InitialPad) << EntryDescPair.first;

44

45 if (FOut.getColumn() > PadForDesc)

46 FOut << '\n';

47

48 FOut.PadToColumn(PadForDesc);

49

50 if (MinLineWidth == 0) {

51 FOut << EntryDescPair.second;

52 return;

53 }

54

55 for (char C : EntryDescPair.second) {

56 if (FOut.getColumn() > MinLineWidth && C == ' ') {

57 FOut << '\n';

58 FOut.PadToColumn(PadForDesc);

59 continue;

60 }

61 FOut << C;

62 }

63}

64

67 auto K =

68 llvm::StringSwitch<std::optional>(

69 ExplorationStrategy)

73 .Case("unexplored_first_queue",

75 .Case("unexplored_first_location_queue",

77 .Case("bfs_block_dfs_contents",

79 .Default(std::nullopt);

80 assert(K && "User mode is invalid.");

81 return *K;

82}

83

85 auto K = llvm::StringSwitch<std::optional>(

86 CTUPhase1InliningMode)

90 .Default(std::nullopt);

91 assert(K && "CTU inlining mode is invalid.");

92 return *K;

93}

94

96 auto K = llvm::StringSwitch<std::optional>(IPAMode)

102 .Default(std::nullopt);

103 assert(K && "IPA Mode is invalid.");

104

105 return *K;

106}

107

108bool

112 return false;

113

114 auto K = llvm::StringSwitch<std::optional>(

115 CXXMemberInliningMode)

120 .Default(std::nullopt);

121

122 assert(K && "Invalid c++ member function inlining mode.");

123

124 return *K >= Param;

125}

126

128 StringRef OptionName,

129 bool SearchInParents) const {

130 assert(!CheckerName.empty() &&

131 "Empty checker name! Make sure the checker object (including it's "

132 "bases!) if fully initialized before calling this function!");

133

134 ConfigTable::const_iterator E = Config.end();

135 do {

136 ConfigTable::const_iterator I =

137 Config.find((Twine(CheckerName) + ":" + OptionName).str());

138 if (I != E)

139 return StringRef(I->getValue());

140 size_t Pos = CheckerName.rfind('.');

141 if (Pos == StringRef::npos)

142 break;

143

144 CheckerName = CheckerName.substr(0, Pos);

145 } while (!CheckerName.empty() && SearchInParents);

146

147 llvm_unreachable("Unknown checker option! Did you call getChecker*Option "

148 "with incorrect parameters? User input must've been "

149 "verified by CheckerRegistry.");

150

151 return "";

152}

153

155 StringRef OptionName,

156 bool SearchInParents) const {

158 C->getTagDescription(), OptionName, SearchInParents);

159}

160

162 StringRef OptionName,

163 bool SearchInParents) const {

164 auto Ret =

165 llvm::StringSwitch<std::optional>(

167 .Case("true", true)

168 .Case("false", false)

169 .Default(std::nullopt);

170

171 assert(Ret &&

172 "This option should be either 'true' or 'false', and should've been "

173 "validated by CheckerRegistry!");

174

175 return *Ret;

176}

177

179 StringRef OptionName,

180 bool SearchInParents) const {

182 C->getTagDescription(), OptionName, SearchInParents);

183}

184

186 StringRef OptionName,

187 bool SearchInParents) const {

188 int Ret = 0;

190 SearchInParents)

191 .getAsInteger(0, Ret);

192 assert(!HasFailed &&

193 "This option should be numeric, and should've been validated by "

194 "CheckerRegistry!");

195 (void)HasFailed;

196 return Ret;

197}

198

200 StringRef OptionName,

201 bool SearchInParents) const {

203 C->getTagDescription(), OptionName, SearchInParents);

204}

bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const

Returns the option controlling which C++ member functions will be considered for inlining.

ConfigTable Config

A key-value table of use-specified configuration values.

bool getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const

Interprets an option's string value as a boolean.

IPAKind getIPAMode() const

Returns the inter-procedural analysis mode.

CTUPhase1InliningKind getCTUPhase1Inlining() const

int getCheckerIntegerOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const

Interprets an option's string value as an integer value.

static void printFormattedEntry(llvm::raw_ostream &Out, std::pair< StringRef, StringRef > EntryDescPair, size_t InitialPad, size_t EntryWidth, size_t MinLineWidth=0)

Convenience function for printing options or checkers and their description in a formatted manner.

ExplorationStrategyKind getExplorationStrategy() const

StringRef getCheckerStringOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const

Query an option's string value.

The JSON file list parser is used to communicate input to InstallAPI.

IPAKind

Describes the different modes of inter-procedural analysis.

@ IPAK_Inlining

Inline callees(C, C++, ObjC) when their definitions are available.

@ IPAK_BasicInlining

Inline C functions and blocks when their definitions are available.

@ IPAK_None

Perform only intra-procedural analysis.

@ IPAK_DynamicDispatch

Enable inlining of dynamically dispatched methods.

@ IPAK_DynamicDispatchBifurcate

Enable inlining of dynamically dispatched methods, bifurcate paths when exact type info is unavailabl...

CXXInlineableMemberKind

Describes the different kinds of C++ member functions which can be considered for inlining by the ana...

@ CIMK_Destructors

Refers to destructors (implicit or explicit).

@ CIMK_MemberFunctions

Refers to regular member function and operator calls.

@ CIMK_Constructors

Refers to constructors (implicit or explicit).

@ CIMK_None

A dummy mode in which no C++ inlining is enabled.

@ UnexploredFirstLocationQueue

Diagnostic wrappers for TextAPI types for error reporting.