Author: Artem Dergachev Date: 2021-03-17T20:58:27-07:00 New Revision: c75b2261a0aada6bf7ddd91f91139c6f06a8e367
URL: https://github.com/llvm/llvm-project/commit/c75b2261a0aada6bf7ddd91f91139c6f06a8e367 DIFF: https://github.com/llvm/llvm-project/commit/c75b2261a0aada6bf7ddd91f91139c6f06a8e367.diff LOG: [analyzer] Introduce common bug category "Unused code". This category is generic enough to hold a variety of checkers. Currently it contains the Dead Stores checker and an alpha unreachable code checker. Differential Revision: https://reviews.llvm.org/D98741 Added: Modified: clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist Removed: ################################################################################ diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h index 062a604a7551..392bc484bf62 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h @@ -21,6 +21,7 @@ extern const char *const UnixAPI; extern const char *const CXXObjectLifecycle; extern const char *const CXXMoveSemantics; extern const char *const SecurityError; +extern const char *const UnusedCode; } // namespace categories } // namespace ento } // namespace clang diff --git a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp index 6bc186aa2755..8c86e83608b1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp @@ -260,8 +260,8 @@ class DeadStoreObs : public LiveVariables::Observer { break; } - BR.EmitBasicReport(AC->getDecl(), Checker, BugType, "Dead store", os.str(), - L, R, Fixits); + BR.EmitBasicReport(AC->getDecl(), Checker, BugType, categories::UnusedCode, + os.str(), L, R, Fixits); } void CheckVarDecl(const VarDecl *VD, const Expr *Ex, const Expr *Val, diff --git a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp index 74eec81ffb3e..d231be64c2e1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp @@ -169,7 +169,7 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, if (SM.isInSystemHeader(SL) || SM.isInExternCSystemHeader(SL)) continue; - B.EmitBasicReport(D, this, "Unreachable code", "Dead code", + B.EmitBasicReport(D, this, "Unreachable code", categories::UnusedCode, "This statement is never executed", DL, SR); } } diff --git a/clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp b/clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp index b61e3075f3ba..d12c35ef156a 100644 --- a/clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp +++ b/clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp @@ -22,6 +22,7 @@ const char *const UnixAPI = "Unix API"; const char *const CXXObjectLifecycle = "C++ object lifecycle"; const char *const CXXMoveSemantics = "C++ move semantics"; const char *const SecurityError = "Security error"; +const char *const UnusedCode = "Unused code"; } // namespace categories } // namespace ento } // namespace clang diff --git a/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist b/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist index 74e11075fe3d..1d82f3cd8424 100644 --- a/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist +++ b/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist @@ -2368,7 +2368,7 @@ </dict> </array> <key>description</key><string>Value stored to 'x' is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead increment</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -11409,7 +11409,7 @@ </dict> </array> <key>description</key><string>Value stored to 'foo' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> diff --git a/clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist b/clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist index d3a1a5c6c47f..b8bc73611111 100644 --- a/clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist +++ b/clang/test/Analysis/Inputs/expected-plists/objc-arc.m.plist @@ -382,7 +382,7 @@ </dict> </array> <key>description</key><string>Value stored to 'x' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -450,7 +450,7 @@ </dict> </array> <key>description</key><string>Value stored to 'obj1' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -518,7 +518,7 @@ </dict> </array> <key>description</key><string>Value stored to 'obj4' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -586,7 +586,7 @@ </dict> </array> <key>description</key><string>Value stored to 'obj5' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -654,7 +654,7 @@ </dict> </array> <key>description</key><string>Value stored to 'obj6' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -1064,7 +1064,7 @@ </dict> </array> <key>description</key><string>Value stored to 'cf1' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -1132,7 +1132,7 @@ </dict> </array> <key>description</key><string>Value stored to 'cf2' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -1200,7 +1200,7 @@ </dict> </array> <key>description</key><string>Value stored to 'cf3' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -1268,7 +1268,7 @@ </dict> </array> <key>description</key><string>Value stored to 'cf4' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> diff --git a/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist b/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist index 76fec546267c..b7ffbf5b5fee 100644 --- a/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist +++ b/clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist @@ -2169,7 +2169,7 @@ </dict> </array> <key>description</key><string>Value stored to 'foo' during its initialization is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead initialization</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> @@ -5654,7 +5654,7 @@ </dict> </array> <key>description</key><string>Value stored to 'x' is never read</string> - <key>category</key><string>Dead store</string> + <key>category</key><string>Unused code</string> <key>type</key><string>Dead increment</string> <key>check_name</key><string>deadcode.DeadStores</string> <!-- This hash is experimental and going to change! --> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits