[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-14 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356142: [analyzer] Fix function macro crash (authored by 
Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D57893?vs=190575=190614#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D57893

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  
cfe/trunk/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp

Index: cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp
===
--- cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp
+++ cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp
@@ -451,3 +451,21 @@
 1 / value; // expected-warning{{Division by zero}}
// expected-warning@-1{{expression result unused}}
 }
+
+#define FOO(x) int foo() { return x; }
+#define APPLY_ZERO1(function) function(0)
+
+APPLY_ZERO1(FOO)
+void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO1
+// CHECK-NEXT: expansionint foo() { return x; }(0)
+
+#define BAR(x) int bar() { return x; }
+#define APPLY_ZERO2 BAR(0)
+
+APPLY_ZERO2
+void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO2
+// CHECK-NEXT: expansionint bar() { return 0; }
Index: cfe/trunk/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- cfe/trunk/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ cfe/trunk/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5577,6 +5577,484 @@

   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col33
+   file0
+  
+  
+   line459
+   col33
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling foo
+ message
+ Calling foo
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier1
+ message
+ Entered call from useZeroApplier1
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line458
+ col1
+ file0
+
+
+ line458
+ col16
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from foo
+ message
+ Returning from foo
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col35
+   file0
+  
+  
+   line459
+   col35
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col35
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col33
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ nameAPPLY_ZERO1
+ expansionint foo() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   

[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-14 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib updated this revision to Diff 190575.
bruntib added a comment.

I've uploaded another version of the last fix. The previous one contained an 
UB, although it worked practically.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -451,3 +451,21 @@
 1 / value; // expected-warning{{Division by zero}}
// expected-warning@-1{{expression result unused}}
 }
+
+#define FOO(x) int foo() { return x; }
+#define APPLY_ZERO1(function) function(0)
+
+APPLY_ZERO1(FOO)
+void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO1
+// CHECK-NEXT: expansionint foo() { return x; }(0)
+
+#define BAR(x) int bar() { return x; }
+#define APPLY_ZERO2 BAR(0)
+
+APPLY_ZERO2
+void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO2
+// CHECK-NEXT: expansionint bar() { return 0; }
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5577,6 +5577,484 @@

   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col33
+   file0
+  
+  
+   line459
+   col33
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling foo
+ message
+ Calling foo
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier1
+ message
+ Entered call from useZeroApplier1
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line458
+ col1
+ file0
+
+
+ line458
+ col16
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from foo
+ message
+ Returning from foo
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col35
+   file0
+  
+  
+   line459
+   col35
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col35
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col33
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ nameAPPLY_ZERO1
+ expansionint foo() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40
+  issue_context_kindfunction
+  issue_contextuseZeroApplier1
+  issue_hash_function_offset0
+  location
+  
+   line459
+   col35
+   file0
+  
+  ExecutedLines
+  
+   0
+   
+458
+459
+   
+  
+  
+  
+   

[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Ah so it was a past-the-end iterator dereference error. Cheers!


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893



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


[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-13 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib updated this revision to Diff 190485.
bruntib added a comment.

I added a condition before std::next() invocations to check if the next element 
is inside the valid interval. This fixes the crash of the build-bot. Sorry for 
the ugly bug.
I don't know if there is a more elegant solution.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -451,3 +451,21 @@
 1 / value; // expected-warning{{Division by zero}}
// expected-warning@-1{{expression result unused}}
 }
+
+#define FOO(x) int foo() { return x; }
+#define APPLY_ZERO1(function) function(0)
+
+APPLY_ZERO1(FOO)
+void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO1
+// CHECK-NEXT: expansionint foo() { return x; }(0)
+
+#define BAR(x) int bar() { return x; }
+#define APPLY_ZERO2 BAR(0)
+
+APPLY_ZERO2
+void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO2
+// CHECK-NEXT: expansionint bar() { return 0; }
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5577,6 +5577,484 @@

   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col33
+   file0
+  
+  
+   line459
+   col33
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling foo
+ message
+ Calling foo
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier1
+ message
+ Entered call from useZeroApplier1
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line458
+ col1
+ file0
+
+
+ line458
+ col16
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from foo
+ message
+ Returning from foo
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col35
+   file0
+  
+  
+   line459
+   col35
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col35
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col33
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ nameAPPLY_ZERO1
+ expansionint foo() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40
+  issue_context_kindfunction
+  issue_contextuseZeroApplier1
+  issue_hash_function_offset0
+  location

[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Some bots also break but emit a different message:

   TEST 'Clang :: Analysis/plist-macros-with-expansion.cpp' 
FAILED 
  Script:
  --
  : 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/lib/clang/9.0.0/include
 -nostdsysteminc -analyze -analyzer-constraints=range -analyzer-checker=core 
-verify 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp
  : 'RUN: at line 3';   
/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/lib/clang/9.0.0/include
 -nostdsysteminc -analyze -analyzer-constraints=range -analyzer-checker=core 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp
 -analyzer-output=plist -o 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/tools/clang/test/Analysis/Output/plist-macros-with-expansion.cpp.tmp.plist
-analyzer-config expand-macros=true
  : 'RUN: at line 8';   cat 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/tools/clang/test/Analysis/Output/plist-macros-with-expansion.cpp.tmp.plist
 | diff -u -w -I "/" -I ".:" -I "version"
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
 -
  : 'RUN: at line 13';   
/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/bin/FileCheck 
--input-file=/b/sanitizer-x86_64-linux-bootstrap/build/llvm_build_asan/tools/clang/test/Analysis/Output/plist-macros-with-expansion.cpp.tmp.plist
 
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:451:7:
 warning: expression result unused
  1 / value; // expected-warning{{Division by zero}}
  ~ ^ ~
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:27:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:40:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:60:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:80:12:
 warning: Dereference of null pointer (loaded from variable 'a')
DEREF(a) = 5; // expected-warning{{Dereference of null pointer}}
  ~  ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:99:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:116:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:136:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:163:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:172:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:181:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  
/b/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:195:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  

[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus requested changes to this revision.
Szelethus added a comment.
This revision now requires changes to proceed.

Let's investigate what's behind this.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893



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


[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus reopened this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Ugh. Reverted the patch.

  FAIL: Clang :: Analysis/plist-macros-with-expansion.cpp (720 of 14281)
   TEST 'Clang :: Analysis/plist-macros-with-expansion.cpp' 
FAILED 
  Script:
  --
  : 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/9.0.0/include 
-nostdsysteminc -analyze -analyzer-constraints=range -analyzer-checker=core 
-verify 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp
  : 'RUN: at line 3';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/lib/clang/9.0.0/include 
-nostdsysteminc -analyze -analyzer-constraints=range -analyzer-checker=core 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp
 -analyzer-output=plist -o 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/clang/test/Analysis/Output/plist-macros-with-expansion.cpp.tmp.plist
-analyzer-config expand-macros=true
  : 'RUN: at line 8';   cat 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/clang/test/Analysis/Output/plist-macros-with-expansion.cpp.tmp.plist
 | diff -u -w -I "/" -I ".:" -I "version"
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
 -
  : 'RUN: at line 13';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/bin/FileCheck 
--input-file=/b/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/clang/test/Analysis/Output/plist-macros-with-expansion.cpp.tmp.plist
 
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp
  --
  Exit Code: 77
  
  Command Output (stderr):
  --
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:451:7:
 warning: expression result unused
  1 / value; // expected-warning{{Division by zero}}
  ~ ^ ~
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:27:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:40:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:60:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:80:12:
 warning: Dereference of null pointer (loaded from variable 'a')
DEREF(a) = 5; // expected-warning{{Dereference of null pointer}}
  ~  ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:99:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:116:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:136:8:
 warning: Dereference of null pointer (loaded from variable 'ptr')
*ptr = 5; // expected-warning{{Dereference of null pointer}}
 ~~~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:163:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:172:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:181:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  
/b/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/plist-macros-with-expansion.cpp:195:6:
 warning: Dereference of null pointer (loaded from variable 'a')
*a = 5; // expected-warning{{Dereference of null pointer}}
 ~ ^
  

[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-12 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC355903: [analyzer] Fix function macro crash (authored by 
Szelethus, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -451,3 +451,21 @@
 1 / value; // expected-warning{{Division by zero}}
// expected-warning@-1{{expression result unused}}
 }
+
+#define FOO(x) int foo() { return x; }
+#define APPLY_ZERO1(function) function(0)
+
+APPLY_ZERO1(FOO)
+void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO1
+// CHECK-NEXT: expansionint foo() { return x; }(0)
+
+#define BAR(x) int bar() { return x; }
+#define APPLY_ZERO2 BAR(0)
+
+APPLY_ZERO2
+void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO2
+// CHECK-NEXT: expansionint bar() { return 0; }
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5577,6 +5577,484 @@

   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col33
+   file0
+  
+  
+   line459
+   col33
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling foo
+ message
+ Calling foo
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier1
+ message
+ Entered call from useZeroApplier1
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line458
+ col1
+ file0
+
+
+ line458
+ col16
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from foo
+ message
+ Returning from foo
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col35
+   file0
+  
+  
+   line459
+   col35
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col35
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col33
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ nameAPPLY_ZERO1
+ expansionint foo() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40
+  issue_context_kindfunction
+  issue_contextuseZeroApplier1
+  issue_hash_function_offset0
+  location
+  
+   line459
+   col35
+   file0
+  
+  ExecutedLines
+  
+   0
+   
+458
+459
+   
+  
+  
+  
+   path
+   

[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-12 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib updated this revision to Diff 190225.

Repository:
  rC Clang

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

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -451,3 +451,21 @@
 1 / value; // expected-warning{{Division by zero}}
// expected-warning@-1{{expression result unused}}
 }
+
+#define FOO(x) int foo() { return x; }
+#define APPLY_ZERO1(function) function(0)
+
+APPLY_ZERO1(FOO)
+void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO1
+// CHECK-NEXT: expansionint foo() { return x; }(0)
+
+#define BAR(x) int bar() { return x; }
+#define APPLY_ZERO2 BAR(0)
+
+APPLY_ZERO2
+void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO2
+// CHECK-NEXT: expansionint bar() { return 0; }
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5577,6 +5577,484 @@

   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col33
+   file0
+  
+  
+   line459
+   col33
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling foo
+ message
+ Calling foo
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier1
+ message
+ Entered call from useZeroApplier1
+
+
+ kindevent
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line458
+ col1
+ file0
+
+
+ line458
+ col16
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line459
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col37
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from foo
+ message
+ Returning from foo
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line459
+   col37
+   file0
+  
+  
+   line459
+   col39
+   file0
+  
+ 
+end
+ 
+  
+   line459
+   col35
+   file0
+  
+  
+   line459
+   col35
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line459
+  col35
+  file0
+ 
+ ranges
+ 
+   
+
+ line459
+ col33
+ file0
+
+
+ line459
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line458
+  col1
+  file0
+ 
+ nameAPPLY_ZERO1
+ expansionint foo() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40
+  issue_context_kindfunction
+  issue_contextuseZeroApplier1
+  issue_hash_function_offset0
+  location
+  
+   line459
+   col35
+   file0
+  
+  ExecutedLines
+  
+   0
+   
+458
+459
+   
+  
+  
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line468
+   col33
+ 

[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-12 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib added a comment.

I rebased the patch on the current master.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893



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


[PATCH] D57893: [analyzer] Fix function macro crash

2019-03-09 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.
Herald added a subscriber: whisperity.

This patch no longer applies cleanly to the latest version of clang -- could 
you rebase please?


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893



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


[PATCH] D57893: [analyzer] Fix function macro crash

2019-02-10 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib updated this revision to Diff 186161.

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

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -441,3 +441,21 @@
 }
 // CHECK: nameYET_ANOTHER_SET_TO_NULL
 // CHECK-NEXT: expansionprint((void *)5); print((void *)Remember the Vasa); ptr = nullptr;
+
+#define FOO(x) int foo() { return x; }
+#define APPLY_ZERO1(function) function(0)
+
+APPLY_ZERO1(FOO)
+void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO1
+// CHECK-NEXT: expansionint foo() { return x; }(0)
+
+#define BAR(x) int bar() { return x; }
+#define APPLY_ZERO2 BAR(0)
+
+APPLY_ZERO2
+void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO2
+// CHECK-NEXT: expansionint bar() { return 0; }
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5168,6 +5168,468 @@
file0
   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line449
+   col33
+   file0
+  
+  
+   line449
+   col33
+   file0
+  
+ 
+end
+ 
+  
+   line449
+   col37
+   file0
+  
+  
+   line449
+   col39
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line449
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line449
+ col37
+ file0
+
+
+ line449
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling foo
+ message
+ Calling foo
+
+
+ kindevent
+ location
+ 
+  line448
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier1
+ message
+ Entered call from useZeroApplier1
+
+
+ kindevent
+ location
+ 
+  line448
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line448
+ col1
+ file0
+
+
+ line448
+ col16
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line449
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line449
+ col37
+ file0
+
+
+ line449
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from foo
+ message
+ Returning from foo
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line449
+   col37
+   file0
+  
+  
+   line449
+   col39
+   file0
+  
+ 
+end
+ 
+  
+   line449
+   col35
+   file0
+  
+  
+   line449
+   col35
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line449
+  col35
+  file0
+ 
+ ranges
+ 
+   
+
+ line449
+ col33
+ file0
+
+
+ line449
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line448
+  col1
+  file0
+ 
+ nameAPPLY_ZERO1
+ expansionint foo() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40
+  issue_context_kindfunction
+  issue_contextuseZeroApplier1
+  issue_hash_function_offset0
+  location
+  
+   line449
+   col35
+   file0
+  
+  
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line458
+   col33
+   file0
+  
+  
+   line458
+ 

[PATCH] D57893: [analyzer] Fix function macro crash

2019-02-08 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib updated this revision to Diff 185971.
bruntib added a comment.

There was another place where this crash could have happened.


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

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -441,3 +441,17 @@
 }
 // CHECK: nameYET_ANOTHER_SET_TO_NULL
 // CHECK-NEXT: expansionprint((void *)5); print((void *)Remember the Vasa); ptr = nullptr;
+
+#define FOO(x) int foo() { return x; }
+#define APPLY_ZERO1(function) function(0)
+#define BAR(x) int bar() { return x; }
+#define APPLY_ZERO2 BAR(0)
+APPLY_ZERO1(FOO)
+APPLY_ZERO2
+void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}}
+void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}}
+
+// CHECK: nameAPPLY_ZERO1
+// CHECK-NEXT: expansionint foo() { return x; }(0)
+// CHECK: nameAPPLY_ZERO2
+// CHECK-NEXT: expansionint bar() { return 0; }
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5168,6 +5168,468 @@
file0
   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line451
+   col33
+   file0
+  
+  
+   line451
+   col33
+   file0
+  
+ 
+end
+ 
+  
+   line451
+   col37
+   file0
+  
+  
+   line451
+   col39
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line451
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line451
+ col37
+ file0
+
+
+ line451
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling foo
+ message
+ Calling foo
+
+
+ kindevent
+ location
+ 
+  line449
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier1
+ message
+ Entered call from useZeroApplier1
+
+
+ kindevent
+ location
+ 
+  line449
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line449
+ col1
+ file0
+
+
+ line449
+ col16
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line451
+  col37
+  file0
+ 
+ ranges
+ 
+   
+
+ line451
+ col37
+ file0
+
+
+ line451
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from foo
+ message
+ Returning from foo
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line451
+   col37
+   file0
+  
+  
+   line451
+   col39
+   file0
+  
+ 
+end
+ 
+  
+   line451
+   col35
+   file0
+  
+  
+   line451
+   col35
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line451
+  col35
+  file0
+ 
+ ranges
+ 
+   
+
+ line451
+ col33
+ file0
+
+
+ line451
+ col41
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line449
+  col1
+  file0
+ 
+ nameAPPLY_ZERO1
+ expansionint foo() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40
+  issue_context_kindfunction
+  issue_contextuseZeroApplier1
+  issue_hash_function_offset0
+  location
+  
+   line451
+   col35
+   file0
+  
+  
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line452
+

[PATCH] D57893: [analyzer] Fix function macro crash

2019-02-08 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Awesome, thanks! Will commit around next Friday.


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

https://reviews.llvm.org/D57893



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


[PATCH] D57893: [analyzer] Fix function macro crash

2019-02-08 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib updated this revision to Diff 185957.
bruntib added a comment.

I've added a test case.


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

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  test/Analysis/plist-macros-with-expansion.cpp

Index: test/Analysis/plist-macros-with-expansion.cpp
===
--- test/Analysis/plist-macros-with-expansion.cpp
+++ test/Analysis/plist-macros-with-expansion.cpp
@@ -441,3 +441,13 @@
 }
 // CHECK: nameYET_ANOTHER_SET_TO_NULL
 // CHECK-NEXT: expansionprint((void *)5); print((void *)Remember the Vasa); ptr = nullptr;
+
+#define FOO(x) int bar() { return x; }
+#define APPLY_ZERO(function) function(0)
+APPLY_ZERO(FOO)
+void useZeroApplier() {
+  (void)(1 / bar()); // expected-warning{{Division by zero}}
+}
+
+// CHECK: nameAPPLY_ZERO
+// CHECK-NEXT: expansionint bar() { return x; }(0)
Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5168,6 +5168,237 @@
file0
   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line449
+   col10
+   file0
+  
+  
+   line449
+   col10
+   file0
+  
+ 
+end
+ 
+  
+   line449
+   col14
+   file0
+  
+  
+   line449
+   col16
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line449
+  col14
+  file0
+ 
+ ranges
+ 
+   
+
+ line449
+ col14
+ file0
+
+
+ line449
+ col18
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Calling bar
+ message
+ Calling bar
+
+
+ kindevent
+ location
+ 
+  line447
+  col1
+  file0
+ 
+ depth1
+ extended_message
+ Entered call from useZeroApplier
+ message
+ Entered call from useZeroApplier
+
+
+ kindevent
+ location
+ 
+  line447
+  col1
+  file0
+ 
+ ranges
+ 
+   
+
+ line447
+ col1
+ file0
+
+
+ line447
+ col15
+ file0
+
+   
+ 
+ depth1
+ extended_message
+ Returning zero
+ message
+ Returning zero
+
+
+ kindevent
+ location
+ 
+  line449
+  col14
+  file0
+ 
+ ranges
+ 
+   
+
+ line449
+ col14
+ file0
+
+
+ line449
+ col18
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Returning from bar
+ message
+ Returning from bar
+
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line449
+   col14
+   file0
+  
+  
+   line449
+   col16
+   file0
+  
+ 
+end
+ 
+  
+   line449
+   col12
+   file0
+  
+  
+   line449
+   col12
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line449
+  col12
+  file0
+ 
+ ranges
+ 
+   
+
+ line449
+ col10
+ file0
+
+
+ line449
+ col18
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line447
+  col1
+  file0
+ 
+ nameAPPLY_ZERO
+ expansionint bar() { return x; }(0)
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_contextb41a3835d64fddaac63749c968f17e81
+  issue_context_kindfunction
+  issue_contextuseZeroApplier
+  issue_hash_function_offset1
+  location
+  
+   line449
+   col12
+   file0
+  
+  
  
 
 
Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -879,8 +879,18 @@
 
 getMacroNameAndPrintExpansion(Printer, ArgIt->getLocation(), PP,
   Info.Args, AlreadyProcessedTokens);
-if 

[PATCH] D57893: [analyzer] Fix function macro crash

2019-02-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus requested changes to this revision.
Szelethus added a comment.
This revision now requires changes to proceed.

Actually, reproducing this with a testcase would be much preferred here too.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893



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


[PATCH] D57893: [analyzer] Fix function macro crash

2019-02-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Cheers! Let's wait for a couple days for feedback, and I'll commit on your 
behalf after that.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57893



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


[PATCH] D57893: [analyzer] Fix function macro crash

2019-02-07 Thread Tibor Brunner via Phabricator via cfe-commits
bruntib created this revision.
bruntib added reviewers: NoQ, george.karpenkov, Szelethus, xazax.hun.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware.
Herald added a project: clang.

When there is a functor-like macro which is passed as parameter to another 
"function" macro then its parameters are not listed at the place of expansion:

#define foo(x) int bar() { return x; }
#define hello(fvar) fvar(0)
hello(foo)
int main() { 1 / bar(); }

Expansion of hello(foo) asserted Clang, because it expected an l_paren token in 
the 3rd line after "foo", since it is a function-like token.


Repository:
  rC Clang

https://reviews.llvm.org/D57893

Files:
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp


Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -879,8 +879,18 @@
 
 getMacroNameAndPrintExpansion(Printer, ArgIt->getLocation(), PP,
   Info.Args, AlreadyProcessedTokens);
-if (MI->getNumParams() != 0)
-  ArgIt = getMatchingRParen(++ArgIt, ArgEnd);
+// Peek the next token if it is a tok::l_paren. This way we can decide
+// if this is the application or just a reference to a function maxro
+// symbol:
+//
+// #define apply(f) ...
+// #define func(x) ...
+// apply(func)
+// apply(func(42))
+if ((++ArgIt)->is(tok::l_paren))
+  ArgIt = getMatchingRParen(ArgIt, ArgEnd);
+else
+  --ArgIt;
   }
   continue;
 }
@@ -941,8 +951,16 @@
 return { MacroName, MI, {} };
 
   RawLexer.LexFromRawLexer(TheTok);
-  assert(TheTok.is(tok::l_paren) &&
- "The token after the macro's identifier token should be '('!");
+  // When this is a token which expands to another macro function then its
+  // parentheses are not at its expansion locaiton. For example:
+  //
+  // #define foo(x) int bar() { return x; }
+  // #define apply_zero(f) f(0)
+  // apply_zero(foo)
+  //   ^
+  //   This is not a tok::l_paren, but foo is a function.
+  if (TheTok.isNot(tok::l_paren))
+return { MacroName, MI, {} };
 
   MacroArgMap Args;
 


Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -879,8 +879,18 @@
 
 getMacroNameAndPrintExpansion(Printer, ArgIt->getLocation(), PP,
   Info.Args, AlreadyProcessedTokens);
-if (MI->getNumParams() != 0)
-  ArgIt = getMatchingRParen(++ArgIt, ArgEnd);
+// Peek the next token if it is a tok::l_paren. This way we can decide
+// if this is the application or just a reference to a function maxro
+// symbol:
+//
+// #define apply(f) ...
+// #define func(x) ...
+// apply(func)
+// apply(func(42))
+if ((++ArgIt)->is(tok::l_paren))
+  ArgIt = getMatchingRParen(ArgIt, ArgEnd);
+else
+  --ArgIt;
   }
   continue;
 }
@@ -941,8 +951,16 @@
 return { MacroName, MI, {} };
 
   RawLexer.LexFromRawLexer(TheTok);
-  assert(TheTok.is(tok::l_paren) &&
- "The token after the macro's identifier token should be '('!");
+  // When this is a token which expands to another macro function then its
+  // parentheses are not at its expansion locaiton. For example:
+  //
+  // #define foo(x) int bar() { return x; }
+  // #define apply_zero(f) f(0)
+  // apply_zero(foo)
+  //   ^
+  //   This is not a tok::l_paren, but foo is a function.
+  if (TheTok.isNot(tok::l_paren))
+return { MacroName, MI, {} };
 
   MacroArgMap Args;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits