[PATCH] D51761: [analyzer] Do not add invalid source location to the coverage information
George Karpenkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 6 17:45:43 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341618: [analyzer] Do not add invalid source location to the coverage information (authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D51761?vs=164330&id=164336#toc
Repository:
rL LLVM
https://reviews.llvm.org/D51761
Files:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1892,6 +1892,7 @@
FullSourceLoc Loc = P->getLocation().asLocation().getExpansionLoc();
FileID FID = Loc.getFileID();
unsigned LineNo = Loc.getLineNumber();
+ assert(FID.isValid());
ExecutedLines[FID.getHashValue()].insert(LineNo);
}
}
@@ -3022,6 +3023,8 @@
SourceLocation Start = SignatureSourceRange.getBegin();
SourceLocation End = Body ? Body->getSourceRange().getBegin()
: SignatureSourceRange.getEnd();
+ if (!Start.isValid() || !End.isValid())
+ return;
unsigned StartLine = SM.getExpansionLineNumber(Start);
unsigned EndLine = SM.getExpansionLineNumber(End);
@@ -3034,6 +3037,8 @@
const Stmt *S, SourceManager &SM,
std::unique_ptr<FilesToLineNumsMap> &ExecutedLines) {
SourceLocation Loc = S->getSourceRange().getBegin();
+ if (!Loc.isValid())
+ return;
SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
FileID FID = SM.getFileID(ExpansionLoc);
unsigned LineNo = SM.getExpansionLineNumber(ExpansionLoc);
Index: cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp
===================================================================
--- cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp
+++ cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp
@@ -0,0 +1,25 @@
+// Faking std::call_once implementation.
+namespace std {
+typedef struct once_flag_s {
+ int _M_once = 0;
+} once_flag;
+
+template <class Callable, class... Args>
+void call_once(once_flag &o, Callable&& func, Args&&... args);
+} // namespace std
+
+int deref(int *x) {
+ return *x;
+}
+
+void call_deref_once() {
+ static std::once_flag once;
+ int *p = nullptr;
+ std::call_once(once, &deref, p);
+}
+
+
+// RUN: rm -rf %t.output
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -analyzer-output html -o %t.output %s
+// RUN: cat %t.output/* | FileCheck %s --match-full-lines
+// CHECK: var relevant_lines = {"1": {"3": 1, "8": 1, "11": 1, "12": 1, "15": 1, "16": 1, "17": 1, "18": 1}};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51761.164336.patch
Type: text/x-patch
Size: 2269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180907/efd83b83/attachment.bin>
More information about the llvm-commits
mailing list