[clang-tools-extra] r374715 - [clang-tidy] bugprone-not-null-terminated-result: checker adjustments 4

2019-10-13 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Oct 13 03:59:30 2019
New Revision: 374715

URL: http://llvm.org/viewvc/llvm-project?rev=374715=rev
Log:
[clang-tidy] bugprone-not-null-terminated-result: checker adjustments 4

Modified:

clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h

Modified: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h?rev=374715=374714=374715=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h
 Sun Oct 13 03:59:30 2019
@@ -13,7 +13,7 @@
 
 #pragma clang system_header
 
-typedef unsigned int size_t;
+typedef __typeof__(sizeof(int)) size_t;
 typedef int errno_t;
 
 size_t strlen(const char *str);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r374713 - [clang-tidy] bugprone-not-null-terminated-result: checker adjustments 3

2019-10-13 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Oct 13 03:41:13 2019
New Revision: 374713

URL: http://llvm.org/viewvc/llvm-project?rev=374713=rev
Log:
[clang-tidy] bugprone-not-null-terminated-result: checker adjustments 3

On Windows the signed/unsigned int conversions of APInt seems broken, so that
two of the test files marked as unsupported on Windows, as a hotfix.

Modified:

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c?rev=374713=374712=374713=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c
 Sun Oct 13 03:41:13 2019
@@ -1,6 +1,11 @@
 // RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
 // RUN: -- -std=c11 -I %S/Inputs/bugprone-not-null-terminated-result
 
+// FIXME: Something wrong with the APInt un/signed conversion on Windows:
+// in 'strncmp(str6, "string", 7);' it tries to inject '4294967302' as length.
+
+// UNSUPPORTED: system-windows
+
 #include "not-null-terminated-result-c.h"
 
 #define __STDC_LIB_EXT1__ 1

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp?rev=374713=374712=374713=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp
 Sun Oct 13 03:41:13 2019
@@ -1,6 +1,11 @@
 // RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \
 // RUN: -- -std=c++11 -I %S/Inputs/bugprone-not-null-terminated-result
 
+// FIXME: Something wrong with the APInt un/signed conversion on Windows:
+// in 'wcsncmp(wcs6, L"string", 7);' it tries to inject '4294967302' as length.
+
+// UNSUPPORTED: system-windows
+
 #include "not-null-terminated-result-cxx.h"
 
 #define __STDC_LIB_EXT1__ 1


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r374712 - [clang-tidy] bugprone-not-null-terminated-result: checker adjustments 2

2019-10-13 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Oct 13 03:20:58 2019
New Revision: 374712

URL: http://llvm.org/viewvc/llvm-project?rev=374712=rev
Log:
[clang-tidy] bugprone-not-null-terminated-result: checker adjustments 2

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp?rev=374712=374711=374712=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
Sun Oct 13 03:20:58 2019
@@ -59,7 +59,8 @@ static const Expr *getDestCapacityExpr(c
 
 // Returns the length of \p E as an 'IntegerLiteral' or a 'StringLiteral'
 // without the null-terminator.
-static int getLength(const Expr *E, const MatchFinder::MatchResult ) {
+static unsigned getLength(const Expr *E,
+  const MatchFinder::MatchResult ) {
   if (!E)
 return 0;
 
@@ -71,10 +72,10 @@ static int getLength(const Expr *E, cons
   if (!isa(LengthVD))
 if (const Expr *LengthInit = LengthVD->getInit())
   if (LengthInit->EvaluateAsInt(Length, *Result.Context))
-return Length.Val.getInt().getSExtValue();
+return Length.Val.getInt().getZExtValue();
 
   if (const auto *LengthIL = dyn_cast(E))
-return LengthIL->getValue().getSExtValue();
+return LengthIL->getValue().getZExtValue();
 
   if (const auto *StrDRE = dyn_cast(E))
 if (const auto *StrVD = dyn_cast(StrDRE->getDecl()))
@@ -306,7 +307,7 @@ static void lengthExprHandle(const Expr
   // Try to obtain an 'IntegerLiteral' and adjust it.
   if (!IsMacroDefinition) {
 if (const auto *LengthIL = dyn_cast(LengthExpr)) {
-  size_t NewLength = LengthIL->getValue().getSExtValue() +
+  size_t NewLength = LengthIL->getValue().getZExtValue() +
  (LengthHandle == LengthHandleKind::Increase
   ? (isInjectUL(Result) ? 1UL : 1)
   : -1);
@@ -327,7 +328,7 @@ static void lengthExprHandle(const Expr
 const Expr *RhsExpr = BO->getRHS()->IgnoreImpCasts();
 
 if (const auto *LhsIL = dyn_cast(LhsExpr)) {
-  if (LhsIL->getValue().getSExtValue() == 1) {
+  if (LhsIL->getValue().getZExtValue() == 1) {
 Diag << FixItHint::CreateRemoval(
 {LhsIL->getBeginLoc(),
  RhsExpr->getBeginLoc().getLocWithOffset(-1)});
@@ -336,7 +337,7 @@ static void lengthExprHandle(const Expr
 }
 
 if (const auto *RhsIL = dyn_cast(RhsExpr)) {
-  if (RhsIL->getValue().getSExtValue() == 1) {
+  if (RhsIL->getValue().getZExtValue() == 1) {
 Diag << FixItHint::CreateRemoval(
 {LhsExpr->getEndLoc().getLocWithOffset(1), RhsIL->getEndLoc()});
 return;
@@ -803,7 +804,7 @@ void NotNullTerminatedResultCheck::check
 StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
 llvm::APInt IntValue;
 ValueStr.getAsInteger(10, IntValue);
-AreSafeFunctionsWanted = IntValue.getSExtValue();
+AreSafeFunctionsWanted = IntValue.getZExtValue();
   }
 
   ++It;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r374711 - [clang-tidy] bugprone-not-null-terminated-result: checker adjustments

2019-10-13 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Oct 13 02:46:56 2019
New Revision: 374711

URL: http://llvm.org/viewvc/llvm-project?rev=374711=rev
Log:
[clang-tidy] bugprone-not-null-terminated-result: checker adjustments

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp?rev=374711=374710=374711=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp 
Sun Oct 13 02:46:56 2019
@@ -71,10 +71,10 @@ static int getLength(const Expr *E, cons
   if (!isa(LengthVD))
 if (const Expr *LengthInit = LengthVD->getInit())
   if (LengthInit->EvaluateAsInt(Length, *Result.Context))
-return Length.Val.getInt().getZExtValue();
+return Length.Val.getInt().getSExtValue();
 
   if (const auto *LengthIL = dyn_cast(E))
-return LengthIL->getValue().getZExtValue();
+return LengthIL->getValue().getSExtValue();
 
   if (const auto *StrDRE = dyn_cast(E))
 if (const auto *StrVD = dyn_cast(StrDRE->getDecl()))
@@ -306,7 +306,7 @@ static void lengthExprHandle(const Expr
   // Try to obtain an 'IntegerLiteral' and adjust it.
   if (!IsMacroDefinition) {
 if (const auto *LengthIL = dyn_cast(LengthExpr)) {
-  size_t NewLength = LengthIL->getValue().getZExtValue() +
+  size_t NewLength = LengthIL->getValue().getSExtValue() +
  (LengthHandle == LengthHandleKind::Increase
   ? (isInjectUL(Result) ? 1UL : 1)
   : -1);
@@ -327,7 +327,7 @@ static void lengthExprHandle(const Expr
 const Expr *RhsExpr = BO->getRHS()->IgnoreImpCasts();
 
 if (const auto *LhsIL = dyn_cast(LhsExpr)) {
-  if (LhsIL->getValue().getZExtValue() == 1) {
+  if (LhsIL->getValue().getSExtValue() == 1) {
 Diag << FixItHint::CreateRemoval(
 {LhsIL->getBeginLoc(),
  RhsExpr->getBeginLoc().getLocWithOffset(-1)});
@@ -336,7 +336,7 @@ static void lengthExprHandle(const Expr
 }
 
 if (const auto *RhsIL = dyn_cast(RhsExpr)) {
-  if (RhsIL->getValue().getZExtValue() == 1) {
+  if (RhsIL->getValue().getSExtValue() == 1) {
 Diag << FixItHint::CreateRemoval(
 {LhsExpr->getEndLoc().getLocWithOffset(1), RhsIL->getEndLoc()});
 return;
@@ -803,7 +803,7 @@ void NotNullTerminatedResultCheck::check
 StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
 llvm::APInt IntValue;
 ValueStr.getAsInteger(10, IntValue);
-AreSafeFunctionsWanted = IntValue.getZExtValue();
+AreSafeFunctionsWanted = IntValue.getSExtValue();
   }
 
   ++It;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r374710 - [clang-tidy] bugprone-not-null-terminated-result: Sphinx adjustments 2

2019-10-13 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Oct 13 01:49:43 2019
New Revision: 374710

URL: http://llvm.org/viewvc/llvm-project?rev=374710=rev
Log:
[clang-tidy] bugprone-not-null-terminated-result: Sphinx adjustments 2

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst?rev=374710=374709=374710=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 Sun Oct 13 01:49:43 2019
@@ -91,32 +91,36 @@ respectively (where only ``strerror_s``
 Memory handler functions
 
 
-- ``memcpy`` Please visit the
-  :ref:`Transformation rules of 'memcpy()'` section.
+``memcpy``
+Please visit the
+:ref:`Transformation rules of 'memcpy()'` section.
+
+``memchr``
+Usually there is a C-style cast and it is needed to be removed, because the
+new function ``strchr``'s return type is correct. The given length is going
+to be removed.
+
+``memmove``
+If safe functions are available the new function is ``memmove_s``, which has
+a new second argument which is the length of the destination array, it is
+adjusted, and the length of the source string is incremented by one.
+If safe functions are not available the given length is incremented by one.
 
-- ``memchr``
-  Usually there is a C-style cast and it is needed to be removed, because the
-  new function ``strchr``'s return type is correct.
-  The given length is going to be removed.
-
-- ``memmove``
-  If safe functions are available the new function is ``memmove_s``, which has
-  a new second argument which is the length of the destination array, it is
-  adjusted, and the length of the source string is incremented by one.
-  If safe functions are not available the given length is incremented by one.
-
-- ``memmove_s``
-  The given length is incremented by one.
+``memmove_s``
+The given length is incremented by one.
 
 String handler functions
 
 
-- ``strerror_s``: given length is incremented by one.
+``strerror_s``
+The given length is incremented by one.
 
-- ``strncmp``: If the third argument is the first or the second argument's
-``length + 1`` it has to be truncated without the ``+ 1`` operation.
+``strncmp``
+If the third argument is the first or the second argument's ``length + 1``
+it has to be truncated without the ``+ 1`` operation.
 
-- ``strxfrm``: given length is incremented by one.
+``strxfrm``
+The given length is incremented by one.
 
 Options
 ---


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r374709 - [clang-tidy] bugprone-not-null-terminated-result: Sphinx adjustments

2019-10-13 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Oct 13 01:41:24 2019
New Revision: 374709

URL: http://llvm.org/viewvc/llvm-project?rev=374709=rev
Log:
[clang-tidy] bugprone-not-null-terminated-result: Sphinx adjustments

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst?rev=374709=374708=374709=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
 Sun Oct 13 01:41:24 2019
@@ -91,21 +91,22 @@ respectively (where only ``strerror_s``
 Memory handler functions
 
 
-- ``memcpy``: Visit the
-:ref:`Transformation rules of 'memcpy()'` section.
+- ``memcpy`` Please visit the
+  :ref:`Transformation rules of 'memcpy()'` section.
 
-- ``memchr``:
-  - Usually there is a C-style cast and it is needed to be removed, because the
-new function ``strchr``'s return type is correct.
-  - The given length is going to be removed.
+- ``memchr``
+  Usually there is a C-style cast and it is needed to be removed, because the
+  new function ``strchr``'s return type is correct.
+  The given length is going to be removed.
 
-- ``memmove``:
-  - If safe functions are available the new function is ``memmove_s``, which 
has
-a new second argument which is the length of the destination array, it is
-adjusted, and the length of the source string is incremented by one.
-  - If safe functions are not available the given length is incremented by one.
+- ``memmove``
+  If safe functions are available the new function is ``memmove_s``, which has
+  a new second argument which is the length of the destination array, it is
+  adjusted, and the length of the source string is incremented by one.
+  If safe functions are not available the given length is incremented by one.
 
-- ``memmove_s``: given length is incremented by one.
+- ``memmove_s``
+  The given length is incremented by one.
 
 String handler functions
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r374707 - [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length

2019-10-13 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Oct 13 01:28:27 2019
New Revision: 374707

URL: http://llvm.org/viewvc/llvm-project?rev=374707=rev
Log:
[clang-tidy] New checker for not null-terminated result caused by strlen(), 
size() or equal length

Summary:
New checker called bugprone-not-null-terminated-result. This checker finds
function calls where it is possible to cause a not null-terminated result.
Usually the proper length of a string is `strlen(src) + 1` or equal length
of this expression, because the null terminator needs an extra space.
Without the null terminator it can result in undefined behaviour when the
string is read.

The following and their respective `wchar_t` based functions are checked:

`memcpy`, `memcpy_s`, `memchr`, `memmove`, `memmove_s`, `strerror_s`,
`strncmp`, `strxfrm`

The following is a real-world example where the programmer forgot to
increase the passed third argument, which is `size_t length`.
That is why the length of the allocated memory is not enough to hold the
null terminator.

```
static char *stringCpy(const std::string ) {
  char *result = reinterpret_cast(malloc(str.size()));
  memcpy(result, str.data(), str.size());
  return result;
}
```

In addition to issuing warnings, fix-it rewrites all the necessary code.
It also tries to adjust the capacity of the destination array:

```
static char *stringCpy(const std::string ) {
  char *result = reinterpret_cast(malloc(str.size() + 1));
  strcpy(result, str.data());
  return result;
}
```

Note: It cannot guarantee to rewrite every of the path-sensitive memory
allocations.

Reviewed By: JonasToth, aaron.ballman, whisperity, alexfh

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D45050

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/NotNullTerminatedResultCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-not-null-terminated-result.rst
clang-tools-extra/trunk/test/clang-tidy/Inputs/

clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/

clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-c.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/bugprone-not-null-terminated-result/not-null-terminated-result-cxx.h

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-in-initialization-strlen.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-before-safe.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-cxx.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe-other.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-memcpy-safe.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-strlen.c

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wcslen.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-not-null-terminated-result-wmemcpy-safe-cxx.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=374707=374706=374707=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Sun Oct 
13 01:28:27 2019
@@ -32,6 +32,7 @@
 #include "MisplacedWideningCastCheck.h"
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
+#include "NotNullTerminatedResultCheck.h"
 #include "ParentVirtualCallCheck.h"
 #include "PosixReturnCheck.h"
 #include "SizeofContainerCheck.h"
@@ -109,6 +110,8 @@ public:
 "bugprone-multiple-statement-macro");
 CheckFactories.registerCheck(
 "bugprone-narrowing-conversions");
+CheckFactories.registerCheck(
+"bugprone-not-null-terminated-result");
 CheckFactories.registerCheck(
 "bugprone-parent-virtual-call");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=374707=374706=374707=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Sun Oct 13 
01:28:27 

r369845 - [analyzer] Analysis: Fix checker silencing

2019-08-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Aug 24 05:17:49 2019
New Revision: 369845

URL: http://llvm.org/viewvc/llvm-project?rev=369845=rev
Log:
[analyzer] Analysis: Fix checker silencing

Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/tools/scan-build/bin/scan-build

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=369845=369844=369845=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Aug 24 05:17:49 2019
@@ -464,22 +464,6 @@ static void parseAnalyzerConfigs(Analyze
 
   // At this point, AnalyzerOptions is configured. Let's validate some options.
 
-  if (!Diags)
-return;
-
-  if (AnOpts.ShouldTrackConditionsDebug && !AnOpts.ShouldTrackConditions)
-Diags->Report(diag::err_analyzer_config_invalid_input)
-<< "track-conditions-debug" << "'track-conditions' to also be enabled";
-
-  if (!AnOpts.CTUDir.empty() && !llvm::sys::fs::is_directory(AnOpts.CTUDir))
-Diags->Report(diag::err_analyzer_config_invalid_input) << "ctu-dir"
-   << "a filename";
-
-  if (!AnOpts.ModelPath.empty() &&
-  !llvm::sys::fs::is_directory(AnOpts.ModelPath))
-Diags->Report(diag::err_analyzer_config_invalid_input) << "model-path"
-   << "a filename";
-
   // FIXME: Here we try to validate the silenced checkers or packages are 
valid.
   // The current approach only validates the registered checkers which does not
   // contain the runtime enabled checkers and optimally we would validate both.
@@ -493,18 +477,37 @@ static void parseAnalyzerConfigs(Analyze
 AnOpts.RawSilencedCheckersAndPackages.split(CheckersAndPackages, ";");
 
 for (const StringRef CheckerOrPackage : CheckersAndPackages) {
-  bool IsChecker = CheckerOrPackage.contains('.');
-  bool IsValidName =
-  IsChecker ? llvm::find(Checkers, CheckerOrPackage) != Checkers.end()
-: llvm::find(Packages, CheckerOrPackage) != Packages.end();
-
-  if (!IsValidName)
-Diags->Report(diag::err_unknown_analyzer_checker_or_package)
-<< CheckerOrPackage;
+  if (Diags) {
+bool IsChecker = CheckerOrPackage.contains('.');
+bool IsValidName =
+IsChecker
+? llvm::find(Checkers, CheckerOrPackage) != Checkers.end()
+: llvm::find(Packages, CheckerOrPackage) != Packages.end();
+
+if (!IsValidName)
+  Diags->Report(diag::err_unknown_analyzer_checker_or_package)
+  << CheckerOrPackage;
+  }
 
   AnOpts.SilencedCheckersAndPackages.emplace_back(CheckerOrPackage);
 }
   }
+
+  if (!Diags)
+return;
+
+  if (AnOpts.ShouldTrackConditionsDebug && !AnOpts.ShouldTrackConditions)
+Diags->Report(diag::err_analyzer_config_invalid_input)
+<< "track-conditions-debug" << "'track-conditions' to also be enabled";
+
+  if (!AnOpts.CTUDir.empty() && !llvm::sys::fs::is_directory(AnOpts.CTUDir))
+Diags->Report(diag::err_analyzer_config_invalid_input) << "ctu-dir"
+   << "a filename";
+
+  if (!AnOpts.ModelPath.empty() &&
+  !llvm::sys::fs::is_directory(AnOpts.ModelPath))
+Diags->Report(diag::err_analyzer_config_invalid_input) << "model-path"
+   << "a filename";
 }
 
 static bool ParseMigratorArgs(MigratorOptions , ArgList ) {

Modified: cfe/trunk/tools/scan-build/bin/scan-build
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build/bin/scan-build?rev=369845=369844=369845=diff
==
--- cfe/trunk/tools/scan-build/bin/scan-build (original)
+++ cfe/trunk/tools/scan-build/bin/scan-build Sat Aug 24 05:17:49 2019
@@ -1889,11 +1889,6 @@ foreach (sort { $Options{DisableCheckers
   # Push checkers in order they were disabled.
   push @AnalysesToRun, "-analyzer-disable-checker", $_;
 }
-foreach (sort { $Options{SilenceCheckers}{$a} <=> 
$Options{SilenceCheckers}{$b} }
- keys %{$Options{SilenceCheckers}}) {
-  # Push checkers in order they were silenced.
-  push @AnalysesToRun, "-analyzer-config silence-checker", $_;
-}
 if ($Options{AnalyzeHeaders}) { push @AnalysesToRun, 
"-analyzer-opt-analyze-headers"; }
 if ($Options{AnalyzerStats}) { push @AnalysesToRun, 
'-analyzer-checker=debug.Stats'; }
 if ($Options{MaxLoop} > 0) { push @AnalysesToRun, "-analyzer-max-loop 
$Options{MaxLoop}"; }
@@ -1903,6 +1898,14 @@ if ($Options{MaxLoop} > 0) { push @Analy
 my $CCC_ANALYZER_ANALYSIS = join ' ', @AnalysesToRun;
 my $CCC_ANALYZER_PLUGINS = join ' ', map { "-load ".$_ } 
@{$Options{PluginsToLoad}};
 my $CCC_ANALYZER_CONFIG = join ' ', map { 

r369615 - [analyzer] CastValueChecker: Model isa(), isa_and_nonnull()

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 19:57:59 2019
New Revision: 369615

URL: http://llvm.org/viewvc/llvm-project?rev=369615=rev
Log:
[analyzer] CastValueChecker: Model isa(), isa_and_nonnull()

Summary: -

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D66423

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/Inputs/llvm.h
cfe/trunk/test/Analysis/cast-value-logic.cpp
cfe/trunk/test/Analysis/cast-value-notes.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=369615=369614=369615=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Wed Aug 21 
19:57:59 2019
@@ -16,6 +16,7 @@
 //
 
//===--===//
 
+#include "clang/AST/DeclTemplate.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -30,7 +31,7 @@ using namespace ento;
 
 namespace {
 class CastValueChecker : public Checker {
-  enum class CallKind { Function, Method };
+  enum class CallKind { Function, Method, InstanceOf };
 
   using CastCheck =
   std::functiongetAsFunction();
+  QualType CastToTy = FD->getTemplateSpecializationArgs()->get(0).getAsType();
+  QualType CastFromTy = getRecordType(Call.parameters()[0]->getType());
+
+  const MemRegion *MR = DV.getAsRegion();
+  const DynamicCastInfo *CastInfo =
+  getDynamicCastInfo(State, MR, CastFromTy, CastToTy);
+
+  bool CastSucceeds;
+  if (CastInfo)
+CastSucceeds = IsInstanceOf && CastInfo->succeeds();
+  else
+CastSucceeds = IsInstanceOf || CastFromTy == CastToTy;
+
+  if (isInfeasibleCast(CastInfo, CastSucceeds)) {
+C.generateSink(State, C.getPredecessor());
+return;
+  }
+
+  // Store the type and the cast information.
+  bool IsKnownCast = CastInfo || CastFromTy == CastToTy;
+  if (!IsKnownCast)
+State = setDynamicTypeAndCastInfo(State, MR, CastFromTy, CastToTy,
+  Call.getResultType(), IsInstanceOf);
+
+  C.addTransition(
+  State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
+  C.getSValBuilder().makeTruthVal(CastSucceeds)),
+  getNoteTag(C, CastInfo, CastToTy, Call.getArgExpr(0), CastSucceeds,
+ IsKnownCast));
+}
+
 
//===--===//
 // Evaluating cast, dyn_cast, cast_or_null, dyn_cast_or_null.
 
//===--===//
@@ -278,6 +327,41 @@ void CastValueChecker::evalGetAs(const C
 }
 
 
//===--===//
+// Evaluating isa, isa_and_nonnull.
+//===--===//
+
+void CastValueChecker::evalIsa(const CallEvent , DefinedOrUnknownSVal DV,
+   CheckerContext ) const {
+  ProgramStateRef NonNullState, NullState;
+  std::tie(NonNullState, NullState) = C.getState()->assume(DV);
+
+  if (NonNullState) {
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/true);
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/false);
+  }
+
+  if (NullState) {
+C.generateSink(NullState, C.getPredecessor());
+  }
+}
+
+void CastValueChecker::evalIsaAndNonNull(const CallEvent ,
+ DefinedOrUnknownSVal DV,
+ CheckerContext ) const {
+  ProgramStateRef NonNullState, NullState;
+  std::tie(NonNullState, NullState) = C.getState()->assume(DV);
+
+  if (NonNullState) {
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/true);
+addInstanceOfTransition(Call, DV, NonNullState, C, /*IsInstanceOf=*/false);
+  }
+
+  if (NullState) {
+addInstanceOfTransition(Call, DV, NullState, C, /*IsInstanceOf=*/false);
+  }
+}
+
+//===--===//
 // Main logic to evaluate a call.
 
//===--===//
 
@@ -287,12 +371,14 @@ bool CastValueChecker::evalCall(const Ca
   if (!Lookup)
 return false;
 
+  const CastCheck  = Lookup->first;
+  CallKind Kind = Lookup->second;
+
   // We need to obtain the record type of the call's result to model it.
-  if (!getRecordType(Call.getResultType())->isRecordType())
+  if (Kind != CallKind::InstanceOf &&
+  !getRecordType(Call.getResultType())->isRecordType())
 return false;
 
-  const CastCheck  = Lookup->first;
-  CallKind Kind = Lookup->second;
   Optional DV;
 
   switch 

r369609 - [analyzer] CastValueChecker: Try to fix the buildbots

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 18:41:06 2019
New Revision: 369609

URL: http://llvm.org/viewvc/llvm-project?rev=369609=rev
Log:
[analyzer] CastValueChecker: Try to fix the buildbots

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=369609=369608=369609=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Wed Aug 21 
18:41:06 2019
@@ -110,7 +110,7 @@ static const NoteTag *getNoteTag(Checker
   Object = Object->IgnoreParenImpCasts();
 
   return C.getNoteTag(
-  [=] {
+  [=]() -> std::string {
 SmallString<128> Msg;
 llvm::raw_svector_ostream Out(Msg);
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r369607 - [analyzer] CastValueChecker: Rewrite dead header hotfix

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 17:36:42 2019
New Revision: 369607

URL: http://llvm.org/viewvc/llvm-project?rev=369607=rev
Log:
[analyzer] CastValueChecker: Rewrite dead header hotfix

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp?rev=369607=369606=369607=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp 
Wed Aug 21 17:36:42 2019
@@ -27,7 +27,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 
 using namespace clang;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp?rev=369607=369606=369607=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp Wed Aug 21 
17:36:42 2019
@@ -21,7 +21,7 @@
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp?rev=369607=369606=369607=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp Wed Aug 21 
17:36:42 2019
@@ -71,7 +71,7 @@
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 
 #include 
 

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=369607=369606=369607=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 Wed Aug 21 17:36:42 2019
@@ -24,7 +24,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
 
 using namespace clang;
 using namespace clang::ento;

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=369607=369606=369607=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 Wed Aug 21 17:36:42 2019
@@ -18,7 +18,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include 

r369605 - [analyzer] CastValueChecker: Store the dynamic types and casts

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 17:20:36 2019
New Revision: 369605

URL: http://llvm.org/viewvc/llvm-project?rev=369605=rev
Log:
[analyzer] CastValueChecker: Store the dynamic types and casts

Summary:
This patch introduces `DynamicCastInfo` similar to `DynamicTypeInfo` which
is stored in `CastSets` which are storing the dynamic cast informations of
objects based on memory regions. It could be used to store and check the
casts and prevent infeasible paths.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D66325

Added:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
cfe/trunk/test/Analysis/Inputs/llvm.h
cfe/trunk/test/Analysis/cast-value-logic.cpp
cfe/trunk/test/Analysis/cast-value-notes.cpp
cfe/trunk/test/Analysis/cast-value-state-dump.cpp
Removed:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/test/Analysis/dump_egraph.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=369605=369604=369605=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Aug 21 17:20:36 2019
@@ -972,6 +972,9 @@ public:
   friend bool operator!=(const QualType , const QualType ) {
 return LHS.Value != RHS.Value;
   }
+  friend bool operator<(const QualType , const QualType ) {
+return LHS.Value < RHS.Value;
+  }
 
   static std::string getAsString(SplitQualType split,
  const PrintingPolicy ) {

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=369605=369604=369605=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Wed Aug 21 17:20:36 2019
@@ -234,7 +234,7 @@ public:
   }
 
   /// A shorthand version of getNoteTag that doesn't require you to accept
-  /// the BugReporterContext arguments when you don't need it.
+  /// the 'BugReporterContext' argument when you don't need it.
   ///
   /// @param Cb Callback only with 'BugReport &' parameter.
   /// @param IsPrunable Whether the note is prunable. It allows BugReporter
@@ -247,6 +247,19 @@ public:
 IsPrunable);
   }
 
+  /// A shorthand version of getNoteTag that doesn't require you to accept
+  /// the arguments when you don't need it.
+  ///
+  /// @param Cb Callback without parameters.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(std::function &,
+bool IsPrunable = false) {
+return getNoteTag([Cb](BugReporterContext &, BugReport &) { return Cb(); },
+  IsPrunable);
+  }
+
   /// A shorthand version of getNoteTag that accepts a plain note.
   ///
   /// @param Note The note.

Added: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h?rev=369605=auto
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h 
(added)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h 
Wed Aug 21 17:20:36 2019
@@ -0,0 +1,55 @@
+//===- DynamicCastInfo.h - Runtime cast information -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICCASTINFO_H
+#define 

r369604 - [analyzer] TrackConstraintBRVisitor: Do not track unknown values

2019-08-21 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Aug 21 17:06:58 2019
New Revision: 369604

URL: http://llvm.org/viewvc/llvm-project?rev=369604=rev
Log:
[analyzer] TrackConstraintBRVisitor: Do not track unknown values

Summary: -

Reviewers: NoQ, Szelethus

Reviewed By: NoQ, Szelethus

Differential Revision: https://reviews.llvm.org/D66267

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/cast-value.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=369604=369603=369604=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug 21 
17:06:58 2019
@@ -1992,9 +1992,10 @@ bool bugreporter::trackExpressionValue(c
   report.markInteresting(V, TKind);
   report.addVisitor(std::make_unique(R));
 
-  // If the contents are symbolic, find out when they became null.
-  if (V.getAsLocSymbol(/*IncludeBaseRegions*/ true))
-report.addVisitor(std::make_unique(
+  // If the contents are symbolic and null, find out when they became null.
+  if (V.getAsLocSymbol(/*IncludeBaseRegions=*/true))
+if (LVState->isNull(V).isConstrainedTrue())
+  report.addVisitor(std::make_unique(
   V.castAs(), false));
 
   // Add visitor, which will suppress inline defensive checks.

Modified: cfe/trunk/test/Analysis/cast-value.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cast-value.cpp?rev=369604=369603=369604=diff
==
--- cfe/trunk/test/Analysis/cast-value.cpp (original)
+++ cfe/trunk/test/Analysis/cast-value.cpp Wed Aug 21 17:06:58 2019
@@ -152,8 +152,7 @@ void evalReferences(const Shape ) {
 void evalNonNullParamNonNullReturnReference(const Shape ) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' 
succeeds}}
-  // expected-note@-2 {{Assuming pointer value is null}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}
@@ -165,8 +164,7 @@ void evalNonNullParamNonNullReturnRefere
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = cast(S);
   // expected-note@-1 {{Checked cast from 'Shape' to 'Circle' succeeds}}
-  // expected-note@-2 {{Assuming pointer value is null}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}
@@ -178,7 +176,6 @@ void evalNonNullParamNonNullReturn(const
 void evalNonNullParamNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' fails}}
-  // expected-note@-2 {{Assuming pointer value is null}}
 
   if (const auto *T = dyn_cast_or_null(S)) {
 // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Triangle' 
succeeds}}
@@ -207,9 +204,8 @@ void evalNullParamNullReturn(const Shape
 
 void evalZeroParamNonNullReturnPointer(const Shape *S) {
   const auto *C = S->castAs();
-  // expected-note@-1 {{Assuming pointer value is null}}
-  // expected-note@-2 {{Checked cast to 'Circle' succeeds}}
-  // expected-note@-3 {{'C' initialized here}}
+  // expected-note@-1 {{Checked cast to 'Circle' succeeds}}
+  // expected-note@-2 {{'C' initialized here}}
 
   (void)(1 / !(bool)C);
   // expected-note@-1 {{'C' is non-null}}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r369078 - [analyzer] Analysis: Silence checkers

2019-08-15 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Thu Aug 15 18:53:14 2019
New Revision: 369078

URL: http://llvm.org/viewvc/llvm-project?rev=369078=rev
Log:
[analyzer] Analysis: Silence checkers

Summary:
This patch introduces a new `analyzer-config` configuration:
`-analyzer-config silence-checkers`
which could be used to silence the given checkers.

It accepts a semicolon separated list, packed into quotation marks, e.g:
`-analyzer-config silence-checkers="core.DivideZero;core.NullDereference"`

It could be used to "disable" core checkers, so they model the analysis as
before, just if some of them are too noisy it prevents to emit reports.

This patch also adds support for that new option to the scan-build.
Passing the option `-disable-checker core.DivideZero` to the scan-build
will be transferred to `-analyzer-config silence-checkers=core.DivideZero`.

Reviewed By: NoQ, Szelethus

Differential Revision: https://reviews.llvm.org/D66042

Added:
cfe/trunk/test/Analysis/silence-checkers-and-packages-core-all.cpp
cfe/trunk/test/Analysis/silence-checkers-and-packages-core-div-by-zero.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
cfe/trunk/test/Analysis/analyzer-config.c
cfe/trunk/tools/scan-build/bin/scan-build
cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=369078=369077=369078=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Thu Aug 15 18:53:14 
2019
@@ -300,7 +300,7 @@ def err_omp_more_one_clause : Error<
   "directive '#pragma omp %0' cannot contain more than one '%1' 
clause%select{| with '%3' name modifier| with 'source' dependence}2">;
 
 // Static Analyzer Core
-def err_unknown_analyzer_checker : Error<
+def err_unknown_analyzer_checker_or_package : Error<
 "no analyzer checkers or packages are associated with '%0'">;
 def note_suggest_disabling_all_checkers : Note<
 "use -analyzer-disable-all-checks to disable all static analyzer 
checkers">;

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def?rev=369078=369077=369078=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def Thu Aug 15 
18:53:14 2019
@@ -380,12 +380,6 @@ ANALYZER_OPTION(
 "Value: \"constructors\", \"destructors\", \"methods\".",
 "destructors")
 
-ANALYZER_OPTION_DEPENDS_ON_USER_MODE(
-StringRef, IPAMode, "ipa",
-"Controls the mode of inter-procedural analysis. Value: \"none\", "
-"\"basic-inlining\", \"inlining\", \"dynamic\", \"dynamic-bifurcate\".",
-/* SHALLOW_VAL */ "inlining", /* DEEP_VAL */ "dynamic-bifurcate")
-
 ANALYZER_OPTION(
 StringRef, ExplorationStrategy, "exploration_strategy",
 "Value: \"dfs\", \"bfs\", \"unexplored_first\", "
@@ -393,5 +387,17 @@ ANALYZER_OPTION(
 "\"bfs_block_dfs_contents\".",
 "unexplored_first_queue")
 
+ANALYZER_OPTION(
+StringRef, RawSilencedCheckersAndPackages, "silence-checkers",
+"A semicolon separated list of checker and package names to silence. "
+"Silenced checkers will not emit reports, but the modeling remain 
enabled.",
+"")
+
+ANALYZER_OPTION_DEPENDS_ON_USER_MODE(
+StringRef, IPAMode, "ipa",
+"Controls the mode of inter-procedural analysis. Value: \"none\", "
+"\"basic-inlining\", \"inlining\", \"dynamic\", \"dynamic-bifurcate\".",
+/* SHALLOW_VAL */ "inlining", /* DEEP_VAL */ "dynamic-bifurcate")
+
 #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
 #undef ANALYZER_OPTION

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=369078=369077=369078=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Thu Aug 15 
18:53:14 2019
@@ -164,7 +164,40 @@ public:
   using ConfigTable = llvm::StringMap;
 
   static std::vector
-  getRegisteredCheckers(bool IncludeExperimental = false);
+  getRegisteredCheckers(bool 

[clang-tools-extra] r369078 - [analyzer] Analysis: Silence checkers

2019-08-15 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Thu Aug 15 18:53:14 2019
New Revision: 369078

URL: http://llvm.org/viewvc/llvm-project?rev=369078=rev
Log:
[analyzer] Analysis: Silence checkers

Summary:
This patch introduces a new `analyzer-config` configuration:
`-analyzer-config silence-checkers`
which could be used to silence the given checkers.

It accepts a semicolon separated list, packed into quotation marks, e.g:
`-analyzer-config silence-checkers="core.DivideZero;core.NullDereference"`

It could be used to "disable" core checkers, so they model the analysis as
before, just if some of them are too noisy it prevents to emit reports.

This patch also adds support for that new option to the scan-build.
Passing the option `-disable-checker core.DivideZero` to the scan-build
will be transferred to `-analyzer-config silence-checkers=core.DivideZero`.

Reviewed By: NoQ, Szelethus

Differential Revision: https://reviews.llvm.org/D66042

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=369078=369077=369078=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Aug 15 18:53:14 2019
@@ -334,8 +334,8 @@ static void setStaticAnalyzerCheckerOpts
 
 typedef std::vector> CheckersList;
 
-static CheckersList getCheckersControlList(ClangTidyContext ,
-   bool IncludeExperimental) {
+static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext ,
+   bool IncludeExperimental) {
   CheckersList List;
 
   const auto  =
@@ -419,9 +419,9 @@ ClangTidyASTConsumerFactory::CreateASTCo
 
 #if CLANG_ENABLE_STATIC_ANALYZER
   AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
-  AnalyzerOptions->CheckersControlList =
-  getCheckersControlList(Context, 
Context.canEnableAnalyzerAlphaCheckers());
-  if (!AnalyzerOptions->CheckersControlList.empty()) {
+  AnalyzerOptions->CheckersAndPackages = getAnalyzerCheckersAndPackages(
+  Context, Context.canEnableAnalyzerAlphaCheckers());
+  if (!AnalyzerOptions->CheckersAndPackages.empty()) {
 setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
 AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
 AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
@@ -447,7 +447,7 @@ std::vector ClangTidyASTCon
   }
 
 #if CLANG_ENABLE_STATIC_ANALYZER
-  for (const auto  : getCheckersControlList(
+  for (const auto  : getAnalyzerCheckersAndPackages(
Context, Context.canEnableAnalyzerAlphaCheckers()))
 CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
 #endif // CLANG_ENABLE_STATIC_ANALYZER


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r368383 - [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-08 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Thu Aug  8 19:24:42 2019
New Revision: 368383

URL: http://llvm.org/viewvc/llvm-project?rev=368383=rev
Log:
[analyzer] CastValueChecker: Model castAs(), getAs()

Summary: Thanks to Kristóf Umann for the great idea!

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D65889

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/cast-value.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=368383=368382=368383=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Thu Aug  8 
19:24:42 2019
@@ -16,168 +16,238 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "llvm/ADT/Optional.h"
+#include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
 class CastValueChecker : public Checker {
+  enum class CastKind { Function, Method };
+
   using CastCheck =
   std::function;
 
+  using CheckKindPair = std::pair;
+
 public:
-  // We have three cases to evaluate a cast:
+  // We have five cases to evaluate a cast:
   // 1) The parameter is non-null, the return value is non-null
   // 2) The parameter is non-null, the return value is null
   // 3) The parameter is null, the return value is null
-  //
   // cast: 1;  dyn_cast: 1, 2;  cast_or_null: 1, 3;  dyn_cast_or_null: 1, 2, 3.
+  //
+  // 4) castAs: has no parameter, the return value is non-null.
+  // 5) getAs:  has no parameter, the return value is null or non-null.
   bool evalCall(const CallEvent , CheckerContext ) const;
 
 private:
-  // These are known in the LLVM project.
-  const CallDescriptionMap CDM = {
-  {{{"llvm", "cast"}, 1}, ::evalCast},
-  {{{"llvm", "dyn_cast"}, 1}, ::evalDynCast},
-  {{{"llvm", "cast_or_null"}, 1}, ::evalCastOrNull},
+  // These are known in the LLVM project. The pairs are in the following form:
+  // {{{namespace, call}, argument-count}, {callback, kind}}
+  const CallDescriptionMap CDM = {
+  {{{"llvm", "cast"}, 1},
+   {::evalCast, CastKind::Function}},
+  {{{"llvm", "dyn_cast"}, 1},
+   {::evalDynCast, CastKind::Function}},
+  {{{"llvm", "cast_or_null"}, 1},
+   {::evalCastOrNull, CastKind::Function}},
   {{{"llvm", "dyn_cast_or_null"}, 1},
-   ::evalDynCastOrNull}};
+   {::evalDynCastOrNull, CastKind::Function}},
+  {{{"clang", "castAs"}, 0},
+   {::evalCastAs, CastKind::Method}},
+  {{{"clang", "getAs"}, 0},
+   {::evalGetAs, CastKind::Method}}};
 
-  void evalCast(const CallExpr *CE, DefinedOrUnknownSVal ParamDV,
+  void evalCast(const CallExpr *CE, DefinedOrUnknownSVal DV,
 CheckerContext ) const;
-  void evalDynCast(const CallExpr *CE, DefinedOrUnknownSVal ParamDV,
+  void evalDynCast(const CallExpr *CE, DefinedOrUnknownSVal DV,
CheckerContext ) const;
-  void evalCastOrNull(const CallExpr *CE, DefinedOrUnknownSVal ParamDV,
+  void evalCastOrNull(const CallExpr *CE, DefinedOrUnknownSVal DV,
   CheckerContext ) const;
-  void evalDynCastOrNull(const CallExpr *CE, DefinedOrUnknownSVal ParamDV,
+  void evalDynCastOrNull(const CallExpr *CE, DefinedOrUnknownSVal DV,
  CheckerContext ) const;
+  void evalCastAs(const CallExpr *CE, DefinedOrUnknownSVal DV,
+  CheckerContext ) const;
+  void evalGetAs(const CallExpr *CE, DefinedOrUnknownSVal DV,
+ CheckerContext ) const;
 };
 } // namespace
 
 static std::string getCastName(const Expr *Cast) {
-  return Cast->getType()->getPointeeCXXRecordDecl()->getNameAsString();
+  QualType Ty = Cast->getType();
+  if (const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl())
+return RD->getNameAsString();
+
+  return Ty->getPointeeCXXRecordDecl()->getNameAsString();
 }
 
-static void evalNonNullParamNonNullReturn(const CallExpr *CE,
-  DefinedOrUnknownSVal ParamDV,
-  CheckerContext ) {
-  ProgramStateRef State = C.getState()->assume(ParamDV, true);
-  if (!State)
-return;
-
-  State = State->BindExpr(CE, C.getLocationContext(), ParamDV, false);
-
-  std::string CastFromName = getCastName(CE->getArg(0));
+static const NoteTag *getCastTag(bool IsNullReturn, const CallExpr *CE,
+ CheckerContext ,
+ bool IsCheckedCast = false) {
+  Optional CastFromName = (CE->getNumArgs() > 0)
+   ? getCastName(CE->getArg(0))
+   : Optional();
   std::string CastToName = getCastName(CE);
 
-  const NoteTag *CastTag = C.getNoteTag(
-  

r368382 - [analyzer] ConditionBRVisitor: Fix HTML PathDiagnosticPopUpPieces

2019-08-08 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Thu Aug  8 19:20:44 2019
New Revision: 368382

URL: http://llvm.org/viewvc/llvm-project?rev=368382=rev
Log:
[analyzer] ConditionBRVisitor: Fix HTML PathDiagnosticPopUpPieces

Summary:
A condition could be a multi-line expression where we create the highlight
in separated chunks. PathDiagnosticPopUpPiece is not made for that purpose,
it cannot be added to multiple lines because we have only one ending part
which contains all the notes. So that it cannot have multiple endings and
therefore this patch narrows down the ranges of the highlight to the given
interesting variable of the condition. It prevents HTML-breaking injections.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D65663

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
cfe/trunk/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
cfe/trunk/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
cfe/trunk/test/Analysis/Inputs/expected-plists/inline-plist.c.plist
cfe/trunk/test/Analysis/Inputs/expected-plists/objc-radar17039661.m.plist
cfe/trunk/test/Analysis/Inputs/expected-plists/plist-output.m.plist

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=368382=368381=368382=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Thu Aug  8 
19:20:44 2019
@@ -2335,12 +2335,12 @@ std::shared_ptr Con
   // Check if the field name of the MemberExprs is ambiguous. Example:
   // " 'a.d' is equal to 'h.d' " in 'test/Analysis/null-deref-path-notes.cpp'.
   bool IsSameFieldName = false;
-  if (const auto *LhsME =
-  dyn_cast(BExpr->getLHS()->IgnoreParenCasts()))
-if (const auto *RhsME =
-dyn_cast(BExpr->getRHS()->IgnoreParenCasts()))
-  IsSameFieldName = LhsME->getMemberDecl()->getName() ==
-RhsME->getMemberDecl()->getName();
+  const auto *LhsME = 
dyn_cast(BExpr->getLHS()->IgnoreParenCasts());
+  const auto *RhsME = 
dyn_cast(BExpr->getRHS()->IgnoreParenCasts());
+
+  if (LhsME && RhsME)
+IsSameFieldName =
+LhsME->getMemberDecl()->getName() == RhsME->getMemberDecl()->getName();
 
   SmallString<128> LhsString, RhsString;
   {
@@ -2410,16 +2410,31 @@ std::shared_ptr Con
 
   Out << (shouldInvert ? LhsString : RhsString);
   const LocationContext *LCtx = N->getLocationContext();
-  PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
+  const SourceManager  = BRC.getSourceManager();
 
   // Convert 'field ...' to 'Field ...' if it is a MemberExpr.
   std::string Message = Out.str();
   Message[0] = toupper(Message[0]);
 
-  // If we know the value create a pop-up note.
-  if (!IsAssuming)
+  // If we know the value create a pop-up note to the value part of 'BExpr'.
+  if (!IsAssuming) {
+PathDiagnosticLocation Loc;
+if (!shouldInvert) {
+  if (LhsME && LhsME->getMemberLoc().isValid())
+Loc = PathDiagnosticLocation(LhsME->getMemberLoc(), SM);
+  else
+Loc = PathDiagnosticLocation(BExpr->getLHS(), SM, LCtx);
+} else {
+  if (RhsME && RhsME->getMemberLoc().isValid())
+Loc = PathDiagnosticLocation(RhsME->getMemberLoc(), SM);
+  else
+Loc = PathDiagnosticLocation(BExpr->getRHS(), SM, LCtx);
+}
+
 return std::make_shared(Loc, Message);
+  }
 
+  PathDiagnosticLocation Loc(Cond, SM, LCtx);
   auto event = std::make_shared(Loc, Message);
   if (shouldPrune.hasValue())
 event->setPrunable(shouldPrune.getValue());
@@ -2472,12 +2487,14 @@ std::shared_ptr Con
 return nullptr;
 
   const LocationContext *LCtx = N->getLocationContext();
-  PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
 
-  // If we know the value create a pop-up note.
-  if (!IsAssuming)
+  // If we know the value create a pop-up note to the 'DRE'.
+  if (!IsAssuming) {
+PathDiagnosticLocation Loc(DRE, BRC.getSourceManager(), LCtx);
 return std::make_shared(Loc, Out.str());
+  }
 
+  PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
   auto event = std::make_shared(Loc, Out.str());
   const ProgramState *state = N->getState().get();
   if (const MemRegion *R = state->getLValue(VD, LCtx).getAsRegion()) {
@@ -2505,11 +2522,17 @@ std::shared_ptr Con
 return nullptr;
 
   const LocationContext *LCtx = N->getLocationContext();
-  PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
+  PathDiagnosticLocation Loc;
+
+  // If we know the value create a pop-up note to the member of the MemberExpr.
+  if (!IsAssuming && ME->getMemberLoc().isValid())
+Loc = PathDiagnosticLocation(ME->getMemberLoc(), BRC.getSourceManager());
+  else
+Loc = PathDiagnosticLocation(Cond, 

r367608 - [analyzer] StackFrameContext: Add NodeBuilderContext::blockCount() to its profile

2019-08-01 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Thu Aug  1 13:41:13 2019
New Revision: 367608

URL: http://llvm.org/viewvc/llvm-project?rev=367608=rev
Log:
[analyzer] StackFrameContext: Add NodeBuilderContext::blockCount() to its 
profile

Summary:
It allows discriminating between stack frames of the same call that is
called multiple times in a loop.

Thanks to Artem Dergachev for the great idea!

Reviewed By: NoQ

Tags: #clang

Differential Revision: https://reviews.llvm.org/D65587

Added:
cfe/trunk/test/Analysis/stack-frame-context-revision.cpp
Modified:
cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/trunk/test/Analysis/loop-block-counts.c
cfe/trunk/test/Analysis/loop-unrolling.cpp

Modified: cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h?rev=367608=367607=367608=diff
==
--- cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h (original)
+++ cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h Thu Aug  1 13:41:13 
2019
@@ -183,9 +183,8 @@ public:
   const ImplicitParamDecl *getSelfDecl() const;
 
   const StackFrameContext *getStackFrame(LocationContext const *Parent,
- const Stmt *S,
- const CFGBlock *Blk,
- unsigned Idx);
+ const Stmt *S, const CFGBlock *Blk,
+ unsigned BlockCount, unsigned Idx);
 
   const BlockInvocationContext *
   getBlockInvocationContext(const LocationContext *parent,
@@ -303,15 +302,19 @@ class StackFrameContext : public Locatio
   // The parent block of the callsite.
   const CFGBlock *Block;
 
+  // The number of times the 'Block' has been visited.
+  // It allows discriminating between stack frames of the same call that is
+  // called multiple times in a loop.
+  const unsigned BlockCount;
+
   // The index of the callsite in the CFGBlock.
-  unsigned Index;
+  const unsigned Index;
 
   StackFrameContext(AnalysisDeclContext *ctx, const LocationContext *parent,
-const Stmt *s, const CFGBlock *blk,
-unsigned idx,
-int64_t ID)
-  : LocationContext(StackFrame, ctx, parent, ID), CallSite(s),
-Block(blk), Index(idx) {}
+const Stmt *s, const CFGBlock *blk, unsigned blockCount,
+unsigned idx, int64_t ID)
+  : LocationContext(StackFrame, ctx, parent, ID), CallSite(s), Block(blk),
+BlockCount(blockCount), Index(idx) {}
 
 public:
   ~StackFrameContext() override = default;
@@ -329,9 +332,10 @@ public:
 
   static void Profile(llvm::FoldingSetNodeID , AnalysisDeclContext *ctx,
   const LocationContext *parent, const Stmt *s,
-  const CFGBlock *blk, unsigned idx) {
+  const CFGBlock *blk, unsigned blockCount, unsigned idx) {
 ProfileCommon(ID, StackFrame, ctx, parent, s);
 ID.AddPointer(blk);
+ID.AddInteger(blockCount);
 ID.AddInteger(idx);
   }
 
@@ -410,8 +414,8 @@ public:
 
   const StackFrameContext *getStackFrame(AnalysisDeclContext *ctx,
  const LocationContext *parent,
- const Stmt *s,
- const CFGBlock *blk, unsigned idx);
+ const Stmt *s, const CFGBlock *blk,
+ unsigned blockCount, unsigned idx);
 
   const ScopeContext *getScope(AnalysisDeclContext *ctx,
const LocationContext *parent,
@@ -483,26 +487,25 @@ public:
   bool synthesizeBodies() const { return SynthesizeBodies; }
 
   const StackFrameContext *getStackFrame(AnalysisDeclContext *Ctx,
- LocationContext const *Parent,
- const Stmt *S,
- const CFGBlock *Blk,
- unsigned Idx) {
-return LocContexts.getStackFrame(Ctx, Parent, S, Blk, Idx);
+ const LocationContext *Parent,
+ const Stmt *S, const CFGBlock *Blk,
+ unsigned BlockCount, unsigned Idx) {
+return LocContexts.getStackFrame(Ctx, Parent, S, Blk, BlockCount, Idx);
   }
 
   // Get the top level stack frame.
   const StackFrameContext *getStackFrame(const Decl *D) {
 return 

r366391 - [analyzer] MallocChecker: Prevent Integer Set Library false positives

2019-07-17 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Jul 17 17:03:55 2019
New Revision: 366391

URL: http://llvm.org/viewvc/llvm-project?rev=366391=rev
Log:
[analyzer] MallocChecker: Prevent Integer Set Library false positives

Summary:
Integer Set Library using retain-count based allocation which is not
modeled in MallocChecker.

Reviewed By: NoQ

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64680

Added:
cfe/trunk/test/Analysis/retain-count-alloc.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=366391=366390=366391=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Wed Jul 17 17:03:55 
2019
@@ -17,6 +17,7 @@
 #include "clang/AST/ParentMap.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -359,6 +360,11 @@ private:
   /// Check if the memory associated with this symbol was released.
   bool isReleased(SymbolRef Sym, CheckerContext ) const;
 
+  /// See if deallocation happens in a suspicious context. If so, escape the
+  /// pointers that otherwise would have been deallocated and return true.
+  bool suppressDeallocationsInSuspiciousContexts(const CallExpr *CE,
+ CheckerContext ) const;
+
   bool checkUseAfterFree(SymbolRef Sym, CheckerContext , const Stmt *S) 
const;
 
   void checkUseZeroAllocated(SymbolRef Sym, CheckerContext ,
@@ -877,6 +883,9 @@ void MallocChecker::checkPostStmt(const
   State = ProcessZeroAllocation(C, CE, 0, State);
   State = ProcessZeroAllocation(C, CE, 1, State);
 } else if (FunI == II_free || FunI == II_g_free || FunI == II_kfree) {
+  if (suppressDeallocationsInSuspiciousContexts(CE, C))
+return;
+
   State = FreeMemAux(C, CE, State, 0, false, ReleasedAllocatedMemory);
 } else if (FunI == II_strdup || FunI == II_win_strdup ||
FunI == II_wcsdup || FunI == II_win_wcsdup) {
@@ -2532,6 +2541,35 @@ bool MallocChecker::isReleased(SymbolRef
   return (RS && RS->isReleased());
 }
 
+bool MallocChecker::suppressDeallocationsInSuspiciousContexts(
+const CallExpr *CE, CheckerContext ) const {
+  if (CE->getNumArgs() == 0)
+return false;
+
+  StringRef FunctionStr = "";
+  if (const auto *FD = dyn_cast(C.getStackFrame()->getDecl()))
+if (const Stmt *Body = FD->getBody())
+  if (Body->getBeginLoc().isValid())
+FunctionStr =
+Lexer::getSourceText(CharSourceRange::getTokenRange(
+ {FD->getBeginLoc(), Body->getBeginLoc()}),
+ C.getSourceManager(), C.getLangOpts());
+
+  // We do not model the Integer Set Library's retain-count based allocation.
+  if (!FunctionStr.contains("__isl_"))
+return false;
+
+  ProgramStateRef State = C.getState();
+
+  for (const Expr *Arg : CE->arguments())
+if (SymbolRef Sym = C.getSVal(Arg).getAsSymbol())
+  if (const RefState *RS = State->get(Sym))
+State = State->set(Sym, RefState::getEscaped(RS));
+
+  C.addTransition(State);
+  return true;
+}
+
 bool MallocChecker::checkUseAfterFree(SymbolRef Sym, CheckerContext ,
   const Stmt *S) const {
 
@@ -2833,7 +2871,6 @@ ProgramStateRef MallocChecker::checkPoin
 if (const RefState *RS = State->get(sym)) {
   if ((RS->isAllocated() || RS->isAllocatedOfSizeZero()) &&
   CheckRefState(RS)) {
-State = State->remove(sym);
 State = State->set(sym, RefState::getEscaped(RS));
   }
 }

Added: cfe/trunk/test/Analysis/retain-count-alloc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-count-alloc.cpp?rev=366391=auto
==
--- cfe/trunk/test/Analysis/retain-count-alloc.cpp (added)
+++ cfe/trunk/test/Analysis/retain-count-alloc.cpp Wed Jul 17 17:03:55 2019
@@ -0,0 +1,37 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix.Malloc \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: We do not model Integer Set Library's retain-count
+//  based allocation. If any of the parameters has an
+//  '__isl_' prefixed macro definition we escape every
+//  of them when we are about to 'free()' something.
+
+#define __isl_take
+#define __isl_keep
+
+struct Object { int Ref; };
+void free(void *);
+
+Object *copyObj(__isl_keep Object *O) {
+  O->Ref++;
+  return O;
+}
+
+void 

r365590 - [analyzer] CastValueChecker: Remove a dump()

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 17:50:01 2019
New Revision: 365590

URL: http://llvm.org/viewvc/llvm-project?rev=365590=rev
Log:
[analyzer] CastValueChecker: Remove a dump()

Summary: Fix a nit.

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365590=365589=365590=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Tue Jul  9 
17:50:01 2019
@@ -163,7 +163,6 @@ bool CastValueChecker::evalCall(const Ca
   if (!Check)
 return false;
 
-  Call.getOriginExpr()->dump();
   const auto *CE = cast(Call.getOriginExpr());
   if (!CE)
 return false;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r365585 - [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 17:20:03 2019
New Revision: 365585

URL: http://llvm.org/viewvc/llvm-project?rev=365585=rev
Log:
[analyzer] CastValueChecker: Model casts

Summary:
It models the LLVM casts:
- `cast<>`
- `dyn_cast<>`
- `cast_or_null<>`
- `dyn_cast_or_null<>`

It has a very basic support without checking the `classof()` function.

(It reapplies the reverted 'llvm-svn: 365582' patch with proper test file.)

Reviewed By: NoQ

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64374

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/test/Analysis/return-value-guaranteed.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=365585=365584=365585=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jul  9 
17:20:03 2019
@@ -100,6 +100,7 @@ def LLVMAlpha : Package<"llvm">, ParentP
 // intended for API modeling that is not controlled by the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, ParentPackage, Hidden;
+def LLVMAPIModeling : Package<"llvm">, ParentPackage, Hidden;
 
 def Debug : Package<"debug">, Hidden;
 
@@ -274,10 +275,6 @@ def NullableReturnedFromNonnullChecker :
 
 let ParentPackage = APIModeling in {
 
-def ReturnValueChecker : Checker<"ReturnValue">,
-  HelpText<"Model the guaranteed boolean return value of function calls">,
-  Documentation;
-
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;
@@ -1109,6 +1106,18 @@ def LLVMConventionsChecker : Checker<"Co
 
 } // end "llvm"
 
+let ParentPackage = LLVMAPIModeling in {
+
+def CastValueChecker : Checker<"CastValue">,
+  HelpText<"Model implementation of custom RTTIs">,
+  Documentation;
+
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
+} // end "apiModeling.llvm"
+
 
//===--===//
 // Checkers modeling Google APIs.
 
//===--===//

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=365585=365584=365585=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Tue Jul  9 17:20:03 2019
@@ -247,6 +247,17 @@ public:
 IsPrunable);
   }
 
+  /// A shorthand version of getNoteTag that accepts a plain note.
+  ///
+  /// @param Note The note.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
+return getNoteTag(
+[Note](BugReporterContext &, BugReport &) { return Note; }, 
IsPrunable);
+  }
+
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=365585=365584=365585=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Jul  9 17:20:03 
2019
@@ -16,6 +16,7 @@ add_clang_library(clangStaticAnalyzerChe
   CallAndMessageChecker.cpp
   CastSizeChecker.cpp
   CastToStructChecker.cpp
+  CastValueChecker.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
   CheckSecuritySyntaxOnly.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365585=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp 

r365584 - Revert "[analyzer] CastValueChecker: Model casts"

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 16:47:09 2019
New Revision: 365584

URL: http://llvm.org/viewvc/llvm-project?rev=365584=rev
Log:
Revert "[analyzer] CastValueChecker: Model casts"

This reverts commit 27cf6664437efd640bb6db5594bafcce68fa2854.

Removed:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/test/Analysis/return-value-guaranteed.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=365584=365583=365584=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jul  9 
16:47:09 2019
@@ -100,7 +100,6 @@ def LLVMAlpha : Package<"llvm">, ParentP
 // intended for API modeling that is not controlled by the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, ParentPackage, Hidden;
-def LLVMAPIModeling : Package<"llvm">, ParentPackage, Hidden;
 
 def Debug : Package<"debug">, Hidden;
 
@@ -275,6 +274,10 @@ def NullableReturnedFromNonnullChecker :
 
 let ParentPackage = APIModeling in {
 
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;
@@ -1106,18 +1109,6 @@ def LLVMConventionsChecker : Checker<"Co
 
 } // end "llvm"
 
-let ParentPackage = LLVMAPIModeling in {
-
-def CastValueChecker : Checker<"CastValue">,
-  HelpText<"Model implementation of custom RTTIs">,
-  Documentation;
-
-def ReturnValueChecker : Checker<"ReturnValue">,
-  HelpText<"Model the guaranteed boolean return value of function calls">,
-  Documentation;
-
-} // end "apiModeling.llvm"
-
 
//===--===//
 // Checkers modeling Google APIs.
 
//===--===//

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=365584=365583=365584=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Tue Jul  9 16:47:09 2019
@@ -247,17 +247,6 @@ public:
 IsPrunable);
   }
 
-  /// A shorthand version of getNoteTag that accepts a plain note.
-  ///
-  /// @param Note The note.
-  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
-  ///to omit the note from the report if it would make the displayed
-  ///bug path significantly shorter.
-  const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
-return getNoteTag(
-[Note](BugReporterContext &, BugReport &) { return Note; }, 
IsPrunable);
-  }
-
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=365584=365583=365584=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Jul  9 16:47:09 
2019
@@ -16,7 +16,6 @@ add_clang_library(clangStaticAnalyzerChe
   CallAndMessageChecker.cpp
   CastSizeChecker.cpp
   CastToStructChecker.cpp
-  CastValueChecker.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
   CheckSecuritySyntaxOnly.cpp

Removed: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365583=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (removed)
@@ -1,190 +0,0 @@
-//===- CastValueChecker - Model implementation of custom RTTIs --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.

r365582 - [analyzer] CastValueChecker: Model casts

2019-07-09 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Tue Jul  9 16:33:23 2019
New Revision: 365582

URL: http://llvm.org/viewvc/llvm-project?rev=365582=rev
Log:
[analyzer] CastValueChecker: Model casts

Summary:
It models the LLVM casts:
- `cast<>`
- `dyn_cast<>`
- `cast_or_null<>`
- `dyn_cast_or_null<>`

It has a very basic support without checking the `classof()` function.

Reviewed By: NoQ

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64374

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
cfe/trunk/test/Analysis/cast-value.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/test/Analysis/return-value-guaranteed.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=365582=365581=365582=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jul  9 
16:33:23 2019
@@ -100,6 +100,7 @@ def LLVMAlpha : Package<"llvm">, ParentP
 // intended for API modeling that is not controlled by the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, ParentPackage, Hidden;
+def LLVMAPIModeling : Package<"llvm">, ParentPackage, Hidden;
 
 def Debug : Package<"debug">, Hidden;
 
@@ -274,10 +275,6 @@ def NullableReturnedFromNonnullChecker :
 
 let ParentPackage = APIModeling in {
 
-def ReturnValueChecker : Checker<"ReturnValue">,
-  HelpText<"Model the guaranteed boolean return value of function calls">,
-  Documentation;
-
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;
@@ -1109,6 +1106,18 @@ def LLVMConventionsChecker : Checker<"Co
 
 } // end "llvm"
 
+let ParentPackage = LLVMAPIModeling in {
+
+def CastValueChecker : Checker<"CastValue">,
+  HelpText<"Model implementation of custom RTTIs">,
+  Documentation;
+
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
+} // end "apiModeling.llvm"
+
 
//===--===//
 // Checkers modeling Google APIs.
 
//===--===//

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=365582=365581=365582=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Tue Jul  9 16:33:23 2019
@@ -247,6 +247,17 @@ public:
 IsPrunable);
   }
 
+  /// A shorthand version of getNoteTag that accepts a plain note.
+  ///
+  /// @param Note The note.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
+return getNoteTag(
+[Note](BugReporterContext &, BugReport &) { return Note; }, 
IsPrunable);
+  }
+
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=365582=365581=365582=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Jul  9 16:33:23 
2019
@@ -16,6 +16,7 @@ add_clang_library(clangStaticAnalyzerChe
   CallAndMessageChecker.cpp
   CastSizeChecker.cpp
   CastToStructChecker.cpp
+  CastValueChecker.cpp
   CheckObjCDealloc.cpp
   CheckObjCInstMethSignature.cpp
   CheckSecuritySyntaxOnly.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp?rev=365582=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp Tue Jul  9 
16:33:23 2019
@@ -0,0 +1,190 @@
+//===- CastValueChecker - Model 

r365103 - [analyzer] ReturnValueChecker: Model the guaranteed boolean return value of function calls

2019-07-03 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Jul  3 17:50:50 2019
New Revision: 365103

URL: http://llvm.org/viewvc/llvm-project?rev=365103=rev
Log:
[analyzer] ReturnValueChecker: Model the guaranteed boolean return value of 
function calls

Summary: It models the known LLVM methods paired with their class.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: dschuff, aheejin, mgorny, szepet, rnkovacs, a.sidorin,
 mikhail.ramalho, donat.nagy, dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63915

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/ReturnValueChecker.cpp
cfe/trunk/test/Analysis/return-value-guaranteed.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=365103=365102=365103=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Wed Jul  3 
17:50:50 2019
@@ -274,6 +274,10 @@ def NullableReturnedFromNonnullChecker :
 
 let ParentPackage = APIModeling in {
 
+def ReturnValueChecker : Checker<"ReturnValue">,
+  HelpText<"Model the guaranteed boolean return value of function calls">,
+  Documentation;
+
 def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">,
   HelpText<"Improve modeling of the C standard library functions">,
   Documentation;

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=365103=365102=365103=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Wed Jul  3 17:50:50 2019
@@ -219,24 +219,34 @@ public:
 Eng.getBugReporter().emitReport(std::move(R));
   }
 
-
   /// Produce a program point tag that displays an additional path note
   /// to the user. This is a lightweight alternative to the
   /// BugReporterVisitor mechanism: instead of visiting the bug report
   /// node-by-node to restore the sequence of events that led to discovering
   /// a bug, you can add notes as you add your transitions.
-  const NoteTag *getNoteTag(NoteTag::Callback &) {
-return Eng.getNoteTags().makeNoteTag(std::move(Cb));
+  ///
+  /// @param Cb Callback with 'BugReporterContext &, BugReport &' parameters.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(NoteTag::Callback &, bool IsPrunable = false) {
+return Eng.getNoteTags().makeNoteTag(std::move(Cb), IsPrunable);
   }
 
   /// A shorthand version of getNoteTag that doesn't require you to accept
   /// the BugReporterContext arguments when you don't need it.
-  const NoteTag *getNoteTag(std::function &) {
+  ///
+  /// @param Cb Callback only with 'BugReport &' parameter.
+  /// @param IsPrunable Whether the note is prunable. It allows BugReporter
+  ///to omit the note from the report if it would make the displayed
+  ///bug path significantly shorter.
+  const NoteTag *getNoteTag(std::function &,
+bool IsPrunable = false) {
 return getNoteTag(
-[Cb](BugReporterContext &, BugReport ) { return Cb(BR); });
+[Cb](BugReporterContext &, BugReport ) { return Cb(BR); },
+IsPrunable);
   }
 
-
   /// Returns the word that should be used to refer to the declaration
   /// in the report.
   StringRef getDeclDescription(const Decl *D);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=365103=365102=365103=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Wed Jul  3 17:50:50 
2019
@@ -83,6 +83,7 @@ add_clang_library(clangStaticAnalyzerChe
   RetainCountChecker/RetainCountDiagnostics.cpp
   ReturnPointerRangeChecker.cpp
   ReturnUndefChecker.cpp
+  ReturnValueChecker.cpp
   RunLoopAutoreleaseLeakChecker.cpp
   SimpleStreamChecker.cpp
   SmartPtrModeling.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/ReturnValueChecker.cpp
URL: 

r364271 - [analyzer] print() JSONify: Create pointers

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 20:17:55 2019
New Revision: 364271

URL: http://llvm.org/viewvc/llvm-project?rev=364271=rev
Log:
[analyzer] print() JSONify: Create pointers

Summary: -

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63726

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
cfe/trunk/test/Analysis/expr-inspection.c
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=364271=364270=364271=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Mon Jun 24 20:17:55 2019
@@ -204,13 +204,13 @@ void Environment::printJson(raw_ostream
 const LocationContext *LCtx, const char *NL,
 unsigned int Space, bool IsDot) const {
   Indent(Out, Space, IsDot) << "\"environment\": ";
-  ++Space;
 
   if (ExprBindings.isEmpty()) {
 Out << "null," << NL;
 return;
   }
 
+  ++Space;
   if (!LCtx) {
 // Find the freshest location context.
 llvm::SmallPtrSet FoundContexts;
@@ -227,7 +227,8 @@ void Environment::printJson(raw_ostream
 
   assert(LCtx);
 
-  Out << '[' << NL; // Start of Environment.
+  Out << "{ \"pointer\": \"" << (const void *)LCtx->getStackFrame()
+  << "\", \"items\": [" << NL;
   PrintingPolicy PP = Ctx.getPrintingPolicy();
 
   LCtx->printJson(Out, NL, Space, IsDot, [&](const LocationContext *LC) {
@@ -280,5 +281,5 @@ void Environment::printJson(raw_ostream
   Out << "null ";
   });
 
-  Indent(Out, --Space, IsDot) << "]," << NL; // End of Environment.
+  Indent(Out, --Space, IsDot) << "]}," << NL;
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=364271=364270=364271=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Mon Jun 24 20:17:55 2019
@@ -2640,7 +2640,7 @@ void RegionStoreManager::printJson(raw_o
 return;
   }
 
-  Out << '[' << NL;
-  Bindings.printJson(Out, NL, ++Space, IsDot);
-  Indent(Out, --Space, IsDot) << "]," << NL;
+  Out << "{ \"pointer\": \"" << Bindings.asStore() << "\", \"items\": [" << NL;
+  Bindings.printJson(Out, NL, Space + 1, IsDot);
+  Indent(Out, Space, IsDot) << "]}," << NL;
 }

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot?rev=364271=364270=364271=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/environment.dot Mon Jun 24 
20:17:55 2019
@@ -34,21 +34,24 @@ Node0x1 [shape=record,label=
   "program_state": {
 "store": null,
 "constraints": null,
-"environment": [
-  {
-"location_context": "#0 Call",
-"lctx_id": 3,
-"calling": "foo",
-"call_line": 4,
-"items": [
-  {
-"stmt_id": 5,
-"pretty": "bar()",
-"value": "Unknown"
-  }
-]
-  }
-]
+"environment": {
+  "pointer": "0x2",
+  "items": [
+{
+  "location_context": "#0 Call",
+  "lctx_id": 3,
+  "calling": "foo",
+  "call_line": 4,
+  "items": [
+{
+  "stmt_id": 5,
+  "pretty": "bar()",
+  "value": "Unknown"
+}
+  ]
+}
+  ]
+}
   }
 }
 \l}"];

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot?rev=364271=364270=364271=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot 
(original)
+++ 

r364270 - [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 20:08:32 2019
New Revision: 364270

URL: http://llvm.org/viewvc/llvm-project?rev=364270=rev
Log:
[analyzer] JsonSupport: Escape escapes

Summary: -

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63462

Modified:
cfe/trunk/include/clang/Basic/JsonSupport.h
cfe/trunk/test/Analysis/dump_egraph.c
cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c

Modified: cfe/trunk/include/clang/Basic/JsonSupport.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/JsonSupport.h?rev=364270=364269=364270=diff
==
--- cfe/trunk/include/clang/Basic/JsonSupport.h (original)
+++ cfe/trunk/include/clang/Basic/JsonSupport.h Mon Jun 24 20:08:32 2019
@@ -31,7 +31,26 @@ inline std::string JsonFormat(StringRef
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@ inline std::string JsonFormat(StringRef
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }

Modified: cfe/trunk/test/Analysis/dump_egraph.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.c?rev=364270=364269=364270=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.c (original)
+++ cfe/trunk/test/Analysis/dump_egraph.c Mon Jun 24 20:08:32 2019
@@ -13,6 +13,8 @@ int getJ();
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@ int foo() {
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c?rev=364270=364269=364270=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c Mon Jun 24 
20:08:32 2019
@@ -15,7 +15,7 @@ void escapes() {
   // CHECK: Environment: 
   // CHECK-SAME: "foo"
   // CHECK-SAME: Element\{"foo",0 S64b,char\}
-  const char *const foo = "foo";
+  const char *const foo = "\x66\x6f\x6f";
 
   // CHECK: BinaryOperator
   // CHECK-SAME: 1 \| 2


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364259 - [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 17:44:33 2019
New Revision: 364259

URL: http://llvm.org/viewvc/llvm-project?rev=364259=rev
Log:
[analyzer] ExprEngine: Escape pointers in bitwise operations

Summary:
After evaluation it would be an Unknown value and tracking would be lost.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63720

Added:
cfe/trunk/test/Analysis/symbol-escape.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=364259=364258=364259=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Mon Jun 24 17:44:33 2019
@@ -100,6 +100,10 @@ void ExprEngine::VisitBinaryOperator(con
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
   if (!Result.isUnknown()) {
 state = state->BindExpr(B, LCtx, Result);
+  } else {
+// If we cannot evaluate the operation escape the operands.
+state = escapeValue(state, LeftV, PSK_EscapeOther);
+state = escapeValue(state, RightV, PSK_EscapeOther);
   }
 
   Bldr.generateNode(B, *it, state);

Added: cfe/trunk/test/Analysis/symbol-escape.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/symbol-escape.cpp?rev=364259=auto
==
--- cfe/trunk/test/Analysis/symbol-escape.cpp (added)
+++ cfe/trunk/test/Analysis/symbol-escape.cpp Mon Jun 24 17:44:33 2019
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape
+//  the operands. After the evaluation it would be an
+//  Unknown value and the tracking would be lost.
+
+typedef unsigned __INTPTR_TYPE__ uintptr_t;
+
+class C {};
+
+C *simple_escape_in_bitwise_op(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast(reinterpret_cast(Bar) & 0x1);
+  (void)Bar;
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here.
+
+  return Bar;
+}
+
+C **indirect_escape_in_bitwise_op() {
+  C *Qux = new C();
+  C **Baz = 
+  Baz = reinterpret_cast(reinterpret_cast(Baz) | 0x1);
+  Baz = reinterpret_cast(reinterpret_cast(Baz) &
+  ~static_cast(0x1));
+  // no-warning: "Potential leak of memory pointed to by 'Qux'" was here.
+
+  delete *Baz;
+  return Baz;
+}
+


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364197 - [analyzer] print() JSONify: ProgramPoint revision

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 09:19:39 2019
New Revision: 364197

URL: http://llvm.org/viewvc/llvm-project?rev=364197=rev
Log:
[analyzer] print() JSONify: ProgramPoint revision

Summary: Now we also print out the filename with its path.

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63438

Modified:
cfe/trunk/lib/Analysis/ProgramPoint.cpp
cfe/trunk/test/Analysis/dump_egraph.c

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=364197=364196=364197=diff
==
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Mon Jun 24 09:19:39 2019
@@ -55,7 +55,8 @@ static void printLocJson(raw_ostream 
   }
 
   Out << "{ \"line\": " << SM.getExpansionLineNumber(Loc)
-  << ", \"column\": " << SM.getExpansionColumnNumber(Loc) << " }";
+  << ", \"column\": " << SM.getExpansionColumnNumber(Loc)
+  << ", \"file\": \"" << SM.getFilename(Loc) << "\" }";
 }
 
 void ProgramPoint::printJson(llvm::raw_ostream , const char *NL) const {

Modified: cfe/trunk/test/Analysis/dump_egraph.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.c?rev=364197=364196=364197=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.c (original)
+++ cfe/trunk/test/Analysis/dump_egraph.c Mon Jun 24 09:19:39 2019
@@ -22,3 +22,5 @@ int foo() {
 
 // CHECK: \"has_report\": true
 
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364193 - [analyzer] Fix JSON dumps for ExplodedNodes

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 09:06:44 2019
New Revision: 364193

URL: http://llvm.org/viewvc/llvm-project?rev=364193=rev
Log:
[analyzer] Fix JSON dumps for ExplodedNodes

Summary:
- Now we could see the `has_report` property in `trim-egraph` mode.
- This patch also removes the trailing comma after each node.

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63436

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/dump_egraph.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=364193=364192=364193=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Jun 24 09:06:44 2019
@@ -3009,7 +3009,7 @@ struct DOTGraphTraits :
 
 for (const auto  : EQClasses) {
   for (const BugReport  : EQ) {
-if (Report.getErrorNode() == N)
+if (Report.getErrorNode()->getState() == N->getState())
   return true;
   }
 }
@@ -3109,11 +3109,7 @@ struct DOTGraphTraits :
   Indent(Out, Space, IsDot) << "\"program_state\": null";
 }
 
-Out << "\\l}";
-if (!N->succ_empty())
-  Out << ',';
-Out << "\\l";
-
+Out << "\\l}\\l";
 return Out.str();
   }
 };

Modified: cfe/trunk/test/Analysis/dump_egraph.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.c?rev=364193=364192=364193=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.c (original)
+++ cfe/trunk/test/Analysis/dump_egraph.c Mon Jun 24 09:06:44 2019
@@ -1,6 +1,12 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot %s
 // RUN: cat %t.dot | FileCheck %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
-trim-egraph %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot \
+// RUN:  -trim-egraph %s
+// RUN: cat %t.dot | FileCheck %s
+
 // REQUIRES: asserts
 
 int getJ();
@@ -10,8 +16,6 @@ int foo() {
   return *x + *y;
 }
 
-// CHECK: digraph "Exploded Graph" {
-
 // CHECK: \"program_points\": [\l\{ \"kind\": 
\"Edge\", \"src_id\": 2, \"dst_id\": 1, \"terminator\": null, \"term_kind\": 
null, \"tag\": null \}\l],\l\"program_state\": null
 
 // CHECK: \"program_points\": [\l\{ \"kind\": 
\"BlockEntrance\", \"block_id\": 1


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r363515 - [analyzer] ReturnVisitor: more portable test case

2019-06-16 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sun Jun 16 10:29:37 2019
New Revision: 363515

URL: http://llvm.org/viewvc/llvm-project?rev=363515=rev
Log:
[analyzer] ReturnVisitor: more portable test case

Modified:
cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp

Modified: cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp?rev=363515=363514=363515=diff
==
--- cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp (original)
+++ cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp Sun Jun 
16 10:29:37 2019
@@ -11,10 +11,9 @@
 // expected-no-diagnostics
 #endif
 
+#include 
 #include "../Inputs/system-header-simulator-cxx.h"
 
-typedef unsigned long uintptr_t;
-
 void error();
 void *malloc(size_t);
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r363491 - [analyzer] ReturnVisitor: Bypass everything to see inlined calls

2019-06-15 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Jun 15 03:05:49 2019
New Revision: 363491

URL: http://llvm.org/viewvc/llvm-project?rev=363491=rev
Log:
[analyzer] ReturnVisitor: Bypass everything to see inlined calls

Summary:
When we traversed backwards on ExplodedNodes to see where processed the
given statement we `break` too early. With the current approach we do not
miss the CallExitEnd ProgramPoint which stands for an inlined call.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62926

Added:
cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/new-ctor-null-throw.cpp
cfe/trunk/test/Analysis/new-ctor-null.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=363491=363490=363491=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Jun 15 
03:05:49 2019
@@ -841,16 +841,38 @@ public:
   return;
 
 // First, find when we processed the statement.
+// If we work with a 'CXXNewExpr' that is going to be purged away before
+// its call take place. We would catch that purge in the last condition
+// as a 'StmtPoint' so we have to bypass it.
+const bool BypassCXXNewExprEval = isa(S);
+
+// This is moving forward when we enter into another context.
+const StackFrameContext *CurrentSFC = Node->getStackFrame();
+
 do {
-  if (auto CEE = Node->getLocationAs())
+  // If that is satisfied we found our statement as an inlined call.
+  if (Optional CEE = Node->getLocationAs())
 if (CEE->getCalleeContext()->getCallSite() == S)
   break;
-  if (auto SP = Node->getLocationAs())
-if (SP->getStmt() == S)
-  break;
 
+  // Try to move forward to the end of the call-chain.
   Node = Node->getFirstPred();
-} while (Node);
+  if (!Node)
+break;
+
+  const StackFrameContext *PredSFC = Node->getStackFrame();
+
+  // If that is satisfied we found our statement.
+  // FIXME: This code currently bypasses the call site for the
+  //conservatively evaluated allocator.
+  if (!BypassCXXNewExprEval)
+if (Optional SP = Node->getLocationAs())
+  // See if we do not enter into another context.
+  if (SP->getStmt() == S && CurrentSFC == PredSFC)
+break;
+
+  CurrentSFC = PredSFC;
+} while (Node->getStackFrame() == CurrentSFC);
 
 // Next, step over any post-statement checks.
 while (Node && Node->getLocation().getAs())

Added: cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp?rev=363491=auto
==
--- cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp (added)
+++ cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp Sat Jun 
15 03:05:49 2019
@@ -0,0 +1,137 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core.CallAndMessage \
+// RUN:  -analyzer-config suppress-null-return-paths=false \
+// RUN:  -verify %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core.CallAndMessage \
+// RUN:  -DSUPPRESSED \
+// RUN:  -verify %s
+
+#ifdef SUPPRESSED
+// expected-no-diagnostics
+#endif
+
+#include "../Inputs/system-header-simulator-cxx.h"
+
+typedef unsigned long uintptr_t;
+
+void error();
+void *malloc(size_t);
+
+
+// From llvm/include/llvm/Support/MathExtras.h
+inline uintptr_t alignAddr(const void *Addr, size_t Alignment) {
+  return (((uintptr_t)Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1));
+}
+
+inline size_t alignmentAdjustment(const void *Ptr, size_t Alignment) {
+  return alignAddr(Ptr, Alignment) - (uintptr_t)Ptr;
+}
+
+
+// From llvm/include/llvm/Support/MemAlloc.h
+inline void *safe_malloc(size_t Sz) {
+  void *Result = malloc(Sz);
+  if (Result == nullptr)
+error();
+
+  return Result;
+}
+
+
+// From llvm/include/llvm/Support/Allocator.h
+class MallocAllocator {
+public:
+  void *Allocate(size_t Size, size_t /*Alignment*/) {
+return safe_malloc(Size);
+  }
+};
+
+class BumpPtrAllocator {
+public:
+  void *Allocate(size_t Size, size_t Alignment) {
+BytesAllocated += Size;
+size_t Adjustment = alignmentAdjustment(CurPtr, Alignment);
+size_t SizeToAllocate = Size;
+
+size_t PaddedSize = SizeToAllocate + Alignment - 1;
+uintptr_t AlignedAddr = alignAddr(Allocator.Allocate(PaddedSize, 

r363187 - [analyzer] ProgramPoint: more explicit printJson()

2019-06-12 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Jun 12 11:24:02 2019
New Revision: 363187

URL: http://llvm.org/viewvc/llvm-project?rev=363187=rev
Log:
[analyzer] ProgramPoint: more explicit printJson()

Summary: Now we print out every possible kinds of ProgramPoints.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62946

Modified:
cfe/trunk/lib/Analysis/ProgramPoint.cpp

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=363187=363186=363187=diff
==
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Wed Jun 12 11:24:02 2019
@@ -99,12 +99,6 @@ void ProgramPoint::printJson(llvm::raw_o
   case ProgramPoint::CallExitEndKind:
 Out << "CallExitEnd\"";
 break;
-  case ProgramPoint::PostStmtPurgeDeadSymbolsKind:
-Out << "PostStmtPurgeDeadSymbols\"";
-break;
-  case ProgramPoint::PreStmtPurgeDeadSymbolsKind:
-Out << "PreStmtPurgeDeadSymbols\"";
-break;
   case ProgramPoint::EpsilonKind:
 Out << "EpsilonPoint\"";
 break;
@@ -210,20 +204,35 @@ void ProgramPoint::printJson(llvm::raw_o
 Out << ", ";
 printLocJson(Out, S->getBeginLoc(), SM);
 
-Out << ", \"stmt_point_kind\": ";
-if (getAs())
-  Out << "\"PreStmt\"";
+Out << ", \"stmt_point_kind\": \"";
+if (getAs())
+  Out << "PreLoad";
+else if (getAs())
+  Out << "PreStore";
+else if (getAs())
+  Out << "PostAllocatorCall";
+else if (getAs())
+  Out << "PostCondition";
 else if (getAs())
-  Out << "\"PostLoad\"";
-else if (getAs())
-  Out << "\"PostStore\"";
+  Out << "PostLoad";
 else if (getAs())
-  Out << "\"PostLValue\"";
-else if (getAs())
-  Out << "\"PostAllocatorCall\"";
-else
-  Out << "null";
+  Out << "PostLValue";
+else if (getAs())
+  Out << "PostStore";
+else if (getAs())
+  Out << "PostStmt";
+else if (getAs())
+  Out << "PostStmtPurgeDeadSymbols";
+else if (getAs())
+  Out << "PreStmtPurgeDeadSymbols";
+else if (getAs())
+  Out << "PreStmt";
+else {
+  Out << "\nKind: '" << getKind();
+  llvm_unreachable("' is unhandled StmtPoint kind!");
+}
 
+Out << '\"';
 break;
   }
   }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r362632 - [analyzer] PathDiagnosticPopUpPiece: working with CharSourceRange

2019-06-05 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed Jun  5 11:55:39 2019
New Revision: 362632

URL: http://llvm.org/viewvc/llvm-project?rev=362632=rev
Log:
[analyzer] PathDiagnosticPopUpPiece: working with CharSourceRange

Summary: Sometimes we are at character boundaries so past the token-range.

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

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=362632=362631=362632=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Wed Jun  5 11:55:39 
2019
@@ -612,7 +612,7 @@ HandlePopUpPieceStartTag(Rewriter ,
   for (const auto  : PopUpRanges) {
 html::HighlightRange(R, Range.getBegin(), Range.getEnd(), "",
  "",
- /*IsTokenRange=*/true);
+ /*IsTokenRange=*/false);
   }
 }
 
@@ -644,12 +644,12 @@ static void HandlePopUpPieceEndTag(Rewri
 Out << "";
 html::HighlightRange(R, Range.getBegin(), Range.getEnd(),
  "", Buf.c_str(),
- /*IsTokenRange=*/true);
+ /*IsTokenRange=*/false);
 
   // Otherwise inject just the new row at the end of the range.
   } else {
 html::HighlightRange(R, Range.getBegin(), Range.getEnd(), "", Buf.c_str(),
- /*IsTokenRange=*/true);
+ /*IsTokenRange=*/false);
   }
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r362249 - [analyzer] print() JSONify: ExplodedNode revision

2019-05-31 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Fri May 31 10:54:12 2019
New Revision: 362249

URL: http://llvm.org/viewvc/llvm-project?rev=362249=rev
Log:
[analyzer] print() JSONify: ExplodedNode revision

Summary: Revert node-ID removal.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp,
 cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62658

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

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=362249=362248=362249=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Fri May 31 10:54:12 2019
@@ -3075,8 +3075,8 @@ struct DOTGraphTraits :
 const unsigned int Space = 1;
 ProgramStateRef State = N->getState();
 
-Out << "{ \"node_id\": \"" << (const void *)N
-<< "\", \"state_id\": " << State->getID()
+Out << "{ \"node_id\": " << N->getID(G) << ", \"pointer\": \""
+<< (const void *)N << "\", \"state_id\": " << State->getID()
 << ", \"has_report\": " << (nodeHasBugReport(N) ? "true" : "false")
 << ",\\l";
 
@@ -3094,7 +3094,7 @@ struct DOTGraphTraits :
   else
 Out << "null }";
 },
-   // Adds a comma and a new-line between each program point.
+// Adds a comma and a new-line between each program point.
 [&](const ExplodedNode *) { Out << ",\\l"; },
 [&](const ExplodedNode *) { return false; });
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r361997 - [analyzer] print() JSONify: getNodeLabel implementation

2019-05-30 Thread Csaba Dabis via cfe-commits
I have not said there is determinism to print out a map as Static Analyzer
cannot provide that. We have no plans to make it deterministic, as it is
just dumping out the ExplodedGraph in JSON format, which is an internal
stuff.

This non-deterministic behaviour has been seen first only some days ago, as
no-one ever was that crazy to rewrite the backend of the Static Analyzer.
Now we are doing that as a part of my GSoC project, and that little QoL
patch-chain cannot take more than a week of work, as we planned.

I have said the non-deterministic behaviour of Windows has been fixed. When
you put that for-loop to `check-clang` on a Linux machine it will pass 100
times, however on Windows it will fail 60 times. I am not a Windows user
and I did not know about that behaviour to write out a map could be that
silly. By "hiding" the non-determinism of Windows map-handling the Test
became deterministic.

We had that structure behind:

First CHECK was:
"constructing_objects": [
  { "location_context": "#0 Call", "calling": "foo", "call_line": null, "
*items*": [
{ "lctx_id": 1, "stmt_id": 1125, "kind": "construct into local
variable", "argument_index": null, "pretty": "T t;", "value": "" }
  ]}
]

Second CHECK was:
"constructing_objects": [
  { "location_context": "#0 Call", "calling": "T::T", "call_line": "16", "
*items*": [
{ "lctx_id": 2, "init_id": 1062, "kind": "construct into member
variable", "argument_index": null, "pretty": "s", "value": ">s" }
  ]},
  { "location_context": "#1 Call", "calling": "foo", "call_line": null, "
*items*": [
{ "lctx_id": 1, "stmt_id": 1125, "kind": "construct into local
variable", "argument_index": null, "pretty": "T t;", "value": "" }
  ]}
]

By removing the `constructing_objects` that Test is deterministic every
time as no map structure with multiple elements involved.

I am also sad because the core developers did not care about maps. I will
not too, as I said it is just dumping out the internal of the internals.

Thanks for your understanding,
Csaba.

On Thu, May 30, 2019 at 5:28 PM Russell Gallop 
wrote:

> Hi Csaba,
>
> I see what Roman means. Output should be deterministic for given input
> (unless there is a very good reason not to (e.g. timing or deliberate
> randomness)).
>
> You can check whether the output is the same with a script like below. It
> looks like the node numbers are different every time. Is there a good
> reason for this?
>
> Regards
> Russ
>
> $ cat test.sh
> #!/bin/bash -xe
>
> python bin/llvm-lit.py -v ../clang/test/Analysis/dump_egraph.cpp
> cp tools/clang/test/Analysis/Output/dump_egraph.cpp.tmp.dot ref.dot
>
> for ((i=0;i<100;i++));
> do
>  python bin/llvm-lit.py -v ../clang/test/Analysis/dump_egraph.cpp
>  diff ref.dot tools/clang/test/Analysis/Output/dump_egraph.cpp.tmp.dot
> done
>
> On Thu, 30 May 2019 at 16:18, Roman Lebedev  wrote:
>
>> I think we're still talking past each other.
>>
>> I'm saying that *any* commit that does not fix the underlying
>> nondeterminizm,
>> but only hides it by deleting tests that showed that said determinism
>> exists in the first place,
>> is not a fix.
>>
>> Roman.
>>
>> On Thu, May 30, 2019 at 6:14 PM Csaba Dabis 
>> wrote:
>> >
>> > Hm, the first `CHECK: constructing_objects` contains only one element,
>> which is fine,
>> > the second `CHECK: constructing_objects` has two, which could be
>> non-determinism,
>> > but surprisingly it is worked as excepted.
>> > Because of the edge-case I have changed my mind:
>> >
>> https://github.com/llvm/llvm-project/commit/32d545f930ce44614ac8398693dacd1d6dbc41a3
>> >
>> > Thanks everyone!
>> >
>> > On Thu, May 30, 2019 at 4:52 PM Roman Lebedev 
>> wrote:
>> >>
>> >> On Thu, May 30, 2019 at 5:48 PM Csaba Dabis via cfe-commits
>> >>  wrote:
>> >> >
>> >> > Thanks you!
>> >> >
>> >> > Fixed by
>> https://github.com/llvm/llvm-project/commit/17604c3486cbe7c27cadac1757cd0a9109a92792
>> >> The non-determinism is still there though, so this isn't correct fix.
>> >>
>> >> > On Thu, May 30, 2019 at 4:16 PM Russell Gallop <
>> russell.gal...@gmail.com> wrote:
>> &

Re: r361997 - [analyzer] print() JSONify: getNodeLabel implementation

2019-05-30 Thread Csaba Dabis via cfe-commits
Hm, the first `CHECK: constructing_objects` contains only one element,
which is fine,
the second `CHECK: constructing_objects` has two, which could be
non-determinism,
but surprisingly it is worked as excepted.
Because of the edge-case I have changed my mind:
https://github.com/llvm/llvm-project/commit/32d545f930ce44614ac8398693dacd1d6dbc41a3

Thanks everyone!

On Thu, May 30, 2019 at 4:52 PM Roman Lebedev  wrote:

> On Thu, May 30, 2019 at 5:48 PM Csaba Dabis via cfe-commits
>  wrote:
> >
> > Thanks you!
> >
> > Fixed by
> https://github.com/llvm/llvm-project/commit/17604c3486cbe7c27cadac1757cd0a9109a92792
> The non-determinism is still there though, so this isn't correct fix.
>
> > On Thu, May 30, 2019 at 4:16 PM Russell Gallop 
> wrote:
> >>
> >> Hi Csaba,
> >>
> >> Failing example attached. Note that the output is different every time
> so there is potentially more than one failure mode.
> >>
> >> Thanks
> >> Russ
> >>
> >> On Thu, 30 May 2019 at 15:05, Csaba Dabis 
> wrote:
> >>>
> >>> Hey!
> >>>
> >>> When it fails, could you provide the DOT dump? The path is:
> llvm-project/build/tools/clang/test/Analysis/Output/dump_egraph.cpp.tmp.dot
> >>>
> >>> Thanks,
> >>> Csaba.
> >>>
> >>> On Thu, May 30, 2019 at 4:00 PM Russell Gallop <
> russell.gal...@gmail.com> wrote:
> >>>>
> >>>> Hi Csaba,
> >>>>
> >>>> The test dump_egraph.cpp appears to be flaky on Windows. For example
> here:
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/26183
> .
> >>>>
> >>>>
> C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Analysis\dump_egraph.cpp:23:11:
> error: CHECK: expected string not found in input
> >>>> // CHECK: \"store\": [\l\{
> \"cluster\": \"t\", \"items\":
> [\l\{ \"kind\":
> \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
> >>>>
> >>>> Running locally, it fails after 2-5 runs for me, running:
> >>>> python bin/llvm-lit.py -v ../clang/test/Analysis/dump_egraph.cpp
> >>>>
> >>>> Please could you take a look?
> >>>>
> >>>> Note that I'm not certain it was this commit that started the
> flakiness, it is the latest which changed the failing line.
> >>>>
> >>>> Thanks
> >>>> Russ
> >>>>
> >>>> On Wed, 29 May 2019 at 19:02, Csaba Dabis via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >>>>>
> >>>>> Author: charusso
> >>>>> Date: Wed May 29 11:05:53 2019
> >>>>> New Revision: 361997
> >>>>>
> >>>>> URL: http://llvm.org/viewvc/llvm-project?rev=361997=rev
> >>>>> Log:
> >>>>> [analyzer] print() JSONify: getNodeLabel implementation
> >>>>>
> >>>>> Summary: This patch also rewrites the ProgramPoint printing.
> >>>>>
> >>>>> Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware,
> Szelethus
> >>>>>
> >>>>> Reviewed By: NoQ
> >>>>>
> >>>>> Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin,
> mikhail.ramalho,
> >>>>>  donat.nagy, dkrupp
> >>>>>
> >>>>> Tags: #clang
> >>>>>
> >>>>> Differential Revision: https://reviews.llvm.org/D62346
> >>>>>
> >>>>> Modified:
> >>>>> cfe/trunk/include/clang/Analysis/ProgramPoint.h
> >>>>> cfe/trunk/lib/Analysis/ProgramPoint.cpp
> >>>>> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
> >>>>> cfe/trunk/test/Analysis/dump_egraph.c
> >>>>> cfe/trunk/test/Analysis/dump_egraph.cpp
> >>>>>
> >>>>> Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
> >>>>> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=361997=361996=361997=diff
> >>>>>
> ==
> >>>>> --- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
> >>>>&

r362101 - [analyzer] print() JSONify chain: Fix possible build-bot breaks

2019-05-30 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Thu May 30 08:15:57 2019
New Revision: 362101

URL: http://llvm.org/viewvc/llvm-project?rev=362101=rev
Log:
[analyzer] print() JSONify chain: Fix possible build-bot breaks

Summary:
Printing constructing_objects could be non-deterministic as it is a map.

Modified:
cfe/trunk/test/Analysis/dump_egraph.cpp

Modified: cfe/trunk/test/Analysis/dump_egraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=362101=362100=362101=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.cpp (original)
+++ cfe/trunk/test/Analysis/dump_egraph.cpp Thu May 30 08:15:57 2019
@@ -16,9 +16,9 @@ void foo() {
   T t;
 }
 
-// CHECK: \"constructing_objects\": [\l\{ 
\"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, 
\"items\": [\l\{ \"lctx_id\": 
1, \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
+// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"lctx_id\": 1, 
\"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
 
-// CHECK: \"constructing_objects\": [\l\{ 
\"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": 
\"16\", \"items\": [\l\{ 
\"lctx_id\": 2, \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member 
variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
+// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"lctx_id\": 2, 
\"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", 
\"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
 
 // CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r361997 - [analyzer] print() JSONify: getNodeLabel implementation

2019-05-30 Thread Csaba Dabis via cfe-commits
Thanks you!

Fixed by
https://github.com/llvm/llvm-project/commit/17604c3486cbe7c27cadac1757cd0a9109a92792

On Thu, May 30, 2019 at 4:16 PM Russell Gallop 
wrote:

> Hi Csaba,
>
> Failing example attached. Note that the output is different every time so
> there is potentially more than one failure mode.
>
> Thanks
> Russ
>
> On Thu, 30 May 2019 at 15:05, Csaba Dabis  wrote:
>
>> Hey!
>>
>> When it fails, could you provide the DOT dump? The path
>> is: 
>> llvm-project/build/tools/clang/test/Analysis/Output/dump_egraph.cpp.tmp.dot
>>
>> Thanks,
>> Csaba.
>>
>> On Thu, May 30, 2019 at 4:00 PM Russell Gallop 
>> wrote:
>>
>>> Hi Csaba,
>>>
>>> The test dump_egraph.cpp appears to be flaky on Windows. For example
>>> here:
>>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/26183
>>> .
>>>
>>> C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Analysis\dump_egraph.cpp:23:11:
>>> error: CHECK: expected string not found in input
>>> // CHECK: \"store\": [\l\{
>>> \"cluster\": \"t\", \"items\":
>>> [\l\{ \"kind\":
>>> \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
>>>
>>> Running locally, it fails after 2-5 runs for me, running:
>>> python bin/llvm-lit.py -v ../clang/test/Analysis/dump_egraph.cpp
>>>
>>> Please could you take a look?
>>>
>>> Note that I'm not certain it was this commit that started the flakiness,
>>> it is the latest which changed the failing line.
>>>
>>> Thanks
>>> Russ
>>>
>>> On Wed, 29 May 2019 at 19:02, Csaba Dabis via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>>> Author: charusso
>>>> Date: Wed May 29 11:05:53 2019
>>>> New Revision: 361997
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=361997=rev
>>>> Log:
>>>> [analyzer] print() JSONify: getNodeLabel implementation
>>>>
>>>> Summary: This patch also rewrites the ProgramPoint printing.
>>>>
>>>> Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus
>>>>
>>>> Reviewed By: NoQ
>>>>
>>>> Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
>>>>  donat.nagy, dkrupp
>>>>
>>>> Tags: #clang
>>>>
>>>> Differential Revision: https://reviews.llvm.org/D62346
>>>>
>>>> Modified:
>>>> cfe/trunk/include/clang/Analysis/ProgramPoint.h
>>>> cfe/trunk/lib/Analysis/ProgramPoint.cpp
>>>> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>>>> cfe/trunk/test/Analysis/dump_egraph.c
>>>> cfe/trunk/test/Analysis/dump_egraph.cpp
>>>>
>>>> Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
>>>> URL:
>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=361997=361996=361997=diff
>>>>
>>>> ==
>>>> --- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
>>>> +++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Wed May 29 11:05:53
>>>> 2019
>>>> @@ -213,7 +213,7 @@ public:
>>>>  ID.AddPointer(getTag());
>>>>}
>>>>
>>>> -  void print(StringRef CR, llvm::raw_ostream ) const;
>>>> +  void printJson(llvm::raw_ostream , const char *NL = "\n") const;
>>>>
>>>>LLVM_DUMP_METHOD void dump() const;
>>>>
>>>>
>>>> Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
>>>> URL:
>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=361997=361996=361997=diff
>>>>
>>>> ==
>>>> --- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
>>>> +++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Wed May 29 11:05:53 2019
>>>> @@ -43,151 +43,152 @@ ProgramPoint ProgramPoint::getProgramPoi
>>>>  }
>>>>
>>>>  LLVM_DUMP_METHOD void ProgramPoint::dump() const {
>>>> -  return print(/*CR=*/"\n", llvm::errs

r362098 - [analyzer] print() JSONify chain: Fix build-bot breaks

2019-05-30 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Thu May 30 07:48:43 2019
New Revision: 362098

URL: http://llvm.org/viewvc/llvm-project?rev=362098=rev
Log:
[analyzer] print() JSONify chain: Fix build-bot breaks

Summary:
Printing out a map structure different in different environments so that
this patch generalize the test-case to check for the 'no stmt'-case
anywhere in the Store.

Modified:
cfe/trunk/test/Analysis/dump_egraph.cpp

Modified: cfe/trunk/test/Analysis/dump_egraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=362098=362097=362098=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.cpp (original)
+++ cfe/trunk/test/Analysis/dump_egraph.cpp Thu May 30 07:48:43 2019
@@ -20,5 +20,5 @@ void foo() {
 
 // CHECK: \"constructing_objects\": [\l\{ 
\"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": 
\"16\", \"items\": [\l\{ 
\"lctx_id\": 2, \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member 
variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
 
-// CHECK: \"store\": [\l\{ \"cluster\": 
\"t\", \"items\": [\l\{ 
\"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, 
#1\}\"
+// CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r361997 - [analyzer] print() JSONify: getNodeLabel implementation

2019-05-30 Thread Csaba Dabis via cfe-commits
Hey!

When it fails, could you provide the DOT dump? The path
is: llvm-project/build/tools/clang/test/Analysis/Output/dump_egraph.cpp.tmp.dot

Thanks,
Csaba.

On Thu, May 30, 2019 at 4:00 PM Russell Gallop 
wrote:

> Hi Csaba,
>
> The test dump_egraph.cpp appears to be flaky on Windows. For example here:
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/26183
> .
>
> C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Analysis\dump_egraph.cpp:23:11:
> error: CHECK: expected string not found in input
> // CHECK: \"store\": [\l\{
> \"cluster\": \"t\", \"items\":
> [\l\{ \"kind\":
> \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
>
> Running locally, it fails after 2-5 runs for me, running:
> python bin/llvm-lit.py -v ../clang/test/Analysis/dump_egraph.cpp
>
> Please could you take a look?
>
> Note that I'm not certain it was this commit that started the flakiness,
> it is the latest which changed the failing line.
>
> Thanks
> Russ
>
> On Wed, 29 May 2019 at 19:02, Csaba Dabis via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: charusso
>> Date: Wed May 29 11:05:53 2019
>> New Revision: 361997
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=361997=rev
>> Log:
>> [analyzer] print() JSONify: getNodeLabel implementation
>>
>> Summary: This patch also rewrites the ProgramPoint printing.
>>
>> Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus
>>
>> Reviewed By: NoQ
>>
>> Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
>>  donat.nagy, dkrupp
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D62346
>>
>> Modified:
>> cfe/trunk/include/clang/Analysis/ProgramPoint.h
>> cfe/trunk/lib/Analysis/ProgramPoint.cpp
>> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>> cfe/trunk/test/Analysis/dump_egraph.c
>> cfe/trunk/test/Analysis/dump_egraph.cpp
>>
>> Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=361997=361996=361997=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
>> +++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Wed May 29 11:05:53
>> 2019
>> @@ -213,7 +213,7 @@ public:
>>  ID.AddPointer(getTag());
>>}
>>
>> -  void print(StringRef CR, llvm::raw_ostream ) const;
>> +  void printJson(llvm::raw_ostream , const char *NL = "\n") const;
>>
>>LLVM_DUMP_METHOD void dump() const;
>>
>>
>> Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=361997=361996=361997=diff
>>
>> ==
>> --- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
>> +++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Wed May 29 11:05:53 2019
>> @@ -43,151 +43,152 @@ ProgramPoint ProgramPoint::getProgramPoi
>>  }
>>
>>  LLVM_DUMP_METHOD void ProgramPoint::dump() const {
>> -  return print(/*CR=*/"\n", llvm::errs());
>> +  return printJson(llvm::errs());
>>  }
>>
>> -static void printLocation(raw_ostream , SourceLocation SLoc,
>> -  const SourceManager ,
>> -  StringRef CR,
>> -  StringRef Postfix) {
>> -  if (SLoc.isFileID()) {
>> -Out << CR << "line=" << SM.getExpansionLineNumber(SLoc)
>> -<< " col=" << SM.getExpansionColumnNumber(SLoc) << Postfix;
>> +static void printLocation(raw_ostream , SourceLocation Loc,
>> +  const SourceManager ) {
>> +  Out << "\"location\": ";
>> +  if (!Loc.isFileID()) {
>> +Out << "null";
>> +return;
>>}
>> +
>> +  Out << "{ \"line\": " << SM.getExpansionLineNumber(Loc)
>> +  << ", \"column\": " << SM.getExpansionColumnNumber(Loc) << " }";
>>  }
>>
>> -void ProgramPoint::print(StringRef CR, llvm::raw_ostream ) const {
>> +void ProgramPoint::pri

r362030 - [analyzer] Remove EndPath function as it is dead code

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 13:47:27 2019
New Revision: 362030

URL: http://llvm.org/viewvc/llvm-project?rev=362030=rev
Log:
[analyzer] Remove EndPath function as it is dead code

Summary: -

Reviewers: george.karpenkov

Reviewed By: george.karpenkov

Subscribers: baloghadamsoftware, cfe-commits, xazax.hun, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D53720

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=362030=362029=362030=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
Wed May 29 13:47:27 2019
@@ -166,8 +166,6 @@ public:
  const char *NL, unsigned int Space,
  bool IsDot) const = 0;
 
-  virtual void EndPath(ProgramStateRef state) {}
-
   /// Convenience method to query the state to see if a symbol is null or
   /// not null, or if neither assumption can be made.
   ConditionTruthVal isNull(ProgramStateRef State, SymbolRef Sym) {

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=362030=362029=362030=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Wed May 29 13:47:27 2019
@@ -634,10 +634,6 @@ public:
 
 return ProgramStateTrait::MakeContext(p);
   }
-
-  void EndPath(ProgramStateRef St) {
-ConstraintMgr->EndPath(St);
-  }
 };
 
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=362030=362029=362030=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed May 29 13:47:27 2019
@@ -2316,7 +2316,6 @@ void ExprEngine::processEndOfFunction(No
Pred->getStackFrame()->getParent()));
 
   PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
-  StateMgr.EndPath(Pred->getState());
 
   ExplodedNodeSet Dst;
   if (Pred->getLocationContext()->inTopFrame()) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r362027 - [analyzer] ConditionBRVisitor: Boolean support

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 13:34:29 2019
New Revision: 362027

URL: http://llvm.org/viewvc/llvm-project?rev=362027=rev
Log:
[analyzer] ConditionBRVisitor: Boolean support

Summary: -

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ, george.karpenkov

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58207

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
cfe/trunk/test/Analysis/inner-pointer.cpp
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=362027=362026=362027=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed May 29 
13:34:29 2019
@@ -2323,10 +2323,17 @@ bool ConditionBRVisitor::printValue(cons
   if (!IsAssuming)
 IntValue = getConcreteIntegerValue(CondVarExpr, N);
 
-  if (IsAssuming || !IntValue.hasValue())
-Out << (TookTrue ? "not equal to 0" : "0");
-  else
-Out << *IntValue.getValue();
+  if (IsAssuming || !IntValue.hasValue()) {
+if (Ty->isBooleanType())
+  Out << (TookTrue ? "true" : "false");
+else
+  Out << (TookTrue ? "not equal to 0" : "0");
+  } else {
+if (Ty->isBooleanType())
+  Out << (IntValue.getValue()->getBoolValue() ? "true" : "false");
+else
+  Out << *IntValue.getValue();
+  }
 
   return true;
 }

Modified: cfe/trunk/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist?rev=362027=362026=362027=diff
==
--- cfe/trunk/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist 
(original)
+++ cfe/trunk/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist Wed 
May 29 13:34:29 2019
@@ -829,9 +829,9 @@

  
  extended_message
- fail is 1
+ fail is true
  message
- fail is 1
+ fail is true
 
 
  kindcontrol

Modified: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp?rev=362027=362026=362027=diff
==
--- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp Wed May 29 
13:34:29 2019
@@ -102,7 +102,7 @@ struct C {
 
   C(int pX, int pY, bool Flag) {
 x = pX;
-if (Flag) // expected-note{{Assuming 'Flag' is not equal to 0}}
+if (Flag) // expected-note{{Assuming 'Flag' is true}}
   // expected-note@-1{{Taking true branch}}
   return; // expected-note{{Returning without writing to 'this->y'}}
 y = pY;

Modified: cfe/trunk/test/Analysis/inner-pointer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inner-pointer.cpp?rev=362027=362026=362027=diff
==
--- cfe/trunk/test/Analysis/inner-pointer.cpp (original)
+++ cfe/trunk/test/Analysis/inner-pointer.cpp Wed May 29 13:34:29 2019
@@ -38,9 +38,9 @@ void deref_after_scope_char(bool cond) {
   std::string s;
   const char *c2 = s.c_str();
   if (cond) {
-// expected-note@-1 {{Assuming 'cond' is not equal to 0}}
+// expected-note@-1 {{Assuming 'cond' is true}}
 // expected-note@-2 {{Taking true branch}}
-// expected-note@-3 {{Assuming 'cond' is 0}}
+// expected-note@-3 {{Assuming 'cond' is false}}
 // expected-note@-4 {{Taking false branch}}
 consume(c); // expected-warning {{Inner pointer of container used after 
re/deallocation}}
 // expected-note@-1 {{Inner pointer of container used after 
re/deallocation}}
@@ -73,9 +73,9 @@ void deref_after_scope_wchar_t(bool cond
   std::wstring s;
   const wchar_t *c2 = s.c_str();
   if (cond) {
-// expected-note@-1 {{Assuming 'cond' is not equal to 0}}
+// expected-note@-1 {{Assuming 'cond' is true}}
 // expected-note@-2 {{Taking true branch}}
-// expected-note@-3 {{Assuming 'cond' is 0}}
+// expected-note@-3 {{Assuming 'cond' is false}}
 // expected-note@-4 {{Taking false branch}}
 consume(c); // expected-warning {{Inner pointer of container used after 
re/deallocation}}
 // expected-note@-1 {{Inner pointer of container used after 
re/deallocation}}
@@ -122,9 +122,9 @@ void 

r362026 - [analyzer] ConditionBRVisitor: MemberExpr support

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 13:29:02 2019
New Revision: 362026

URL: http://llvm.org/viewvc/llvm-project?rev=362026=rev
Log:
[analyzer] ConditionBRVisitor: MemberExpr support

Summary: -

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58206

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/Inputs/expected-plists/edges-new.mm.plist

cfe/trunk/test/Analysis/diagnostics/Inputs/expected-plists/deref-track-symbolic-region.c.plist
cfe/trunk/test/Analysis/diagnostics/deref-track-symbolic-region.c
cfe/trunk/test/Analysis/diagnostics/dtors.cpp
cfe/trunk/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
cfe/trunk/test/Analysis/inlining/path-notes.cpp
cfe/trunk/test/Analysis/null-deref-path-notes.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp
cfe/trunk/test/Analysis/uninit-vals.m

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h?rev=362026=362025=362026=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
Wed May 29 13:29:02 2019
@@ -203,6 +203,11 @@ public:
 bool TookTrue, bool IsAssuming);
 
   std::shared_ptr
+  VisitTrueTest(const Expr *Cond, const MemberExpr *ME, BugReporterContext 
,
+BugReport , const ExplodedNode *N, bool TookTrue,
+bool IsAssuming);
+
+  std::shared_ptr
   VisitConditionVariable(StringRef LhsString, const Expr *CondVarExpr,
  BugReporterContext , BugReport ,
  const ExplodedNode *N, bool TookTrue);
@@ -225,7 +230,8 @@ public:
 BugReporterContext ,
 BugReport ,
 const ExplodedNode *N,
-Optional );
+Optional ,
+bool IsSameFieldName);
 
   static bool isPieceMessageGeneric(const PathDiagnosticPiece *Piece);
 };

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=362026=362025=362026=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed May 29 
13:29:02 2019
@@ -1991,6 +1991,11 @@ ConditionBRVisitor::VisitTrueTest(const
BRC, R, N, TookTrueTmp, IsAssuming))
   return P;
 break;
+  case Stmt::MemberExprClass:
+if (auto P = VisitTrueTest(Cond, cast(CondTmp),
+   BRC, R, N, TookTrueTmp, IsAssuming))
+  return P;
+break;
   case Stmt::UnaryOperatorClass: {
 const auto *UO = cast(CondTmp);
 if (UO->getOpcode() == UO_LNot) {
@@ -2025,7 +2030,8 @@ bool ConditionBRVisitor::patternMatch(co
   BugReporterContext ,
   BugReport ,
   const ExplodedNode *N,
-  Optional ) {
+  Optional ,
+  bool IsSameFieldName) {
   const Expr *OriginalExpr = Ex;
   Ex = Ex->IgnoreParenCasts();
 
@@ -2091,6 +2097,17 @@ bool ConditionBRVisitor::patternMatch(co
 return false;
   }
 
+  if (const auto *ME = dyn_cast(Ex)) {
+if (!IsSameFieldName)
+  Out << "field '" << ME->getMemberDecl()->getName() << '\'';
+else
+  Out << '\''
+  << Lexer::getSourceText(
+ CharSourceRange::getTokenRange(Ex->getSourceRange()),
+ BRC.getSourceManager(), BRC.getASTContext().getLangOpts(), 0)
+  << '\'';
+  }
+
   return false;
 }
 
@@ -2100,13 +2117,23 @@ std::shared_ptr Con
   bool shouldInvert = false;
   Optional shouldPrune;
 
+  // Check if the field name of the MemberExprs is ambiguous. Example:
+  // " 'a.d' is equal to 'h.d' " in 'test/Analysis/null-deref-path-notes.cpp'.
+  bool IsSameFieldName = false;
+  if (const auto *LhsME =
+  dyn_cast(BExpr->getLHS()->IgnoreParenCasts()))
+if (const auto *RhsME =
+dyn_cast(BExpr->getRHS()->IgnoreParenCasts()))
+  IsSameFieldName = LhsME->getMemberDecl()->getName() ==
+

r362025 - [analyzer] ConditionBRVisitor: Remove duplicated code

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 13:18:07 2019
New Revision: 362025

URL: http://llvm.org/viewvc/llvm-project?rev=362025=rev
Log:
[analyzer] ConditionBRVisitor: Remove duplicated code

Summary: -

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58199

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h?rev=362025=362024=362025=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
Wed May 29 13:18:07 2019
@@ -207,6 +207,18 @@ public:
  BugReporterContext , BugReport ,
  const ExplodedNode *N, bool TookTrue);
 
+  /// Tries to print the value of the given expression.
+  ///
+  /// \param CondVarExpr The expression to print its value.
+  /// \param Out The stream to print.
+  /// \param N The node where we encountered the condition.
+  /// \param TookTrue Whether we took the \c true branch of the condition.
+  ///
+  /// \return Whether the print was successful. (The printing is successful if
+  /// we model the value and we could obtain it.)
+  bool printValue(const Expr *CondVarExpr, raw_ostream ,
+  const ExplodedNode *N, bool TookTrue, bool IsAssuming);
+
   bool patternMatch(const Expr *Ex,
 const Expr *ParentEx,
 raw_ostream ,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=362025=362024=362025=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed May 29 
13:18:07 2019
@@ -2190,17 +2190,7 @@ std::shared_ptr Con
   llvm::raw_svector_ostream Out(buf);
   Out << "Assuming " << LhsString << " is ";
 
-  QualType Ty = CondVarExpr->getType();
-
-  if (Ty->isPointerType())
-Out << (TookTrue ? "not null" : "null");
-  else if (Ty->isObjCObjectPointerType())
-Out << (TookTrue ? "not nil" : "nil");
-  else if (Ty->isBooleanType())
-Out << (TookTrue ? "true" : "false");
-  else if (Ty->isIntegralOrEnumerationType())
-Out << (TookTrue ? "non-zero" : "zero");
-  else
+  if (!printValue(CondVarExpr, Out, N, TookTrue, /*IsAssuming=*/true))
 return nullptr;
 
   const LocationContext *LCtx = N->getLocationContext();
@@ -2232,22 +,7 @@ std::shared_ptr Con
 
   Out << (IsAssuming ? "Assuming '" : "'") << VD->getDeclName() << "' is ";
 
-  QualType Ty = VD->getType();
-
-  if (Ty->isPointerType())
-Out << (TookTrue ? "non-null" : "null");
-  else if (Ty->isObjCObjectPointerType())
-Out << (TookTrue ? "non-nil" : "nil");
-  else if (Ty->isScalarType()) {
-Optional IntValue;
-if (!IsAssuming)
-  IntValue = getConcreteIntegerValue(DRE, N);
-
-if (IsAssuming || !IntValue.hasValue())
-  Out << (TookTrue ? "not equal to 0" : "0");
-else
-  Out << *IntValue.getValue();
-  } else
+  if (!printValue(DRE, Out, N, TookTrue, IsAssuming))
 return nullptr;
 
   const LocationContext *LCtx = N->getLocationContext();
@@ -2271,6 +2246,36 @@ std::shared_ptr Con
   return std::move(event);
 }
 
+bool ConditionBRVisitor::printValue(const Expr *CondVarExpr, raw_ostream ,
+const ExplodedNode *N, bool TookTrue,
+bool IsAssuming) {
+  QualType Ty = CondVarExpr->getType();
+
+  if (Ty->isPointerType()) {
+Out << (TookTrue ? "non-null" : "null");
+return true;
+  }
+
+  if (Ty->isObjCObjectPointerType()) {
+Out << (TookTrue ? "non-nil" : "nil");
+return true;
+  }
+
+  if (!Ty->isIntegralOrEnumerationType())
+return false;
+
+  Optional IntValue;
+  if (!IsAssuming)
+IntValue = getConcreteIntegerValue(CondVarExpr, N);
+
+  if (IsAssuming || !IntValue.hasValue())
+Out << (TookTrue ? "not equal to 0" : "0");
+  else
+Out << *IntValue.getValue();
+
+  return true;
+}
+
 const char *const ConditionBRVisitor::GenericTrueMessage =
 "Assuming the condition is true";
 const char *const ConditionBRVisitor::GenericFalseMessage =


___
cfe-commits mailing list
cfe-commits@lists.llvm.org

r362023 - [analyzer] ConditionBRVisitor: Test 'add-pop-up-notes=false'

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 13:13:29 2019
New Revision: 362023

URL: http://llvm.org/viewvc/llvm-project?rev=362023=rev
Log:
[analyzer] ConditionBRVisitor: Test 'add-pop-up-notes=false'

Summary: -

Reviewers: NoQ, alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61060

Modified:

cfe/trunk/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
cfe/trunk/test/Analysis/NewDelete-path-notes.cpp

Modified: 
cfe/trunk/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist?rev=362023=362022=362023=diff
==
--- 
cfe/trunk/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist 
(original)
+++ 
cfe/trunk/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist 
Wed May 29 13:13:29 2019
@@ -13,30 +13,30 @@
  kindevent
  location
  
-  line7
-  col12
+  line24
+  col3
   file0
  
  ranges
  

 
- line7
- col12
+ line24
+ col3
  file0
 
 
- line7
- col18
+ line24
+ col10
  file0
 

  
  depth0
  extended_message
- Memory is allocated
+ Attempt to free released memory
  message
- Memory is allocated
+ Attempt to free released memory
 
 
  kindcontrol
@@ -46,26 +46,26 @@
 start
  
   
-   line7
-   col3
+   line17
+   col1
file0
   
   
-   line7
-   col5
+   line17
+   col4
file0
   
  
 end
  
   
-   line9
+   line18
col3
file0
   
   
-   line9
-   col4
+   line18
+   col5
file0
   
  
@@ -73,6 +73,35 @@
   
 
 
+ kindevent
+ location
+ 
+  line18
+  col12
+  file0
+ 
+ ranges
+ 
+   
+
+ line18
+ col12
+ file0
+
+
+ line18
+ col18
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Memory is allocated
+ message
+ Memory is allocated
+
+
  kindcontrol
  edges
   
@@ -80,26 +109,26 @@
 start
  
   
-   line9
+   line18
col3
file0
   
   
-   line9
-   col4
+   line18
+   col5
file0
   
  
 end
  
   
-   line9
-   col7
+   line20
+   col3
file0
   
   
-   line9
-   col7
+   line20
+   col4
file0
   
  
@@ -107,34 +136,6 @@
   
 
 
- kindpop-up
- location
- 
-  line9
-  col7
-  file0
- 
- ranges
- 
-   
-
- line9
- col7
- file0
-
-
- line9
- col7
- file0
-
-   
- 
- extended_message
- p is non-null
- message
- p is non-null
-
-
  kindcontrol
  edges
   
@@ -142,25 +143,25 @@
 start
  
   
-   line9
-   col7
+   line20
+   col3
file0
   
   
-   line9
-   col7
+   line20
+   col4
file0
   
  
 end
  
   
-   line11
+   line21
col5
file0
   
   
-   line11
+   line21
col10
file0
   
@@ -172,7 +173,7 @@
  kindevent
  location
  
-  line11
+  line21
   col5
   file0
  
@@ -180,12 +181,12 @@
  

 
- line11
+ line21
  col5
  file0
 
 
- line11
+ line21
  col12
  file0
 
@@ -205,12 +206,12 @@
 start
  
   
-   line11
+   line21
col5
file0
   
   
-   line11
+   line21
col10
file0
   
@@ -218,12 +219,12 @@
 end
  
   
-   line14
+   line24
col3
file0
   
   
-   line14
+   line24
col8
file0
   
@@ -231,35 +232,6 @@


r362014 - [analyzer] [NFC] PathDiagnostic: Create PathDiagnosticPopUpPiece

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 12:21:59 2019
New Revision: 362014

URL: http://llvm.org/viewvc/llvm-project?rev=362014=rev
Log:
[analyzer] [NFC] PathDiagnostic: Create PathDiagnosticPopUpPiece

Summary:
This new piece is similar to our macro expansion printing in HTML reports:
On mouse-hover event it pops up on variables. Similar to note pieces it
supports `plist` diagnostics as well.

It is optional, on by default: `add-pop-up-notes=true`.

Extra: In HTML reports `background-color: LemonChiffon` was too light,
changed to `PaleGoldenRod`.

Reviewers: NoQ, alexfh

Reviewed By: NoQ

Subscribers: cfe-commits, gerazo, gsd, george.karpenkov, alexfh, xazax.hun,
 baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho,
 Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60670

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
cfe/trunk/test/Analysis/analyzer-config.c

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def?rev=362014=362013=362014=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def Wed May 29 
12:21:59 2019
@@ -204,6 +204,10 @@ ANALYZER_OPTION(bool, ShouldPrunePaths,
 "be pruned out of the final output.",
 true)
 
+ANALYZER_OPTION(bool, ShouldAddPopUpNotes, "add-pop-up-notes",
+"Whether pop-up notes should be added to the final output.",
+true)
+
 ANALYZER_OPTION(
 bool, ShouldConditionalizeStaticInitializers,
 "cfg-conditional-static-initializers",

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=362014=362013=362014=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
Wed May 29 12:21:59 2019
@@ -367,7 +367,7 @@ public:
 
 class PathDiagnosticPiece: public llvm::FoldingSetNode {
 public:
-  enum Kind { ControlFlow, Event, Macro, Call, Note };
+  enum Kind { ControlFlow, Event, Macro, Call, Note, PopUp };
   enum DisplayHint { Above, Below };
 
 private:
@@ -482,7 +482,7 @@ public:
 
   static bool classof(const PathDiagnosticPiece *P) {
 return P->getKind() == Event || P->getKind() == Macro ||
-   P->getKind() == Note;
+   P->getKind() == Note || P->getKind() == PopUp;
   }
 };
 
@@ -746,7 +746,7 @@ public:
 class PathDiagnosticNotePiece: public PathDiagnosticSpotPiece {
 public:
   PathDiagnosticNotePiece(const PathDiagnosticLocation , StringRef S,
-   bool AddPosRange = true)
+  bool AddPosRange = true)
   : PathDiagnosticSpotPiece(Pos, S, Note, AddPosRange) {}
   ~PathDiagnosticNotePiece() override;
 
@@ -755,6 +755,22 @@ public:
   }
 
   void dump() const override;
+
+  void Profile(llvm::FoldingSetNodeID ) const override;
+};
+
+class PathDiagnosticPopUpPiece: public PathDiagnosticSpotPiece {
+public:
+  PathDiagnosticPopUpPiece(const PathDiagnosticLocation , StringRef S,
+   bool AddPosRange = true)
+  : PathDiagnosticSpotPiece(Pos, S, PopUp, AddPosRange) {}
+  ~PathDiagnosticPopUpPiece() override;
+
+  static bool classof(const PathDiagnosticPiece *P) {
+return P->getKind() == PopUp;
+  }
+
+  void dump() const override;
 
   void Profile(llvm::FoldingSetNodeID ) const override;
 };

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=362014=362013=362014=diff
==
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Wed May 29 12:21:59 2019
@@ -306,14 +306,16 @@ h1 { font-size:14pt }
 .keyword { color: blue }
 .string_literal { color: red }
 .directive { color: darkmagenta }
-/* Macro expansions. */
-.expansion { display: none; }
-.macro:hover .expansion {
+
+/* Macros and variables could have pop-up notes hidden by default.
+  - Macro pop-up:expansion of the macro
+  - 

r362011 - [analyzer] print() JSONify chain: Generic stmt_id

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 11:58:41 2019
New Revision: 362011

URL: http://llvm.org/viewvc/llvm-project?rev=362011=rev
Log:
[analyzer] print() JSONify chain: Generic stmt_id

Summary: Some environment create less statements so make them generic.

Modified:
cfe/trunk/test/Analysis/dump_egraph.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: cfe/trunk/test/Analysis/dump_egraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=362011=362010=362011=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.cpp (original)
+++ cfe/trunk/test/Analysis/dump_egraph.cpp Wed May 29 11:58:41 2019
@@ -16,9 +16,9 @@ void foo() {
   T t;
 }
 
-// CHECK: \"constructing_objects\": [\l\{ 
\"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, 
\"items\": [\l\{ \"lctx_id\": 
1, \"stmt_id\": 1155, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
+// CHECK: \"constructing_objects\": [\l\{ 
\"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, 
\"items\": [\l\{ \"lctx_id\": 
1, \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
 
-// CHECK: \"constructing_objects\": [\l\{ 
\"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": 
\"16\", \"items\": [\l\{ 
\"lctx_id\": 2, \"init_id\": 1092, \"kind\": \"construct into member 
variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
+// CHECK: \"constructing_objects\": [\l\{ 
\"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": 
\"16\", \"items\": [\l\{ 
\"lctx_id\": 2, \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member 
variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
 
 // CHECK: \"store\": [\l\{ \"cluster\": 
\"t\", \"items\": [\l\{ 
\"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, 
#1\}\"
 

Modified: cfe/trunk/test/Analysis/expr-inspection.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/expr-inspection.c?rev=362011=362010=362011=diff
==
--- cfe/trunk/test/Analysis/expr-inspection.c (original)
+++ cfe/trunk/test/Analysis/expr-inspection.c Wed May 29 11:58:41 2019
@@ -31,7 +31,7 @@ void foo(int x) {
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "environment": [
 // CHECK-NEXT: { "location_context": "#0 Call", "calling": "foo", 
"call_line": null, "items": [
-// CHECK-NEXT:   { "lctx_id": 1, "stmt_id": 847, "pretty": 
"clang_analyzer_printState", "value": "{clang_analyzer_printState}" }
+// CHECK-NEXT:   { "lctx_id": 1, "stmt_id": {{[0-9]+}}, "pretty": 
"clang_analyzer_printState", "value": "{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "constraints": [


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r362008 - [analyzer] print() JSONify: SVal implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 11:38:52 2019
New Revision: 362008

URL: http://llvm.org/viewvc/llvm-project?rev=362008=rev
Log:
[analyzer] print() JSONify: SVal implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
 Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62497

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h?rev=362008=362007=362008=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h Wed May 
29 11:38:52 2019
@@ -190,6 +190,9 @@ public:
 
   const MemRegion *getAsRegion() const;
 
+  /// printJson - Pretty-prints in JSON format.
+  void printJson(raw_ostream , bool AddQuotes) const;
+
   void dumpToStream(raw_ostream ) const;
   void dump() const;
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=362008=362007=362008=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Wed May 29 11:38:52 2019
@@ -263,10 +263,12 @@ void Environment::printJson(raw_ostream
   Indent(Out, InnerSpace, IsDot)
   << "{ \"lctx_id\": " << LC->getID()
   << ", \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
-
   S->printJson(Out, nullptr, PP, /*AddQuotes=*/true);
 
-  Out << ", \"value\": \"" << I->second << "\" }";
+  Out << ", \"value\": ";
+  I->second.printJson(Out, /*AddQuotes=*/true);
+
+  Out << " }";
 
   if (I != LastI)
 Out << ',';

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp?rev=362008=362007=362008=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp Wed May 29 11:38:52 2019
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
@@ -283,6 +284,15 @@ SVal loc::ConcreteInt::evalBinOp(BasicVa
 
 LLVM_DUMP_METHOD void SVal::dump() const { dumpToStream(llvm::errs()); }
 
+void SVal::printJson(raw_ostream , bool AddQuotes) const {
+  std::string Buf;
+  llvm::raw_string_ostream TempOut(Buf);
+
+  dumpToStream(TempOut);
+
+  Out << JsonFormat(TempOut.str(), AddQuotes);
+}
+
 void SVal::dumpToStream(raw_ostream ) const {
   switch (getBaseKind()) {
 case UnknownValKind:


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r362003 - [analyzer] print() JSONify: CFG implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 11:29:31 2019
New Revision: 362003

URL: http://llvm.org/viewvc/llvm-project?rev=362003=rev
Log:
[analyzer] print() JSONify: CFG implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
 donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62496

Modified:
cfe/trunk/include/clang/Analysis/CFG.h
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Analysis/ProgramPoint.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=362003=362002=362003=diff
==
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Wed May 29 11:29:31 2019
@@ -882,7 +882,11 @@ public:
   void dump(const CFG *cfg, const LangOptions , bool ShowColors = false) 
const;
   void print(raw_ostream , const CFG* cfg, const LangOptions ,
  bool ShowColors) const;
+
   void printTerminator(raw_ostream , const LangOptions ) const;
+  void printTerminatorJson(raw_ostream , const LangOptions ,
+   bool AddQuotes) const;
+  
   void printAsOperand(raw_ostream , bool /*PrintType*/) {
 OS << "BB#" << getBlockID();
   }

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=362003=362002=362003=diff
==
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed May 29 11:29:31 2019
@@ -27,10 +27,11 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
-#include "clang/Analysis/Support/BumpVector.h"
 #include "clang/Analysis/ConstructionContext.h"
+#include "clang/Analysis/Support/BumpVector.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
@@ -5561,6 +5562,17 @@ void CFGBlock::printTerminator(raw_ostre
   TPrinter.print(getTerminator());
 }
 
+/// printTerminatorJson - Pretty-prints the terminator in JSON format.
+void CFGBlock::printTerminatorJson(raw_ostream , const LangOptions ,
+   bool AddQuotes) const {
+  std::string Buf;
+  llvm::raw_string_ostream TempOut(Buf);
+
+  printTerminator(TempOut, LO);
+
+  Out << JsonFormat(TempOut.str(), AddQuotes);
+}
+
 Stmt *CFGBlock::getTerminatorCondition(bool StripParens) {
   Stmt *Terminator = getTerminatorStmt();
   if (!Terminator)

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=362003=362002=362003=diff
==
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Wed May 29 11:29:31 2019
@@ -149,13 +149,16 @@ void ProgramPoint::printJson(llvm::raw_o
 const BlockEdge  = castAs();
 const Stmt *T = E.getSrc()->getTerminatorStmt();
 Out << "Edge\", \"src_id\": " << E.getSrc()->getBlockID()
-<< ", \"dst_id\": " << E.getDst()->getBlockID()
-<< ", \"terminator\": " << (!T ? "null, \"term_kind\": null" : "\"");
-if (!T)
+<< ", \"dst_id\": " << E.getDst()->getBlockID() << ", \"terminator\": 
";
+
+if (!T) {
+  Out << "null, \"term_kind\": null";
   break;
+}
 
-E.getSrc()->printTerminator(Out, Context.getLangOpts());
-Out << "\", ";
+E.getSrc()->printTerminatorJson(Out, Context.getLangOpts(),
+/*AddQuotes=*/true);
+Out << ", ";
 printLocJson(Out, T->getBeginLoc(), SM);
 
 Out << ", \"term_kind\": \"";


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r362002 - [analyzer] print() JSONify: Decl revision

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 11:21:14 2019
New Revision: 362002

URL: http://llvm.org/viewvc/llvm-project?rev=362002=rev
Log:
[analyzer] print() JSONify: Decl revision

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
 donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62495

Modified:
cfe/trunk/lib/Analysis/ProgramPoint.cpp

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=362002=362001=362002=diff
==
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Wed May 29 11:21:14 2019
@@ -116,18 +116,16 @@ void ProgramPoint::printJson(llvm::raw_o
 
   case ProgramPoint::PreImplicitCallKind: {
 ImplicitCallPoint PC = castAs();
-Out << "PreCall\", \"stmt\": \"";
-PC.getDecl()->print(Out, Context.getLangOpts());
-Out << "\", ";
+Out << "PreCall\", \"decl\": \""
+<< PC.getDecl()->getAsFunction()->getQualifiedNameAsString() << "\", ";
 printLocJson(Out, PC.getLocation(), SM);
 break;
   }
 
   case ProgramPoint::PostImplicitCallKind: {
 ImplicitCallPoint PC = castAs();
-Out << "PostCall\", \"stmt\": \"";
-PC.getDecl()->print(Out, Context.getLangOpts());
-Out << "\", ";
+Out << "PostCall\", \"decl\": \""
+<< PC.getDecl()->getAsFunction()->getQualifiedNameAsString() << "\", ";
 printLocJson(Out, PC.getLocation(), SM);
 break;
   }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r362000 - [analyzer][AST] print() JSONify: Stmt implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 11:17:18 2019
New Revision: 362000

URL: http://llvm.org/viewvc/llvm-project?rev=362000=rev
Log:
[analyzer][AST] print() JSONify: Stmt implementation

Summary:
This patch also adds a function called `JsonFormat()` which:
- Flattens the string so removes the new-lines.
- Escapes double quotes.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
 donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62494

Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/JsonSupport.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Analysis/ProgramPoint.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=362000=361999=362000=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed May 29 11:17:18 2019
@@ -1100,6 +1100,10 @@ public:
StringRef NewlineSymbol = "\n",
const ASTContext *Context = nullptr) const;
 
+  /// Pretty-prints in JSON format.
+  void printJson(raw_ostream , PrinterHelper *Helper,
+ const PrintingPolicy , bool AddQuotes) const;
+
   /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
   ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
   void viewAST() const;

Modified: cfe/trunk/include/clang/Basic/JsonSupport.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/JsonSupport.h?rev=362000=361999=362000=diff
==
--- cfe/trunk/include/clang/Basic/JsonSupport.h (original)
+++ cfe/trunk/include/clang/Basic/JsonSupport.h Wed May 29 11:17:18 2019
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_BASIC_JSONSUPPORT_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
 
 
@@ -22,6 +23,41 @@ inline raw_ostream (raw_ostream &
   return Out;
 }
 
+inline std::string JsonFormat(StringRef RawSR, bool AddQuotes) {
+  if (RawSR.empty())
+return "null";
+
+  // Trim special characters.
+  std::string Str = RawSR.trim().str();
+  size_t Pos = 0;
+
+  // Escape double quotes.
+  while (true) {
+Pos = Str.find('\"', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current double quote is escaped.
+if (TempPos != Str.find("\\\"", TempPos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the escape-character move plus one.
+}
+
+++Pos;
+  }
+
+  // Remove new-lines.
+  Str.erase(std::remove(Str.begin(), Str.end(), '\n'), Str.end());
+
+  if (!AddQuotes)
+return Str;
+
+  return '\"' + Str + '\"';
+}
+
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_JSONSUPPORT_H

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=362000=361999=362000=diff
==
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Wed May 29 11:17:18 2019
@@ -36,6 +36,7 @@
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/ExpressionTraits.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Lambda.h"
 #include "clang/Basic/OpenMPKinds.h"
@@ -2395,12 +2396,21 @@ void Stmt::dumpPretty(const ASTContext &
   printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts()));
 }
 
-void Stmt::printPretty(raw_ostream , PrinterHelper *Helper,
+void Stmt::printPretty(raw_ostream , PrinterHelper *Helper,
const PrintingPolicy , unsigned Indentation,
-   StringRef NL,
-   const ASTContext *Context) const {
-  StmtPrinter P(OS, Helper, Policy, Indentation, NL, Context);
-  P.Visit(const_cast(this));
+   StringRef NL, const ASTContext *Context) const {
+  StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context);
+  P.Visit(const_cast(this));
+}
+
+void Stmt::printJson(raw_ostream , PrinterHelper *Helper,
+ const PrintingPolicy , bool AddQuotes) const {
+  std::string Buf;
+  llvm::raw_string_ostream TempOut(Buf);
+
+  printPretty(TempOut, Helper, Policy);
+
+  Out << JsonFormat(TempOut.str(), AddQuotes);
 }
 
 
//===--===//

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: 

r361997 - [analyzer] print() JSONify: getNodeLabel implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 11:05:53 2019
New Revision: 361997

URL: http://llvm.org/viewvc/llvm-project?rev=361997=rev
Log:
[analyzer] print() JSONify: getNodeLabel implementation

Summary: This patch also rewrites the ProgramPoint printing.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
 donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62346

Modified:
cfe/trunk/include/clang/Analysis/ProgramPoint.h
cfe/trunk/lib/Analysis/ProgramPoint.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/dump_egraph.c
cfe/trunk/test/Analysis/dump_egraph.cpp

Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=361997=361996=361997=diff
==
--- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Wed May 29 11:05:53 2019
@@ -213,7 +213,7 @@ public:
 ID.AddPointer(getTag());
   }
 
-  void print(StringRef CR, llvm::raw_ostream ) const;
+  void printJson(llvm::raw_ostream , const char *NL = "\n") const;
 
   LLVM_DUMP_METHOD void dump() const;
 

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=361997=361996=361997=diff
==
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Wed May 29 11:05:53 2019
@@ -43,151 +43,152 @@ ProgramPoint ProgramPoint::getProgramPoi
 }
 
 LLVM_DUMP_METHOD void ProgramPoint::dump() const {
-  return print(/*CR=*/"\n", llvm::errs());
+  return printJson(llvm::errs());
 }
 
-static void printLocation(raw_ostream , SourceLocation SLoc,
-  const SourceManager ,
-  StringRef CR,
-  StringRef Postfix) {
-  if (SLoc.isFileID()) {
-Out << CR << "line=" << SM.getExpansionLineNumber(SLoc)
-<< " col=" << SM.getExpansionColumnNumber(SLoc) << Postfix;
+static void printLocation(raw_ostream , SourceLocation Loc,
+  const SourceManager ) {
+  Out << "\"location\": ";
+  if (!Loc.isFileID()) {
+Out << "null";
+return;
   }
+
+  Out << "{ \"line\": " << SM.getExpansionLineNumber(Loc)
+  << ", \"column\": " << SM.getExpansionColumnNumber(Loc) << " }";
 }
 
-void ProgramPoint::print(StringRef CR, llvm::raw_ostream ) const {
+void ProgramPoint::printJson(llvm::raw_ostream , const char *NL) const {
   const ASTContext  =
   getLocationContext()->getAnalysisDeclContext()->getASTContext();
   const SourceManager  = Context.getSourceManager();
+
+  Out << "\"kind\": \"";
   switch (getKind()) {
   case ProgramPoint::BlockEntranceKind:
-Out << "Block Entrance: B"
+Out << "BlockEntrance\""
+<< ", \"block_id\": "
 << castAs().getBlock()->getBlockID();
 break;
 
   case ProgramPoint::FunctionExitKind: {
 auto FEP = getAs();
-Out << "Function Exit: B" << FEP->getBlock()->getBlockID();
+Out << "FunctionExit\""
+<< ", \"block_id\": " << FEP->getBlock()->getBlockID()
+<< ", \"stmt_id\": ";
+
 if (const ReturnStmt *RS = FEP->getStmt()) {
-  Out << CR << " Return: S" << RS->getID(Context) << CR;
-  RS->printPretty(Out, /*helper=*/nullptr, Context.getPrintingPolicy(),
-  /*Indentation=*/2, /*NewlineSymbol=*/CR);
+  Out << RS->getID(Context) << ", \"stmt\": \"";
+  RS->printPretty(Out, /*Helper=*/nullptr, Context.getPrintingPolicy());
+  Out << '\"';
+} else {
+  Out << "null, \"stmt\": null";
 }
 break;
   }
   case ProgramPoint::BlockExitKind:
-assert(false);
+llvm_unreachable("BlockExitKind");
 break;
-
   case ProgramPoint::CallEnterKind:
-Out << "CallEnter";
+Out << "CallEnter\"";
 break;
-
   case ProgramPoint::CallExitBeginKind:
-Out << "CallExitBegin";
+Out << "CallExitBegin\"";
 break;
-
   case ProgramPoint::CallExitEndKind:
-Out << "CallExitEnd";
+Out << "CallExitEnd\"";
 break;
-
   case ProgramPoint::PostStmtPurgeDeadSymbolsKind:
-Out << "PostStmtPurgeDeadSymbols";
+Out << "PostStmtPurgeDeadSymbols\"";
 break;
-
   case ProgramPoint::PreStmtPurgeDeadSymbolsKind:
-Out << "PreStmtPurgeDeadSymbols";
+Out << "PreStmtPurgeDeadSymbols\"";
 break;
-
   case ProgramPoint::EpsilonKind:
-Out << "Epsilon Point";
+Out << "EpsilonPoint\"";
 break;
 
-  case ProgramPoint::LoopExitKind: {
-LoopExit LE = castAs();
-Out << "LoopExit: " << LE.getLoopStmt()->getStmtClassName();
+  case ProgramPoint::LoopExitKind:
+Out << "LoopExit\", \"stmt\": \""
+<< 

r361983 - [analyzer] print() JSONify: Program state implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 09:22:21 2019
New Revision: 361983

URL: http://llvm.org/viewvc/llvm-project?rev=361983=rev
Log:
[analyzer] print() JSONify: Program state implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62087

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/test/Analysis/dump_egraph.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=361983=361982=361983=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Wed May 29 09:22:21 2019
@@ -425,8 +425,8 @@ public:
 
   // Pretty-printing.
   void printJson(raw_ostream , const LocationContext *LCtx = nullptr,
- const char *NL = "\n", const char *Sep = "",
- unsigned int Space = 0, bool IsDot = false) const;
+ const char *NL = "\n", unsigned int Space = 0,
+ bool IsDot = false) const;
 
   void printDOT(raw_ostream , const LocationContext *LCtx = nullptr,
 unsigned int Space = 0) const;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=361983=361982=361983=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Wed May 29 09:22:21 2019
@@ -10,13 +10,14 @@
 //
 
//===--===//
 
-#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Basic/JsonSupport.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -441,15 +442,18 @@ void ProgramState::setStore(const StoreR
 
//===--===//
 
 void ProgramState::printJson(raw_ostream , const LocationContext *LCtx,
- const char *NL, const char *Sep,
- unsigned int Space, bool IsDot) const {
-  // Print the store.
+ const char *NL, unsigned int Space,
+ bool IsDot) const {
+  Indent(Out, Space, IsDot) << "\"program_state\": {" << NL;
+  ++Space;
+
   ProgramStateManager  = getStateManager();
-  const ASTContext  = getStateManager().getContext();
+
+  // Print the store.
   Mgr.getStoreManager().printJson(Out, getStore(), NL, Space, IsDot);
 
   // Print out the environment.
-  Env.printJson(Out, Context, LCtx, NL, Space, IsDot);
+  Env.printJson(Out, Mgr.getContext(), LCtx, NL, Space, IsDot);
 
   // Print out the constraints.
   Mgr.getConstraintManager().printJson(Out, this, NL, Space, IsDot);
@@ -459,11 +463,14 @@ void ProgramState::printJson(raw_ostream
 
   // Print checker-specific data.
   Mgr.getOwningEngine().printJson(Out, this, LCtx, NL, Space, IsDot);
+
+  --Space;
+  Indent(Out, Space, IsDot) << '}';
 }
 
 void ProgramState::printDOT(raw_ostream , const LocationContext *LCtx,
 unsigned int Space) const {
-  printJson(Out, LCtx, "\\l", "\\|", Space, /*IsDot=*/true);
+  printJson(Out, LCtx, /*NL=*/"\\l", Space, /*IsDot=*/true);
 }
 
 LLVM_DUMP_METHOD void ProgramState::dump() const {

Modified: cfe/trunk/test/Analysis/dump_egraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=361983=361982=361983=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.cpp (original)
+++ cfe/trunk/test/Analysis/dump_egraph.cpp Wed May 29 09:22:21 2019
@@ -16,9 +16,9 @@ void foo() {
   T t;
 }
 
-// CHECK: \"constructing_objects\": [\l\{ \"location_context\": 
\"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": 
[\l\{ \"lctx_id\": 

r361982 - [analyzer] print() JSONify: Checker messages implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 09:02:33 2019
New Revision: 361982

URL: http://llvm.org/viewvc/llvm-project?rev=361982=rev
Log:
[analyzer] print() JSONify: Checker messages implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62086

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/expr-inspection.c
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h?rev=361982=361981=361982=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h Wed May 29 
09:02:33 2019
@@ -406,16 +406,21 @@ public:
   ///
   /// Unlike most other callbacks, any checker can simply implement the virtual
   /// method CheckerBase::printState if it has custom data to print.
-  /// \param Out The output stream
+  ///
+  /// \param Out   The output stream
   /// \param State The state being printed
-  /// \param NL The preferred representation of a newline.
-  /// \param Sep The preferred separator between different kinds of data.
-  void runCheckersForPrintState(raw_ostream , ProgramStateRef State,
-const char *NL, const char *Sep);
+  /// \param NLThe preferred representation of a newline.
+  /// \param Sep   The preferred separator between different messages.
+  /// \param Space The preferred space between the left side and the message.
+  /// \param IsDot Whether the message will be printed in 'dot' format.
+  void runCheckersForPrintStateJson(raw_ostream , ProgramStateRef State,
+const char *NL = "\n",
+unsigned int Space = 0,
+bool IsDot = false) const;
 
-//===--===//
-// Internal registration functions for AST traversing.
-//===--===//
+  
//===--===//
+  // Internal registration functions for AST traversing.
+  
//===--===//
 
   // Functions used by the registration mechanism, checkers should not touch
   // these directly.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp?rev=361982=361981=361982=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp Wed May 29 09:02:33 
2019
@@ -14,6 +14,7 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Analysis/ProgramPoint.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -698,11 +699,73 @@ void CheckerManager::runCheckersOnEndOfT
 EndOfTranslationUnitChecker(TU, mgr, BR);
 }
 
-void CheckerManager::runCheckersForPrintState(raw_ostream ,
-  ProgramStateRef State,
-  const char *NL, const char *Sep) 
{
-  for (const auto  : CheckerTags)
-CheckerTag.second->printState(Out, State, NL, Sep);
+void CheckerManager::runCheckersForPrintStateJson(raw_ostream ,
+  ProgramStateRef State,
+  const char *NL,
+  unsigned int Space,
+  bool IsDot) const {
+  Indent(Out, Space, IsDot) << "\"checker_messages\": ";
+
+  // Create a temporary stream to see whether we have any message.
+  SmallString<1024> TempBuf;
+  llvm::raw_svector_ostream TempOut(TempBuf);
+  unsigned int InnerSpace = Space + 2;
+
+  // Create the new-line in JSON with enough space.
+  SmallString<128> NewLine;
+  llvm::raw_svector_ostream NLOut(NewLine);
+  NLOut << "\", " << NL; // Inject the ending and a new 
line
+  Indent(NLOut, InnerSpace, IsDot) << "\"";  // then begin the next message.
+
+  ++Space;
+  bool HasMessage = false;
+
+  // Store the last CheckerTag.
+  const void *LastCT = nullptr;
+  for (const 

r361980 - [analyzer] print() JSONify: Constructing objects implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 08:58:26 2019
New Revision: 361980

URL: http://llvm.org/viewvc/llvm-project?rev=361980=rev
Log:
[analyzer] print() JSONify: Constructing objects implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62085

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/test/Analysis/dump_egraph.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=361980=361979=361980=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Wed 
May 29 08:58:26 2019
@@ -376,10 +376,10 @@ public:
const LocationContext *LCtx,
const CallEvent *Call) override;
 
-  /// printState - Called by ProgramStateManager to print checker-specific 
data.
-  void printState(raw_ostream , ProgramStateRef State,
-  const LocationContext *LCtx, const char *NL,
-  unsigned int Space, bool IsDot) const override;
+  /// printJson - Called by ProgramStateManager to print checker-specific data.
+  void printJson(raw_ostream , ProgramStateRef State,
+ const LocationContext *LCtx, const char *NL,
+ unsigned int Space, bool IsDot) const override;
 
   ProgramStateManager () override { return StateMgr; }
 

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h?rev=361980=361979=361980=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h Wed 
May 29 08:58:26 2019
@@ -158,10 +158,10 @@ public:
const CallEvent *Call,
RegionAndSymbolInvalidationTraits ) = 0;
 
-  /// printState - Called by ProgramStateManager to print checker-specific 
data.
-  virtual void printState(raw_ostream , ProgramStateRef State,
-  const LocationContext *LCtx, const char *NL,
-  unsigned int Space, bool IsDot) const = 0;
+  /// printJson - Called by ProgramStateManager to print checker-specific data.
+  virtual void printJson(raw_ostream , ProgramStateRef State,
+ const LocationContext *LCtx, const char *NL,
+ unsigned int Space, bool IsDot) const = 0;
 
   /// Called by CoreEngine when the analysis worklist is either empty or the
   //  maximum number of analysis steps have been reached.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=361980=361979=361980=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed May 29 08:58:26 2019
@@ -33,6 +33,7 @@
 #include "clang/Analysis/ConstructionContext.h"
 #include "clang/Analysis/ProgramPoint.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/PrettyStackTrace.h"
@@ -141,21 +142,47 @@ public:
 return getLocationContext()->getDecl()->getASTContext();
   }
 
-  void print(llvm::raw_ostream , PrinterHelper *Helper, PrintingPolicy ) 
{
-OS << "(LC" << getLocationContext()->getID() << ',';
-if (const Stmt *S = getItem().getStmtOrNull())
-  OS << 'S' << S->getID(getASTContext());
+  void printJson(llvm::raw_ostream , PrinterHelper *Helper,
+ PrintingPolicy ) const {
+const Stmt *S = getItem().getStmtOrNull();
+const CXXCtorInitializer *I = nullptr;
+if (!S)
+  I = getItem().getCXXCtorInitializer();
+
+// IDs
+Out << "\"lctx_id\": " << getLocationContext()->getID() << ", ";
+
+if (S)
+  Out << "\"stmt_id\": " << S->getID(getASTContext());
 else
-  OS << 'I' << getItem().getCXXCtorInitializer()->getID(getASTContext());
-OS << ',' << getItem().getKindAsString();
+  Out << 

r361979 - [analyzer] print() JSONify: Type information implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 08:53:12 2019
New Revision: 361979

URL: http://llvm.org/viewvc/llvm-project?rev=361979=rev
Log:
[analyzer] print() JSONify: Type information implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62083

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h?rev=361979=361978=361979=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h 
Wed May 29 08:53:12 2019
@@ -29,12 +29,11 @@ class MemRegion;
 /// symbol to its most likely type.
 struct DynamicTypeMap {};
 
-using DynamicTypeMapImpl =
-llvm::ImmutableMap;
+using DynamicTypeMapTy = llvm::ImmutableMap;
 
 template <>
 struct ProgramStateTrait
-: public ProgramStatePartialTrait {
+: public ProgramStatePartialTrait {
   static void *GDMIndex();
 };
 
@@ -54,8 +53,9 @@ inline ProgramStateRef setDynamicTypeInf
 DynamicTypeInfo(NewTy, CanBeSubClassed));
 }
 
-void printDynamicTypeInfo(ProgramStateRef State, raw_ostream ,
-  const char *NL, const char *Sep);
+void printDynamicTypeInfoJson(raw_ostream , ProgramStateRef State,
+  const char *NL = "\n", unsigned int Space = 0,
+  bool IsDot = false);
 
 } // namespace ento
 } // namespace clang

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp?rev=361979=361978=361979=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp Wed May 29 
08:53:12 2019
@@ -114,8 +114,8 @@ public:
 void DynamicTypePropagation::checkDeadSymbols(SymbolReaper ,
   CheckerContext ) const {
   ProgramStateRef State = C.getState();
-  DynamicTypeMapImpl TypeMap = State->get();
-  for (DynamicTypeMapImpl::iterator I = TypeMap.begin(), E = TypeMap.end();
+  DynamicTypeMapTy TypeMap = State->get();
+  for (DynamicTypeMapTy::iterator I = TypeMap.begin(), E = TypeMap.end();
I != E; ++I) {
 if (!SR.isLiveRegion(I->first)) {
   State = State->remove(I->first);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp?rev=361979=361978=361979=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp Wed May 29 08:53:12 
2019
@@ -13,6 +13,7 @@
 
//===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -53,27 +54,38 @@ ProgramStateRef setDynamicTypeInfo(Progr
   return NewState;
 }
 
-void printDynamicTypeInfo(ProgramStateRef State, raw_ostream ,
-  const char *NL, const char *Sep) {
-  bool First = true;
-  for (const auto  : State->get()) {
-if (First) {
-  Out << NL << "Dynamic types of regions:" << NL;
-  First = false;
-}
-const MemRegion *MR = I.first;
-const DynamicTypeInfo  = I.second;
-Out << MR << " : ";
+void printDynamicTypeInfoJson(raw_ostream , ProgramStateRef State,
+  const char *NL, unsigned int Space, bool IsDot) {
+  Indent(Out, Space, IsDot) << "\"dynamic_types\": ";
+
+  const DynamicTypeMapTy  = State->get();
+  if (DTM.isEmpty()) {
+Out << "null," << NL;
+return;
+  }
+
+  ++Space;
+  Out << '[' << NL;
+  for (DynamicTypeMapTy::iterator I = DTM.begin(); I != DTM.end(); ++I) {
+const MemRegion *MR = I->first;
+const DynamicTypeInfo  = I->second;
+Out << "{ \"region\": \"" << MR << "\", \"dyn_type\": ";
 

r361978 - [analyzer] print() JSONify: Constraints implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 08:43:26 2019
New Revision: 361978

URL: http://llvm.org/viewvc/llvm-project?rev=361978=rev
Log:
[analyzer] print() JSONify: Constraints implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62082

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=361978=361977=361978=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
Wed May 29 08:43:26 2019
@@ -162,10 +162,9 @@ public:
   virtual ProgramStateRef removeDeadBindings(ProgramStateRef state,
  SymbolReaper& SymReaper) = 0;
 
-  virtual void print(ProgramStateRef state,
- raw_ostream ,
- const char* nl,
- const char *sep) = 0;
+  virtual void printJson(raw_ostream , ProgramStateRef State,
+ const char *NL, unsigned int Space,
+ bool IsDot) const = 0;
 
   virtual void EndPath(ProgramStateRef state) {}
 

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h?rev=361978=361977=361978=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 (original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 Wed May 29 08:43:26 2019
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONSTRAINTMANAGER_H
 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONSTRAINTMANAGER_H
 
+#include "clang/Basic/JsonSupport.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h"
 
@@ -208,17 +209,32 @@ public:
 return State->set(CZ);
   }
 
-  void print(ProgramStateRef St, raw_ostream , const char *nl,
- const char *sep) override {
-
-auto CZ = St->get();
+  void printJson(raw_ostream , ProgramStateRef State, const char *NL = 
"\n",
+ unsigned int Space = 0, bool IsDot = false) const override {
+ConstraintSMTType Constraints = State->get();
+
+Indent(Out, Space, IsDot) << "\"constraints\": ";
+if (Constraints.isEmpty()) {
+  Out << "null," << NL;
+  return;
+}
 
-OS << nl << sep << "Constraints:";
-for (auto I = CZ.begin(), E = CZ.end(); I != E; ++I) {
-  OS << nl << ' ' << I->first << " : ";
-  I->second->print(OS);
+++Space;
+Out << '[' << NL;
+for (ConstraintSMTType::iterator I = Constraints.begin();
+ I != Constraints.end(); ++I) {
+  Indent(Out, Space, IsDot)
+  << "{ \"symbol\": \"" << I->first << "\", \"range\": \"";
+  I->second->print(Out);
+  Out << "\" }";
+
+  if (std::next(I) != Constraints.end())
+Out << ',';
+  Out << NL;
 }
-OS << nl;
+
+--Space;
+Indent(Out, Space, IsDot) << "],";
   }
 
   bool haveEqualConstraints(ProgramStateRef S1,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=361978=361977=361978=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Wed May 29 08:43:26 2019
@@ -452,7 +452,7 @@ void ProgramState::printJson(raw_ostream
   Env.printJson(Out, Context, LCtx, NL, Space, IsDot);
 
   // Print out the constraints.
-  Mgr.getConstraintManager().print(this, Out, NL, Sep);
+  Mgr.getConstraintManager().printJson(Out, this, NL, Space, IsDot);
 
   // Print out the tracked dynamic types.
   printDynamicTypeInfo(this, Out, NL, Sep);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
URL: 

r361976 - [analyzer] print() JSONify: Environment implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 08:36:58 2019
New Revision: 361976

URL: http://llvm.org/viewvc/llvm-project?rev=361976=rev
Log:
[analyzer] print() JSONify: Environment implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62081

Modified:
cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PrettyStackTraceLocationContext.h
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h?rev=361976=361975=361976=diff
==
--- cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h (original)
+++ cfe/trunk/include/clang/Analysis/AnalysisDeclContext.h Wed May 29 08:36:58 
2019
@@ -274,11 +274,17 @@ public:
   virtual void Profile(llvm::FoldingSetNodeID ) = 0;
 
   void dumpStack(
-  raw_ostream , StringRef Indent = {}, const char *NL = "\n",
-  const char *Sep = "",
+  raw_ostream , const char *NL = "\n",
   std::function printMoreInfoPerContext =
   [](const LocationContext *) {}) const;
-  void dumpStack() const;
+
+  void printJson(
+  raw_ostream , const char *NL = "\n", unsigned int Space = 0,
+  bool IsDot = false,
+  std::function printMoreInfoPerContext =
+  [](const LocationContext *) {}) const;
+
+  void dump() const;
 
 public:
   static void ProfileCommon(llvm::FoldingSetNodeID ,

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h?rev=361976=361975=361976=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h Wed 
May 29 08:36:58 2019
@@ -91,9 +91,9 @@ public:
 return ExprBindings == RHS.ExprBindings;
   }
 
-  void print(raw_ostream , const char *NL, const char *Sep,
- const ASTContext ,
- const LocationContext *WithLC = nullptr) const;
+  void printJson(raw_ostream , const ASTContext ,
+ const LocationContext *LCtx = nullptr, const char *NL = "\n",
+ unsigned int Space = 0, bool IsDot = false) const;
 };
 
 class EnvironmentManager {

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=361976=361975=361976=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Wed 
May 29 08:36:58 2019
@@ -377,9 +377,9 @@ public:
const CallEvent *Call) override;
 
   /// printState - Called by ProgramStateManager to print checker-specific 
data.
-  void printState(raw_ostream , ProgramStateRef State, const char *NL,
-  const char *Sep,
-  const LocationContext *LCtx = nullptr) override;
+  void printState(raw_ostream , ProgramStateRef State,
+  const LocationContext *LCtx, const char *NL,
+  unsigned int Space, bool IsDot) const override;
 
   ProgramStateManager () override { return StateMgr; }
 

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h?rev=361976=361975=361976=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h Wed 
May 29 08:36:58 2019
@@ -160,8 +160,8 @@ public:
 
   /// printState - Called by ProgramStateManager to print checker-specific 
data.
   virtual void printState(raw_ostream , ProgramStateRef State,
-  const char *NL, const char *Sep,
-  const 

r361972 - [analyzer] print() JSONify: Store implementation

2019-05-29 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Wed May 29 08:25:19 2019
New Revision: 361972

URL: http://llvm.org/viewvc/llvm-project?rev=361972=rev
Log:
[analyzer] print() JSONify: Store implementation

Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61912

Added:
cfe/trunk/include/clang/Basic/JsonSupport.h
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Added: cfe/trunk/include/clang/Basic/JsonSupport.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/JsonSupport.h?rev=361972=auto
==
--- cfe/trunk/include/clang/Basic/JsonSupport.h (added)
+++ cfe/trunk/include/clang/Basic/JsonSupport.h Wed May 29 08:25:19 2019
@@ -0,0 +1,27 @@
+//===- JsonSupport.h - JSON Output Utilities *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_BASIC_JSONSUPPORT_H
+#define LLVM_CLANG_BASIC_JSONSUPPORT_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/Support/raw_ostream.h"
+
+
+namespace clang {
+
+inline raw_ostream (raw_ostream , const unsigned int Space,
+   bool IsDot) {
+  for (unsigned int I = 0; I < Space * 2; ++I)
+Out << (IsDot ? "" : " ");
+  return Out;
+}
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_JSONSUPPORT_H

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=361972=361971=361972=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Wed May 29 08:25:19 2019
@@ -424,10 +424,12 @@ public:
   }
 
   // Pretty-printing.
-  void print(raw_ostream , const char *nl = "\n", const char *sep = "",
- const LocationContext *CurrentLC = nullptr) const;
-  void printDOT(raw_ostream ,
-const LocationContext *CurrentLC = nullptr) const;
+  void printJson(raw_ostream , const LocationContext *LCtx = nullptr,
+ const char *NL = "\n", const char *Sep = "",
+ unsigned int Space = 0, bool IsDot = false) const;
+
+  void printDOT(raw_ostream , const LocationContext *LCtx = nullptr,
+unsigned int Space = 0) const;
 
   void dump() const;
 

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h?rev=361972=361971=361972=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h Wed May 
29 08:25:19 2019
@@ -253,7 +253,8 @@ public:
   virtual bool scanReachableSymbols(Store S, const MemRegion *R,
 ScanReachableSymbols ) = 0;
 
-  virtual void print(Store store, raw_ostream , const char* nl) = 0;
+  virtual void printJson(raw_ostream , Store S, const char *NL,
+ unsigned int Space, bool IsDot) const = 0;
 
   class BindingsHandler {
   public:

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=361972=361971=361972=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Wed May 29 08:25:19 2019
@@ -440,16 +440,16 @@ void ProgramState::setStore(const StoreR
 //  State pretty-printing.
 
//===--===//
 
-void ProgramState::print(raw_ostream ,
- const char *NL, const char *Sep,
- const LocationContext *LC) const {
+void ProgramState::printJson(raw_ostream , const LocationContext *LCtx,
+ const char *NL, const char *Sep,
+ unsigned int Space, bool IsDot) const {
   // 

r356323 - [analyzer] ConditionBRVisitor: Unknown condition evaluation support

2019-03-16 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Mar 16 06:47:55 2019
New Revision: 356323

URL: http://llvm.org/viewvc/llvm-project?rev=356323=rev
Log:
[analyzer] ConditionBRVisitor: Unknown condition evaluation support

Summary:
If the constraint information is not changed between two program states the
analyzer has not learnt new information and made no report. But it is
possible to happen because we have no information at all. The new approach
evaluates the condition to determine if that is the case and let the user
know we just `Assuming...` some value.

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: llvm-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gsd, gerazo

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D57410

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/macros.cpp
cfe/trunk/test/Analysis/uninit-vals.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=356323=356322=356323=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Mar 16 
06:47:55 2019
@@ -1815,12 +1815,6 @@ std::shared_ptr
 ConditionBRVisitor::VisitNodeImpl(const ExplodedNode *N,
   BugReporterContext , BugReport ) {
   ProgramPoint progPoint = N->getLocation();
-  ProgramStateRef CurrentState = N->getState();
-  ProgramStateRef PreviousState = N->getFirstPred()->getState();
-
-  // If the constraint information does not changed there is no assumption.
-  if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState))
-return nullptr;
 
   // If an assumption was made on a branch, it should be caught
   // here by looking at the state transition.
@@ -1910,6 +1904,18 @@ std::shared_ptr
 ConditionBRVisitor::VisitTrueTest(const Expr *Cond, bool tookTrue,
   BugReporterContext , BugReport ,
   const ExplodedNode *N) {
+  ProgramStateRef CurrentState = N->getState();
+  ProgramStateRef PreviousState = N->getFirstPred()->getState();
+  const LocationContext *LCtx = N->getLocationContext();
+
+  // If the constraint information is changed between the current and the
+  // previous program state we assuming the newly seen constraint information.
+  // If we cannot evaluate the condition (and the constraints are the same)
+  // the analyzer has no information about the value and just assuming it.
+  if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState) 
&&
+  CurrentState->getSVal(Cond, LCtx).isValid())
+return nullptr;
+
   // These will be modified in code below, but we need to preserve the original
   //  values in case we want to throw the generic message.
   const Expr *CondTmp = Cond;
@@ -1945,7 +1951,6 @@ ConditionBRVisitor::VisitTrueTest(const
 
   // Condition too complex to explain? Just say something so that the user
   // knew we've made some path decision at this point.
-  const LocationContext *LCtx = N->getLocationContext();
   PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
   if (!Loc.isValid() || !Loc.asLocation().isValid())
 return nullptr;

Modified: cfe/trunk/test/Analysis/diagnostics/macros.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/macros.cpp?rev=356323=356322=356323=diff
==
--- cfe/trunk/test/Analysis/diagnostics/macros.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/macros.cpp Sat Mar 16 06:47:55 2019
@@ -30,7 +30,8 @@ void testnullptrMacro(int *p) {
 
 // There are no path notes on the comparison to float types.
 void testDoubleMacro(double d) {
-  if (d == DBL_MAX) { // expected-note {{Taking true branch}}
+  if (d == DBL_MAX) { // expected-note {{Assuming 'd' is equal to DBL_MAX}}
+  // expected-note@-1 {{Taking true branch}}
 
 char *p = NULL; // expected-note {{'p' initialized to a null pointer 
value}}
 *p = 7; // expected-warning {{Dereference of null pointer (loaded 
from variable 'p')}}

Modified: cfe/trunk/test/Analysis/uninit-vals.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals.m?rev=356323=356322=356323=diff
==
--- cfe/trunk/test/Analysis/uninit-vals.m (original)
+++ cfe/trunk/test/Analysis/uninit-vals.m Sat Mar 16 06:47:55 2019
@@ -164,7 +164,8 @@ void PR14765_test() {
// expected-note@-1{{TRUE}}
 
   testObj->origin = makePoint(0.0, 0.0);
-  if (testObj->size > 0) { ; } // expected-note{{Taking false 

r356322 - [analyzer] ConditionBRVisitor: Remove GDM checking

2019-03-16 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Mar 16 04:55:07 2019
New Revision: 356322

URL: http://llvm.org/viewvc/llvm-project?rev=356322=rev
Log:
[analyzer] ConditionBRVisitor: Remove GDM checking

Summary:
Removed the `GDM` checking what could prevent reports made by this visitor.
Now we rely on constraint changes instead.
(It reapplies 356318 with a feature from 356319 because build-bot failure.)

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: cfe-commits, jdoerfert, gerazo, xazax.hun, baloghadamsoftware,
szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D54811

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=356322=356321=356322=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
Sat Mar 16 04:55:07 2019
@@ -79,6 +79,9 @@ public:
   ConstraintManager() = default;
   virtual ~ConstraintManager();
 
+  virtual bool haveEqualConstraints(ProgramStateRef S1,
+ProgramStateRef S2) const = 0;
+
   virtual ProgramStateRef assume(ProgramStateRef state,
  DefinedSVal Cond,
  bool Assumption) = 0;

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=356322=356321=356322=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Sat Mar 16 04:55:07 2019
@@ -588,11 +588,15 @@ public:
   ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState,
ProgramStateRef GDMState);
 
-  bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) {
+  bool haveEqualConstraints(ProgramStateRef S1, ProgramStateRef S2) const {
+return ConstraintMgr->haveEqualConstraints(S1, S2);
+  }
+
+  bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) const {
 return S1->Env == S2->Env;
   }
 
-  bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) {
+  bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) const {
 return S1->store == S2->store;
   }
 

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h?rev=356322=356321=356322=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 (original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 Sat Mar 16 04:55:07 2019
@@ -220,6 +220,11 @@ public:
 OS << nl;
   }
 
+  bool haveEqualConstraints(ProgramStateRef S1,
+ProgramStateRef S2) const override {
+return S1->get() == S2->get();
+  }
+
   bool canReasonAbout(SVal X) const override {
 const TargetInfo  = getBasicVals().getContext().getTargetInfo();
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=356322=356321=356322=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Mar 16 
04:55:07 2019
@@ -1816,13 +1816,10 @@ ConditionBRVisitor::VisitNodeImpl(const
   BugReporterContext , BugReport ) {
   ProgramPoint progPoint = N->getLocation();
   ProgramStateRef CurrentState = N->getState();
-  ProgramStateRef PrevState = N->getFirstPred()->getState();
+  ProgramStateRef PreviousState = N->getFirstPred()->getState();
 
-  // Compare the GDMs of the state, because that is where constraints
-  // are managed.  Note that ensure that we only look at nodes that
-  // were generated by the analyzer engine proper, not 

r356321 - Revert "[analyzer] ConditionBRVisitor: Remove GDM checking"

2019-03-16 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Mar 16 03:44:49 2019
New Revision: 356321

URL: http://llvm.org/viewvc/llvm-project?rev=356321=rev
Log:
Revert "[analyzer] ConditionBRVisitor: Remove GDM checking"

This reverts commit f962485adad9d646511fd3240c0408d9554e6784.

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=356321=356320=356321=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
Sat Mar 16 03:44:49 2019
@@ -79,9 +79,6 @@ public:
   ConstraintManager() = default;
   virtual ~ConstraintManager();
 
-  virtual bool haveEqualConstraints(ProgramStateRef S1,
-ProgramStateRef S2) const = 0;
-
   virtual ProgramStateRef assume(ProgramStateRef state,
  DefinedSVal Cond,
  bool Assumption) = 0;

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=356321=356320=356321=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Sat Mar 16 03:44:49 2019
@@ -588,15 +588,11 @@ public:
   ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState,
ProgramStateRef GDMState);
 
-  bool haveEqualConstraints(ProgramStateRef S1, ProgramStateRef S2) const {
-return ConstraintMgr->haveEqualConstraints(S1, S2);
-  }
-
-  bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) const {
+  bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) {
 return S1->Env == S2->Env;
   }
 
-  bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) const {
+  bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) {
 return S1->store == S2->store;
   }
 

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h?rev=356321=356320=356321=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 (original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 Sat Mar 16 03:44:49 2019
@@ -220,11 +220,6 @@ public:
 OS << nl;
   }
 
-  bool haveEqualConstraints(ProgramStateRef S1,
-ProgramStateRef S2) const override {
-return S1->get() == S2->get();
-  }
-
   bool canReasonAbout(SVal X) const override {
 const TargetInfo  = getBasicVals().getContext().getTargetInfo();
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=356321=356320=356321=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Mar 16 
03:44:49 2019
@@ -1816,10 +1816,13 @@ ConditionBRVisitor::VisitNodeImpl(const
   BugReporterContext , BugReport ) {
   ProgramPoint progPoint = N->getLocation();
   ProgramStateRef CurrentState = N->getState();
-  ProgramStateRef PreviousState = N->getFirstPred()->getState();
+  ProgramStateRef PrevState = N->getFirstPred()->getState();
 
-  // If the constraint information does not changed there is no assumption.
-  if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState))
+  // Compare the GDMs of the state, because that is where constraints
+  // are managed.  Note that ensure that we only look at nodes that
+  // were generated by the analyzer engine proper, not checkers.
+  if (CurrentState->getGDM().getRoot() ==
+  PrevState->getGDM().getRoot())
 return nullptr;
 
   // If an assumption was made on a branch, it should be caught

Modified: 

r356320 - Revert "[analyzer] ConditionBRVisitor: Unknown condition evaluation support"

2019-03-16 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Mar 16 03:06:06 2019
New Revision: 356320

URL: http://llvm.org/viewvc/llvm-project?rev=356320=rev
Log:
Revert "[analyzer] ConditionBRVisitor: Unknown condition evaluation support"

This reverts commit 0fe67a61cd4aec13c7969a179517f1cc06ab05cd.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/macros.cpp
cfe/trunk/test/Analysis/uninit-vals.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=356320=356319=356320=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Mar 16 
03:06:06 2019
@@ -1815,6 +1815,12 @@ std::shared_ptr
 ConditionBRVisitor::VisitNodeImpl(const ExplodedNode *N,
   BugReporterContext , BugReport ) {
   ProgramPoint progPoint = N->getLocation();
+  ProgramStateRef CurrentState = N->getState();
+  ProgramStateRef PreviousState = N->getFirstPred()->getState();
+
+  // If the constraint information does not changed there is no assumption.
+  if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState))
+return nullptr;
 
   // If an assumption was made on a branch, it should be caught
   // here by looking at the state transition.
@@ -1883,8 +1889,6 @@ std::shared_ptr Con
 break;
   }
 
-  Cond = Cond->IgnoreParens();
-
   // However, when we encounter a logical operator as a branch condition,
   // then the condition is actually its RHS, because LHS would be
   // the condition for the logical operator terminator.
@@ -1904,18 +1908,6 @@ std::shared_ptr
 ConditionBRVisitor::VisitTrueTest(const Expr *Cond, bool tookTrue,
   BugReporterContext , BugReport ,
   const ExplodedNode *N) {
-  ProgramStateRef CurrentState = N->getState();
-  ProgramStateRef PreviousState = N->getFirstPred()->getState();
-  const LocationContext *LCtx = N->getLocationContext();
-
-  // If the constraint information is changed between the current and the
-  // previous program state we assuming the newly seen constraint information.
-  // If we cannot evaluate the condition (and the constraints are the same)
-  // the analyzer has no information about the value and just assuming it.
-  if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState) 
&&
-  CurrentState->getSVal(Cond, LCtx).isValid())
-return nullptr;
-
   // These will be modified in code below, but we need to preserve the original
   //  values in case we want to throw the generic message.
   const Expr *CondTmp = Cond;
@@ -1951,6 +1943,7 @@ ConditionBRVisitor::VisitTrueTest(const
 
   // Condition too complex to explain? Just say something so that the user
   // knew we've made some path decision at this point.
+  const LocationContext *LCtx = N->getLocationContext();
   PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
   if (!Loc.isValid() || !Loc.asLocation().isValid())
 return nullptr;

Modified: cfe/trunk/test/Analysis/diagnostics/macros.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/macros.cpp?rev=356320=356319=356320=diff
==
--- cfe/trunk/test/Analysis/diagnostics/macros.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/macros.cpp Sat Mar 16 03:06:06 2019
@@ -30,8 +30,7 @@ void testnullptrMacro(int *p) {
 
 // There are no path notes on the comparison to float types.
 void testDoubleMacro(double d) {
-  if (d == DBL_MAX) { // expected-note {{Assuming 'd' is equal to DBL_MAX}}
-  // expected-note@-1 {{Taking true branch}}
+  if (d == DBL_MAX) { // expected-note {{Taking true branch}}
 
 char *p = NULL; // expected-note {{'p' initialized to a null pointer 
value}}
 *p = 7; // expected-warning {{Dereference of null pointer (loaded 
from variable 'p')}}

Modified: cfe/trunk/test/Analysis/uninit-vals.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals.m?rev=356320=356319=356320=diff
==
--- cfe/trunk/test/Analysis/uninit-vals.m (original)
+++ cfe/trunk/test/Analysis/uninit-vals.m Sat Mar 16 03:06:06 2019
@@ -164,8 +164,7 @@ void PR14765_test() {
// expected-note@-1{{TRUE}}
 
   testObj->origin = makePoint(0.0, 0.0);
-  if (testObj->size > 0) { ; } // expected-note{{Assuming the condition is 
false}}
-   // expected-note@-1{{Taking false branch}}
+  if (testObj->size > 0) { ; } // expected-note{{Taking false branch}}
 
   // FIXME: Assigning to 'testObj->origin' kills the default binding for the
 

r356319 - [analyzer] ConditionBRVisitor: Unknown condition evaluation support

2019-03-16 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Mar 16 02:24:30 2019
New Revision: 356319

URL: http://llvm.org/viewvc/llvm-project?rev=356319=rev
Log:
[analyzer] ConditionBRVisitor: Unknown condition evaluation support

Summary: If the constraint information is not changed between two program 
states the analyzer has not learnt new information and made no report. But it 
is possible to happen because we have no information at all. The new approach 
evaluates the condition to determine if that is the case and let the user know 
we just 'Assuming...' some value.

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, 
Szelethus, donat.nagy, dkrupp, gsd, gerazo

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57410

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/macros.cpp
cfe/trunk/test/Analysis/uninit-vals.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=356319=356318=356319=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Mar 16 
02:24:30 2019
@@ -1815,12 +1815,6 @@ std::shared_ptr
 ConditionBRVisitor::VisitNodeImpl(const ExplodedNode *N,
   BugReporterContext , BugReport ) {
   ProgramPoint progPoint = N->getLocation();
-  ProgramStateRef CurrentState = N->getState();
-  ProgramStateRef PreviousState = N->getFirstPred()->getState();
-
-  // If the constraint information does not changed there is no assumption.
-  if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState))
-return nullptr;
 
   // If an assumption was made on a branch, it should be caught
   // here by looking at the state transition.
@@ -1889,6 +1883,8 @@ std::shared_ptr Con
 break;
   }
 
+  Cond = Cond->IgnoreParens();
+
   // However, when we encounter a logical operator as a branch condition,
   // then the condition is actually its RHS, because LHS would be
   // the condition for the logical operator terminator.
@@ -1908,6 +1904,18 @@ std::shared_ptr
 ConditionBRVisitor::VisitTrueTest(const Expr *Cond, bool tookTrue,
   BugReporterContext , BugReport ,
   const ExplodedNode *N) {
+  ProgramStateRef CurrentState = N->getState();
+  ProgramStateRef PreviousState = N->getFirstPred()->getState();
+  const LocationContext *LCtx = N->getLocationContext();
+
+  // If the constraint information is changed between the current and the
+  // previous program state we assuming the newly seen constraint information.
+  // If we cannot evaluate the condition (and the constraints are the same)
+  // the analyzer has no information about the value and just assuming it.
+  if (BRC.getStateManager().haveEqualConstraints(CurrentState, PreviousState) 
&&
+  CurrentState->getSVal(Cond, LCtx).isValid())
+return nullptr;
+
   // These will be modified in code below, but we need to preserve the original
   //  values in case we want to throw the generic message.
   const Expr *CondTmp = Cond;
@@ -1943,7 +1951,6 @@ ConditionBRVisitor::VisitTrueTest(const
 
   // Condition too complex to explain? Just say something so that the user
   // knew we've made some path decision at this point.
-  const LocationContext *LCtx = N->getLocationContext();
   PathDiagnosticLocation Loc(Cond, BRC.getSourceManager(), LCtx);
   if (!Loc.isValid() || !Loc.asLocation().isValid())
 return nullptr;

Modified: cfe/trunk/test/Analysis/diagnostics/macros.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/macros.cpp?rev=356319=356318=356319=diff
==
--- cfe/trunk/test/Analysis/diagnostics/macros.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/macros.cpp Sat Mar 16 02:24:30 2019
@@ -30,7 +30,8 @@ void testnullptrMacro(int *p) {
 
 // There are no path notes on the comparison to float types.
 void testDoubleMacro(double d) {
-  if (d == DBL_MAX) { // expected-note {{Taking true branch}}
+  if (d == DBL_MAX) { // expected-note {{Assuming 'd' is equal to DBL_MAX}}
+  // expected-note@-1 {{Taking true branch}}
 
 char *p = NULL; // expected-note {{'p' initialized to a null pointer 
value}}
 *p = 7; // expected-warning {{Dereference of null pointer (loaded 
from variable 'p')}}

Modified: cfe/trunk/test/Analysis/uninit-vals.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals.m?rev=356319=356318=356319=diff
==
--- cfe/trunk/test/Analysis/uninit-vals.m (original)
+++ 

r356318 - [analyzer] ConditionBRVisitor: Remove GDM checking

2019-03-16 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Mar 16 02:16:16 2019
New Revision: 356318

URL: http://llvm.org/viewvc/llvm-project?rev=356318=rev
Log:
[analyzer] ConditionBRVisitor: Remove GDM checking

Summary: Removed the `GDM` checking what could prevent reports made by this 
visitor. Now we rely on constraint changes instead.

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: jdoerfert, gerazo, xazax.hun, baloghadamsoftware, szepet, 
a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D54811

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=356318=356317=356318=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
Sat Mar 16 02:16:16 2019
@@ -79,6 +79,9 @@ public:
   ConstraintManager() = default;
   virtual ~ConstraintManager();
 
+  virtual bool haveEqualConstraints(ProgramStateRef S1,
+ProgramStateRef S2) const = 0;
+
   virtual ProgramStateRef assume(ProgramStateRef state,
  DefinedSVal Cond,
  bool Assumption) = 0;

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=356318=356317=356318=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Sat Mar 16 02:16:16 2019
@@ -588,11 +588,15 @@ public:
   ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState,
ProgramStateRef GDMState);
 
-  bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) {
+  bool haveEqualConstraints(ProgramStateRef S1, ProgramStateRef S2) const {
+return ConstraintMgr->haveEqualConstraints(S1, S2);
+  }
+
+  bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) const {
 return S1->Env == S2->Env;
   }
 
-  bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) {
+  bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) const {
 return S1->store == S2->store;
   }
 

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h?rev=356318=356317=356318=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 (original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
 Sat Mar 16 02:16:16 2019
@@ -220,6 +220,11 @@ public:
 OS << nl;
   }
 
+  bool haveEqualConstraints(ProgramStateRef S1,
+ProgramStateRef S2) const override {
+return S1->get() == S2->get();
+  }
+
   bool canReasonAbout(SVal X) const override {
 const TargetInfo  = getBasicVals().getContext().getTargetInfo();
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=356318=356317=356318=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Mar 16 
02:16:16 2019
@@ -1816,13 +1816,10 @@ ConditionBRVisitor::VisitNodeImpl(const
   BugReporterContext , BugReport ) {
   ProgramPoint progPoint = N->getLocation();
   ProgramStateRef CurrentState = N->getState();
-  ProgramStateRef PrevState = N->getFirstPred()->getState();
+  ProgramStateRef PreviousState = N->getFirstPred()->getState();
 
-  // Compare the GDMs of the state, because that is where constraints
-  // are managed.  Note that ensure that we only look at nodes that
-  // were generated by the analyzer engine proper, not checkers.
-  if (CurrentState->getGDM().getRoot() ==
-  PrevState->getGDM().getRoot())
+  

r356307 - hello, clang

2019-03-15 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Fri Mar 15 16:44:35 2019
New Revision: 356307

URL: http://llvm.org/viewvc/llvm-project?rev=356307=rev
Log:
hello, clang

Test commit with head and body.

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h?rev=356307=356306=356307=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h Fri 
Mar 15 16:44:35 2019
@@ -194,7 +194,7 @@ public:
   void enqueueStmtNode(ExplodedNode *N, const CFGBlock *Block, unsigned Idx);
 };
 
-// TODO: Turn into a calss.
+// TODO: Turn into a class.
 struct NodeBuilderContext {
   const CoreEngine 
   const CFGBlock *Block;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits