[PATCH] D18210: [analyzer] Fix an assertion fail in hash generation.

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 16 06:32:01 PDT 2016


xazax.hun created this revision.
xazax.hun added reviewers: dcoughlin, zaks.anna.
xazax.hun added subscribers: cfe-commits, dkrupp.

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.

This error was reproduced by an internal checker that warned when the header guard is missing in a header. The location of the warning was the sart location of the header file which might only contain whitespaces in some cases.

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 easy to wrote a custom debug checker for that purpuse but I think it might not worth the effort.

http://reviews.llvm.org/D18210

Files:
  lib/StaticAnalyzer/Core/IssueHash.cpp

Index: lib/StaticAnalyzer/Core/IssueHash.cpp
===================================================================
--- lib/StaticAnalyzer/Core/IssueHash.cpp
+++ lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -132,8 +132,11 @@
 
   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 =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18210.50819.patch
Type: text/x-patch
Size: 728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160316/a09771e2/attachment.bin>


More information about the cfe-commits mailing list