r254394 - [analyzer] Fix IssueHash generation.
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 1 01:00:42 PST 2015
Author: xazax
Date: Tue Dec 1 03:00:41 2015
New Revision: 254394
URL: http://llvm.org/viewvc/llvm-project?rev=254394&view=rev
Log:
[analyzer] Fix IssueHash generation.
Differential Revision: http://reviews.llvm.org/D14919
Original patch by: Gyorgy Orban!
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/IssueHash.h
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
cfe/trunk/test/Analysis/bug_hash_test.cpp
cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/IssueHash.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/IssueHash.h?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/IssueHash.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/IssueHash.h Tue Dec 1 03:00:41 2015
@@ -15,6 +15,7 @@ namespace clang {
class Decl;
class SourceManager;
class FullSourceLoc;
+class LangOptions;
/// \brief Get an MD5 hash to help identify bugs.
///
@@ -37,13 +38,14 @@ class FullSourceLoc;
llvm::SmallString<32> GetIssueHash(const SourceManager &SM,
FullSourceLoc &IssueLoc,
llvm::StringRef CheckerName,
- llvm::StringRef BugType, const Decl *D);
+ llvm::StringRef BugType, const Decl *D,
+ const LangOptions &LangOpts);
/// \brief Get the string representation of issue hash. See GetIssueHash() for
/// more information.
std::string GetIssueString(const SourceManager &SM, FullSourceLoc &IssueLoc,
llvm::StringRef CheckerName, llvm::StringRef BugType,
- const Decl *D);
+ const Decl *D, const LangOptions &LangOpts);
} // namespace clang
#endif
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Dec 1 03:00:41 2015
@@ -1717,7 +1717,7 @@ SourceLocation SourceManager::translateL
unsigned Col) const {
// Lines are used as a one-based index into a zero-based array. This assert
// checks for possible buffer underruns.
- assert(Line != 0 && "Passed a zero-based line");
+ assert(Line && Col && "Line and column should start from 1!");
if (FID.isInvalid())
return SourceLocation();
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp Tue Dec 1 03:00:41 2015
@@ -230,11 +230,12 @@ public:
if (!N)
return;
+ const LangOptions &Opts = C.getLangOpts();
const SourceManager &SM = C.getSourceManager();
FullSourceLoc FL(S->getLocStart(), SM);
std::string HashContent =
GetIssueString(SM, FL, getCheckName().getName(), BT->getCategory(),
- C.getLocationContext()->getDecl());
+ C.getLocationContext()->getDecl(), Opts);
C.emitReport(llvm::make_unique<BugReport>(*BT, HashContent, N));
}
Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Tue Dec 1 03:00:41 2015
@@ -255,8 +255,8 @@ void HTMLDiagnostics::ReportDiag(const P
os << "\n<!-- FUNCTIONNAME " << declName << " -->\n";
os << "\n<!-- ISSUEHASHCONTENTOFLINEINCONTEXT "
- << GetIssueHash(SMgr, L, D.getCheckName(), D.getBugType(), DeclWithIssue)
- << " -->\n";
+ << GetIssueHash(SMgr, L, D.getCheckName(), D.getBugType(), DeclWithIssue,
+ PP.getLangOpts()) << " -->\n";
os << "\n<!-- BUGLINE "
<< LineNumber
Modified: cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp Tue Dec 1 03:00:41 2015
@@ -127,14 +127,13 @@ static StringRef GetNthLineOfFile(llvm::
}
static std::string NormalizeLine(const SourceManager &SM, FullSourceLoc &L,
- const Decl *D) {
+ const LangOptions &LangOpts) {
static StringRef Whitespaces = " \t\n";
- const LangOptions &Opts = D->getASTContext().getLangOpts();
StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
L.getExpansionLineNumber());
unsigned col = Str.find_first_not_of(Whitespaces);
-
+ col++;
SourceLocation StartOfLine =
SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col);
llvm::MemoryBuffer *Buffer =
@@ -145,7 +144,7 @@ static std::string NormalizeLine(const S
const char *BufferPos = SM.getCharacterData(StartOfLine);
Token Token;
- Lexer Lexer(SM.getLocForStartOfFile(SM.getFileID(StartOfLine)), Opts,
+ Lexer Lexer(SM.getLocForStartOfFile(SM.getFileID(StartOfLine)), LangOpts,
Buffer->getBufferStart(), BufferPos, Buffer->getBufferEnd());
size_t NextStart = 0;
@@ -175,20 +174,23 @@ static llvm::SmallString<32> GetHashOfCo
std::string clang::GetIssueString(const SourceManager &SM,
FullSourceLoc &IssueLoc,
StringRef CheckerName, StringRef BugType,
- const Decl *D) {
+ const Decl *D,
+ const LangOptions &LangOpts) {
static StringRef Delimiter = "$";
return (llvm::Twine(CheckerName) + Delimiter +
GetEnclosingDeclContextSignature(D) + Delimiter +
llvm::utostr(IssueLoc.getExpansionColumnNumber()) + Delimiter +
- NormalizeLine(SM, IssueLoc, D) + Delimiter + BugType)
+ NormalizeLine(SM, IssueLoc, LangOpts) + Delimiter + BugType)
.str();
}
SmallString<32> clang::GetIssueHash(const SourceManager &SM,
FullSourceLoc &IssueLoc,
StringRef CheckerName, StringRef BugType,
- const Decl *D) {
+ const Decl *D,
+ const LangOptions &LangOpts) {
+
return GetHashOfContent(
- GetIssueString(SM, IssueLoc, CheckerName, BugType, D));
+ GetIssueString(SM, IssueLoc, CheckerName, BugType, D, LangOpts));
}
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Tue Dec 1 03:00:41 2015
@@ -399,7 +399,7 @@ void PlistDiagnostics::FlushDiagnosticsI
*SM);
const Decl *DeclWithIssue = D->getDeclWithIssue();
EmitString(o, GetIssueHash(*SM, L, D->getCheckName(), D->getBugType(),
- DeclWithIssue))
+ DeclWithIssue, LangOpts))
<< '\n';
// Output information about the semantic context where
Modified: cfe/trunk/test/Analysis/bug_hash_test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/bug_hash_test.cpp?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/bug_hash_test.cpp (original)
+++ cfe/trunk/test/Analysis/bug_hash_test.cpp Tue Dec 1 03:00:41 2015
@@ -288,17 +288,17 @@ void testLambda() {
// CHECK-NEXT: </array>
// CHECK-NEXT: <key>depth</key><integer>0</integer>
// CHECK-NEXT: <key>extended_message</key>
-// CHECK-NEXT: <string>debug.DumpBugHash$int f()$28$namespaceAA{$debug</string>
+// CHECK-NEXT: <string>debug.DumpBugHash$int f()$28$constexprintf(){return5;}$debug</string>
// CHECK-NEXT: <key>message</key>
-// CHECK-NEXT: <string>debug.DumpBugHash$int f()$28$namespaceAA{$debug</string>
+// CHECK-NEXT: <string>debug.DumpBugHash$int f()$28$constexprintf(){return5;}$debug</string>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
-// CHECK-NEXT: <key>description</key><string>debug.DumpBugHash$int f()$28$namespaceAA{$debug</string>
+// CHECK-NEXT: <key>description</key><string>debug.DumpBugHash$int f()$28$constexprintf(){return5;}$debug</string>
// CHECK-NEXT: <key>category</key><string>debug</string>
// CHECK-NEXT: <key>type</key><string>Dump hash components</string>
// CHECK-NEXT: <key>check_name</key><string>debug.DumpBugHash</string>
// CHECK-NEXT: <!-- This hash is experimental and going to change! -->
-// CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>f8ee38da3de42e209c4afa886b5531ab</string>
+// CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>f5471f52854dc14167fe96db50c4ba5f</string>
// CHECK-NEXT: <key>issue_context_kind</key><string>function</string>
// CHECK-NEXT: <key>issue_context</key><string>f</string>
// CHECK-NEXT: <key>issue_hash_function_offset</key><string>0</string>
Modified: cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp?rev=254394&r1=254393&r2=254394&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp Tue Dec 1 03:00:41 2015
@@ -949,7 +949,7 @@ void callInMacroArg() {
// CHECK-NEXT: <key>type</key><string>Bad deallocator</string>
// CHECK-NEXT: <key>check_name</key><string>unix.MismatchedDeallocator</string>
// CHECK-NEXT: <!-- This hash is experimental and going to change! -->
-// CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>f21ac032efaa3d1459a5ed31f0ad44f0</string>
+// CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>f689fbd54138491e228f0f89bb02bfb2</string>
// CHECK-NEXT: <key>issue_context_kind</key><string>function</string>
// CHECK-NEXT: <key>issue_context</key><string>mainPlusHeader</string>
// CHECK-NEXT: <key>issue_hash_function_offset</key><string>2</string>
More information about the cfe-commits
mailing list