From df7682b19c5fef024ba10a2f77028c2093a306fd Mon Sep 17 00:00:00 2001
From: Andre Maroneze <andre.maroneze@cea.fr>
Date: Mon, 19 Oct 2020 21:56:14 +0200
Subject: [PATCH] [analysis-scripts] add a few more heuristics for difficulty
 estimation

---
 share/analysis-scripts/estimate_difficulty.py | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/share/analysis-scripts/estimate_difficulty.py b/share/analysis-scripts/estimate_difficulty.py
index 02de99f5a0b..8f5e89b3354 100755
--- a/share/analysis-scripts/estimate_difficulty.py
+++ b/share/analysis-scripts/estimate_difficulty.py
@@ -219,3 +219,27 @@ for header in chevron_includes:
             non_posix_headers.append(header)
             print(f"- warning: included non-POSIX header <{header}>")
 print(f"Header-related warnings: {len(non_posix_headers)}")
+
+
+# dynamic allocation
+
+dynalloc_functions = set(["malloc", "calloc", "free", "realloc", "alloca", "mmap"])
+dyncallees = dynalloc_functions.intersection(callees)
+if dyncallees:
+    print(f"- note: calls to dynamic allocation functions: {', '.join(sorted(dyncallees))}")
+
+
+# unsupported C11-specific features
+
+c11_unsupported = ["_Alignas", "_Alignof", "_Generic", "_Static_assert"]
+
+for keyword in c11_unsupported:
+    out = subprocess.Popen(["grep", "-n", '\\b' + keyword + '\\b'] + files + ["/dev/null"],
+                           stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    lines = out.communicate()[0].decode('utf-8').splitlines()
+    if lines:
+        n = len(lines)
+        print(f"- warning: found {n} line{'s' if n > 1 else ''} with occurrences of unsupported C11 construct '{keyword}'")
+
+# TODO:
+# - detect absence of 'main' function (library)
-- 
GitLab