]> granicus.if.org Git - clang/commitdiff
[analyzer] Hide developer-only checker/package options by default
authorKristof Umann <kristof.umann@ericsson.com>
Thu, 23 May 2019 22:07:16 +0000 (22:07 +0000)
committerKristof Umann <kristof.umann@ericsson.com>
Thu, 23 May 2019 22:07:16 +0000 (22:07 +0000)
These options are now only visible under
-analyzer-checker-option-help-developer.

Differential Revision: https://reviews.llvm.org/D61839

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361561 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/CC1Options.td
include/clang/StaticAnalyzer/Checkers/CheckerBase.td
include/clang/StaticAnalyzer/Checkers/Checkers.td
include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
lib/Frontend/CompilerInvocation.cpp
lib/FrontendTool/ExecuteCompilerInvocation.cpp
lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
test/Analysis/analyzer-checker-option-help.c
utils/TableGen/ClangSACheckersEmitter.cpp

index 7605b3fc131acdb53187df017fc7f6a9298e83a3..6ebd679ec3c21a59f25b5a6dc476b25b70bc732c 100644 (file)
@@ -151,6 +151,10 @@ def analyzer_config : Separate<["-"], "analyzer-config">,
 def analyzer_checker_option_help : Flag<["-"], "analyzer-checker-option-help">,
   HelpText<"Display the list of checker and package options">;
 
+def analyzer_checker_option_help_developer : Flag<["-"], "analyzer-checker-option-help-developer">,
+  HelpText<"Display the list of checker and package options meant for "
+           "development purposes only">;
+
 def analyzer_config_compatibility_mode : Separate<["-"], "analyzer-config-compatibility-mode">,
   HelpText<"Don't emit errors on invalid analyzer-config inputs">;
 
index 3c7c6fe9b2abc19fb9b29ac5f1da3fe96b2ab9d3..9fb3184cfe2a06291ec733886ae7e262aaaf8f71 100644 (file)
@@ -25,13 +25,22 @@ class Type<CmdLineOptionTypeEnum val> {
   bits<2> Type = val.Type;
 }
 
+/// Marks the entry hidden. Hidden entries won't be displayed in
+/// -analyzer-checker-option-help.
+class HiddenEnum<bit val> {
+  bit Val = val;
+}
+def DontHide : HiddenEnum<0>;
+def Hide : HiddenEnum<1>;
+
 /// Describes an option for a checker or a package.
 class CmdLineOption<CmdLineOptionTypeEnum type, string cmdFlag, string desc,
-                    string defaultVal> {
+                    string defaultVal, HiddenEnum isHidden = DontHide> {
   bits<2> Type = type.Type;
-  string CmdFlag = cmdFlag;
-  string Desc = desc;
-  string DefaultVal = defaultVal;
+  string  CmdFlag = cmdFlag;
+  string  Desc = desc;
+  string  DefaultVal = defaultVal;
+  bit     Hidden = isHidden.Val;
 }
 
 /// Describes a list of package options.
index 911edd8066cbc1be33e7e5d5444e761477eaa9d7..7669d223100488c479472c86ff7b32b5b797a5e6 100644 (file)
@@ -519,7 +519,8 @@ def UninitializedObjectChecker: Checker<"UninitializedObject">,
                   "for each uninitalized field, as opposed to emitting one "
                   "warning per constructor call, and listing the uninitialized "
                   "fields that belongs to it in notes.",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "CheckPointeeInitialization",
                   "If set to false, the checker will not analyze "
@@ -918,7 +919,8 @@ def RetainCountChecker : Checker<"RetainCount">,
                   "OSObject instances. By default, the checker only checks "
                   "retain-release rules for Objective-C NSObject instances "
                   "and CoreFoundation objects.",
-                  "true">,
+                  "true",
+                  Hide>,
     CmdLineOption<Boolean,
                   "TrackNSCFStartParam",
                   "Check not only that the code follows retain-release rules "
@@ -1046,7 +1048,8 @@ def NonLocalizedStringChecker : Checker<"NonLocalizedStringChecker">,
                   "(Aggressive) or NonLocalized only if it is not backed by a "
                   "SymRegion (Non-Aggressive), basically leaving only string "
                   "literals as NonLocalized.",
-                  "false">
+                  "false",
+                  Hide>
   ]>,
   Documentation<HasDocumentation>;
 
@@ -1110,67 +1113,83 @@ def AnalysisOrderChecker : Checker<"AnalysisOrder">,
     CmdLineOption<Boolean,
                   "PreStmtCastExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PostStmtCastExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PreStmtArraySubscriptExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PostStmtArraySubscriptExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PreStmtCXXNewExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PostStmtCXXNewExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PreStmtOffsetOfExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PostStmtOffsetOfExpr",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PreCall",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "PostCall",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "EndFunction",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "NewAllocator",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "Bind",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "LiveSymbols",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "RegionChanges",
                   "",
-                  "false">,
+                  "false",
+                  Hide>,
     CmdLineOption<Boolean,
                   "*",
                   "Enables all callbacks.",
-                  "false">
+                  "false",
+                  Hide>
   ]>,
   Documentation<NotDocumented>;
 
index 1c45ffdff89af3b4b0d53597f26293ef73866b32..c83696d70bfdefd299a6b7f6393abbad0f23c66f 100644 (file)
@@ -224,6 +224,7 @@ public:
   unsigned ShowCheckerHelpDeveloper : 1;
   unsigned ShowEnabledCheckerList : 1;
   unsigned ShowCheckerOptionList : 1;
+  unsigned ShowCheckerOptionDeveloperList : 1;
   unsigned ShowConfigOptionsList : 1;
   unsigned ShouldEmitErrorsOnInvalidConfigValue : 1;
   unsigned AnalyzeAll : 1;
@@ -287,7 +288,8 @@ public:
   AnalyzerOptions()
       : DisableAllChecks(false), ShowCheckerHelp(false),
         ShowCheckerHelpAlpha(false), ShowCheckerHelpDeveloper(false),
-        ShowEnabledCheckerList(false), ShowCheckerOptionList(false),
+        ShowEnabledCheckerList(false),
+        ShowCheckerOptionList(false), ShowCheckerOptionDeveloperList(false),
         ShowConfigOptionsList(false), AnalyzeAll(false),
         AnalyzerDisplayProgress(false), AnalyzeNestedBlocks(false),
         eagerlyAssumeBinOpBifurcation(false), TrimGraph(false),
index 3a05c928774c087a8bd833ab738a96c7a7e44edb..9af8f91e70277ee346132feb514216f06a43a93b 100644 (file)
@@ -98,11 +98,13 @@ public:
     StringRef OptionName;
     StringRef DefaultValStr;
     StringRef Description;
+    bool IsHidden;
 
     CmdLineOption(StringRef OptionType, StringRef OptionName,
-                  StringRef DefaultValStr, StringRef Description)
+                  StringRef DefaultValStr, StringRef Description, bool IsHidden)
         : OptionType(OptionType), OptionName(OptionName),
-          DefaultValStr(DefaultValStr), Description(Description) {
+          DefaultValStr(DefaultValStr), Description(Description),
+          IsHidden(IsHidden) {
 
       assert((OptionType == "bool" || OptionType == "string" ||
               OptionType == "int") &&
@@ -239,7 +241,7 @@ public:
   /// non-compatibility mode.
   void addCheckerOption(StringRef OptionType, StringRef CheckerFullName,
                         StringRef OptionName, StringRef DefaultValStr,
-                        StringRef Description);
+                        StringRef Description, bool IsHidden = false);
 
   /// Adds a package to the registry.
   void addPackage(StringRef FullName);
@@ -255,7 +257,7 @@ public:
   /// non-compatibility mode.
   void addPackageOption(StringRef OptionType, StringRef PackageFullName,
                         StringRef OptionName, StringRef DefaultValStr,
-                        StringRef Description);
+                        StringRef Description, bool IsHidden = false);
 
   // FIXME: This *really* should be added to the frontend flag descriptions.
   /// Initializes a CheckerManager by calling the initialization functions for
index 34693af8f4fd3ce8f79c1d75c67c2c0d38eb47b5..36519c6d487a83d6ca9195fc2651b738d1dd1ce9 100644 (file)
@@ -289,6 +289,8 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
   Opts.ShowCheckerHelpDeveloper =
       Args.hasArg(OPT_analyzer_checker_help_developer);
   Opts.ShowCheckerOptionList = Args.hasArg(OPT_analyzer_checker_option_help);
+  Opts.ShowCheckerOptionDeveloperList =
+      Args.hasArg(OPT_analyzer_checker_option_help_developer);
   Opts.ShowConfigOptionsList = Args.hasArg(OPT_analyzer_config_help);
   Opts.ShowEnabledCheckerList = Args.hasArg(OPT_analyzer_list_enabled_checkers);
   Opts.ShouldEmitErrorsOnInvalidConfigValue =
index ea720c83c29339f75b344b844d2c89fc77ff31fd..a5f51ab7ae293edb39528628a41417c1442cd76c 100644 (file)
@@ -249,7 +249,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
   }
 
   // Honor -analyzer-checker-option-help.
-  if (Clang->getAnalyzerOpts()->ShowCheckerOptionList) {
+  if (AnOpts.ShowCheckerOptionList || AnOpts.ShowCheckerOptionDeveloperList) {
     ento::printCheckerConfigList(llvm::outs(),
                                  Clang->getFrontendOpts().Plugins,
                                  *Clang->getAnalyzerOpts(),
index 5f96389e597b425117630b51ceedb5b5f8033952..f3a4765c9ee0fd5cc46f4a9b3fcb7baec29988ee 100644 (file)
@@ -180,12 +180,12 @@ CheckerRegistry::CheckerRegistry(
   addDependency(FULLNAME, DEPENDENCY);
 
 #define GET_CHECKER_OPTIONS
-#define CHECKER_OPTION(TYPE, FULLNAME, CMDFLAG, DESC, DEFAULT_VAL)             \
-  addCheckerOption(TYPE, FULLNAME, CMDFLAG, DEFAULT_VAL, DESC);
+#define CHECKER_OPTION(TYPE, FULLNAME, CMDFLAG, DESC, DEFAULT_VAL, IS_HIDDEN)  \
+  addCheckerOption(TYPE, FULLNAME, CMDFLAG, DEFAULT_VAL, DESC, IS_HIDDEN);
 
 #define GET_PACKAGE_OPTIONS
-#define PACKAGE_OPTION(TYPE, FULLNAME, CMDFLAG, DESC, DEFAULT_VAL)             \
-  addPackageOption(TYPE, FULLNAME, CMDFLAG, DEFAULT_VAL, DESC);
+#define PACKAGE_OPTION(TYPE, FULLNAME, CMDFLAG, DESC, DEFAULT_VAL, IS_HIDDEN)  \
+  addPackageOption(TYPE, FULLNAME, CMDFLAG, DEFAULT_VAL, DESC, IS_HIDDEN);
 
 #include "clang/StaticAnalyzer/Checkers/Checkers.inc"
 #undef CHECKER_DEPENDENCY
@@ -396,10 +396,10 @@ void CheckerRegistry::addPackageOption(StringRef OptionType,
                                        StringRef PackageFullName,
                                        StringRef OptionName,
                                        StringRef DefaultValStr,
-                                       StringRef Description) {
+                                       StringRef Description, bool IsHidden) {
   PackageOptions.emplace_back(
-      PackageFullName,
-      CmdLineOption{OptionType, OptionName, DefaultValStr, Description});
+      PackageFullName, CmdLineOption{OptionType, OptionName, DefaultValStr,
+                                     Description, IsHidden});
 }
 
 void CheckerRegistry::addChecker(InitializationFunction Rfn,
@@ -421,10 +421,10 @@ void CheckerRegistry::addCheckerOption(StringRef OptionType,
                                        StringRef CheckerFullName,
                                        StringRef OptionName,
                                        StringRef DefaultValStr,
-                                       StringRef Description) {
+                                       StringRef Description, bool IsHidden) {
   CheckerOptions.emplace_back(
-      CheckerFullName,
-      CmdLineOption{OptionType, OptionName, DefaultValStr, Description});
+      CheckerFullName, CmdLineOption{OptionType, OptionName, DefaultValStr,
+                                     Description, IsHidden});
 }
 
 void CheckerRegistry::initializeManager(CheckerManager &CheckerMgr) const {
@@ -577,6 +577,9 @@ void CheckerRegistry::printCheckerOptionList(raw_ostream &Out) const {
   }
 
   for (const std::pair<StringRef, const CmdLineOption &> &Entry : OptionMap) {
+    if (!AnOpts.ShowCheckerOptionDeveloperList && Entry.second.IsHidden)
+      continue;
+
     const CmdLineOption &Option = Entry.second;
     std::string FullOption = (Entry.first + ":" + Option.OptionName).str();
 
index f59d8515823cce2658d055f59a8e3cfb09ca48e0..bc8ed09d43e1725cebb1e26af9461365a7101e0e 100644 (file)
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -analyzer-checker-option-help 2>&1 | FileCheck %s
 
+// RUN: %clang_cc1 -analyzer-checker-option-help-developer \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-HIDDEN
+
 // CHECK: OVERVIEW: Clang Static Analyzer Checker and Package Option List
 //
 // CHECK: USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>
@@ -17,3 +20,6 @@
 // CHECK:        the first statement in the group is representative
 // CHECK:        for all other statements in the group in
 // CHECK:        terms of complexity. (default: 50)
+
+// CHECK-NOT:     optin.cplusplus.UninitializedObject:NotesAsWarnings
+// CHECK-HIDDEN:  optin.cplusplus.UninitializedObject:NotesAsWarnings
index 428a5c81276b89e3e72e50cc2ce008145aad62e1..7c1827ec2e48a5ef1705714ab3ce11c8996a1151 100644 (file)
@@ -113,6 +113,7 @@ static std::string getCheckerOptionType(const Record &R) {
 static bool isHidden(const Record *R) {
   if (R->getValueAsBit("Hidden"))
     return true;
+
   // Not declared as hidden, check the parent package if it is hidden.
   if (DefInit *DI = dyn_cast<DefInit>(R->getValueInit("ParentPackage")))
     return isHidden(DI->getDef());
@@ -121,21 +122,38 @@ static bool isHidden(const Record *R) {
 }
 
 static void printChecker(llvm::raw_ostream &OS, const Record &R) {
-    OS << "CHECKER(" << "\"";
-    OS.write_escaped(getCheckerFullName(&R)) << "\", ";
-    OS << R.getName() << ", ";
-    OS << "\"";
-    OS.write_escaped(getStringValue(R, "HelpText")) << "\", ";
-    OS << "\"";
-    OS.write_escaped(getCheckerDocs(R));
-    OS << "\", ";
-
-    if (!isHidden(&R))
-      OS << "false";
-    else
-      OS << "true";
+  OS << "CHECKER(" << "\"";
+  OS.write_escaped(getCheckerFullName(&R)) << "\", ";
+  OS << R.getName() << ", ";
+  OS << "\"";
+  OS.write_escaped(getStringValue(R, "HelpText")) << "\", ";
+  OS << "\"";
+  OS.write_escaped(getCheckerDocs(R));
+  OS << "\", ";
+
+  if (!isHidden(&R))
+    OS << "false";
+  else
+    OS << "true";
+
+  OS << ")\n";
+}
+
+static void printOption(llvm::raw_ostream &OS, StringRef FullName,
+                        const Record &R) {
+  OS << "\"";
+  OS.write_escaped(getCheckerOptionType(R)) << "\", \"";
+  OS.write_escaped(FullName) << "\", ";
+  OS << '\"' << getStringValue(R, "CmdFlag") << "\", ";
+  OS << '\"';
+  OS.write_escaped(getStringValue(R, "Desc")) << "\", ";
+  OS << '\"';
+  OS.write_escaped(getStringValue(R, "DefaultVal")) << "\", ";
 
-    OS << ")\n";
+  if (!R.getValueAsBit("Hidden"))
+    OS << "false";
+  else
+    OS << "true";
 }
 
 namespace clang {
@@ -196,14 +214,8 @@ void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) {
     std::vector<Record *> PackageOptions = Package
                                        ->getValueAsListOfDefs("PackageOptions");
     for (Record *PackageOpt : PackageOptions) {
-      OS << "PACKAGE_OPTION(\"";
-      OS.write_escaped(getCheckerOptionType(*PackageOpt)) << "\", \"";
-      OS.write_escaped(getPackageFullName(Package)) << "\", ";
-      OS << '\"' << getStringValue(*PackageOpt, "CmdFlag") << "\", ";
-      OS << '\"';
-      OS.write_escaped(getStringValue(*PackageOpt, "Desc")) << "\", ";
-      OS << '\"';
-      OS.write_escaped(getStringValue(*PackageOpt, "DefaultVal")) << "\"";
+      OS << "PACKAGE_OPTION(";
+      printOption(OS, getPackageFullName(Package), *PackageOpt);
       OS << ")\n";
     }
   }
@@ -277,16 +289,9 @@ void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) {
     std::vector<Record *> CheckerOptions = Checker
                                        ->getValueAsListOfDefs("CheckerOptions");
     for (Record *CheckerOpt : CheckerOptions) {
-      OS << "CHECKER_OPTION(\"";
-      OS << getCheckerOptionType(*CheckerOpt) << "\", \"";
-      OS.write_escaped(getCheckerFullName(Checker)) << "\", ";
-      OS << '\"' << getStringValue(*CheckerOpt, "CmdFlag") << "\", ";
-      OS << '\"';
-      OS.write_escaped(getStringValue(*CheckerOpt, "Desc")) << "\", ";
-      OS << '\"';
-      OS.write_escaped(getStringValue(*CheckerOpt, "DefaultVal")) << "\"";
-      OS << ")";
-      OS << '\n';
+      OS << "CHECKER_OPTION(";
+      printOption(OS, getCheckerFullName(Checker), *CheckerOpt);
+      OS << ")\n";
     }
   }
   OS << "#endif // GET_CHECKER_OPTIONS\n"