analyzer: add regression test [PR103685]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 19 Jan 2022 17:09:09 +0000 (12:09 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 20 Jan 2022 23:42:33 +0000 (18:42 -0500)
PR analyzer/103685 reports a false positive from -Wanalyzer-null-dereference
seen at -O2 with GCC 11.  I can reproduce it with GCC 11, but not with
trunk; this patch adds a reduced test case that reproduces it with
GCC 11 as a regression test for GCC 12 onwards.

gcc/testsuite/ChangeLog:
PR analyzer/103685
* gcc.dg/analyzer/torture/pr103685.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/testsuite/gcc.dg/analyzer/torture/pr103685.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr103685.c b/gcc/testsuite/gcc.dg/analyzer/torture/pr103685.c
new file mode 100644 (file)
index 0000000..1b22248
--- /dev/null
@@ -0,0 +1,33 @@
+typedef struct ec_key_st EC_KEY;
+typedef struct ec_group_st EC_GROUP;
+typedef struct R3410_ec {
+  int nid;
+  EC_GROUP *group;
+} R3410_ec_params;
+extern R3410_ec_params R3410_2012_512_paramset[];
+
+static R3410_ec_params *gost_nid2params(int nid) {
+  R3410_ec_params *params;
+
+  params = R3410_2012_512_paramset;
+  while (params->nid != 0) {
+    if (params->nid == nid)
+      return params;
+    params++;
+  }
+
+  return ((void *)0);
+}
+
+int fill_GOST_EC_params(EC_KEY *eckey, int nid) {
+  R3410_ec_params *params = gost_nid2params(nid);
+  if (!eckey || !params) {
+    return 0;
+  }
+
+  if (params->group) {
+    return 1;
+  }
+
+  return 0;
+}