summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/StaticAnalyzer/Core/IssueHash.h6
-rw-r--r--clang/lib/Basic/SourceManager.cpp2
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp3
-rw-r--r--clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp4
-rw-r--r--clang/lib/StaticAnalyzer/Core/IssueHash.cpp18
-rw-r--r--clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp2
-rw-r--r--clang/test/Analysis/bug_hash_test.cpp8
-rw-r--r--clang/test/Analysis/diagnostics/report-issues-within-main-file.cpp2
8 files changed, 25 insertions, 20 deletions
diff --git a/clang/include/clang/StaticAnalyzer/Core/IssueHash.h b/clang/include/clang/StaticAnalyzer/Core/IssueHash.h
index 913ab7964fb..b3c4f146559 100644
--- a/clang/include/clang/StaticAnalyzer/Core/IssueHash.h
+++ b/clang/include/clang/StaticAnalyzer/Core/IssueHash.h
@@ -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
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 80a003fc932..4c501616a3e 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1717,7 +1717,7 @@ SourceLocation SourceManager::translateLineCol(FileID FID,
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();
diff --git a/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp b/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
index acf00041365..2eef1688d4c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
@@ -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));
}
diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 86eab41a4cc..183acbe1d91 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -255,8 +255,8 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
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
diff --git a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
index abe20d6774f..0a3af3dcc7e 100644
--- a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -127,14 +127,13 @@ static StringRef GetNthLineOfFile(llvm::MemoryBuffer *Buffer, int Line) {
}
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 SourceManager &SM, FullSourceLoc &L,
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> GetHashOfContent(StringRef Content) {
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));
}
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index 2bf439477b0..3e428fa9224 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -399,7 +399,7 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
*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
diff --git a/clang/test/Analysis/bug_hash_test.cpp b/clang/test/Analysis/bug_hash_test.cpp
index 4b46004dcda..b73528e88d2 100644
--- a/clang/test/Analysis/bug_hash_test.cpp
+++ b/clang/test/Analysis/bug_hash_test.cpp
@@ -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>
diff --git a/clang/test/Analysis/diagnostics/report-issues-within-main-file.cpp b/clang/test/Analysis/diagnostics/report-issues-within-main-file.cpp
index cb998965f76..5fd7abd03c4 100644
--- a/clang/test/Analysis/diagnostics/report-issues-within-main-file.cpp
+++ b/clang/test/Analysis/diagnostics/report-issues-within-main-file.cpp
@@ -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>
OpenPOWER on IntegriCloud