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.
Successfully regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r12-6781-gf5a9d76be849b4cf20b1b687febc34a937381dc3. gcc/testsuite/ChangeLog: PR analyzer/103685 * gcc.dg/analyzer/torture/pr103685.c: New test. Signed-off-by: David Malcolm <dmalc...@redhat.com> --- .../gcc.dg/analyzer/torture/pr103685.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/pr103685.c diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr103685.c b/gcc/testsuite/gcc.dg/analyzer/torture/pr103685.c new file mode 100644 index 00000000000..1b222487417 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/pr103685.c @@ -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; +} -- 2.26.3