[PATCH] D65209: [analyzer] Fix a SARIF exporter crash with macro expansions

2019-08-27 Thread Joe Ranieri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3385c5cc4dfd: Fix a SARIF exporter crash with macro 
expansions (authored by jranieri-grammatech).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65209/new/

https://reviews.llvm.org/D65209

Files:
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
  clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c

Index: clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
===
--- clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
+++ clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
@@ -1,5 +1,7 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest,unix.Malloc %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
 #include "../Inputs/system-header-simulator.h"
+#include "../Inputs/system-header-simulator-for-malloc.h"
+#define ERR -1
 
 int atoi(const char *nptr);
 
@@ -20,10 +22,19 @@
   return 0;
 }
 
+int leak(int i) {
+  void *mem = malloc(8);
+  if (i < 4)
+return ERR; // expected-warning {{Potential leak of memory pointed to by 'mem'}}
+  free(mem);
+  return 0;
+}
+
 int main(void) {
   f();
   g();
   h(0);
+  leak(0);
   return 0;
 }
 
Index: clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
===
--- clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
+++ clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
@@ -6,7 +6,7 @@
 {
   "fileLocation": {
   },
-  "length": 686,
+  "length": 951,
   "mimeType": "text/plain",
   "roles": [
 "resultFile"
@@ -43,6 +43,16 @@
 "name": {
   "text": "core.DivideZero"
 }
+  },
+  {
+"fullDescription": {
+  "text": "Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free()."
+},
+"helpUri": "https://clang-analyzer.llvm.org/available_checks.html#unix.Malloc;,
+"id": "unix.Malloc",
+"name": {
+  "text": "unix.Malloc"
+}
   }
 ]
   },
@@ -65,9 +75,9 @@
   },
   "region": {
 "endColumn": 6,
-"endLine": 24,
+"endLine": 34,
 "startColumn": 3,
-"startLine": 24
+"startLine": 34
   }
 }
   }
@@ -84,9 +94,9 @@
   },
   "region": {
 "endColumn": 18,
-"endLine": 9,
+"endLine": 11,
 "startColumn": 11,
-"startLine": 9
+"startLine": 11
   }
 }
   }
@@ -104,9 +114,9 @@
 },
 "region": {
   "endColumn": 18,
-  "endLine": 9,
+  "endLine": 11,
   "startColumn": 11,
-  "startLine": 9
+  "startLine": 11
 }
   }
 }
@@ -135,9 +145,9 @@
   },
   "region": {
 "endColumn": 6,
-"endLine": 25,
+"endLine": 35,
 "startColumn": 3,
-"startLine": 25
+"startLine": 35
   }
 }
   }
@@ -154,9 +164,9 @@
   },
   "region": {
 "endColumn": 11,
-"endLine": 13,
+"endLine": 15,
 "startColumn": 3,
-"startLine": 13
+"startLine": 15
   }
 }
   }
@@ -173,9 +183,9 @@
   },
  

[PATCH] D65209: [analyzer] Fix a SARIF exporter crash with macro expansions

2019-08-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D65209#1606075 , @aaron.ballman 
wrote:

> This LGTM, but I'd appreciate a second reviewer chiming in only because Joe 
> is a coworker.


Sufficient time has passed that any concerns other reviewers have can be 
addressed post-commit. Continues to LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65209/new/

https://reviews.llvm.org/D65209



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


[PATCH] D65209: [analyzer] Fix a SARIF exporter crash with macro expansions

2019-07-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

This LGTM, but I'd appreciate a second reviewer chiming in only because Joe is 
a coworker.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65209/new/

https://reviews.llvm.org/D65209



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


[PATCH] D65209: [analyzer] Fix a SARIF exporter crash with macro expansions

2019-07-24 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech created this revision.
jranieri-grammatech added reviewers: NoQ, george.karpenkov, aaron.ballman.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.
jranieri-grammatech added a parent revision: D65206: [analyzer] Fix text range 
end columns in SARIF to be exclusive.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65209

Files:
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
  clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c

Index: clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
===
--- clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
+++ clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
@@ -1,5 +1,7 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest,unix.Malloc %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
 #include "../Inputs/system-header-simulator.h"
+#include "../Inputs/system-header-simulator-for-malloc.h"
+#define ERR -1
 
 int atoi(const char *nptr);
 
@@ -20,10 +22,19 @@
   return 0;
 }
 
+int leak(int i) {
+  void *mem = malloc(8);
+  if (i < 4)
+return ERR; // expected-warning {{Potential leak of memory pointed to by 'mem'}}
+  free(mem);
+  return 0;
+}
+
 int main(void) {
   f();
   g();
   h(0);
+  leak(0);
   return 0;
 }
 
Index: clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
===
--- clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
+++ clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
@@ -6,7 +6,7 @@
 {
   "fileLocation": {
   },
-  "length": 686,
+  "length": 951,
   "mimeType": "text/plain",
   "roles": [
 "resultFile"
@@ -43,6 +43,16 @@
 "name": {
   "text": "core.DivideZero"
 }
+  },
+  {
+"fullDescription": {
+  "text": "Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free()."
+},
+"helpUri": "https://clang-analyzer.llvm.org/available_checks.html#unix.Malloc;,
+"id": "unix.Malloc",
+"name": {
+  "text": "unix.Malloc"
+}
   }
 ]
   },
@@ -65,9 +75,9 @@
   },
   "region": {
 "endColumn": 6,
-"endLine": 24,
+"endLine": 34,
 "startColumn": 3,
-"startLine": 24
+"startLine": 34
   }
 }
   }
@@ -84,9 +94,9 @@
   },
   "region": {
 "endColumn": 18,
-"endLine": 9,
+"endLine": 11,
 "startColumn": 11,
-"startLine": 9
+"startLine": 11
   }
 }
   }
@@ -104,9 +114,9 @@
 },
 "region": {
   "endColumn": 18,
-  "endLine": 9,
+  "endLine": 11,
   "startColumn": 11,
-  "startLine": 9
+  "startLine": 11
 }
   }
 }
@@ -135,9 +145,9 @@
   },
   "region": {
 "endColumn": 6,
-"endLine": 25,
+"endLine": 35,
 "startColumn": 3,
-"startLine": 25
+"startLine": 35
   }
 }
   }
@@ -154,9 +164,9 @@
   },
   "region": {
 "endColumn": 11,
-"endLine": 13,
+"endLine": 15,
 "startColumn": 3,
-"startLine": 13
+