summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Stahl <r.stahl@tum.de>2018-07-04 14:12:58 +0000
committerRafael Stahl <r.stahl@tum.de>2018-07-04 14:12:58 +0000
commitd29eb3a6ffe17e9da5dcaa4fb50c5738e0a57d1e (patch)
tree493fb73fce4c980880d1a8d7b7f27bae8322083f
parent06787e3d57b9ee0cc5e3bf5003b2f95f4c357c9a (diff)
downloadclang-d29eb3a6ffe17e9da5dcaa4fb50c5738e0a57d1e.tar.gz
[analyzer][ctu] fix unsortable diagnostics
Summary: In the provided test case the PathDiagnostic compare function was not able to find a difference. Reviewers: xazax.hun, NoQ, dcoughlin, george.karpenkov Reviewed By: george.karpenkov Subscribers: a_sidorin, szepet, rnkovacs, a.sidorin, mikhail.ramalho, cfe-commits Differential Revision: https://reviews.llvm.org/D48474 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336275 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/StaticAnalyzer/Core/PathDiagnostic.cpp10
-rw-r--r--test/Analysis/Inputs/ctu-other.cpp7
-rw-r--r--test/Analysis/Inputs/externalFnMap.txt1
-rw-r--r--test/Analysis/ctu-hdr.h3
-rw-r--r--test/Analysis/ctu-main.cpp7
5 files changed, 25 insertions, 3 deletions
diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index 95a7f33ce8..1b698ec5c0 100644
--- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -406,11 +406,15 @@ static bool compareCrossTUSourceLocs(FullSourceLoc XL, FullSourceLoc YL) {
std::pair<bool, bool> InSameTU = SM.isInTheSameTranslationUnit(XOffs, YOffs);
if (InSameTU.first)
return XL.isBeforeInTranslationUnitThan(YL);
- const FileEntry *XFE = SM.getFileEntryForID(XL.getFileID());
- const FileEntry *YFE = SM.getFileEntryForID(YL.getFileID());
+ const FileEntry *XFE = SM.getFileEntryForID(XL.getSpellingLoc().getFileID());
+ const FileEntry *YFE = SM.getFileEntryForID(YL.getSpellingLoc().getFileID());
if (!XFE || !YFE)
return XFE && !YFE;
- return XFE->getName() < YFE->getName();
+ int NameCmp = XFE->getName().compare(YFE->getName());
+ if (NameCmp != 0)
+ return NameCmp == -1;
+ // Last resort: Compare raw file IDs that are possibly expansions.
+ return XL.getFileID() < YL.getFileID();
}
static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y) {
diff --git a/test/Analysis/Inputs/ctu-other.cpp b/test/Analysis/Inputs/ctu-other.cpp
index eceac5af3c..8cad861578 100644
--- a/test/Analysis/Inputs/ctu-other.cpp
+++ b/test/Analysis/Inputs/ctu-other.cpp
@@ -1,3 +1,5 @@
+#include "../ctu-hdr.h"
+
int callback_to_main(int x);
int f(int x) {
return x - 1;
@@ -68,3 +70,8 @@ int chf1(int x) {
typedef struct { int n; } Anonymous;
int fun_using_anon_struct(int n) { Anonymous anon; anon.n = n; return anon.n; }
+
+int other_macro_diag(int x) {
+ MACRODIAG();
+ return x;
+}
diff --git a/test/Analysis/Inputs/externalFnMap.txt b/test/Analysis/Inputs/externalFnMap.txt
index 805990f25c..5461685dc6 100644
--- a/test/Analysis/Inputs/externalFnMap.txt
+++ b/test/Analysis/Inputs/externalFnMap.txt
@@ -12,3 +12,4 @@ c:@F@h_chain#I# ctu-chain.cpp.ast
c:@N@chns@S@chcls@F@chf4#I# ctu-chain.cpp.ast
c:@N@chns@F@chf2#I# ctu-chain.cpp.ast
c:@F@fun_using_anon_struct#I# ctu-other.cpp.ast
+c:@F@other_macro_diag#I# ctu-other.cpp.ast
diff --git a/test/Analysis/ctu-hdr.h b/test/Analysis/ctu-hdr.h
new file mode 100644
index 0000000000..5a1e694d06
--- /dev/null
+++ b/test/Analysis/ctu-hdr.h
@@ -0,0 +1,3 @@
+#define MACRODIAG() clang_analyzer_warnIfReached()
+
+void clang_analyzer_warnIfReached();
diff --git a/test/Analysis/ctu-main.cpp b/test/Analysis/ctu-main.cpp
index 3e9db816f2..33da84962c 100644
--- a/test/Analysis/ctu-main.cpp
+++ b/test/Analysis/ctu-main.cpp
@@ -4,6 +4,8 @@
// RUN: cp %S/Inputs/externalFnMap.txt %T/ctudir/
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config experimental-enable-naive-ctu-analysis=true -analyzer-config ctu-dir=%T/ctudir -verify %s
+#include "ctu-hdr.h"
+
void clang_analyzer_eval(int);
int f(int);
@@ -41,6 +43,7 @@ int chf1(int x);
}
int fun_using_anon_struct(int);
+int other_macro_diag(int);
int main() {
clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}
@@ -58,4 +61,8 @@ int main() {
clang_analyzer_eval(chns::chf1(4) == 12); // expected-warning{{TRUE}}
clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}
+
+ clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}
+ // expected-warning@Inputs/ctu-other.cpp:75{{REACHABLE}}
+ MACRODIAG(); // expected-warning{{REACHABLE}}
}