aboutsummaryrefslogtreecommitdiff
path: root/clang/utils
diff options
context:
space:
mode:
authorziqingluo-90 <ziqing@udel.edu>2023-10-20 14:21:34 -0700
committerziqingluo-90 <ziqing@udel.edu>2023-10-20 14:27:14 -0700
commita4323586fcbb20f39f00d5d1bc4a94a1aeea15c4 (patch)
treefa97963375cad6075dfc4f88b567ebc1c93fa578 /clang/utils
parenta9694043c9b8625fbe0d1a34bc5afadf380cda97 (diff)
downloadllvm-a4323586fcbb20f39f00d5d1bc4a94a1aeea15c4.zip
llvm-a4323586fcbb20f39f00d5d1bc4a94a1aeea15c4.tar.gz
llvm-a4323586fcbb20f39f00d5d1bc4a94a1aeea15c4.tar.bz2
[-Wunsafe-buffer-usage] Add AST info to the unclaimed DRE debug notes for analysis
- For a better understand of what the unsupported cases are, we add more information to the debug note---a string of ancestor AST nodes of the unclaimed DRE. For example, an unclaimed DRE p in an expression `*(p++)` will result in a string starting with `DRE ==> UnaryOperator(++) ==> Paren ==> UnaryOperator(*)`. - To find out the most common patterns of those unsupported use cases, we add a simple script to build a prefix tree over those strings and count each prefix. The script reads input line by line, assumes a line is a list of words separated by `==>`s, and builds a prefix tree over those lists. Reviewed by: t-rasmud (Rashmi Mudduluru), NoQ (Artem Dergachev) Differential revision: https://reviews.llvm.org/D158561
Diffstat (limited to 'clang/utils')
-rw-r--r--clang/utils/analyze_safe_buffer_debug_notes.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/clang/utils/analyze_safe_buffer_debug_notes.py b/clang/utils/analyze_safe_buffer_debug_notes.py
new file mode 100644
index 0000000..f0a6e4d
--- /dev/null
+++ b/clang/utils/analyze_safe_buffer_debug_notes.py
@@ -0,0 +1,39 @@
+import sys
+from collections import OrderedDict
+
+class Trie:
+ def __init__(self, name):
+ self.name = name
+ self.children = OrderedDict()
+ self.count = 1
+
+ def add(self, name):
+ if name in self.children:
+ self.children[name].count += 1
+ else:
+ self.children[name] = Trie(name)
+ return self.children[name]
+
+ def print(self, depth):
+ if depth > 0:
+ print('|', end="")
+ for i in range(depth):
+ print('-', end="")
+ if depth > 0:
+ print(end=" ")
+ print(self.name, '#', self.count)
+ for key, child in self.children.items():
+ child.print(depth + 1)
+
+
+Root = Trie("Root")
+
+if __name__ == "__main__":
+ for line in sys.stdin:
+ words = line.split('==>')
+ words = [word.strip() for word in words]
+ MyTrie = Root;
+ for word in words:
+ MyTrie = MyTrie.add(word)
+
+ Root.print(0)