r264851 - [analyzer] Fix an assertion fail in hash generation.

Gabor Horvath via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 30 03:08:59 PDT 2016


Author: xazax
Date: Wed Mar 30 05:08:59 2016
New Revision: 264851

URL: http://llvm.org/viewvc/llvm-project?rev=264851&view=rev
Log:
[analyzer] Fix an assertion fail in hash generation.

In case the (uniqueing) location of the diagnostic is in a line that only
contains whitespaces there was an assertion fail during issue hash generation.

Unfortunately I am unable to reproduce this error with the built in checkers, 
so no there is no failing test case with this patch. It would be possible to
write a debug checker for that purpuse but it does not worth the effort.

Differential Revision: http://reviews.llvm.org/D18210

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp?rev=264851&r1=264850&r2=264851&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp Wed Mar 30 05:08:59 2016
@@ -132,8 +132,11 @@ static std::string NormalizeLine(const S
 
   StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
                                    L.getExpansionLineNumber());
-  unsigned col = Str.find_first_not_of(Whitespaces);
-  col++;
+  StringRef::size_type col = Str.find_first_not_of(Whitespaces);
+  if (col == StringRef::npos)
+    col = 1; // The line only contains whitespace.
+  else
+    col++;
   SourceLocation StartOfLine =
       SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col);
   llvm::MemoryBuffer *Buffer =




More information about the cfe-commits mailing list