]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: Move gcc.dg/analyzer tests to c-c++-common (1) [PR96395]
authorbenjamin priour <vultkayn@gcc.gnu.org>
Sun, 27 Aug 2023 12:36:14 +0000 (14:36 +0200)
committerbenjamin priour <vultkayn@gcc.gnu.org>
Sun, 27 Aug 2023 12:50:43 +0000 (14:50 +0200)
First batch of moving tests from under gcc.dg/analyzer into
c-c++-common/analyzer.

C builtins are not recognized as such by C++, therefore
this patch no longer uses tree.h:fndecl_built_in_p to recognize
a builtin function, but rather the function names.

Thus functions named as C builtins - such as calloc, sprintf ... -
are recognized as such both in C and C++ sources by the analyzer.

For user-declared functions named after builtins, the latters' function_decl
tree are now preferred over the function_decl the user declared, even
when the FE consider their declaration to mismatch
(Wbuiltin-declaration-mismatch emitted). This mainly comes into account
in the handling of these function attributes : the analyzer uses
the builtin's attributes defined in gcc/builtins.def.

Signed-off-by: benjamin priour <priour.be@gmail.com>
gcc/analyzer/ChangeLog:

PR analyzer/96395
* analyzer.h (class known_function): Add virtual casts
to builtin_known_function.
(class builtin_known_function): New subclass of known_function
for builtins.
* kf.cc (class kf_alloca): Now derived from
builtin_known_function.
(class kf_calloc): Likewise.
(class kf_free): Likewise.
(class kf_malloc): Likewise.
(class kf_memcpy_memmove): Likewise.
(class kf_memset): Likewise.
(class kf_realloc): Likewise.
(class kf_strchr): Likewise.
(class kf_sprintf): Likewise.
(class kf_strcat): Likewise.
(class kf_strcpy): Likewise.
(class kf_strdup): Likewise.
(class kf_strlen): Likewise.
(class kf_strndup): Likewise.
(register_known_functions): Builtins are now registered as
known_functions by name rather than by their BUILTIN_CODE.
* known-function-manager.cc (get_normal_builtin): New overload.
* known-function-manager.h: New overload declaration.
* region-model.cc (region_model::get_builtin_kf): New function.
* region-model.h (class region_model): Add declaration of
get_builtin_kf.
* sm-fd.cc: For called recognized as builtins, use the
attributes of that builtin as defined in gcc/builtins.def
rather than the user's.
* sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.

gcc/testsuite/ChangeLog:

PR analyzer/96395
* gcc.dg/analyzer/aliasing-3.c: Moved to...
* c-c++-common/analyzer/aliasing-3.c: ...here.
* gcc.dg/analyzer/aliasing-pr106473.c: Moved to...
* c-c++-common/analyzer/aliasing-pr106473.c: ...here.
* gcc.dg/analyzer/asm-x86-dyndbg-2.c: Moved to...
* c-c++-common/analyzer/asm-x86-dyndbg-2.c: ...here.
* gcc.dg/analyzer/asm-x86-lp64-2.c: Moved to...
* c-c++-common/analyzer/asm-x86-lp64-2.c: ...here.
* gcc.dg/analyzer/atomic-builtins-haproxy-proxy.c: Moved to...
* c-c++-common/analyzer/atomic-builtins-haproxy-proxy.c: ...here.
* gcc.dg/analyzer/atomic-builtins-qemu-sockets.c: Moved to...
* c-c++-common/analyzer/atomic-builtins-qemu-sockets.c: ...here.
* gcc.dg/analyzer/attr-malloc-6.c: Moved to...
* c-c++-common/analyzer/attr-malloc-6.c: ...here.
* gcc.dg/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c: Moved to...
* c-c++-common/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c: ...here.
* gcc.dg/analyzer/attr-tainted_args-1.c: Moved to...
* c-c++-common/analyzer/attr-tainted_args-1.c: ...here.
* gcc.dg/analyzer/call-summaries-pr107158.c: Moved to...
* c-c++-common/analyzer/call-summaries-pr107158.c: ...here.
* gcc.dg/analyzer/calloc-1.c: Moved to...
* c-c++-common/analyzer/calloc-1.c: ...here.
* gcc.dg/analyzer/compound-assignment-5.c: Moved to...
* c-c++-common/analyzer/compound-assignment-5.c: ...here.
* gcc.dg/analyzer/coreutils-cksum-pr108664.c: Moved to...
* c-c++-common/analyzer/coreutils-cksum-pr108664.c: ...here.
* gcc.dg/analyzer/coreutils-sum-pr108666.c: Moved to...
* c-c++-common/analyzer/coreutils-sum-pr108666.c: ...here.
* gcc.dg/analyzer/deref-before-check-pr108455-1.c: Moved to...
* c-c++-common/analyzer/deref-before-check-pr108455-1.c: ...here.
* gcc.dg/analyzer/deref-before-check-pr108455-git-pack-revindex.c: Moved to...
* c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c: ...here.
* gcc.dg/analyzer/deref-before-check-pr108475-1.c: Moved to...
* c-c++-common/analyzer/deref-before-check-pr108475-1.c: ...here.
* gcc.dg/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c: Moved to...
* c-c++-common/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c: ...here.
* gcc.dg/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c: Moved to...
* c-c++-common/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c: ...here.
* gcc.dg/analyzer/deref-before-check-pr109239-linux-bus.c: Moved to...
* c-c++-common/analyzer/deref-before-check-pr109239-linux-bus.c: ...here.
* gcc.dg/analyzer/deref-before-check-pr77425.c: Moved to...
* c-c++-common/analyzer/deref-before-check-pr77425.c: ...here.
* gcc.dg/analyzer/exec-1.c: Moved to...
* c-c++-common/analyzer/exec-1.c: ...here.
* gcc.dg/analyzer/feasibility-3.c: Moved to...
* c-c++-common/analyzer/feasibility-3.c: ...here.
* gcc.dg/analyzer/fields.c: Moved to...
* c-c++-common/analyzer/fields.c: ...here.
* gcc.dg/analyzer/function-ptr-5.c: Moved to...
* c-c++-common/analyzer/function-ptr-5.c: ...here.
* gcc.dg/analyzer/infinite-recursion-pr108524-1.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-pr108524-1.c: ...here.
* gcc.dg/analyzer/infinite-recursion-pr108524-2.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-pr108524-2.c: ...here.
* gcc.dg/analyzer/infinite-recursion-pr108524-qobject-json-parser.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-pr108524-qobject-json-parser.c: ...here.
* gcc.dg/analyzer/init.c: Moved to...
* c-c++-common/analyzer/init.c: ...here.
* gcc.dg/analyzer/inlining-3-multiline.c: Moved to...
* c-c++-common/analyzer/inlining-3-multiline.c: ...here.
* gcc.dg/analyzer/inlining-3.c: Moved to...
* c-c++-common/analyzer/inlining-3.c: ...here.
* gcc.dg/analyzer/inlining-4-multiline.c: Moved to...
* c-c++-common/analyzer/inlining-4-multiline.c: ...here.
* gcc.dg/analyzer/inlining-4.c: Moved to...
* c-c++-common/analyzer/inlining-4.c: ...here.
* gcc.dg/analyzer/leak-pr105906.c: Moved to...
* c-c++-common/analyzer/leak-pr105906.c: ...here.
* gcc.dg/analyzer/leak-pr108045-with-call-summaries.c: Moved to...
* c-c++-common/analyzer/leak-pr108045-with-call-summaries.c: ...here.
* gcc.dg/analyzer/leak-pr108045-without-call-summaries.c: Moved to...
* c-c++-common/analyzer/leak-pr108045-without-call-summaries.c: ...here.
* gcc.dg/analyzer/leak-pr109059-1.c: Moved to...
* c-c++-common/analyzer/leak-pr109059-1.c: ...here.
* gcc.dg/analyzer/leak-pr109059-2.c: Moved to...
* c-c++-common/analyzer/leak-pr109059-2.c: ...here.
* gcc.dg/analyzer/malloc-2.c: Moved to...
* c-c++-common/analyzer/malloc-2.c: ...here.
* gcc.dg/analyzer/memcpy-2.c: Moved to...
* c-c++-common/analyzer/memcpy-2.c: ...here.
* gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c: Moved to...
* c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c: ...here.
* gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c: Moved to...
* c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c: ...here.
* gcc.dg/analyzer/null-deref-pr108806-qemu.c: Moved to...
* c-c++-common/analyzer/null-deref-pr108806-qemu.c: ...here.
* gcc.dg/analyzer/null-deref-pr108830.c: Moved to...
* c-c++-common/analyzer/null-deref-pr108830.c: ...here.
* gcc.dg/analyzer/pr101962.c: Moved to...
* c-c++-common/analyzer/pr101962.c: ...here.
* gcc.dg/analyzer/pr103217-2.c: Moved to...
* c-c++-common/analyzer/pr103217-2.c: ...here.
* gcc.dg/analyzer/pr103217.c: Moved to...
* c-c++-common/analyzer/pr103217.c: ...here.
* gcc.dg/analyzer/pr104029.c: Moved to...
* c-c++-common/analyzer/pr104029.c: ...here.
* gcc.dg/analyzer/pr104062.c: Moved to...
* c-c++-common/analyzer/pr104062.c: ...here.
* gcc.dg/analyzer/pr105783.c: Moved to...
* c-c++-common/analyzer/pr105783.c: ...here.
* gcc.dg/analyzer/pr107345.c: Moved to...
* c-c++-common/analyzer/pr107345.c: ...here.
* gcc.dg/analyzer/pr93695-1.c: Moved to...
* c-c++-common/analyzer/pr93695-1.c: ...here.
* gcc.dg/analyzer/pr94596.c: Moved to...
* c-c++-common/analyzer/pr94596.c: ...here.
* gcc.dg/analyzer/pr94839.c: Moved to...
* c-c++-common/analyzer/pr94839.c: ...here.
* gcc.dg/analyzer/pr95152-4.c: C only.
* gcc.dg/analyzer/pr95152-5.c: C only.
* gcc.dg/analyzer/pr95240.c: Moved to...
* c-c++-common/analyzer/pr95240.c: ...here.
* gcc.dg/analyzer/pr96639.c: Moved to...
* c-c++-common/analyzer/pr96639.c: ...here.
* gcc.dg/analyzer/pr96653.c: Moved to...
* c-c++-common/analyzer/pr96653.c: ...here.
* gcc.dg/analyzer/pr96792.c: Moved to...
* c-c++-common/analyzer/pr96792.c: ...here.
* gcc.dg/analyzer/pr96841.c: Moved to...
* c-c++-common/analyzer/pr96841.c: ...here.
* gcc.dg/analyzer/pr98564.c: Moved to...
* c-c++-common/analyzer/pr98564.c: ...here.
* gcc.dg/analyzer/pr98628.c: Moved to...
* c-c++-common/analyzer/pr98628.c: ...here.
* gcc.dg/analyzer/pr98969.c: Moved to...
* c-c++-common/analyzer/pr98969.c: ...here.
* gcc.dg/analyzer/pr99193-2.c: Moved to...
* c-c++-common/analyzer/pr99193-2.c: ...here.
* gcc.dg/analyzer/pr99193-3.c: Moved to...
* c-c++-common/analyzer/pr99193-3.c: ...here.
* gcc.dg/analyzer/pr99716-1.c: Moved to...
* c-c++-common/analyzer/pr99716-1.c: ...here.
* gcc.dg/analyzer/pr99774-1.c: Moved to...
* c-c++-common/analyzer/pr99774-1.c: ...here.
* gcc.dg/analyzer/realloc-1.c: Moved to...
* c-c++-common/analyzer/realloc-1.c: ...here.
* gcc.dg/analyzer/realloc-2.c: Moved to...
* c-c++-common/analyzer/realloc-2.c: ...here.
* gcc.dg/analyzer/realloc-3.c: Moved to...
* c-c++-common/analyzer/realloc-3.c: ...here.
* gcc.dg/analyzer/realloc-4.c: Moved to...
* c-c++-common/analyzer/realloc-4.c: ...here.
* gcc.dg/analyzer/realloc-5.c: Moved to...
* c-c++-common/analyzer/realloc-5.c: ...here.
* gcc.dg/analyzer/realloc-pr110014.c: Moved to...
* c-c++-common/analyzer/realloc-pr110014.c: ...here.
* gcc.dg/analyzer/snprintf-concat.c: Moved to...
* c-c++-common/analyzer/snprintf-concat.c: ...here.
* gcc.dg/analyzer/sock-1.c: Moved to...
* c-c++-common/analyzer/sock-1.c: ...here.
* gcc.dg/analyzer/sprintf-concat.c: Moved to...
* c-c++-common/analyzer/sprintf-concat.c: ...here.
* gcc.dg/analyzer/string-ops-concat-pair.c: Moved to...
* c-c++-common/analyzer/string-ops-concat-pair.c: ...here.
* gcc.dg/analyzer/string-ops-dup.c: Moved to...
* c-c++-common/analyzer/string-ops-dup.c: ...here.
* gcc.dg/analyzer/switch-enum-pr105273-git-vreportf-2.c: Moved to...
* c-c++-common/analyzer/switch-enum-pr105273-git-vreportf-2.c: ...here.
* gcc.dg/analyzer/symbolic-12.c: Moved to...
* c-c++-common/analyzer/symbolic-12.c: ...here.
* gcc.dg/analyzer/uninit-alloca.c: Moved to...
* c-c++-common/analyzer/uninit-alloca.c: ...here.
* gcc.dg/analyzer/untracked-2.c: Moved to...
* c-c++-common/analyzer/untracked-2.c: ...here.
* gcc.dg/analyzer/vasprintf-1.c: Moved to...
* c-c++-common/analyzer/vasprintf-1.c: ...here.
* gcc.dg/analyzer/write-to-const-1.c: Moved to...
* c-c++-common/analyzer/write-to-const-1.c: ...here.
* gcc.dg/analyzer/write-to-function-1.c: C only.
* gcc.dg/analyzer/write-to-string-literal-1.c: Moved to...
* c-c++-common/analyzer/write-to-string-literal-1.c: ...here.
* gcc.dg/analyzer/write-to-string-literal-4-disabled.c: Moved to...
* c-c++-common/analyzer/write-to-string-literal-4-disabled.c: ...here.
* gcc.dg/analyzer/write-to-string-literal-5.c: Moved to...
* c-c++-common/analyzer/write-to-string-literal-5.c: ...here.
* g++.dg/analyzer/analyzer.exp: Now also run tests under
c-c++-common/analyzer.
* gcc.dg/analyzer/analyzer-decls.h: Add NULL definition.
* gcc.dg/analyzer/analyzer.exp: Now also run tests under
c-c++-common/analyzer.
* gcc.dg/analyzer/pr104369-1.c: C only.
* gcc.dg/analyzer/pr104369-2.c: Likewise.
* gcc.dg/analyzer/pr93355-localealias-feasibility-2.c: Likewise.
* gcc.dg/analyzer/sprintf-1.c: Split into C-only and
C++-friendly bits.
* gcc.dg/analyzer/allocation-size-multiline-1.c: Removed.
* gcc.dg/analyzer/allocation-size-multiline-2.c: Removed.
* gcc.dg/analyzer/allocation-size-multiline-3.c: Removed.
* gcc.dg/analyzer/data-model-11.c: Removed.
* gcc.dg/analyzer/pr61861.c: C only.
* gcc.dg/analyzer/pr93457.c: Removed.
* gcc.dg/analyzer/pr97568.c: Removed.
* gcc.dg/analyzer/write-to-string-literal-4.c: Removed.
* c-c++-common/analyzer/allocation-size-multiline-1.c: New test.
* c-c++-common/analyzer/allocation-size-multiline-2.c: New test.
* c-c++-common/analyzer/allocation-size-multiline-3.c: New test.
* c-c++-common/analyzer/data-model-11.c: New test.
* c-c++-common/analyzer/pr93457.c: New test.
* c-c++-common/analyzer/pr97568.c: New test.
* c-c++-common/analyzer/sprintf-2.c: C++-friendly bit of
previous gcc.dg/analyzer/sprintf-1.c.
* c-c++-common/analyzer/write-to-string-literal-4.c: New test.

120 files changed:
gcc/analyzer/analyzer.h
gcc/analyzer/kf.cc
gcc/analyzer/known-function-manager.cc
gcc/analyzer/known-function-manager.h
gcc/analyzer/region-model.cc
gcc/analyzer/region-model.h
gcc/analyzer/sm-fd.cc
gcc/analyzer/sm-malloc.cc
gcc/testsuite/c-c++-common/analyzer/aliasing-3.c [moved from gcc/testsuite/gcc.dg/analyzer/aliasing-3.c with 89% similarity]
gcc/testsuite/c-c++-common/analyzer/aliasing-pr106473.c [moved from gcc/testsuite/gcc.dg/analyzer/aliasing-pr106473.c with 53% similarity]
gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/asm-x86-dyndbg-2.c [moved from gcc/testsuite/gcc.dg/analyzer/asm-x86-dyndbg-2.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/asm-x86-lp64-2.c [moved from gcc/testsuite/gcc.dg/analyzer/asm-x86-lp64-2.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/atomic-builtins-haproxy-proxy.c [moved from gcc/testsuite/gcc.dg/analyzer/atomic-builtins-haproxy-proxy.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/atomic-builtins-qemu-sockets.c [moved from gcc/testsuite/gcc.dg/analyzer/atomic-builtins-qemu-sockets.c with 74% similarity]
gcc/testsuite/c-c++-common/analyzer/attr-malloc-6.c [moved from gcc/testsuite/gcc.dg/analyzer/attr-malloc-6.c with 88% similarity]
gcc/testsuite/c-c++-common/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c [moved from gcc/testsuite/gcc.dg/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/attr-tainted_args-1.c [moved from gcc/testsuite/gcc.dg/analyzer/attr-tainted_args-1.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/call-summaries-pr107158.c [moved from gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/calloc-1.c [moved from gcc/testsuite/gcc.dg/analyzer/calloc-1.c with 87% similarity]
gcc/testsuite/c-c++-common/analyzer/compound-assignment-5.c [moved from gcc/testsuite/gcc.dg/analyzer/compound-assignment-5.c with 83% similarity]
gcc/testsuite/c-c++-common/analyzer/coreutils-cksum-pr108664.c [moved from gcc/testsuite/gcc.dg/analyzer/coreutils-cksum-pr108664.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/coreutils-sum-pr108666.c [moved from gcc/testsuite/gcc.dg/analyzer/coreutils-sum-pr108666.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/data-model-11.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-1.c [moved from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108455-1.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c [moved from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108455-git-pack-revindex.c with 98% similarity]
gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108475-1.c [moved from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108475-1.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c [moved from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c [moved from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr109239-linux-bus.c [moved from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr109239-linux-bus.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr77425.c [moved from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr77425.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/exec-1.c [moved from gcc/testsuite/gcc.dg/analyzer/exec-1.c with 59% similarity]
gcc/testsuite/c-c++-common/analyzer/feasibility-3.c [moved from gcc/testsuite/gcc.dg/analyzer/feasibility-3.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/fields.c [moved from gcc/testsuite/gcc.dg/analyzer/fields.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/function-ptr-5.c [moved from gcc/testsuite/gcc.dg/analyzer/function-ptr-5.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108524-1.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-1.c with 98% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108524-2.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-2.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108524-qobject-json-parser.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-qobject-json-parser.c with 99% similarity]
gcc/testsuite/c-c++-common/analyzer/init.c [moved from gcc/testsuite/gcc.dg/analyzer/init.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-3-multiline.c with 55% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-3.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-3.c with 51% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-4-multiline.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-4-multiline.c with 54% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-4.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-4.c with 51% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-pr105906.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-pr105906.c with 81% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-pr108045-with-call-summaries.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-pr108045-with-call-summaries.c with 87% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-pr108045-without-call-summaries.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-pr108045-without-call-summaries.c with 87% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-pr109059-1.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-pr109059-1.c with 93% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-pr109059-2.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-pr109059-2.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-2.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-2.c with 89% similarity]
gcc/testsuite/c-c++-common/analyzer/memcpy-2.c [moved from gcc/testsuite/gcc.dg/analyzer/memcpy-2.c with 79% similarity]
gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c [moved from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c with 93% similarity]
gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c [moved from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c with 93% similarity]
gcc/testsuite/c-c++-common/analyzer/null-deref-pr108806-qemu.c [moved from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108806-qemu.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/null-deref-pr108830.c [moved from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108830.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/pr101962.c [moved from gcc/testsuite/gcc.dg/analyzer/pr101962.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/pr103217-2.c [moved from gcc/testsuite/gcc.dg/analyzer/pr103217-2.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/pr103217.c [moved from gcc/testsuite/gcc.dg/analyzer/pr103217.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/pr104029.c [moved from gcc/testsuite/gcc.dg/analyzer/pr104029.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/pr104062.c [moved from gcc/testsuite/gcc.dg/analyzer/pr104062.c with 70% similarity]
gcc/testsuite/c-c++-common/analyzer/pr105783.c [moved from gcc/testsuite/gcc.dg/analyzer/pr105783.c with 85% similarity]
gcc/testsuite/c-c++-common/analyzer/pr107345.c [moved from gcc/testsuite/gcc.dg/analyzer/pr107345.c with 73% similarity]
gcc/testsuite/c-c++-common/analyzer/pr93457.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/pr93695-1.c [moved from gcc/testsuite/gcc.dg/analyzer/pr93695-1.c with 83% similarity]
gcc/testsuite/c-c++-common/analyzer/pr94596.c [moved from gcc/testsuite/gcc.dg/analyzer/pr94596.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/pr94839.c [moved from gcc/testsuite/gcc.dg/analyzer/pr94839.c with 82% similarity]
gcc/testsuite/c-c++-common/analyzer/pr95240.c [moved from gcc/testsuite/gcc.dg/analyzer/pr95240.c with 89% similarity]
gcc/testsuite/c-c++-common/analyzer/pr96639.c [moved from gcc/testsuite/gcc.dg/analyzer/pr96639.c with 80% similarity]
gcc/testsuite/c-c++-common/analyzer/pr96653.c [moved from gcc/testsuite/gcc.dg/analyzer/pr96653.c with 98% similarity]
gcc/testsuite/c-c++-common/analyzer/pr96792.c [moved from gcc/testsuite/gcc.dg/analyzer/pr96792.c with 93% similarity]
gcc/testsuite/c-c++-common/analyzer/pr96841.c [moved from gcc/testsuite/gcc.dg/analyzer/pr96841.c with 89% similarity]
gcc/testsuite/c-c++-common/analyzer/pr97568.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/pr98564.c [moved from gcc/testsuite/gcc.dg/analyzer/pr98564.c with 59% similarity]
gcc/testsuite/c-c++-common/analyzer/pr98628.c [moved from gcc/testsuite/gcc.dg/analyzer/pr98628.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/pr98969.c [moved from gcc/testsuite/gcc.dg/analyzer/pr98969.c with 61% similarity]
gcc/testsuite/c-c++-common/analyzer/pr99193-2.c [moved from gcc/testsuite/gcc.dg/analyzer/pr99193-2.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/pr99193-3.c [moved from gcc/testsuite/gcc.dg/analyzer/pr99193-3.c with 91% similarity]
gcc/testsuite/c-c++-common/analyzer/pr99716-1.c [moved from gcc/testsuite/gcc.dg/analyzer/pr99716-1.c with 93% similarity]
gcc/testsuite/c-c++-common/analyzer/pr99774-1.c [moved from gcc/testsuite/gcc.dg/analyzer/pr99774-1.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/realloc-1.c [moved from gcc/testsuite/gcc.dg/analyzer/realloc-1.c with 84% similarity]
gcc/testsuite/c-c++-common/analyzer/realloc-2.c [moved from gcc/testsuite/gcc.dg/analyzer/realloc-2.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/realloc-3.c [moved from gcc/testsuite/gcc.dg/analyzer/realloc-3.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/realloc-4.c [moved from gcc/testsuite/gcc.dg/analyzer/realloc-4.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/realloc-5.c [moved from gcc/testsuite/gcc.dg/analyzer/realloc-5.c with 90% similarity]
gcc/testsuite/c-c++-common/analyzer/realloc-pr110014.c [moved from gcc/testsuite/gcc.dg/analyzer/realloc-pr110014.c with 70% similarity]
gcc/testsuite/c-c++-common/analyzer/snprintf-concat.c [moved from gcc/testsuite/gcc.dg/analyzer/snprintf-concat.c with 81% similarity]
gcc/testsuite/c-c++-common/analyzer/sock-1.c [moved from gcc/testsuite/gcc.dg/analyzer/sock-1.c with 91% similarity]
gcc/testsuite/c-c++-common/analyzer/sprintf-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/sprintf-concat.c [moved from gcc/testsuite/gcc.dg/analyzer/sprintf-concat.c with 82% similarity]
gcc/testsuite/c-c++-common/analyzer/string-ops-concat-pair.c [moved from gcc/testsuite/gcc.dg/analyzer/string-ops-concat-pair.c with 83% similarity]
gcc/testsuite/c-c++-common/analyzer/string-ops-dup.c [moved from gcc/testsuite/gcc.dg/analyzer/string-ops-dup.c with 83% similarity]
gcc/testsuite/c-c++-common/analyzer/switch-enum-pr105273-git-vreportf-2.c [moved from gcc/testsuite/gcc.dg/analyzer/switch-enum-pr105273-git-vreportf-2.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/symbolic-12.c [moved from gcc/testsuite/gcc.dg/analyzer/symbolic-12.c with 88% similarity]
gcc/testsuite/c-c++-common/analyzer/uninit-alloca.c [moved from gcc/testsuite/gcc.dg/analyzer/uninit-alloca.c with 57% similarity]
gcc/testsuite/c-c++-common/analyzer/untracked-2.c [moved from gcc/testsuite/gcc.dg/analyzer/untracked-2.c with 76% similarity]
gcc/testsuite/c-c++-common/analyzer/vasprintf-1.c [moved from gcc/testsuite/gcc.dg/analyzer/vasprintf-1.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/write-to-const-1.c [moved from gcc/testsuite/gcc.dg/analyzer/write-to-const-1.c with 91% similarity]
gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-1.c [moved from gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-1.c with 73% similarity]
gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-4-disabled.c [moved from gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4-disabled.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-5.c [moved from gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-5.c with 59% similarity]
gcc/testsuite/g++.dg/analyzer/analyzer.exp
gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-1.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-2.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-3.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/analyzer-decls.h
gcc/testsuite/gcc.dg/analyzer/analyzer.exp
gcc/testsuite/gcc.dg/analyzer/data-model-11.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/pr104369-1.c
gcc/testsuite/gcc.dg/analyzer/pr104369-2.c
gcc/testsuite/gcc.dg/analyzer/pr61861.c
gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility-2.c
gcc/testsuite/gcc.dg/analyzer/pr93457.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/pr95152-4.c
gcc/testsuite/gcc.dg/analyzer/pr95152-5.c
gcc/testsuite/gcc.dg/analyzer/pr97568.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/sprintf-1.c
gcc/testsuite/gcc.dg/analyzer/write-to-function-1.c
gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4.c [deleted file]

index 93a28b4b5cffb5a71a9f2ff69c0611baad9a88ae..9b351b5ed5689a55ca90114dc8501dd7d65dd909 100644 (file)
@@ -128,6 +128,10 @@ struct interesting_t;
 
 class feasible_node;
 
+class known_function;
+  class builtin_known_function;
+  class internal_known_function;
+
 /* Forward decls of functions.  */
 
 extern void dump_tree (pretty_printer *pp, tree t);
@@ -279,6 +283,24 @@ public:
   {
     return;
   }
+
+  virtual const builtin_known_function *
+  dyn_cast_builtin_kf () const { return NULL; }
+};
+
+/* Subclass of known_function for builtin functions.  */
+
+class builtin_known_function : public known_function
+{
+public:
+  virtual enum built_in_function builtin_code () const = 0;
+  tree builtin_decl () const {
+    gcc_assert (builtin_code () < END_BUILTINS);
+    return builtin_info[builtin_code ()].decl;
+  }
+
+  const builtin_known_function *
+  dyn_cast_builtin_kf () const final override { return this; }
 };
 
 /* Subclass of known_function for IFN_* functions.  */
index 36d9d10bb013251a5a5ace26e74919c7e978ac8e..333ffd9751ae85023e8b82e46d79b4eeb57b4afa 100644 (file)
@@ -53,13 +53,17 @@ impl_call_pre (const call_details &cd) const
 
 /* Handler for "alloca".  */
 
-class kf_alloca : public known_function
+class kf_alloca : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return cd.num_args () == 1;
   }
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_ALLOCA;
+  }
   void impl_call_pre (const call_details &cd) const final override;
 };
 
@@ -322,7 +326,7 @@ public:
 
 /* Handler for "calloc".  */
 
-class kf_calloc : public known_function
+class kf_calloc : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
@@ -331,6 +335,11 @@ public:
            && cd.arg_is_size_p (0)
            && cd.arg_is_size_p (1));
   }
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_CALLOC;
+  }
+
   void impl_call_pre (const call_details &cd) const final override;
 };
 
@@ -462,12 +471,16 @@ public:
    all pointers to the region to the "freed" state together, regardless
    of casts.  */
 
-class kf_free : public known_function
+class kf_free : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
   {
-    return (cd.num_args () == 0 && cd.arg_is_pointer_p (0));
+    return (cd.num_args () == 1 && cd.arg_is_pointer_p (0));
+  }
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_FREE;
   }
   void impl_call_post (const call_details &cd) const final override;
 };
@@ -488,7 +501,7 @@ kf_free::impl_call_post (const call_details &cd) const
 
 /* Handle the on_call_pre part of "malloc".  */
 
-class kf_malloc : public known_function
+class kf_malloc : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
@@ -496,6 +509,10 @@ public:
     return (cd.num_args () == 1
            && cd.arg_is_size_p (0));
   }
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_MALLOC;
+  }
   void impl_call_pre (const call_details &cd) const final override;
 };
 
@@ -520,9 +537,18 @@ kf_malloc::impl_call_pre (const call_details &cd) const
 /* TODO: complain about overlapping src and dest for the memcpy
    variants.  */
 
-class kf_memcpy_memmove : public known_function
+class kf_memcpy_memmove : public builtin_known_function
 {
 public:
+  enum kf_memcpy_memmove_variant
+  {
+    KF_MEMCPY,
+    KF_MEMCPY_CHK,
+    KF_MEMMOVE,
+    KF_MEMMOVE_CHK,
+  };
+  kf_memcpy_memmove (enum kf_memcpy_memmove_variant variant)
+    : m_variant (variant) {};
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return (cd.num_args () == 3
@@ -530,7 +556,25 @@ public:
            && cd.arg_is_pointer_p (1)
            && cd.arg_is_size_p (2));
   }
+  enum built_in_function builtin_code () const final override
+  {
+    switch (m_variant)
+      {
+      case KF_MEMCPY:
+       return BUILT_IN_MEMCPY;
+      case KF_MEMCPY_CHK:
+       return BUILT_IN_MEMCPY_CHK;
+      case KF_MEMMOVE:
+       return BUILT_IN_MEMMOVE;
+      case KF_MEMMOVE_CHK:
+       return BUILT_IN_MEMMOVE_CHK;
+      default:
+       gcc_unreachable ();
+      }
+  }
   void impl_call_pre (const call_details &cd) const final override;
+private:
+  const enum kf_memcpy_memmove_variant m_variant;
 };
 
 void
@@ -557,15 +601,21 @@ kf_memcpy_memmove::impl_call_pre (const call_details &cd) const
 
 /* Handler for "memset" and "__builtin_memset".  */
 
-class kf_memset : public known_function
+class kf_memset : public builtin_known_function
 {
 public:
+  kf_memset (bool chk_variant) : m_chk_variant (chk_variant) {}
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return (cd.num_args () == 3 && cd.arg_is_pointer_p (0));
   }
-
+  enum built_in_function builtin_code () const final override
+  {
+    return m_chk_variant ? BUILT_IN_MEMSET_CHK : BUILT_IN_MEMSET;
+  }
   void impl_call_pre (const call_details &cd) const final override;
+private:
+  const bool m_chk_variant;
 };
 
 void
@@ -747,7 +797,7 @@ public:
    Each of these has a custom_edge_info subclass, which updates
    the region_model and sm-state of the destination state.  */
 
-class kf_realloc : public known_function
+class kf_realloc : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
@@ -756,6 +806,12 @@ public:
            && cd.arg_is_pointer_p (0)
            && cd.arg_is_size_p (1));
   }
+
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_REALLOC;
+  }
+
   void impl_call_post (const call_details &cd) const final override;
 };
 
@@ -968,7 +1024,7 @@ kf_realloc::impl_call_post (const call_details &cd) const
 
 /* Handler for "strchr" and "__builtin_strchr".  */
 
-class kf_strchr : public known_function
+class kf_strchr : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
@@ -979,6 +1035,11 @@ public:
   {
     cd.check_for_null_terminated_string_arg (0);
   }
+
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_STRCHR;
+  }
   void impl_call_post (const call_details &cd) const final override;
 };
 
@@ -1055,7 +1116,7 @@ kf_strchr::impl_call_post (const call_details &cd) const
      int sprintf(char *str, const char *format, ...);
 */
 
-class kf_sprintf : public known_function
+class kf_sprintf : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
@@ -1065,6 +1126,11 @@ public:
            && cd.arg_is_pointer_p (1));
   }
 
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_SPRINTF;
+  }
+
   void impl_call_pre (const call_details &cd) const final override
   {
     /* For now, merely assume that the destination buffer gets set to a
@@ -1108,10 +1174,12 @@ public:
 
 /* Handler for "strcat" and "__builtin_strcat_chk".  */
 
-class kf_strcat : public known_function
+class kf_strcat : public builtin_known_function
 {
 public:
-  kf_strcat (unsigned int num_args) : m_num_args (num_args) {}
+  kf_strcat (unsigned int num_args, bool chk_variant)
+    : m_num_args (num_args),
+      m_chk_variant (chk_variant) {}
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return (cd.num_args () == m_num_args
@@ -1119,6 +1187,11 @@ public:
            && cd.arg_is_pointer_p (1));
   }
 
+  enum built_in_function builtin_code () const final override
+  {
+    return m_chk_variant ? BUILT_IN_STRCAT_CHK : BUILT_IN_STRCAT;
+  }
+
   void impl_call_pre (const call_details &cd) const final override
   {
     region_model *model = cd.get_model ();
@@ -1159,25 +1232,32 @@ public:
 
 private:
   unsigned int m_num_args;
+  const bool m_chk_variant;
 };
 
 /* Handler for "strcpy" and "__builtin_strcpy_chk".  */
 
-class kf_strcpy : public known_function
+class kf_strcpy : public builtin_known_function
 {
 public:
-  kf_strcpy (unsigned int num_args) : m_num_args (num_args) {}
+  kf_strcpy (unsigned int num_args, bool chk_variant)
+    : m_num_args (num_args),
+      m_chk_variant (chk_variant) {}
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return (cd.num_args () == m_num_args
            && cd.arg_is_pointer_p (0)
            && cd.arg_is_pointer_p (1));
   }
-
+  enum built_in_function builtin_code () const final override
+  {
+    return m_chk_variant ? BUILT_IN_STRCPY_CHK : BUILT_IN_STRCPY;
+  }
   void impl_call_pre (const call_details &cd) const final override;
 
 private:
   unsigned int m_num_args;
+  const bool m_chk_variant;
 };
 
 void
@@ -1207,13 +1287,17 @@ kf_strcpy::impl_call_pre (const call_details &cd) const
 
 /* Handler for "strdup" and "__builtin_strdup".  */
 
-class kf_strdup : public known_function
+class kf_strdup : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return (cd.num_args () == 1 && cd.arg_is_pointer_p (0));
   }
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_STRDUP;
+  }
   void impl_call_pre (const call_details &cd) const final override
   {
     region_model *model = cd.get_model ();
@@ -1234,13 +1318,18 @@ public:
 
 /* Handler for "strlen" and for "__analyzer_get_strlen".  */
 
-class kf_strlen : public known_function
+class kf_strlen : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return (cd.num_args () == 1 && cd.arg_is_pointer_p (0));
   }
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_STRLEN;
+  }
+
   void impl_call_pre (const call_details &cd) const final override
   {
     if (const svalue *strlen_sval
@@ -1266,13 +1355,17 @@ make_kf_strlen ()
 
 /* Handler for "strndup" and "__builtin_strndup".  */
 
-class kf_strndup : public known_function
+class kf_strndup : public builtin_known_function
 {
 public:
   bool matches_call_types_p (const call_details &cd) const final override
   {
     return (cd.num_args () == 2 && cd.arg_is_pointer_p (0));
   }
+  enum built_in_function builtin_code () const final override
+  {
+    return BUILT_IN_STRNDUP;
+  }
   void impl_call_pre (const call_details &cd) const final override
   {
     region_model *model = cd.get_model ();
@@ -1445,44 +1538,73 @@ register_known_functions (known_function_manager &kfm)
     kfm.add (IFN_UBSAN_BOUNDS, make_unique<kf_ubsan_bounds> ());
   }
 
-  /* Built-ins the analyzer has known_functions for.  */
+  /* GCC built-ins that do not correspond to a function
+     in the standard library.  */
   {
-    kfm.add (BUILT_IN_ALLOCA, make_unique<kf_alloca> ());
-    kfm.add (BUILT_IN_ALLOCA_WITH_ALIGN, make_unique<kf_alloca> ());
-    kfm.add (BUILT_IN_CALLOC, make_unique<kf_calloc> ());
     kfm.add (BUILT_IN_EXPECT, make_unique<kf_expect> ());
     kfm.add (BUILT_IN_EXPECT_WITH_PROBABILITY, make_unique<kf_expect> ());
-    kfm.add (BUILT_IN_FREE, make_unique<kf_free> ());
-    kfm.add (BUILT_IN_MALLOC, make_unique<kf_malloc> ());
-    kfm.add (BUILT_IN_MEMCPY, make_unique<kf_memcpy_memmove> ());
-    kfm.add (BUILT_IN_MEMCPY_CHK, make_unique<kf_memcpy_memmove> ());
-    kfm.add (BUILT_IN_MEMMOVE, make_unique<kf_memcpy_memmove> ());
-    kfm.add (BUILT_IN_MEMMOVE_CHK, make_unique<kf_memcpy_memmove> ());
-    kfm.add (BUILT_IN_MEMSET, make_unique<kf_memset> ());
-    kfm.add (BUILT_IN_MEMSET_CHK, make_unique<kf_memset> ());
-    kfm.add (BUILT_IN_REALLOC, make_unique<kf_realloc> ());
-    kfm.add (BUILT_IN_SPRINTF, make_unique<kf_sprintf> ());
+    kfm.add (BUILT_IN_ALLOCA_WITH_ALIGN, make_unique<kf_alloca> ());
     kfm.add (BUILT_IN_STACK_RESTORE, make_unique<kf_stack_restore> ());
     kfm.add (BUILT_IN_STACK_SAVE, make_unique<kf_stack_save> ());
-    kfm.add (BUILT_IN_STRCAT, make_unique<kf_strcat> (2));
-    kfm.add (BUILT_IN_STRCAT_CHK, make_unique<kf_strcat> (3));
-    kfm.add (BUILT_IN_STRCHR, make_unique<kf_strchr> ());
-    kfm.add (BUILT_IN_STRCPY, make_unique<kf_strcpy> (2));
-    kfm.add (BUILT_IN_STRCPY_CHK, make_unique<kf_strcpy> (3));
-    kfm.add (BUILT_IN_STRDUP, make_unique<kf_strdup> ());
-    kfm.add (BUILT_IN_STRNDUP, make_unique<kf_strndup> ());
-    kfm.add (BUILT_IN_STRLEN, make_kf_strlen ());
 
     register_atomic_builtins (kfm);
     register_varargs_builtins (kfm);
   }
 
-  /* Known builtins and C standard library functions.  */
+  /* Known builtins and C standard library functions
+     the analyzer has known functions for.  */
   {
-    kfm.add ("memset", make_unique<kf_memset> ());
-    kfm.add ("strcat", make_unique<kf_strcat> (2));
+    kfm.add ("alloca", make_unique<kf_alloca> ());
+    kfm.add ("__builtin_alloca", make_unique<kf_alloca> ());
+    kfm.add ("calloc", make_unique<kf_calloc> ());
+    kfm.add ("__builtin_calloc", make_unique<kf_calloc> ());
+    kfm.add ("free", make_unique<kf_free> ());
+    kfm.add ("__builtin_free", make_unique<kf_free> ());
+    kfm.add ("malloc", make_unique<kf_malloc> ());
+    kfm.add ("__builtin_malloc", make_unique<kf_malloc> ());
+    kfm.add ("memcpy",
+             make_unique<kf_memcpy_memmove> (kf_memcpy_memmove::KF_MEMCPY));
+    kfm.add ("__builtin_memcpy",
+             make_unique<kf_memcpy_memmove> (kf_memcpy_memmove::KF_MEMCPY));
+    kfm.add ("__memcpy_chk", make_unique<kf_memcpy_memmove>
+                             (kf_memcpy_memmove::KF_MEMCPY_CHK));
+    kfm.add ("__builtin___memcpy_chk", make_unique<kf_memcpy_memmove>
+                             (kf_memcpy_memmove::KF_MEMCPY_CHK));
+    kfm.add ("memmove",
+             make_unique<kf_memcpy_memmove> (kf_memcpy_memmove::KF_MEMMOVE));
+    kfm.add ("__builtin_memmove",
+             make_unique<kf_memcpy_memmove> (kf_memcpy_memmove::KF_MEMMOVE));
+    kfm.add ("__memmove_chk", make_unique<kf_memcpy_memmove>
+                             (kf_memcpy_memmove::KF_MEMMOVE_CHK));
+    kfm.add ("__builtin___memmove_chk", make_unique<kf_memcpy_memmove>
+                             (kf_memcpy_memmove::KF_MEMMOVE_CHK));
+    kfm.add ("memset", make_unique<kf_memset> (false));
+    kfm.add ("__builtin_memset", make_unique<kf_memset> (false));
+    kfm.add ("__memset_chk", make_unique<kf_memset> (true));
+    kfm.add ("__builtin___memset_chk", make_unique<kf_memset> (true));
+    kfm.add ("realloc", make_unique<kf_realloc> ());
+    kfm.add ("__builtin_realloc", make_unique<kf_realloc> ());
+    kfm.add ("sprintf", make_unique<kf_sprintf> ());
+    kfm.add ("__builtin_sprintf", make_unique<kf_sprintf> ());
+    kfm.add ("strchr", make_unique<kf_strchr> ());
+    kfm.add ("__builtin_strchr", make_unique<kf_strchr> ());
+    kfm.add ("strcpy", make_unique<kf_strcpy> (2, false));
+    kfm.add ("__builtin_strcpy", make_unique<kf_strcpy> (2, false));
+    kfm.add ("__strcpy_chk", make_unique<kf_strcpy> (3, true));
+    kfm.add ("__builtin___strcpy_chk", make_unique<kf_strcpy> (3, true));
+    kfm.add ("strcat", make_unique<kf_strcat> (2, false));
+    kfm.add ("__builtin_strcat", make_unique<kf_strcat> (2, false));
+    kfm.add ("__strcat_chk", make_unique<kf_strcat> (3, true));
+    kfm.add ("__builtin___strcat_chk", make_unique<kf_strcat> (3, true));
     kfm.add ("strdup", make_unique<kf_strdup> ());
+    kfm.add ("__builtin_strdup", make_unique<kf_strdup> ());
     kfm.add ("strndup", make_unique<kf_strndup> ());
+    kfm.add ("__builtin_strndup", make_unique<kf_strndup> ());
+    kfm.add ("strlen", make_unique<kf_strlen> ());
+    kfm.add ("__builtin_strlen", make_unique<kf_strlen> ());
+
+    register_atomic_builtins (kfm);
+    register_varargs_builtins (kfm);
   }
 
   /* Known POSIX functions, and some non-standard extensions.  */
index 4a2cf52d0b873f891581c52a7ffe04d2fc7f5bde..615c495f895d77a8cbcbc1355e940fb6b8b0d797 100644 (file)
@@ -137,6 +137,13 @@ known_function_manager::get_normal_builtin (enum built_in_function name) const
   return m_combined_fns_arr[name];
 }
 
+const known_function *
+known_function_manager::
+get_normal_builtin (const builtin_known_function *builtin_kf) const
+{
+  return get_normal_builtin (builtin_kf->builtin_code ());
+}
+
 /* Get any known_function matching IDENTIFIER, without type-checking.
    Return NULL if there isn't one.  */
 
index 1432e548acb9ed936fec8a95e3f94f11abb21ac3..04f49ceb768fc1fe8ca375bd0414a9b3894c16dd 100644 (file)
@@ -54,6 +54,8 @@ private:
   DISABLE_COPY_AND_ASSIGN (known_function_manager);
 
   const known_function *get_normal_builtin (enum built_in_function name) const;
+  const known_function *
+  get_normal_builtin (const builtin_known_function *builtin_kf) const;
   const known_function *get_by_identifier (tree identifier) const;
 
   /* Map from identifier to known_function instance.
index 02c073c15bccc489f88bea5972e09e2d9f377319..4f31a6dcf0f6c016b940172f1dfa4efc8934ef4c 100644 (file)
@@ -1514,6 +1514,62 @@ region_model::get_known_function (enum internal_fn ifn) const
   return known_fn_mgr->get_internal_fn (ifn);
 }
 
+/* Get any builtin_known_function for CALL and emit any warning to CTXT
+   if not NULL.
+
+   The call must match all assumptions made by the known_function (such as
+   e.g. "argument 1's type must be a pointer type").
+
+   Return NULL if no builtin_known_function is found, or it does
+   not match the assumption(s).
+
+   Internally calls get_known_function to find a known_function and cast it
+   to a builtin_known_function.
+
+   For instance, calloc is a C builtin, defined in gcc/builtins.def
+   by the DEF_LIB_BUILTIN macro. Such builtins are recognized by the
+   analyzer by their name, so that even in C++ or if the user redeclares
+   them but mismatch their signature, they are still recognized as builtins.
+
+   Cases when a supposed builtin is not flagged as one by the FE:
+
+    The C++ FE does not recognize calloc as a builtin if it has not been
+    included from a standard header, but the C FE does. Hence in C++ if
+    CALL comes from a calloc and stdlib is not included,
+    gcc/tree.h:fndecl_built_in_p (CALL) would be false.
+
+    In C code, a __SIZE_TYPE__ calloc (__SIZE_TYPE__, __SIZE_TYPE__) user
+    declaration has obviously a mismatching signature from the standard, and
+    its function_decl tree won't be unified by
+    gcc/c-decl.cc:match_builtin_function_types.
+
+   Yet in both cases the analyzer should treat the calls as a builtin calloc
+   so that extra attributes unspecified by the standard but added by GCC
+   (e.g. sprintf attributes in gcc/builtins.def), useful for the detection of
+   dangerous behavior, are indeed processed.
+
+   Therefore for those cases when a "builtin flag" is not added by the FE,
+   builtins' kf are derived from builtin_known_function, whose method
+   builtin_known_function::builtin_decl returns the builtin's
+   function_decl tree as defined in gcc/builtins.def, with all the extra
+   attributes.  */
+
+const builtin_known_function *
+region_model::get_builtin_kf (const gcall *call,
+                              region_model_context *ctxt /* = NULL */) const
+{
+  region_model *mut_this = const_cast <region_model *> (this);
+  tree callee_fndecl = mut_this->get_fndecl_for_call (call, ctxt);
+  if (! callee_fndecl)
+    return NULL;
+
+  call_details cd (call, mut_this, ctxt);
+  if (const known_function *kf = get_known_function (callee_fndecl, cd))
+    return kf->dyn_cast_builtin_kf ();
+
+  return NULL;
+}
+
 /* Update this model for the CALL stmt, using CTXT to report any
    diagnostics - the first half.
 
index 40259625fb0625a6a4a0c6cdd00796d9b06e23bc..10b2a59e787089d63ebbae3f9f12426d7222dd1c 100644 (file)
@@ -528,6 +528,10 @@ class region_model
                                        bool include_terminator,
                                        const svalue **out_sval);
 
+  const builtin_known_function *
+  get_builtin_kf (const gcall *call,
+                 region_model_context *ctxt = NULL) const;
+
 private:
   const region *get_lvalue_1 (path_var pv, region_model_context *ctxt) const;
   const svalue *get_rvalue_1 (path_var pv, region_model_context *ctxt) const;
index c75744ff63a9d53b7498f4e199f363cc390a9866..34bbd84f6e7e2e8a413f0731086a8be7b88450e1 100644 (file)
@@ -1294,8 +1294,19 @@ fd_state_machine::check_for_fd_attrs (
     const gcall *call, const tree callee_fndecl, const char *attr_name,
     access_directions fd_attr_access_dir) const
 {
-
-  tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (callee_fndecl));
+  /* Handle interesting fd attributes of the callee_fndecl,
+     or prioritize those of the builtin that callee_fndecl is
+     expected to be.
+     Might want this to be controlled by a flag.  */
+  tree fndecl = callee_fndecl;
+  /* If call is recognized as a builtin known_function,
+     use that builtin's function_decl.  */
+  if (const region_model *old_model = sm_ctxt->get_old_region_model ())
+    if (const builtin_known_function *builtin_kf
+        = old_model->get_builtin_kf (call))
+      fndecl = builtin_kf->builtin_decl ();
+
+  tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
   attrs = lookup_attribute (attr_name, attrs);
   if (!attrs)
     return;
@@ -1325,13 +1336,15 @@ fd_state_machine::check_for_fd_attrs (
                   // attributes
        {
 
+         /* Do use the fndecl that caused the warning so that the
+            misused attributes are printed and the user not confused.  */
          if (is_closed_fd_p (state))
            {
 
              sm_ctxt->warn (node, stmt, arg,
                             make_unique<fd_use_after_close>
                               (*this, diag_arg,
-                               callee_fndecl, attr_name,
+                               fndecl, attr_name,
                                arg_idx));
              continue;
            }
@@ -1343,7 +1356,7 @@ fd_state_machine::check_for_fd_attrs (
                  sm_ctxt->warn (node, stmt, arg,
                                 make_unique<fd_use_without_check>
                                 (*this, diag_arg,
-                                 callee_fndecl, attr_name,
+                                 fndecl, attr_name,
                                  arg_idx));
                  continue;
                }
@@ -1361,7 +1374,7 @@ fd_state_machine::check_for_fd_attrs (
                      node, stmt, arg,
                      make_unique<fd_access_mode_mismatch> (*this, diag_arg,
                                                            DIRS_WRITE,
-                                                           callee_fndecl,
+                                                           fndecl,
                                                            attr_name,
                                                            arg_idx));
                }
@@ -1375,7 +1388,7 @@ fd_state_machine::check_for_fd_attrs (
                      node, stmt, arg,
                      make_unique<fd_access_mode_mismatch> (*this, diag_arg,
                                                            DIRS_READ,
-                                                           callee_fndecl,
+                                                           fndecl,
                                                            attr_name,
                                                            arg_idx));
                }
index ec763254b29605ac3b031a046729cf0e04ca7946..2ff777daaca69b1911acf0e3980237d695cf7a9f 100644 (file)
@@ -1965,71 +1965,88 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt,
        malloc_state_machine *mutable_this
          = const_cast <malloc_state_machine *> (this);
 
-       /* Handle "__attribute__((malloc(FOO)))".   */
-       if (const deallocator_set *deallocators
+       /* Handle interesting attributes of the callee_fndecl,
+          or prioritize those of the builtin that callee_fndecl is expected
+          to be.
+          Might want this to be controlled by a flag.  */
+       {
+         tree fndecl = callee_fndecl;
+         /* If call is recognized as a builtin known_function, use that
+            builtin's function_decl.  */
+         if (const region_model *old_model = sm_ctxt->get_old_region_model ())
+           if (const builtin_known_function *builtin_kf
+               = old_model->get_builtin_kf (call))
+             fndecl = builtin_kf->builtin_decl ();
+
+         /* Handle "__attribute__((malloc(FOO)))".   */
+         if (const deallocator_set *deallocators
              = mutable_this->get_or_create_custom_deallocator_set
-                 (callee_fndecl))
+                 (fndecl))
+           {
+             tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (fndecl));
+             bool returns_nonnull
+               = lookup_attribute ("returns_nonnull", attrs);
+             on_allocator_call (sm_ctxt, call, deallocators, returns_nonnull);
+           }
+
          {
-           tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (callee_fndecl));
-           bool returns_nonnull
-             = lookup_attribute ("returns_nonnull", attrs);
-           on_allocator_call (sm_ctxt, call, deallocators, returns_nonnull);
+           /* Handle "__attribute__((nonnull))".   */
+           tree fntype = TREE_TYPE (fndecl);
+           bitmap nonnull_args = get_nonnull_args (fntype);
+           if (nonnull_args)
+             {
+               for (unsigned i = 0; i < gimple_call_num_args (stmt); i++)
+                 {
+                   tree arg = gimple_call_arg (stmt, i);
+                   if (TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE)
+                     continue;
+                   /* If we have a nonnull-args, and either all pointers, or
+                      just the specified pointers.  */
+                   if (bitmap_empty_p (nonnull_args)
+                       || bitmap_bit_p (nonnull_args, i))
+                     {
+                       state_t state = sm_ctxt->get_state (stmt, arg);
+                       /* Can't use a switch as the states are non-const.  */
+                       /* Do use the fndecl that caused the warning so that the
+                          misused attributes are printed and the user not
+                          confused.  */
+                       if (unchecked_p (state))
+                         {
+                           tree diag_arg = sm_ctxt->get_diagnostic_tree (arg);
+                           sm_ctxt->warn (node, stmt, arg,
+                                         make_unique<possible_null_arg>
+                                           (*this, diag_arg, fndecl, i));
+                           const allocation_state *astate
+                             = as_a_allocation_state (state);
+                           sm_ctxt->set_next_state (stmt, arg,
+                                                   astate->get_nonnull ());
+                         }
+                       else if (state == m_null)
+                         {
+                           tree diag_arg = sm_ctxt->get_diagnostic_tree (arg);
+                           sm_ctxt->warn (node, stmt, arg,
+                                         make_unique<null_arg>
+                                           (*this, diag_arg, fndecl, i));
+                           sm_ctxt->set_next_state (stmt, arg, m_stop);
+                         }
+                       else if (state == m_start)
+                         maybe_assume_non_null (sm_ctxt, arg, stmt);
+                     }
+                 }
+               BITMAP_FREE (nonnull_args);
+             }
          }
 
-       /* Handle "__attribute__((nonnull))".   */
-       {
-         tree fntype = TREE_TYPE (callee_fndecl);
-         bitmap nonnull_args = get_nonnull_args (fntype);
-         if (nonnull_args)
+         /* Check for this after nonnull, so that if we have both
+            then we transition to "freed", rather than "checked".  */
+         unsigned dealloc_argno = fndecl_dealloc_argno (fndecl);
+         if (dealloc_argno != UINT_MAX)
            {
-             for (unsigned i = 0; i < gimple_call_num_args (stmt); i++)
-               {
-                 tree arg = gimple_call_arg (stmt, i);
-                 if (TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE)
-                   continue;
-                 /* If we have a nonnull-args, and either all pointers, or just
-                    the specified pointers.  */
-                 if (bitmap_empty_p (nonnull_args)
-                     || bitmap_bit_p (nonnull_args, i))
-                   {
-                     state_t state = sm_ctxt->get_state (stmt, arg);
-                     /* Can't use a switch as the states are non-const.  */
-                     if (unchecked_p (state))
-                       {
-                         tree diag_arg = sm_ctxt->get_diagnostic_tree (arg);
-                         sm_ctxt->warn (node, stmt, arg,
-                                        make_unique<possible_null_arg>
-                                          (*this, diag_arg, callee_fndecl, i));
-                         const allocation_state *astate
-                           = as_a_allocation_state (state);
-                         sm_ctxt->set_next_state (stmt, arg,
-                                                  astate->get_nonnull ());
-                       }
-                     else if (state == m_null)
-                       {
-                         tree diag_arg = sm_ctxt->get_diagnostic_tree (arg);
-                         sm_ctxt->warn (node, stmt, arg,
-                                        make_unique<null_arg>
-                                          (*this, diag_arg, callee_fndecl, i));
-                         sm_ctxt->set_next_state (stmt, arg, m_stop);
-                       }
-                     else if (state == m_start)
-                       maybe_assume_non_null (sm_ctxt, arg, stmt);
-                   }
-               }
-             BITMAP_FREE (nonnull_args);
+             const deallocator *d
+               = mutable_this->get_or_create_deallocator (fndecl);
+             on_deallocator_call (sm_ctxt, node, call, d, dealloc_argno);
            }
        }
-
-       /* Check for this after nonnull, so that if we have both
-          then we transition to "freed", rather than "checked".  */
-       unsigned dealloc_argno = fndecl_dealloc_argno (callee_fndecl);
-       if (dealloc_argno != UINT_MAX)
-         {
-           const deallocator *d
-             = mutable_this->get_or_create_deallocator (callee_fndecl);
-           on_deallocator_call (sm_ctxt, node, call, d, dealloc_argno);
-         }
       }
 
   /* Look for pointers explicitly being compared against zero
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/aliasing-3.c
rename to gcc/testsuite/c-c++-common/analyzer/aliasing-3.c
index 003077ad5c1a7e8c30b36b79e9574df34e658753..30772dca454f1aa6bc222df43ba2468e7a2dfdbd 100644 (file)
@@ -1,6 +1,4 @@
-#include "analyzer-decls.h"
-
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct s1
 {
@@ -39,7 +37,7 @@ static struct s2 *p2_glob = NULL;
 void test_2 (struct s2 **pp2, struct s2 *p2_parm)
 {
   /* Ensure that p2_glob is modified.  */
-  p2_glob = __builtin_malloc (sizeof (struct s2));
+  p2_glob = (struct s2 *) __builtin_malloc (sizeof (struct s2));
   if (!p2_glob)
     return;
 
@@ -61,7 +59,7 @@ struct s3 *p3_glob = NULL;
 
 void test_3 (struct s3 **pp3, struct s3 *p3_parm)
 {
-  p3_glob = __builtin_malloc (sizeof (struct s3));
+  p3_glob = (struct s3 *) __builtin_malloc (sizeof (struct s3));
   if (!p3_glob)
     return;
 
similarity index 53%
rename from gcc/testsuite/gcc.dg/analyzer/aliasing-pr106473.c
rename to gcc/testsuite/c-c++-common/analyzer/aliasing-pr106473.c
index afd1492252e0aff12efefd51fb75eb1433070ca6..4affa27b26cd67872edd6d939896ef3c14b78385 100644 (file)
@@ -1,5 +1,5 @@
 void foo(char **args[], int *argc)
 {
   *argc = 1;
-  (*args)[0] = __builtin_malloc(42);
+  (*args)[0] = (char *) __builtin_malloc(42);
 }
diff --git a/gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-1.c b/gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-1.c
new file mode 100644 (file)
index 0000000..de1a49c
--- /dev/null
@@ -0,0 +1,96 @@
+/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
+
+#include <stdint.h>
+
+void test_constant_1 (void)
+{
+  int32_t *ptr = (int32_t *) __builtin_malloc (1); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+  __builtin_free (ptr);
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_malloc (1);
+                              ^~~~~~~~~~~~~~~~~~~~
+  'test_constant_1': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_malloc (1);
+    |                              ^~~~~~~~~~~~~~~~~~~~
+    |                              |
+    |                              (1) allocated 1 byte here
+    |                              (2) assigned to 'int32_t *'
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_malloc (1);
+                              ~~~~~~~~~~~~~~~~~^~~
+  'void test_constant_1()': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_malloc (1);
+    |                              ~~~~~~~~~~~~~~~~~^~~
+    |                                               |
+    |                                               (1) allocated 1 byte here
+    |                                               (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+void test_constant_2 (void)
+{
+  int32_t *ptr = (int32_t *) __builtin_malloc (2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+  __builtin_free (ptr);
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_malloc (2);
+                              ^~~~~~~~~~~~~~~~~~~~
+  'test_constant_2': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_malloc (2);
+    |                              ^~~~~~~~~~~~~~~~~~~~
+    |                              |
+    |                              (1) allocated 2 bytes here
+    |                              (2) assigned to 'int32_t *'
+    |
+   { dg-end-multiline-output "" { target c } } */
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_malloc (2);
+                              ~~~~~~~~~~~~~~~~~^~~
+  'void test_constant_2()': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_malloc (2);
+    |                              ~~~~~~~~~~~~~~~~~^~~
+    |                                               |
+    |                                               (1) allocated 2 bytes here
+    |                                               (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+void test_symbolic (int n)
+{
+  int32_t *ptr = (int32_t *) __builtin_malloc (n * 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+  __builtin_free (ptr);
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_malloc (n * 2);
+                              ^~~~~~~~~~~~~~~~~~~~~~~~
+  'test_symbolic': event 1
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_malloc (n * 2);
+    |                              ^~~~~~~~~~~~~~~~~~~~~~~~
+    |                              |
+    |                              (1) allocated 'n * 2' bytes and assigned to 'int32_t *'
+    |
+   { dg-end-multiline-output "" { target c } } */
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_malloc (n * 2);
+                              ~~~~~~~~~~~~~~~~~^~~~~~~
+  'void test_symbolic(int)': event 1
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_malloc (n * 2);
+    |                              ~~~~~~~~~~~~~~~~~^~~~~~~
+    |                                               |
+    |                                               (1) allocated '(n * 2)' bytes and assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
diff --git a/gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-2.c b/gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-2.c
new file mode 100644 (file)
index 0000000..a5def27
--- /dev/null
@@ -0,0 +1,98 @@
+/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-fine-grained" } */
+/* { dg-require-effective-target alloca } */
+
+#include <stdint.h>
+
+void test_constant_1 (void)
+{
+  int32_t *ptr = (int32_t *) __builtin_alloca (1); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_alloca (1);
+                              ^~~~~~~~~~~~~~~~~~~~
+  'test_constant_1': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_alloca (1);
+    |                              ^~~~~~~~~~~~~~~~~~~~
+    |                              |
+    |                              (1) allocated 1 byte here
+    |                              (2) assigned to 'int32_t *'
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_alloca (1);
+                              ~~~~~~~~~~~~~~~~~^~~
+  'void test_constant_1()': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_alloca (1);
+    |                              ~~~~~~~~~~~~~~~~~^~~
+    |                                               |
+    |                                               (1) allocated 1 byte here
+    |                                               (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+void test_constant_2 (void)
+{
+  int32_t *ptr = (int32_t *) __builtin_alloca (2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_alloca (2);
+                              ^~~~~~~~~~~~~~~~~~~~
+  'test_constant_2': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_alloca (2);
+    |                              ^~~~~~~~~~~~~~~~~~~~
+    |                              |
+    |                              (1) allocated 2 bytes here
+    |                              (2) assigned to 'int32_t *'
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_alloca (2);
+                              ~~~~~~~~~~~~~~~~~^~~
+  'void test_constant_2()': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_alloca (2);
+    |                              ~~~~~~~~~~~~~~~~~^~~
+    |                                               |
+    |                                               (1) allocated 2 bytes here
+    |                                               (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+void test_symbolic (int n)
+{
+  int32_t *ptr = (int32_t *) __builtin_alloca (n * 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_alloca (n * 2);
+                              ^~~~~~~~~~~~~~~~~~~~~~~~
+  'test_symbolic': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_alloca (n * 2);
+    |                              ^~~~~~~~~~~~~~~~~~~~~~~~
+    |                              |
+    |                              (1) allocated 'n * 2' bytes here
+    |                              (2) assigned to 'int32_t *'
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) __builtin_alloca (n * 2);
+                              ~~~~~~~~~~~~~~~~~^~~~~~~
+  'void test_symbolic(int)': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) __builtin_alloca (n * 2);
+    |                              ~~~~~~~~~~~~~~~~~^~~~~~~
+    |                                               |
+    |                                               (1) allocated '(n * 2)' bytes here
+    |                                               (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+/* FIXME: am getting a duplicate warning here for some reason
+   without -fanalyzer-fine-grained (PR PR analyzer/107851).  */
+
diff --git a/gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-3.c b/gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-3.c
new file mode 100644 (file)
index 0000000..3cf7fb0
--- /dev/null
@@ -0,0 +1,68 @@
+/* Verify that we warn for incorrect uses of "alloca" (which may be in a 
+   macro in a system header), and that the output looks correct.  */
+
+/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-fine-grained" } */
+/* { dg-require-effective-target alloca } */
+
+#include <stdint.h>
+#include "../../gcc.dg/analyzer/test-alloca.h"
+
+void test_constant_99 (void)
+{
+  int32_t *ptr = (int32_t *) alloca (99); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) alloca (99);
+                              ^~~~~~
+  'test_constant_99': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) alloca (99);
+    |                              ^~~~~~
+    |                              |
+    |                              (1) allocated 99 bytes here
+    |                              (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) alloca (99);
+                              ^~~~~~
+  'void test_constant_99()': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) alloca (99);
+    |                              ^~~~~~
+    |                              |
+    |                              (1) allocated 99 bytes here
+    |                              (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+void test_symbolic (int n)
+{
+  int32_t *ptr = (int32_t *) alloca (n * 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+}
+
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) alloca (n * 2);
+                              ^~~~~~
+  'test_symbolic': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) alloca (n * 2);
+    |                              ^~~~~~
+    |                              |
+    |                              (1) allocated 'n * 2' bytes here
+    |                              (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   int32_t *ptr = (int32_t *) alloca (n * 2);
+                              ^~~~~~
+  'void test_symbolic(int)': events 1-2
+    |
+    |   int32_t *ptr = (int32_t *) alloca (n * 2);
+    |                              ^~~~~~
+    |                              |
+    |                              (1) allocated '(n * 2)' bytes here
+    |                              (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/asm-x86-dyndbg-2.c
rename to gcc/testsuite/c-c++-common/analyzer/asm-x86-dyndbg-2.c
index 8111709206f21d418083a268523421468fd5c99e..d5e748c9acd7334df3474a6c9a3f35ce5223e1e5 100644 (file)
@@ -8,9 +8,11 @@
 /* Adapted from various files in the Linux kernel, all of which have:  */
 /* SPDX-License-Identifier: GPL-2.0 */
 
-typedef _Bool                  bool;
-#define true 1
-#define false 0
+#ifndef __cplusplus 
+  typedef _Bool bool;
+  #define true 1
+  #define false 0
+#endif
 
 typedef struct {} atomic_t;
 
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/asm-x86-lp64-2.c
rename to gcc/testsuite/c-c++-common/analyzer/asm-x86-lp64-2.c
index 2864ab69d2ab9b447250d7137dca8cc86fc758b6..37c487a69c267f6ba1fec3ee1cc8a7911ddb42d3 100644 (file)
@@ -3,7 +3,9 @@
 
 /* Adapted from Linux x86: page_ref_dec_and_test.c (GPL-2.0).  */
 
-typedef _Bool bool;
+#ifndef __cplusplus 
+  typedef _Bool bool;
+#endif
 
 typedef struct {
   int counter;
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/atomic-builtins-haproxy-proxy.c
rename to gcc/testsuite/c-c++-common/analyzer/atomic-builtins-haproxy-proxy.c
index 72953a561b87124438b3a27478f6753ab5c1be8a..fbe89f7dfbbc4ff40ffaaba35e6ce6dcd0700917 100644 (file)
@@ -37,7 +37,7 @@ proxy_capture_error(struct proxy* proxy,
 
   /* [...snip...] */
 
-  es = malloc(sizeof(*es));
+  es = (struct error_snapshot *) malloc(sizeof(*es));
   if (!es)
     return;
 
similarity index 74%
rename from gcc/testsuite/gcc.dg/analyzer/atomic-builtins-qemu-sockets.c
rename to gcc/testsuite/c-c++-common/analyzer/atomic-builtins-qemu-sockets.c
index cd90f8f263d95ec1579977bc73ee478a41969d83..05ac339ada7ba374d3a42d489bcc9d9340a2804d 100644 (file)
@@ -5,7 +5,7 @@ struct foo {
 void *
 test (const char *str)
 {
-  struct foo *p = __builtin_malloc(sizeof(struct foo));
+  struct foo *p = (struct foo *) __builtin_malloc(sizeof(struct foo));
   if (!p)
     return p;
 
similarity index 88%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-6.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-6.c
index bd28107d0d7449c886576909bdd4e0a9cc46b279..1665d4128f59fb3e2e123a254220d173096e44eb 100644 (file)
@@ -74,7 +74,7 @@ void warn_fdopen (void)
 
   {
     FILE *q = fdopen (0);     // { dg-message "allocated here" }
-    q = realloc (q, 7);       // { dg-warning "'realloc' called on 'q' returned from a mismatched allocation function" }
+    q = (FILE *) realloc (q, 7);       // { dg-warning "'realloc' called on 'q' returned from a mismatched allocation function" }
     sink (q);
   }
 }
@@ -117,7 +117,7 @@ void warn_fopen (void)
 
   {
     FILE *q = fdopen (0);
-    q = realloc (q, 7);       // { dg-warning "'realloc' called on 'q' returned from a mismatched allocation function" }
+    q = (FILE *) realloc (q, 7);       // { dg-warning "'realloc' called on 'q' returned from a mismatched allocation function" }
     sink (q);
   }
 }
@@ -170,18 +170,18 @@ void test_tmpfile (void)
 void warn_malloc (void)
 {
   {
-    FILE *p = malloc (100);   // { dg-message "allocated here" }
+    FILE *p = (FILE *) malloc (100);   // { dg-message "allocated here" }
     fclose (p);               // { dg-warning "'p' should have been deallocated with 'free' but was deallocated with 'fclose'" }
   }
 
   {
-    FILE *p = malloc (100);   // { dg-message "allocated here" }
+    FILE *p = (FILE *) malloc (100);   // { dg-message "allocated here" }
     p = freopen ("1", "r", p);// { dg-warning "'p' should have been deallocated with 'free' but was deallocated with 'freopen'" }
     fclose (p);
   }
 
   {
-    FILE *p = malloc (100);   // { dg-message "allocated here" }
+    FILE *p = (FILE *) malloc (100);   // { dg-message "allocated here" }
     pclose (p);               // { dg-warning "'p' should have been deallocated with 'free' but was deallocated with 'pclose'" }
   }
 }
@@ -222,7 +222,7 @@ void test_acquire (void)
 
   {
     FILE *p = acquire ();     // { dg-message "allocated here \\(expects deallocation with 'release'\\)" }
-    p = realloc (p, 123);     // { dg-warning "'p' should have been deallocated with 'release' but was deallocated with 'realloc'" }
+    p = (FILE *) realloc (p, 123);     // { dg-warning "'p' should have been deallocated with 'release' but was deallocated with 'realloc'" }
     sink (p);
   }
 }
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-CVE-2019-19078-usb-leak.c
index e086843c42b68852d2a15757f0ff27e253052e3c..24fb46bd5a9bf11f8bf44c2881336141613ca732 100644 (file)
@@ -3,7 +3,10 @@
 
 typedef unsigned char u8;
 typedef unsigned short u16;
-typedef _Bool bool;
+
+#ifndef __cplusplus 
+  typedef _Bool bool;
+#endif
 
 #define        ENOMEM          12
 #define        EINVAL          22
@@ -149,7 +152,7 @@ static int ath10k_usb_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
                        goto err;
                }
 
-               skb = items[i].transfer_context;
+               skb = (struct sk_buff *) items[i].transfer_context;
                urb_context->skb = skb;
 
                urb = usb_alloc_urb(0, GFP_ATOMIC); /* { dg-message "allocated here" } */
@@ -209,7 +212,7 @@ static const struct ath10k_hif_ops ath10k_usb_hif_ops = {
 
 /* Simulate code to register the callback.  */
 extern void callback_registration (const void *);
-int ath10k_usb_probe(void)
+void ath10k_usb_probe(void)
 {
   callback_registration(&ath10k_usb_hif_ops);
 }
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/attr-tainted_args-1.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-tainted_args-1.c
index e1d87c9cece1b5325876b85be592a8a59c2b1a78..0ff344699671b7f10f1fb690469c8e7f4b20d933 100644 (file)
@@ -1,7 +1,7 @@
 // TODO: remove need for this option
 /* { dg-additional-options "-fanalyzer-checker=taint" } */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct arg_buf
 {
@@ -23,7 +23,7 @@ test_1 (int i, void *p, char *q)
   __analyzer_dump_state ("taint", q); /* { dg-warning "state: 'tainted'" } */
   __analyzer_dump_state ("taint", *q); /* { dg-warning "state: 'tainted'" } */
 
-  struct arg_buf *args = p;
+  struct arg_buf *args = (struct arg_buf *) p;
   __analyzer_dump_state ("taint", args->i); /* { dg-warning "state: 'tainted'" } */
   __analyzer_dump_state ("taint", args->j); /* { dg-warning "state: 'tainted'" } */  
 }
@@ -49,7 +49,7 @@ test_2a (int i, void *p, char *q)
   __analyzer_dump_state ("taint", p); /* { dg-warning "state: 'start'" } */
   __analyzer_dump_state ("taint", q); /* { dg-warning "state: 'start'" } */
 
-  struct arg_buf *args = p;
+  struct arg_buf *args = (struct arg_buf *) p;
   __analyzer_dump_state ("taint", args->i); /* { dg-warning "state: 'start'" } */
   __analyzer_dump_state ("taint", args->j); /* { dg-warning "state: 'start'" } */  
 }
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-pr107158.c
index 54f442f0ad414b3eb8222238a050dabd88959c16..d4cf079cef84e909bd4c563f8d88a52ff5e045f4 100644 (file)
@@ -25,7 +25,7 @@ __attribute__((__noreturn__)) void failed(const char *message);
 static char *string_dup(const char *string) {
   char *buf;
 
-  if ((buf = malloc(strlen(string) + 1)) == ((void *)0))
+  if ((buf = (char *) malloc(strlen(string) + 1)) == ((void *)0))
     failed("malloc() failed");
 
   return strcpy(buf, string);
@@ -37,7 +37,7 @@ static void store_data(const char *name, const char *type) {
   if ((p = (struct mydata *)malloc(sizeof(struct mydata))) == ((void *)0))
     failed("malloc() failed");
 
-  p->link = ((void *)0);
+  p->link = (struct mydata *)((void *)0);
   p->name = string_dup(name);
   p->type = string_dup(type);
 
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/calloc-1.c
rename to gcc/testsuite/c-c++-common/analyzer/calloc-1.c
index bc28128671f9cad40f421b054d1409266beac371..6bd658ec94a497fa40dda3785ea0ffc65e351ad3 100644 (file)
@@ -1,9 +1,6 @@
-#include "analyzer-decls.h"
-
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef __SIZE_TYPE__ size_t;
 
-#define NULL ((void *)0)
-
 extern void *calloc (size_t __nmemb, size_t __size)
   __attribute__ ((__nothrow__ , __leaf__))
   __attribute__ ((__malloc__))
@@ -13,7 +10,7 @@ char *test_1 (size_t sz)
 {
   char *p;
 
-  p = calloc (1, 3);
+  p = (char *) calloc (1, 3);
   if (!p)
     return NULL;
 
similarity index 83%
rename from gcc/testsuite/gcc.dg/analyzer/compound-assignment-5.c
rename to gcc/testsuite/c-c++-common/analyzer/compound-assignment-5.c
index ccf8fe392bfa867952944a6c0768cb2e194022e9..3ce2b72c8ff3b503103b852fedfb6f29a6b2e044 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct coord
 {
@@ -23,7 +23,7 @@ void test_1 (void)
 
 /* Copying from an on-stack array to a global array.  */
 
-struct coord glob_arr[16];
+struct coord glob_arr2[16];
 
 void test_2 (void)
 {
@@ -31,32 +31,30 @@ void test_2 (void)
   arr[3].x = 5;
   arr[3].y = 6;
 
-  glob_arr[7] = arr[3];
+  glob_arr2[7] = arr[3];
 
-  __analyzer_eval (glob_arr[7].x == 5); /* { dg-warning "TRUE" } */
-  __analyzer_eval (glob_arr[7].y == 6); /* { dg-warning "TRUE" } */
+  __analyzer_eval (glob_arr2[7].x == 5); /* { dg-warning "TRUE" } */
+  __analyzer_eval (glob_arr2[7].y == 6); /* { dg-warning "TRUE" } */
 }
 
 /* Copying from a partially initialized on-stack array to a global array.  */
 
-struct coord glob_arr[16];
+struct coord glob_arr3[16];
 
 void test_3 (void)
 {
   struct coord arr[16];
   arr[3].y = 6;
 
-  glob_arr[7] = arr[3]; // or should the uninit warning be here?
+  glob_arr3[7] = arr[3]; // or should the uninit warning be here?
 
-  __analyzer_eval (glob_arr[7].x); /* { dg-warning "uninitialized" "uninit" { xfail *-*-* } } */
+  __analyzer_eval (glob_arr3[7].x); /* { dg-warning "uninitialized" "uninit" { xfail *-*-* } } */
   /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
-  __analyzer_eval (glob_arr[7].y == 6); /* { dg-warning "TRUE" } */
+  __analyzer_eval (glob_arr3[7].y == 6); /* { dg-warning "TRUE" } */
 }
 
 /* Symbolic bindings: copying from one array to another.  */
 
-struct coord glob_arr[16];
-
 void test_4 (int i)
 {
   struct coord arr_a[16];
@@ -77,8 +75,6 @@ void test_4 (int i)
 
 /* Symbolic bindings: copying within an array: symbolic src and dest  */
 
-struct coord glob_arr[16];
-
 void test_5a (int i, int j)
 {
   struct coord arr[16];
@@ -95,8 +91,6 @@ void test_5a (int i, int j)
 
 /* Symbolic bindings: copying within an array: symbolic src, concrete dest.  */
 
-struct coord glob_arr[16];
-
 void test_5b (int i)
 {
   struct coord arr[16];
@@ -113,8 +107,6 @@ void test_5b (int i)
 
 /* Symbolic bindings: copying within an array: concrete src, symbolic dest.  */
 
-struct coord glob_arr[16];
-
 void test_5c (int i)
 {
   struct coord arr[16];
@@ -132,10 +124,12 @@ void test_5c (int i)
 /* No info on the subregion being copied, and hence
    binding_cluster2::maybe_get_compound_binding should return NULL.  */
 
+struct coord glob_arr6[16];
+
 void test_6 (void)
 {
   struct coord arr[16];
-  arr[7] = glob_arr[3];
+  arr[7] = glob_arr6[3];
 
   __analyzer_eval (arr[7].x == 5); /* { dg-warning "UNKNOWN" } */
   __analyzer_eval (arr[7].y == 6); /* { dg-warning "UNKNOWN" } */
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/coreutils-cksum-pr108664.c
rename to gcc/testsuite/c-c++-common/analyzer/coreutils-cksum-pr108664.c
index 62698f3d148ea01fb20922052f75417b02b0df15..7ae4e6b06bea96842957c4922674af2f5510c766 100644 (file)
@@ -7,6 +7,11 @@ typedef long unsigned int size_t;
 typedef unsigned int __uint32_t;
 typedef unsigned long int __uintmax_t;
 typedef struct _IO_FILE FILE;
+
+#ifndef __cplusplus
+  typedef _Bool bool;
+#endif
+
 extern size_t
 fread_unlocked(void* __restrict __ptr,
                size_t __size,
@@ -30,7 +35,7 @@ __errno_location(void) __attribute__((__nothrow__, __leaf__))
 __attribute__((__const__));
 extern uint_fast32_t const crctab[8][256];
 
-static _Bool
+static bool
 cksum_slice8(FILE* fp, uint_fast32_t* crc_out, uintmax_t* length_out)
 {
   uint32_t buf[(1 << 16) / sizeof(uint32_t)];
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/coreutils-sum-pr108666.c
rename to gcc/testsuite/c-c++-common/analyzer/coreutils-sum-pr108666.c
index 9d13fce853191b2cd4cf10dd4ec8964e8d06cd20..5684d1b02d454fe0a05b2c004dd20a1411f00763 100644 (file)
@@ -35,7 +35,7 @@ bsd_sum_stream(FILE* stream, void* resstream, uintmax_t* length)
   int checksum = 0;
   uintmax_t total_bytes = 0;
   static const size_t buffer_length = 32768;
-  uint8_t* buffer = malloc(buffer_length);
+  uint8_t* buffer = (uint8_t *) malloc(buffer_length);
 
   if (!buffer)
     return -1;
diff --git a/gcc/testsuite/c-c++-common/analyzer/data-model-11.c b/gcc/testsuite/c-c++-common/analyzer/data-model-11.c
new file mode 100644 (file)
index 0000000..0e64e5b
--- /dev/null
@@ -0,0 +1,6 @@
+int test (void)
+{
+  const unsigned char *s = (const unsigned char *) "abc";
+  const signed char *t = (const signed char *) "xyz";
+  return s[1] + t[1];
+}
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108455-1.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-1.c
index d7d873edc51dbe9811a1c065126d9de1a8fc7c98..5f2ca9669313035b713aa3fd18ab5bfac518b837 100644 (file)
@@ -19,7 +19,7 @@ int test_1 (void) {
   }
 
   data = could_fail_2 (fd);
-  hdr = data;
+  hdr = (struct header *) data;
 
   if (hdr->signature != 42) {
     ret = -2;
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108455-git-pack-revindex.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-git-pack-revindex.c
index 7553f86051d678d21f0ca382de245a8427085027..7431bd11c42843564c69c3d7702c3d598fd2b601 100644 (file)
@@ -95,7 +95,7 @@ int load_revindex_from_disk(char *revindex_name, uint32_t num_objects,
   }
 
   data = xmmap(((void *)0), revindex_size, 0x1, 0x02, fd, 0);
-  hdr = data;
+  hdr = (struct revindex_header *) data;
 
   if (git_bswap32(hdr->signature) != 0x52494458) {
     ret =
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108475-1.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108475-1.c
index fa3beaaa15ffe2b466f163e22e3f1428b835b127..0d5edf821f23af30405e408a8fdfade7e72255da 100644 (file)
@@ -1,6 +1,7 @@
 /* Reduced from haproxy-2.7.1: src/tcpcheck.c.  */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
 
 int
 test_1 (char **args, int cur_arg)
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108475-haproxy-tcpcheck.c
index 1180e17e5552a12584d419c2eee79ca2c0843f8e..7123cf5196b742672858599f0f7bb262bf3d8277 100644 (file)
@@ -3,7 +3,9 @@
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
 
 extern void *calloc(size_t __nmemb, size_t __size)
     __attribute__((__nothrow__, __leaf__)) __attribute__((__malloc__))
@@ -86,7 +88,7 @@ void free_tcpcheck(struct tcpcheck_rule *rule, int in_pool);
 void free_tcpcheck_http_hdr(struct tcpcheck_http_hdr *hdr);
 
 #define ist(str) ({                                                    \
-       char *__x = (void *)(str);                                     \
+       char *__x = (char *) ((void *)(str));                                     \
        (struct ist){                                                  \
                .ptr = __x,                                            \
                .len = __builtin_constant_p(str) ?                     \
@@ -114,7 +116,7 @@ struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg,
     goto error;
   }
 
-  chk = calloc(1, sizeof(*chk));
+  chk = (struct tcpcheck_rule *) calloc(1, sizeof(*chk));
   if (!chk) {
     /* [...snip...] */
     goto error;
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr109060-haproxy-cfgparse.c
index 4f50882eb8ac85268d558631ffe7f5e4c1137841..1d28e10747cd5df1e3353cd53b302b6e909ed7c0 100644 (file)
@@ -51,7 +51,7 @@ parse_process_number(const char* arg,
   else if (strcmp(arg, "even") == 0)
     *proc |= (~0UL / 3UL) << 1;
   else {
-    const char *p, *dash = ((void*)0);
+    const char *p, *dash = (const char *) ((void*)0);
     unsigned int low, high;
 
     for (p = arg; *p; p++) {
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr109239-linux-bus.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr109239-linux-bus.c
index 49b6420cc6b530d5e6c0ddb1fd61df8450d5a74d..add7731c6b0000953abae27c32203525466041cc 100644 (file)
@@ -1,7 +1,8 @@
 /* Reduced from linux-5.10.162's drivers-base-bus.c  */
 /* { dg-additional-options "-fno-delete-null-pointer-checks -O2" } */
 
-#define NULL ((void*)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
 
 typedef unsigned int __kernel_size_t;
 typedef int __kernel_ssize_t;
@@ -57,7 +58,7 @@ struct kset*
 to_kset(struct kobject* kobj)
 {
   return kobj ? ({
-    void* __mptr = (void*)(kobj);
+    char* __mptr = (char*)(kobj);
     ((struct kset*)(__mptr - __builtin_offsetof(struct kset, kobj)));
   }) : NULL;
 }
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-pr77425.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr77425.c
index 1ceea97b422477e0fd2495884f462055a0c931bb..c9be77c0553e0f63c441a97c065def9d36b83bce 100644 (file)
@@ -1,7 +1,9 @@
 /* Fixed in r7-2945-g61f46d0e6dd568.
    Simplified from gcc/ipa-devirt.c.  */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+
 typedef struct odr_type_d {
   /* .... */
   int id;
similarity index 59%
rename from gcc/testsuite/gcc.dg/analyzer/exec-1.c
rename to gcc/testsuite/c-c++-common/analyzer/exec-1.c
index 6b71118bd54687746ae5f2073c727f20390a9c88..25b88995515fb7acfce52908207e8203c3621d7e 100644 (file)
@@ -1,4 +1,10 @@
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+#ifdef __cplusplus
+  #define CONST_CAST(type) const_cast<type>
+#else
+  #define CONST_CAST(type)
+#endif
 
 extern int execl(const char *pathname, const char *arg, ...);
 extern int execlp(const char *file, const char *arg, ...);
@@ -19,25 +25,25 @@ int test_execlpl_ls_al ()
 
 int test_execle_ls_al ()
 {
-  const char *env[3] = {"FOO=BAR", "BAZ", NULL};
+  char * env[3] = {CONST_CAST(char *)("FOO=BAR"), CONST_CAST(char *)("BAZ"), NULL};
   return execl ("/usr/bin/ls", "ls", "-al", NULL, env);
 }
 
 int test_execv_ls_al ()
 {
-  char *argv[3] = {"ls", "-al", NULL};
+  char * argv[3] = {CONST_CAST(char *)("ls"), CONST_CAST(char *)("-al"), NULL};
   return execv ("/usr/bin/ls", argv);
 }
 
 int test_execvp_ls_al ()
 {
-  char *argv[3] = {"ls", "-al", NULL};
+  char *argv[3] = {CONST_CAST(char *)("ls"), CONST_CAST(char *)("-al"), NULL};
   return execvp ("ls", argv);
 }
 
 int test_execvpe_ls_al ()
 {
-  char *env[3] = {"FOO=BAR", "BAZ", NULL};
-  char *argv[3] = {"ls", "-al", NULL};
+  char *env[3] = {CONST_CAST(char *)("FOO=BAR"), CONST_CAST(char *)("BAZ"), NULL};
+  char *argv[3] = {CONST_CAST(char *)("ls"), CONST_CAST(char *)("-al"), NULL};
   return execvpe ("ls", argv, env);
 }
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/feasibility-3.c
rename to gcc/testsuite/c-c++-common/analyzer/feasibility-3.c
index 0c0bd14fa54a7d147dc48a1547a4f0565adc9fb8..2fcd064e801f853883364855aba0557145801d74 100644 (file)
@@ -4,7 +4,9 @@
 /* Types.  */
 
 typedef unsigned char u8;
+#ifndef __cplusplus
 typedef _Bool bool;
+#endif
 typedef unsigned int gfp_t;
 
 struct file;
@@ -67,7 +69,7 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde)
 
 static inline struct proc_inode *PROC_I(const struct inode *inode)
 {
-  void *__mptr = (void *)(inode);
+  char *__mptr = (char *)(inode);
   return ((struct proc_inode *)(__mptr - __builtin_offsetof(struct proc_inode, vfs_inode)));
 }
 
@@ -89,8 +91,11 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 {
  struct proc_dir_entry *pde = PDE(inode);
  int rv = 0;
- typeof(((struct proc_ops*)0)->proc_open) open;
- typeof(((struct proc_ops*)0)->proc_release) release;
+
+
+ int (*open)(struct inode *, struct file *);
+ int (*release)(struct inode *, struct file *);
+
  struct pde_opener *pdeo;
 
  if (pde_is_permanent(pde)) {
@@ -104,7 +109,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 
  release = pde->proc_ops->proc_release;
  if (release) {
-  pdeo = kmem_cache_alloc(pde_opener_cache,
+  pdeo = (struct pde_opener *) kmem_cache_alloc(pde_opener_cache,
                          ((( gfp_t)(0x400u|0x800u))
                           | (( gfp_t)0x40u)
                           | (( gfp_t)0x80u)));
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/fields.c
rename to gcc/testsuite/c-c++-common/analyzer/fields.c
index 0bf877fcf1e7017ff64c9692a51ae4210414ed58..18595307c9bdc063355adc3738b716eb93ca7fbb 100644 (file)
@@ -30,7 +30,7 @@ recvauth_common (int problem)
     krb5_error error;
     const char *message = error_message(problem);
     error.text.length = strlen(message) + 1;
-    if (!(error.text.data = malloc(error.text.length))) {
+    if (!(error.text.data = (char *) malloc(error.text.length))) {
       goto cleanup;
     }
     free(error.text.data);
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/function-ptr-5.c
rename to gcc/testsuite/c-c++-common/analyzer/function-ptr-5.c
index 3c46f2890821f3117b1a687777ad9ace18e4d30b..2b83978c1ada48abfbe775d2aa87746213139bd7 100644 (file)
@@ -1,4 +1,4 @@
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void calling_null_fn_ptr_1 (void)
 {
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-1.c
rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108524-1.c
index d9221fa8dc5a5ce3d762eb49382b1de0e9e421ef..26fc8d2e8d4f71982ffedae2dfbfdce9f2627b59 100644 (file)
@@ -3,7 +3,9 @@
 
 /* { dg-additional-options "-fno-analyzer-call-summaries -Wno-analyzer-too-complex" } */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+
 typedef __builtin_va_list va_list;
 
 typedef struct _GQueue GQueue;
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-2.c
rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108524-2.c
index 58f6d2f4463698b7fd288c8ce22085605d366b21..d483d7e643c21db1b58cd36831139f9192bf814c 100644 (file)
@@ -62,7 +62,7 @@ void test_5 (struct st2 *p)
 
 void test_6 (struct st2 *p)
 {
-  struct st2 *q = __builtin_malloc (p->i);
+  struct st2 *q = (struct st2 *) __builtin_malloc (p->i);
   if (!q)
     return;
   q->i = p->i;
@@ -72,7 +72,7 @@ void test_6 (struct st2 *p)
 
 void test_7 (struct st2 *p)
 {
-  struct st2 *q = __builtin_malloc (p->i);
+  struct st2 *q = (struct st2 *) __builtin_malloc (p->i);
   q->i = p->i; /* { dg-warning "dereference of possibly-NULL 'q'" } */
   test_7 (q);
   __builtin_free (q);
similarity index 99%
rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108524-qobject-json-parser.c
rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108524-qobject-json-parser.c
index b40326fc252dcf146a9248569c04da5a2e6b7375..64ea62edd65819b1b31a28a914a69c94f5674e2f 100644 (file)
@@ -3,7 +3,9 @@
 
 /* { dg-additional-options "-fno-analyzer-call-summaries -Wno-analyzer-too-complex" } */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+
 typedef __builtin_va_list va_list;
 typedef __SIZE_TYPE__ size_t;
 
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/init.c
rename to gcc/testsuite/c-c++-common/analyzer/init.c
index e51d88e9ff927b60361c08daf56f36166076ce8c..cd3c16f476627612b647d5685dc0385085cca364 100644 (file)
@@ -5,7 +5,7 @@
    gimple assign stmts, with just "zero-init everything" CONSTRUCTORs
    and "clobber" CONSTRUCTORs.  */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct coord
 {
@@ -95,7 +95,7 @@ void test_9 (void)
 
 void test_10 (void)
 {
-  struct coord c[2] = {{.y = 4, .x = 3}, {5, 6}};
+  struct coord c[2] = {{.x = 3, .y = 4}, {5, 6}};
   __analyzer_eval (c[0].x == 3); /* { dg-warning "TRUE" } */
   __analyzer_eval (c[0].y == 4); /* { dg-warning "TRUE" } */  
   __analyzer_eval (c[1].x == 5); /* { dg-warning "TRUE" } */
similarity index 55%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-3-multiline.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
index 15a2dd8f0e134ed42bfacc936815d6f3b807b1bc..fbd20e949b601ce2c57c40580cb6468867ad9a8c 100644 (file)
@@ -4,8 +4,8 @@
 /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
 /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
 
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
 
 struct input_file_st 
 {
@@ -61,4 +61,39 @@ test (const input_file *inpf)
     |          (4) ...to here
     |          (5) argument 1 ('<unknown>') NULL where non-null expected
     |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+
+
+/* { dg-begin-multiline-output "" }
+   return __builtin_strlen (f);
+          ~~~~~~~~~~~~~~~~~^~~
+  'size_t test(const input_file*)': events 1-2 (depth 1)
+    |
+    | test (const input_file *inpf)
+    | ^~~~
+    | |
+    | (1) entry to 'test'
+    |
+    |   const char *f = get_input_file_name (inpf);
+    |                                       ~
+    |                                       |
+    |                                       (2) inlined call to 'get_input_file_name' from 'test'
+    |
+    +--> 'const char* get_input_file_name(const input_file*)': event 3 (depth 2)
+           |
+           |   if (inpf)
+           |   ^~
+           |   |
+           |   (3) following 'false' branch (when 'inpf' is NULL)...
+           |
+    <------+
+    |
+  'size_t test(const input_file*)': events 4-5 (depth 1)
+    |
+    |   return __builtin_strlen (f);
+    |          ~~~~~~~~~~~~~~~~~^~~
+    |                           |
+    |                           (4) ...to here
+    |                           (5) argument 1 ('<unknown>') NULL where non-null expected
+    |
+   { dg-end-multiline-output "" { target c++ } } */
\ No newline at end of file
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-3.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-3.c
index 7a292ac87fa0eac6387c9a36b0724cae0ed0751a..0345585bed2aa9383ffa96872f5678f4fddfae34 100644 (file)
@@ -3,8 +3,9 @@
 
 /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
 
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+
 
 struct input_file_st 
 {
@@ -16,7 +17,9 @@ typedef struct input_file_st input_file;
 static inline const char*
 get_input_file_name (const input_file *inpf)
 {
-  if (inpf) /* { dg-message "following 'false' branch \\(when 'inpf' is NULL\\)\\.\\.\\. \\(fndecl 'get_input_file_name', depth 2\\)" } */
+  if (inpf)
+    /* { dg-message "following 'false' branch \\(when 'inpf' is NULL\\)\\.\\.\\. \\(fndecl 'get_input_file_name', depth 2\\)" "" { target c } .-1 } */
+    /* { dg-message "following 'false' branch \\(when 'inpf' is NULL\\)\\.\\.\\. \\(fndecl 'const char\\* get_input_file_name\\(const input_file\\*\\)', depth 2\\)" "" { target c++ } .-2 } */
     return inpf->inpname;
   return NULL;
 }
@@ -26,5 +29,6 @@ test (const input_file *inpf)
 {
   const char *f = get_input_file_name (inpf);
   return __builtin_strlen (f); /* { dg-warning "use of NULL" "warning" } */
-  /* { dg-message "NULL where non-null expected \\(fndecl 'test', depth 1\\)" "message" { target *-*-* } .-1 } */
+  /* { dg-message "NULL where non-null expected \\(fndecl 'test', depth 1\\)" "message" { target c } .-1 } */
+  /* { dg-message "NULL where non-null expected \\(fndecl 'size_t test\\(const input_file\\*\\)', depth 1\\)" "message" { target c++  } .-2 } */
 }
similarity index 54%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-4-multiline.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-4-multiline.c
index 0413c39af038d7b7cd440f4649d6c2eea8617df6..c870a9f654d906981132505efbc8a3e9076288fc 100644 (file)
@@ -4,7 +4,8 @@
 /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
 /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
 
 static inline const char*
 inner (int flag)
@@ -69,4 +70,48 @@ outer (int flag)
     |          |
     |          (6) dereference of NULL '<unknown>'
     |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   return *middle (flag);
+                       ^
+  'char outer(int)': events 1-2 (depth 1)
+    |
+    | outer (int flag)
+    | ^~~~~
+    | |
+    | (1) entry to 'outer'
+    |
+    |   return *middle (flag);
+    |                  ~
+    |                  |
+    |                  (2) inlined call to 'middle' from 'outer'
+    |
+    +--> 'const char* middle(int)': event 3 (depth 2)
+           |
+           |   return inner (flag);
+           |                ^
+           |                |
+           |                (3) inlined call to 'inner' from 'middle'
+           |
+           +--> 'const char* inner(int)': event 4 (depth 3)
+                  |
+                  |   if (flag)
+                  |   ^~
+                  |   |
+                  |   (4) following 'true' branch (when 'flag != 0')...
+                  |
+    <-------------+
+    |
+  'char outer(int)': event 5 (depth 1)
+    |
+    |cc1plus:
+    | (5): ...to here
+    |
+  'char outer(int)': event 6 (depth 1)
+    |
+    |   return *middle (flag);
+    |                       ^
+    |                       |
+    |                       (6) dereference of NULL '<unknown>'
+    |
+   { dg-end-multiline-output "" { target c++ } } */
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-4.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-4.c
index f4e42084c918df7a6ab79db71bebfee1b89144d4..85b42445d26eb9a590bc81a86ef375b328b197b9 100644 (file)
@@ -3,12 +3,14 @@
 
 /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 static inline const char*
 inner (int flag)
 {
-  if (flag) /* { dg-message "following 'true' branch \\(when 'flag != 0'\\)\\.\\.\\. \\(fndecl 'inner', depth 3\\)" } */
+  if (flag)
+  /* { dg-message "following 'true' branch \\(when 'flag != 0'\\)\\.\\.\\. \\(fndecl 'inner', depth 3\\)" "" { target c } .-1 } */
+  /* { dg-message "following 'true' branch \\(when 'flag != 0'\\)\\.\\.\\. \\(fndecl 'const char\\* inner\\(int\\)', depth 3\\)" "" { target c++ } .-2 } */
     return NULL;
   return "foo";
 }
@@ -23,5 +25,6 @@ char
 outer (int flag)
 {
   return *middle (flag); /* { dg-warning "dereference of NULL" "warning" } */
-  /* { dg-message "\\(fndecl 'outer', depth 1\\)" "message" { target *-*-* } .-1 } */
+  /* { dg-message "\\(fndecl 'outer', depth 1\\)" "message" { target c } .-1 } */
+  /* { dg-message "\\(fndecl 'char outer\\(int\\)', depth 1\\)" "message" { target c++ } .-2 } */
 }
similarity index 81%
rename from gcc/testsuite/gcc.dg/analyzer/leak-pr105906.c
rename to gcc/testsuite/c-c++-common/analyzer/leak-pr105906.c
index 72901e4d1eb60391daeddf042a39d7132077ece3..a37aa59ca7b1b520a7481cf63e9593db61a192c2 100644 (file)
@@ -1,6 +1,7 @@
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
 
 #define LEN 64
 
@@ -13,7 +14,7 @@ epystr_explode(const char *delim, char *str)
        if (str == NULL || delim == NULL)
                return NULL;
 
-       out = __builtin_malloc(LEN * sizeof(char *));
+       out = (char **) __builtin_malloc(LEN * sizeof(char *));
        if (out == NULL)
                return NULL;
 
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/leak-pr108045-with-call-summaries.c
rename to gcc/testsuite/c-c++-common/analyzer/leak-pr108045-with-call-summaries.c
index d63be06a9bbbfc0683ae7e8aec68577692df708a..e4be5093641b4421efea38ecd045dd55b91bf15c 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-additional-options "-fanalyzer-call-summaries" } */
 
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 /* data structures */
 
@@ -31,7 +31,7 @@ struct screen_s *screen_create(size_t cols, size_t rows)
 {
        struct screen_s *result = NULL;
 
-       result = __builtin_calloc(1, sizeof(*result));
+       result = (struct screen_s *) __builtin_calloc(1, sizeof(*result));
        if (!result)
                return NULL;
 
@@ -39,7 +39,7 @@ struct screen_s *screen_create(size_t cols, size_t rows)
        result->rows = rows;
 
        /* make one allocation which will be accessed like a 2D array */
-       result->data = __builtin_calloc(rows, sizeof(result->data) + sizeof(*result->data) * cols);
+       result->data = (char **) __builtin_calloc(rows, sizeof(result->data) + sizeof(*result->data) * cols);
        if (!result->data) {
                __builtin_free(result);
                return NULL;
@@ -91,7 +91,7 @@ void resize_screen(size_t cols, size_t rows)
 
 int main(void)
 {
-       ctx = __builtin_calloc(1, sizeof(*ctx));
+       ctx = (struct context_s *) __builtin_calloc(1, sizeof(*ctx));
        if (!ctx)
                __builtin_abort();
 
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/leak-pr108045-without-call-summaries.c
rename to gcc/testsuite/c-c++-common/analyzer/leak-pr108045-without-call-summaries.c
index ae7a7d5c1594a6c0282406b875d5c60b08638815..3196e99ba37fbb05a0f4bce82b0910134c1c6b5d 100644 (file)
@@ -2,7 +2,7 @@
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 /* data structures */
 
@@ -32,7 +32,7 @@ struct screen_s *screen_create(size_t cols, size_t rows)
 {
        struct screen_s *result = NULL;
 
-       result = __builtin_calloc(1, sizeof(*result));
+       result = (struct screen_s *) __builtin_calloc(1, sizeof(*result));
        if (!result)
                return NULL;
 
@@ -40,7 +40,7 @@ struct screen_s *screen_create(size_t cols, size_t rows)
        result->rows = rows;
 
        /* make one allocation which will be accessed like a 2D array */
-       result->data = __builtin_calloc(rows, sizeof(result->data) + sizeof(*result->data) * cols);
+       result->data = (char **) __builtin_calloc(rows, sizeof(result->data) + sizeof(*result->data) * cols);
        if (!result->data) {
                __builtin_free(result);
                return NULL;
@@ -92,7 +92,7 @@ void resize_screen(size_t cols, size_t rows)
 
 int main(void)
 {
-       ctx = __builtin_calloc(1, sizeof(*ctx));
+       ctx = (struct context_s *) __builtin_calloc(1, sizeof(*ctx));
        if (!ctx)
                __builtin_abort();
 
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/leak-pr109059-1.c
rename to gcc/testsuite/c-c++-common/analyzer/leak-pr109059-1.c
index 033ab79460e6d7da82ad64dfa88e79b311231e9b..ae196d75b935d28016cf9a0a9fbf7b700e597478 100644 (file)
@@ -27,7 +27,7 @@ cfg_register_postparser(char* name, int (*func)())
 {
   struct cfg_postparser* cp;
 
-  cp = calloc(1, sizeof(*cp));
+  cp = (struct cfg_postparser *) calloc(1, sizeof(*cp));
   if (!cp) {
     /* [...snip...] */
     return 0;
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/leak-pr109059-2.c
rename to gcc/testsuite/c-c++-common/analyzer/leak-pr109059-2.c
index 125bce84864f97142a51d37cbebe252586d64a5b..26329ffac46ff411e5c9467b96f0f3430d6b56b7 100644 (file)
@@ -26,7 +26,7 @@ test_1 (char* name)
 {
   struct cfg_postparser* cp;
 
-  cp = calloc(1, sizeof(*cp));
+  cp = (struct cfg_postparser*) calloc(1, sizeof(*cp));
   if (!cp) {
     /* [...snip...] */
     return 0;
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-2.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-2.c
index bb93c53d3e0f155be989ed25cfa61d781eb0687a..ed68209da7275f0fdce2641cc06c37f63a87181f 100644 (file)
@@ -16,7 +16,7 @@ void test_1 (void)
 
 int *test_2 (void)
 {
-  int *i = malloc (sizeof (int)); /* { dg-message "\\(1\\) this call could return NULL" } */
+  int *i = (int *) malloc (sizeof (int)); /* { dg-message "\\(1\\) this call could return NULL" } */
   *i = 42; /* { dg-warning "dereference of possibly-NULL 'i'" "warning" } */
   /* { dg-message "\\(2\\) 'i' could be NULL: unchecked value from \\(1\\)" "event" { target *-*-* } .-1 } */
   return i; 
similarity index 79%
rename from gcc/testsuite/gcc.dg/analyzer/memcpy-2.c
rename to gcc/testsuite/c-c++-common/analyzer/memcpy-2.c
index 51e4a69495171c88f09eefe14bf62a6fd5f72b38..25b0a5e4ff48a181d59ee5ad09fcb00fa0c29973 100644 (file)
@@ -1,8 +1,9 @@
 /* { dg-additional-options "-Wno-stringop-overflow -Wno-analyzer-out-of-bounds" } */
 
-void
-main (int c, void *v)
+int
+test (int c, void *v)
 {
   static char a[] = "";
   __builtin_memcpy (v, a, -1);
+  return 0;
 }
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c
index cb46827ab65c5f0227c1a0b286f49e182534050d..c46ffe91a6b4611dfb4afe7424b7227fe9b018bb 100644 (file)
@@ -61,12 +61,12 @@ static inline enum obj_type obj_type(const enum obj_type *t)
 }
 static inline struct connection *__objt_conn(enum obj_type *t)
 {
- return ((struct connection *)(((void *)(t)) - ((long)&((struct connection *)0)->obj_type)));
+ return ((struct connection *)(((char *)(t)) - ((long)&((struct connection *)0)->obj_type)));
 }
 static inline struct connection *objt_conn(enum obj_type *t)
 {
  if (!t || *t != OBJ_TYPE_CONN)
-   return ((void *)0);
+   return (struct connection *)((void *)0);
  return __objt_conn(t);
 }
 struct session {
@@ -80,7 +80,7 @@ SSL *ssl_sock_get_ssl_object(struct connection *conn);
 /*****************************************************************************/
 
 int
-smp_fetch_ssl_fc_has_early(const struct arg *args, struct sample *smp, const char *kw, void *private)
+smp_fetch_ssl_fc_has_early(const struct arg *args, struct sample *smp, const char *kw, void *Private)
 {
  SSL *ssl;
  struct connection *conn;
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c
index fbacb6ca2d32524379e171e66b866c959523912b..ef34a76c50d63cdb692d5843bb3db2afe4068ee1 100644 (file)
@@ -60,12 +60,12 @@ static inline enum obj_type obj_type(const enum obj_type *t)
 }
 static inline struct connection *__objt_conn(enum obj_type *t)
 {
- return ((struct connection *)(((void *)(t)) - ((long)&((struct connection *)0)->obj_type)));
+ return ((struct connection *)(((char *)(t)) - ((long)&((struct connection *)0)->obj_type)));
 }
 static inline struct connection *objt_conn(enum obj_type *t)
 {
  if (!t || *t != OBJ_TYPE_CONN)
-   return ((void *)0);
+   return (struct connection *) ((void *)0);
  return __objt_conn(t);
 }
 struct session {
@@ -79,7 +79,7 @@ SSL *ssl_sock_get_ssl_object(struct connection *conn);
 /*****************************************************************************/
 
 int
-smp_fetch_ssl_fc_has_early(const struct arg *args, struct sample *smp, const char *kw, void *private)
+smp_fetch_ssl_fc_has_early(const struct arg *args, struct sample *smp, const char *kw, void *Private)
 {
  SSL *ssl;
  struct connection *conn;
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108806-qemu.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr108806-qemu.c
index 3ab72c053af74223284164bd969be0f3579f8f9d..f7f6923927fc977fe1a2839dc34ebb09b6372f8f 100644 (file)
@@ -1,6 +1,6 @@
 /* Reduced from qemu-7.2.0's hw/intc/omap_intc.c */
 
-#define NULL ((void*)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef unsigned char __uint8_t;
 typedef unsigned int __uint32_t;
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108830.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr108830.c
index 417ab00794de81d7096bcf63526702e5ca98127a..0c95148ebd57f63f153f0d6d7021dc36e5240f60 100644 (file)
@@ -2,7 +2,7 @@
 
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
-#define NULL ((void*)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -43,7 +43,7 @@ struct apr_hash_t
 static apr_hash_entry_t**
 alloc_array(apr_hash_t* ht, unsigned int max)
 {
-  return memset(apr_palloc(ht->pool, sizeof(*ht->array) * (max + 1)),
+  return (apr_hash_entry_t **) memset(apr_palloc(ht->pool, sizeof(*ht->array) * (max + 1)),
                 0,
                 sizeof(*ht->array) * (max + 1));
 }
@@ -57,7 +57,7 @@ apr_hash_merge(apr_pool_t* p,
   apr_hash_entry_t* new_vals = NULL;
   apr_hash_entry_t* iter;
   unsigned int i, j, k;
-  res = apr_palloc(p, sizeof(apr_hash_t));
+  res = (apr_hash_t *) apr_palloc(p, sizeof(apr_hash_t));
   res->pool = p;
   res->free = NULL;
   res->hash_func = base->hash_func;
@@ -69,7 +69,7 @@ apr_hash_merge(apr_pool_t* p,
   res->seed = base->seed;
   res->array = alloc_array(res, res->max);
   if (base->count + overlay->count) {
-    new_vals =
+    new_vals = (apr_hash_entry_t *)
       apr_palloc(p, sizeof(apr_hash_entry_t) * (base->count + overlay->count));
   }
   j = 0;
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/pr101962.c
rename to gcc/testsuite/c-c++-common/analyzer/pr101962.c
index 5eb7cf0b995e2d0102396bbecafb5715606a9795..32cef1617c1be0126fcca7a45de2c755633802ed 100644 (file)
@@ -1,6 +1,5 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
-#define NULL ((void *)0)
 
 /* Verify that the analyzer makes the simplifying assumption that we don't
    hit NULL when incrementing pointers to non-NULL memory regions.  */
@@ -35,7 +34,7 @@ maybe_inc_char_ptr (const char *ptr)
   return ++ptr;
 }
 
-char
+void
 test_s (void)
 {
   const char *msg = "hello world";
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/pr103217-2.c
rename to gcc/testsuite/c-c++-common/analyzer/pr103217-2.c
index aa8bca7ce5f099c4db7e1aa07656453826cfb379..69ba6454e57e4b88f17bc7e1e5e6e9e79f9cfd80 100644 (file)
@@ -30,7 +30,7 @@ struct test {
 };
 
 int main(int argc, char *argv[]) {
-       struct test *options = calloc(1, sizeof(*options));
+       struct test *options = (struct test *) calloc(1, sizeof(*options));
        int rc;
        if (!options)
                abort();
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/pr103217.c
rename to gcc/testsuite/c-c++-common/analyzer/pr103217.c
index 08889acb2c912ecba216451c43c0dfe3a28cbfab..ae298ccaebbefef77c4c9cdc676406ce2afe2277 100644 (file)
@@ -13,7 +13,7 @@ extern char *optarg;
 extern void free (void *__ptr)
   __attribute__ ((__nothrow__ , __leaf__));
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 char *xstrdup(const char *src) {
        char *val = strdup(src);
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/pr104029.c
rename to gcc/testsuite/c-c++-common/analyzer/pr104029.c
index adf15ed356f7350d1c774ce1f4d7e72c64fa3b4f..873f0eb16b7e2407924fd21689ab83f7aa38ad29 100644 (file)
@@ -23,7 +23,7 @@ int heapsort(void *vbase, size_t nmemb, size_t size, t_compfunc compar) {
     return (-1);
   }
 
-  k = my_malloc1(__FILE__, __LINE__, size);
+  k = (char *) my_malloc1(__FILE__, __LINE__, size);
 
   abase = (char *)vbase - size;
 
similarity index 70%
rename from gcc/testsuite/gcc.dg/analyzer/pr104062.c
rename to gcc/testsuite/c-c++-common/analyzer/pr104062.c
index 7129c27f60b91435a0f15daa04d77b6800f5fb03..9b44893dd4ba4cc0c59163e0564d24c63161af3e 100644 (file)
@@ -7,7 +7,7 @@ realloc (void *, __SIZE_TYPE__);
 void
 foo (void)
 {
-  int *ap5 = calloc (4, sizeof *ap5);
-  int *ap7 = realloc (ap5, sizeof *ap5);
+  int *ap5 = (int *) calloc (4, sizeof *ap5);
+  int *ap7 = (int *) realloc (ap5, sizeof *ap5);
 } /* { dg-warning "leak of 'ap5'" "leak of ap5" } */
 /* { dg-warning "leak of 'ap7'" "leak of ap7" { target *-*-* } .-1 } */
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/pr105783.c
rename to gcc/testsuite/c-c++-common/analyzer/pr105783.c
index 00f44d04b64a4e4fd8bca5dd28e388433428e01f..f17519415cef4365a5314c49722e9fc29b35788a 100644 (file)
@@ -1,11 +1,15 @@
 /* { dg-additional-options "-O" } */
 
+#ifndef __cplusplus
+typedef _Bool bool;
+#endif
+
 struct ss_s {
     union out_or_counting_u {
        char *newstr;
        unsigned long long cnt;
     } uu;
-    _Bool counting;
+    bool counting;
 };
 
 struct ss_s ss_init(void) {
similarity index 73%
rename from gcc/testsuite/gcc.dg/analyzer/pr107345.c
rename to gcc/testsuite/c-c++-common/analyzer/pr107345.c
index 540596d1182b92e47a32abe5d6c67412ae47f55c..ea1925bfa190ba5f52d0d7dcd87324c0f6306902 100644 (file)
@@ -9,7 +9,8 @@ int main() {
   int g = 0;
   int *h[2][1];
   h[1][0] = f;
-  if (g == (h[1][0])) { /* { dg-warning "comparison between pointer and integer" } */
+  if (g == (h[1][0])) { /* { dg-warning "comparison between pointer and integer" "" { target c } } */
+  /* { dg-error "ISO C\\+\\+ forbids comparison between pointer and integer" "" { target c++ } .-1 } */
     unsigned int *i = 0;
   }
   printf("NPD_FLAG: %d\n ", *f);
diff --git a/gcc/testsuite/c-c++-common/analyzer/pr93457.c b/gcc/testsuite/c-c++-common/analyzer/pr93457.c
new file mode 100644 (file)
index 0000000..71b3962
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+void
+p5 (const void *);
+
+void
+s5 (const void *cl)
+{
+  p5 (&cl[1]); /* { dg-warning "dereferencing 'void \\*' pointer" "" { target c } } */
+  /* { dg-warning "pointer of type 'void \\*' used in arithmetic" "" { target c++ } .-1 } */
+  /* { dg-error "'const void\\*' is not a pointer-to-object type" "" { target c++ } .-2 } */
+}
similarity index 83%
rename from gcc/testsuite/gcc.dg/analyzer/pr93695-1.c
rename to gcc/testsuite/c-c++-common/analyzer/pr93695-1.c
index e0500c49be727bab0e49564492bd386fb6fd0587..529c60131ca49ec07602498bd4feb332afc40506 100644 (file)
@@ -11,7 +11,7 @@ test_1 (void)
   int i;
 
   for (i = 0; i < ARRAY_SIZE (p); ++i)
-    p[i] = __builtin_malloc (sizeof (i));
+    p[i] = (int *) __builtin_malloc (sizeof (i));
 
   for (i = 0; i < ARRAY_SIZE (p); ++i)
     __builtin_free (p [i]);
@@ -28,7 +28,7 @@ test_2 (int n)
     return;
 
   for (i = 0; i < n; ++i)
-    p[i] = __builtin_malloc (sizeof (i));
+    p[i] = (int *) __builtin_malloc (sizeof (i));
 
   for (i = 0; i < n; ++i)
     __builtin_free (p [i]);
@@ -41,7 +41,7 @@ test_3 (int **p, int n)
 {
   int i;
   for (i = 0; i < n; ++i)
-    p[i] = __builtin_malloc (sizeof (i));
+    p[i] = (int *) __builtin_malloc (sizeof (i));
 }
 
 void
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/pr94596.c
rename to gcc/testsuite/c-c++-common/analyzer/pr94596.c
index 055d20980647a9afd3cde08a3c532fbe9a7d7b97..10ea549924e0728e35056dc0a8ea70eaa69bff52 100644 (file)
  * limitations under the License.
  */
 
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+
+#ifndef __cplusplus
 #define false 0
+#endif
 
 #define OBJECT_OFFSETOF(OBJECT, MEMBER)\
-    __builtin_offsetof(typeof(*(OBJECT)), MEMBER)
+    __builtin_offsetof(struct zone_limit, MEMBER)
 
 #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER)                      \
-    ((typeof(OBJECT)) (void *)                                      \
+    ((struct zone_limit *) (void *)                                      \
      ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER)))
 
 #define ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER)                      \
similarity index 82%
rename from gcc/testsuite/gcc.dg/analyzer/pr94839.c
rename to gcc/testsuite/c-c++-common/analyzer/pr94839.c
index 46c8bb98bd23f3d5b671f0d113a86441010e5586..26e7e616cf6d049340c6b8c8dbc93b3586166893 100644 (file)
@@ -13,7 +13,7 @@ int bitmap_create(struct bitmap *bm, int min, int max)
 
   bm->min = min;
   bm->max = max;
-  bm->vec = __builtin_calloc(sz, sizeof(int));
+  bm->vec = (int *) __builtin_calloc(sz, sizeof(int));
   if (!bm->vec)
     return (-12);
   return 0; /* { dg-bogus "leak" } */
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/pr95240.c
rename to gcc/testsuite/c-c++-common/analyzer/pr95240.c
index c84c64de8b838df53319270a00d66bae0dfcdbb5..afd831b3d265b8de075a9d94ad61d33511b2c814 100644 (file)
@@ -8,7 +8,7 @@ static char *activeTroubleArray;
 int
 initActiveTroubleArray ()
 {
-  activeTroubleArray = calloc (1, 1);
+  activeTroubleArray = (char *) calloc (1, 1);
   return activeTroubleArray ? 0 : 1;
 }
 
similarity index 80%
rename from gcc/testsuite/gcc.dg/analyzer/pr96639.c
rename to gcc/testsuite/c-c++-common/analyzer/pr96639.c
index aedf0464dc937d6b90f6aba04b865fc6b0fae0c9..b95217df6c41d8e08085e444fbe43a0c0918d01f 100644 (file)
@@ -3,7 +3,7 @@ void *calloc (__SIZE_TYPE__, __SIZE_TYPE__);
 int
 x7 (void)
 {
-  int **md = calloc (1, sizeof (void *));
+  int **md = (int **) calloc (1, sizeof (void *));
 
   return md[0][0]; /* { dg-warning "possibly-NULL" "unchecked deref" } */
   /* { dg-warning "leak of 'md'" "leak" { target *-*-* } .-1 } */
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/pr96653.c
rename to gcc/testsuite/c-c++-common/analyzer/pr96653.c
index e5e387c44a51a2e4487355aa0e2b0f5027bdc48b..75f3d23aa986267cd2f03693ca54be23387c1034 100644 (file)
@@ -753,7 +753,7 @@ const char *v4l2_ctrl_get_name(u32 id) {
   case ((0x00a30000 | 0x900) + 4):
     return "MD Region Grid";
   default:
-    return ((void *)0);
+    return (const char *) ((void *)0);
   }
 }
 
@@ -989,40 +989,40 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
     *type = V4L2_CTRL_TYPE_U32;
     break;
   case ((0x00990000 | 0x900) + 250):
-    *type = 0x0103;
+    *type = (enum v4l2_ctrl_type) 0x0103;
     break;
   case ((0x00990000 | 0x900) + 251):
-    *type = 0x0104;
+    *type = (enum v4l2_ctrl_type) 0x0104;
     break;
   case ((0x00990000 | 0x900) + 292):
-    *type = 0x0105;
+    *type = (enum v4l2_ctrl_type) 0x0105;
     break;
   case ((0x00990000 | 0x900) + 1000):
-    *type = 0x0110;
+    *type = (enum v4l2_ctrl_type) 0x0110;
     break;
   case ((0x00990000 | 0x900) + 1001):
-    *type = 0x0111;
+    *type = (enum v4l2_ctrl_type) 0x0111;
     break;
   case ((0x00990000 | 0x900) + 1002):
-    *type = 0x0112;
+    *type = (enum v4l2_ctrl_type) 0x0112;
     break;
   case ((0x00990000 | 0x900) + 1003):
-    *type = 0x0113;
+    *type = (enum v4l2_ctrl_type) 0x0113;
     break;
   case ((0x00990000 | 0x900) + 1004):
-    *type = 0x0114;
+    *type = (enum v4l2_ctrl_type) 0x0114;
     break;
   case ((0x00990000 | 0x900) + 2000):
-    *type = 0x301;
+    *type = (enum v4l2_ctrl_type) 0x301;
     break;
   case ((0x00990000 | 0x900) + 1008):
-    *type = 0x0120;
+    *type = (enum v4l2_ctrl_type) 0x0120;
     break;
   case ((0x00990000 | 0x900) + 1009):
-    *type = 0x0121;
+    *type = (enum v4l2_ctrl_type) 0x0121;
     break;
   case ((0x00990000 | 0x900) + 1010):
-    *type = 0x0122;
+    *type = (enum v4l2_ctrl_type) 0x0122;
     break;
   case ((0x009e0000 | 0x900) + 8):
     *type = V4L2_CTRL_TYPE_AREA;
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/pr96792.c
rename to gcc/testsuite/c-c++-common/analyzer/pr96792.c
index 7757645a133956efdea47fb67b6a0e4bf0de9e42..accaf22ba705b46af4e314b244f9a3c9684daa5a 100644 (file)
@@ -1,4 +1,4 @@
-#define NULL (void *)0
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct block
 {
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/pr96841.c
rename to gcc/testsuite/c-c++-common/analyzer/pr96841.c
index 14f3f7a86a338686ec660fb9970ecafd2f425097..b2951a0651ceae12aedb41ae1da315da80154a58 100644 (file)
@@ -1,4 +1,4 @@
-/* { dg-additional-options "-O1 -Wno-builtin-declaration-mismatch" } */
+/* { dg-additional-options "-O1 -Wno-builtin-declaration-mismatch -Wno-analyzer-too-complex" } */
 
 int
 l8 (void);
diff --git a/gcc/testsuite/c-c++-common/analyzer/pr97568.c b/gcc/testsuite/c-c++-common/analyzer/pr97568.c
new file mode 100644 (file)
index 0000000..da97b9d
--- /dev/null
@@ -0,0 +1,31 @@
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+
+extern int *const p1;
+
+int *const p2 = NULL;
+
+int v3;
+extern int *const p3 = &v3; /* { dg-warning "'p3' initialized and declared 'extern'" "C FE warning" { target c } } */
+
+int v4;
+int *const p4 = &v4;
+
+int main (void)
+{
+  __analyzer_describe (0, p1); /* { dg-message "INIT_VAL\\(p1\\)" "" { target c } } */
+   /* { dg-message "INIT_VAL\\(int\\* const p1\\)" "" { target c++ } .-1 } */
+  __analyzer_eval (p1 == NULL); /* { dg-message "UNKNOWN" } */
+
+  __analyzer_eval (p2 == NULL); /* { dg-message "TRUE" } */
+
+  __analyzer_describe (0, p3); /* { dg-message "&v3" "" { target c } } */
+   /* { dg-message "&int v3" "" { target c++ } .-1 } */
+  __analyzer_eval (p3 == NULL); /* { dg-message "FALSE" } */
+
+  __analyzer_describe (0, p4); /* { dg-message "&v4" "" { target c } } */
+  /* { dg-message "&int v4" "" { target c++ } .-1 } */
+  __analyzer_eval (p4 == NULL); /* { dg-message "FALSE" } */
+
+  return p1[0];
+}
similarity index 59%
rename from gcc/testsuite/gcc.dg/analyzer/pr98564.c
rename to gcc/testsuite/c-c++-common/analyzer/pr98564.c
index 74b1abec6bf2254aa17b9afc5a32c1bd46fdbb89..a404e358cd29d35550895f0f69ca56d9dd6e06e2 100644 (file)
@@ -2,5 +2,5 @@ void *calloc (__SIZE_TYPE__, __SIZE_TYPE__);
 
 void test_1 (void)
 {
-  int *p = calloc (0, 1); /* { dg-message "allocated here" } */
+  int *p = (int *) calloc (0, 1); /* { dg-message "allocated here" } */
 } /* { dg-warning "leak of 'p'" } */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/pr98628.c
rename to gcc/testsuite/c-c++-common/analyzer/pr98628.c
index fa0ca961c465c2362c0c77829b2aae454749d35f..f339c495fd4c5b7e340d8e2a0ed464f789d0803a 100644 (file)
@@ -1,12 +1,12 @@
 /* { dg-additional-options "-O1" } */
 
 void foo(void *);
-struct chanset_t help_subst_chan;
-struct chanset_t *help_subst_chan_0_0;
 struct chanset_t {
   struct chanset_t *next;
   char dname[];
 };
+struct chanset_t help_subst_chan;
+struct chanset_t *help_subst_chan_0_0;
 void help_subst(char *writeidx) {
   for (;; help_subst_chan = *help_subst_chan_0_0) {
     foo(help_subst_chan.next->dname);
similarity index 61%
rename from gcc/testsuite/gcc.dg/analyzer/pr98969.c
rename to gcc/testsuite/c-c++-common/analyzer/pr98969.c
index e4e4f0591979d9cd56efdf3f0479108eda964fa4..4fe76012f0058238c2cd428f314508484ec478ff 100644 (file)
@@ -7,14 +7,15 @@ void
 test_1 (__UINTPTR_TYPE__ i)
 {
   struct foo *f = (struct foo *)i;
-  f->expr = __builtin_malloc (1024);
+  f->expr = (char *) __builtin_malloc (1024);
 } /* { dg-bogus "leak" } */
 
 void
 test_2 (__UINTPTR_TYPE__ i)
 {
   __builtin_free (((struct foo *)i)->expr);
-  __builtin_free (((struct foo *)i)->expr); /* { dg-warning "double-'free' of '\\*\\(\\(struct foo \\*\\)i\\)\\.expr'" } */
+  __builtin_free (((struct foo *)i)->expr); /* { dg-warning "double-'free' of '\\*\\(\\(struct foo \\*\\)i\\)\\.expr'" "" { target c } } */
+  /* { dg-warning "double-'free' of '\\*\\(\\(foo\\*\\)i\\)\\.foo::expr'" "" { target c++ } .-1 } */
 }
 
 void
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/pr99193-2.c
rename to gcc/testsuite/c-c++-common/analyzer/pr99193-2.c
index 40e61817503f1550b47ba9de8113bc363ff3efd8..791b857dcc56bc2b4af5cbb43966efc6f84fb7f3 100644 (file)
@@ -56,7 +56,7 @@ make_display_name (struct drv *drvs)
     ret = single_drive_display_name (drvs);
     len = __builtin_strlen (ret);
 
-    ret = realloc (ret, len + pluses + 1); /* { dg-bogus "'free'" } */
+    ret = (char *) realloc (ret, len + pluses + 1); /* { dg-bogus "'free'" } */
     if (ret == NULL)
       error (EXIT_FAILURE, errno, "realloc");
     for (i = len; i < len + pluses; ++i)
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/pr99193-3.c
rename to gcc/testsuite/c-c++-common/analyzer/pr99193-3.c
index d64b0458e9eb6ac13baf58ea73a5ba06b25c5175..696ded00738864ad87cf379ad2b5e7cbe1d91322 100644 (file)
@@ -8,7 +8,7 @@
 typedef __SIZE_TYPE__ size_t;
 typedef __builtin_va_list va_list;
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern void free (void *);
 extern void *realloc (void *__ptr, size_t __size)
@@ -35,7 +35,7 @@ debug_help (const char **cmds, size_t argc, char *const *const argv)
   len = __builtin_strlen (r);
   for (i = 0; cmds[i] != NULL; ++i) {
     len += __builtin_strlen (cmds[i]) + 1;
-    p = realloc (r, len + 1); /* { dg-bogus "'free'" } */
+    p = (char *) realloc (r, len + 1); /* { dg-bogus "'free'" } */
     if (p == NULL) {
       free (r);
       return NULL;
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/pr99716-1.c
rename to gcc/testsuite/c-c++-common/analyzer/pr99716-1.c
index 2ccdcc73a5c29a34977a3cc629596d43b21a24cc..41be8cab0480e433a679b47d4c208a7b71824299 100644 (file)
@@ -4,7 +4,8 @@ FILE* fopen (const char*, const char*);
 int   fclose (FILE*);
 int fprintf (FILE *, const char *, ...);
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
 
 void
 test_1 (void)
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/pr99774-1.c
rename to gcc/testsuite/c-c++-common/analyzer/pr99774-1.c
index a0bca8b1fe252745835ffd84f8b11f16e570453c..184baeef935dd30712e55c81f4fa75e239a9a1b7 100644 (file)
@@ -42,7 +42,7 @@ int vu_check_queue_inflights(VuVirtq *vq) {
   int i = 0;
 
   if (vq->inuse) {
-    vq->resubmit_list = calloc(vq->inuse, sizeof(VuVirtqInflightDesc));
+    vq->resubmit_list = (VuVirtqInflightDesc *) calloc(vq->inuse, sizeof(VuVirtqInflightDesc));
     if (!vq->resubmit_list) {
       return -1;
     }
similarity index 84%
rename from gcc/testsuite/gcc.dg/analyzer/realloc-1.c
rename to gcc/testsuite/c-c++-common/analyzer/realloc-1.c
index 9951e118efeb5d50a78adb413474b3bda8a17659..75e0b10e964b06aea062704f7272da6b8de5bd13 100644 (file)
@@ -20,14 +20,14 @@ void *test_1 (void *ptr)
   return realloc (ptr, 1024);
 }
 
-void *test_2 (void *ptr)
+void test_2 (void *ptr)
 {
   void *p = malloc (1024); /* { dg-message "allocated here" } */
   p = realloc (p, 4096); /* { dg-message "when 'realloc' fails" } */
   free (p);
 } /* { dg-warning "leak of 'p'" } */ // ideally this would be on the realloc stmt
 
-void *test_3 (void *ptr)
+void test_3 (void *ptr)
 {
   void *p = malloc (1024);
   void *q = realloc (p, 4096);
@@ -45,7 +45,7 @@ void *test_4 (void)
 int *test_5 (int *p)
 {
   *p = 42;
-  int *q = realloc (p, sizeof(int) * 4); /* { dg-message "when 'realloc' fails" } */
+  int *q = (int *) realloc (p, sizeof(int) * 4); /* { dg-message "when 'realloc' fails" } */
   *q = 43; /* { dg-warning "dereference of NULL 'q'" } */
   return q;
 }
@@ -60,7 +60,7 @@ void test_6 (size_t sz)
 void *test_7 (size_t sz)
 {
   char buf[100]; /* { dg-message "region created on stack here" } */
-  void *p = realloc (&buf, sz); /* { dg-warning "'realloc' of '&buf' which points to memory on the stack" } */
+  void *p = realloc (&buf, sz); /* { dg-warning "'realloc' of '& ?buf' which points to memory on the stack" } */
   return p;  
 }
 
@@ -91,5 +91,6 @@ void test_9 (void *p)
 
 void test_10 (char *s, int n)
 {
-  __builtin_realloc(s, n); /* { dg-warning "ignoring return value of '__builtin_realloc' declared with attribute 'warn_unused_result'" } */
+  __builtin_realloc(s, n); /* { dg-warning "ignoring return value of '__builtin_realloc' declared with attribute 'warn_unused_result'" "" { target c } } */
+  /* { dg-warning "ignoring return value of 'void\\* __builtin_realloc\\(void\\*, (long )?unsigned int\\)' declared with attribute 'warn_unused_result'" "" { target c++ } .-1 } */
 } /* { dg-warning "leak" } */
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/realloc-2.c
rename to gcc/testsuite/c-c++-common/analyzer/realloc-2.c
index ab3e4b6628a3693dee76c6539851bbe34f35cf17..e608e0e19c3898713d597a264c170212a2b7e517 100644 (file)
@@ -1,11 +1,9 @@
 /* { dg-additional-options "-fno-analyzer-suppress-followups" } */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef __SIZE_TYPE__ size_t;
 
-#define NULL ((void *)0)
-
 extern void *malloc (size_t __size)
   __attribute__ ((__nothrow__ , __leaf__))
   __attribute__ ((__malloc__))
@@ -21,7 +19,7 @@ char *test_8 (size_t sz)
 {
   char *p, *q;
 
-  p = malloc (3);
+  p = (char *) malloc (3);
   if (!p)
     return NULL;
 
@@ -35,7 +33,7 @@ char *test_8 (size_t sz)
   __analyzer_eval (p[1] == 'b'); /* { dg-warning "TRUE" } */
   __analyzer_eval (p[2] == 'c'); /* { dg-warning "TRUE" } */
 
-  q = realloc (p, 6);
+  q = (char *) realloc (p, 6);
 
   /* We should have 3 nodes, corresponding to "failure",
      "success without moving", and "success with moving".  */
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/realloc-3.c
rename to gcc/testsuite/c-c++-common/analyzer/realloc-3.c
index eec61497d5b4dbf6b979c0a276adcf2c42267a1c..b38013569e4903a97d5ea33b9e297a699c690015 100644 (file)
@@ -1,10 +1,9 @@
 /* { dg-additional-options "-fno-analyzer-suppress-followups" } */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef __SIZE_TYPE__ size_t;
 
-#define NULL ((void *)0)
 
 extern void *calloc (size_t __nmemb, size_t __size)
   __attribute__ ((__nothrow__ , __leaf__))
@@ -27,7 +26,7 @@ char *test_8 (size_t sz)
 {
   char *p, *q;
 
-  p = calloc (1, 3);
+  p = (char *) calloc (1, 3);
   if (!p)
     return NULL;
 
@@ -37,7 +36,7 @@ char *test_8 (size_t sz)
   __analyzer_eval (p[1] == 0); /* { dg-warning "TRUE" } */
   __analyzer_eval (p[2] == 0); /* { dg-warning "TRUE" } */
 
-  q = realloc (p, 6);
+  q = (char *) realloc (p, 6);
 
   /* We should have 3 nodes, corresponding to "failure",
      "success without moving", and "success with moving".  */
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/realloc-4.c
rename to gcc/testsuite/c-c++-common/analyzer/realloc-4.c
index ac338ec0497376a7e2604b7f63d9db42a7d9588f..7e9a8edcac85883519f9246dbf2332ccb89e8cb1 100644 (file)
@@ -1,8 +1,7 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef __SIZE_TYPE__ size_t;
 
-#define NULL ((void *)0)
 
 extern void *calloc (size_t __nmemb, size_t __size)
   __attribute__ ((__nothrow__ , __leaf__))
@@ -34,7 +33,7 @@ char *test_8 (char *p, size_t sz)
   __analyzer_eval (p[1] == 'b'); /* { dg-warning "TRUE" } */
   __analyzer_eval (p[2] == 'c'); /* { dg-warning "TRUE" } */
 
-  q = realloc (p, 6);
+  q = (char *) realloc (p, 6);
 
   /* We should have 3 nodes, corresponding to "failure",
      "success without moving", and "success with moving".  */
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/realloc-5.c
rename to gcc/testsuite/c-c++-common/analyzer/realloc-5.c
index f65f2c6ca2519acab49dc60bb4e597ada9c0e01e..d469ae9306b5a7d2254ced90ca2c33230ab3ee12 100644 (file)
@@ -1,10 +1,9 @@
 /* { dg-additional-options "-fno-analyzer-suppress-followups" } */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef __SIZE_TYPE__ size_t;
 
-#define NULL ((void *)0)
 
 extern void *malloc (size_t __size)
   __attribute__ ((__nothrow__ , __leaf__))
@@ -22,12 +21,12 @@ extern void *memset (void *__ptr, int __value, size_t __size);
 
 void test_1 ()
 {
-  char *p = malloc (16);
+  char *p = (char *) malloc (16);
   if (!p)
     return;
   memset (p, 1, 16);
 
-  char *q = realloc (p, 8);
+  char *q = (char *) realloc (p, 8);
   if (!q)
     {
       free (p);
similarity index 70%
rename from gcc/testsuite/gcc.dg/analyzer/realloc-pr110014.c
rename to gcc/testsuite/c-c++-common/analyzer/realloc-pr110014.c
index d76b87814136ceefb50bb1925e5385ee70eeddf2..e25722a3328ad744fced7f69bdf2abd01cc7f191 100644 (file)
@@ -8,18 +8,18 @@ slurp (long *buffer, unsigned long file_size)
   unsigned long cc;
   if (!__builtin_add_overflow (file_size - file_size % sizeof (long),
                               2 * sizeof (long), &cc))
-    buffer = realloc (buffer, cc);
+    buffer = (long *) realloc (buffer, cc);
   return buffer;
 }
 
 long *
 slurp1 (long *buffer, unsigned long file_size)
 {
-  return realloc (buffer, file_size - file_size % sizeof (long));
+  return (long *) realloc (buffer, file_size - file_size % sizeof (long));
 }
 
 long *
 slurp2 (long *buffer, unsigned long file_size)
 {
-  return realloc (buffer, (file_size / sizeof (long)) * sizeof (long));
+  return (long *) realloc (buffer, (file_size / sizeof (long)) * sizeof (long));
 }
similarity index 81%
rename from gcc/testsuite/gcc.dg/analyzer/snprintf-concat.c
rename to gcc/testsuite/c-c++-common/analyzer/snprintf-concat.c
index a557dee6e4406f01f83a1ae36dd4e7185e652f10..c40440c490560d15afdab896a8f7e5032d246f22 100644 (file)
@@ -1,5 +1,5 @@
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern size_t
 strlen(const char* __s) __attribute__((__nothrow__, __leaf__))
@@ -17,7 +17,7 @@ char *
 test_1 (const char *a, const char *b)
 {
   size_t sz = strlen (a) + strlen (b) + 2;
-  char *p = malloc (sz);
+  char *p = (char *) malloc (sz);
   if (!p)
     return NULL;
   snprintf (p, sz, "%s/%s", a, b);
@@ -28,7 +28,7 @@ void
 test_2 (const char *a, const char *b)
 {
   size_t sz = strlen (a) + strlen (b) + 2;
-  char *p = malloc (sz); /* { dg-message "allocated here" "PR 107017" { xfail *-*-* } } */
+  char *p = (char *) malloc (sz); /* { dg-message "allocated here" "PR 107017" { xfail *-*-* } } */
   if (!p)
     return;
   snprintf (p, sz, "%s/%s", a, b); /* { dg-warning "leak of 'p'" "PR 107017" { xfail *-*-* } } */
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/sock-1.c
rename to gcc/testsuite/c-c++-common/analyzer/sock-1.c
index 0f3e822492f077a516239c553e329a43458bbc1b..e5e2f23bba0c74f2ad9507058a00f00a9f4f5d32 100644 (file)
@@ -5,7 +5,9 @@ typedef __u32 u32;
 typedef __s64 s64;
 typedef __u64 u64;
 typedef long long __kernel_time64_t;
+#ifndef __cplusplus
 typedef _Bool bool;
+#endif
 typedef __s64 time64_t;
 struct __kernel_timespec {
  __kernel_time64_t tv_sec;
@@ -76,12 +78,12 @@ struct sock {
 
 static ktime_t sock_read_timestamp(struct sock *sk)
 {
-  return *(const volatile typeof(sk->sk_stamp) *)&(sk->sk_stamp);
+  return *(const volatile ktime_t *)&(sk->sk_stamp);
 }
 
 static void sock_write_timestamp(struct sock *sk, ktime_t kt)
 {
-  *(volatile typeof(sk->sk_stamp) *)&(sk->sk_stamp) = kt;
+  *(volatile ktime_t *)&(sk->sk_stamp) = kt;
 }
 
 /* [...snip...] */
@@ -108,5 +110,5 @@ int sock_gettstamp(struct socket *sock, void *userstamp,
 
  if (time32)
   return put_old_timespec32(&ts, userstamp);
- return put_timespec64(&ts, userstamp);
+ return put_timespec64(&ts, (struct __kernel_timespec *) userstamp);
 }
diff --git a/gcc/testsuite/c-c++-common/analyzer/sprintf-2.c b/gcc/testsuite/c-c++-common/analyzer/sprintf-2.c
new file mode 100644 (file)
index 0000000..4e10130
--- /dev/null
@@ -0,0 +1,59 @@
+/* See e.g. https://en.cppreference.com/w/c/io/fprintf
+   and https://www.man7.org/linux/man-pages/man3/sprintf.3.html */
+
+extern int
+sprintf(char* dst, const char* fmt, ...)
+  __attribute__((__nothrow__));
+
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+int
+test_passthrough (char* dst, const char* fmt)
+{
+  /* This assumes that fmt doesn't have any arguments.  */
+  return sprintf (dst, fmt);
+}
+
+void
+test_known (void)
+{
+  char buf[10];
+  int res = sprintf (buf, "foo");
+  /* TODO: ideally we would know the value of "res" is 3,
+     and known the content and strlen of "buf" after the call */
+}
+
+int
+test_null_dst (void)
+{
+  return sprintf (NULL, "hello world"); /* { dg-warning "use of NULL where non-null expected" } */
+}
+
+int
+test_null_fmt (char *dst)
+{
+  return sprintf (dst, NULL);  /* { dg-warning "use of NULL where non-null expected" } */
+}
+
+int
+test_uninit_dst (void)
+{
+  char *dst;
+  return sprintf (dst, "hello world"); /* { dg-warning "use of uninitialized value 'dst'" } */
+}
+
+int
+test_uninit_fmt_ptr (char *dst)
+{
+  const char *fmt;
+  return sprintf (dst, fmt); /* { dg-warning "use of uninitialized value 'fmt'" } */
+}
+
+void
+test_strlen_1 (void)
+{
+  char buf[10];
+  sprintf (buf, "msg: %s\n", "abc");
+  __analyzer_eval (__builtin_strlen (buf) == 8); /* { dg-warning "UNKNOWN" } */
+  // TODO: ideally would be TRUE  
+}
similarity index 82%
rename from gcc/testsuite/gcc.dg/analyzer/sprintf-concat.c
rename to gcc/testsuite/c-c++-common/analyzer/sprintf-concat.c
index 0094f3e64496fdf008059869727885185794f224..ad744588bc0c0e229cf31d65e3d1f2dc3f96b9fd 100644 (file)
@@ -1,5 +1,5 @@
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern size_t
 strlen(const char* __s) __attribute__((__nothrow__, __leaf__))
@@ -17,7 +17,7 @@ char *
 test_1 (const char *a, const char *b)
 {
   size_t sz = strlen (a) + strlen (b) + 2;
-  char *p = malloc (sz);
+  char *p = (char *) malloc (sz);
   if (!p)
     return NULL;
   sprintf (p, "%s/%s", a, b);
@@ -28,7 +28,7 @@ void
 test_2 (const char *a, const char *b)
 {
   size_t sz = strlen (a) + strlen (b) + 2;
-  char *p = malloc (sz); /* { dg-message "allocated here" } */
+  char *p = (char *) malloc (sz); /* { dg-message "allocated here" } */
   if (!p)
     return;
   sprintf (p, "%s/%s", a, b); /* { dg-warning "leak of 'p' " } */
similarity index 83%
rename from gcc/testsuite/gcc.dg/analyzer/string-ops-concat-pair.c
rename to gcc/testsuite/c-c++-common/analyzer/string-ops-concat-pair.c
index f5bcd67594fa7747feb245787a39facd197a89fe..254730b2ad4eff261afb659cb28aa952e15dadf3 100644 (file)
@@ -1,5 +1,5 @@
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 /* Concatenating a pair of strings.  */
 
@@ -9,7 +9,7 @@ char *
 alloc_dup_of_concatenated_pair_1_correct (const char *x, const char *y)
 {
   size_t sz = __builtin_strlen (x) + __builtin_strlen (y) + 1;
-  char *result = __builtin_malloc (sz);
+  char *result = (char *) __builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, __builtin_strlen (x));
@@ -25,7 +25,7 @@ alloc_dup_of_concatenated_pair_1_incorrect (const char *x, const char *y)
 {
   /* Forgetting to add space for the terminator here.  */
   size_t sz = __builtin_strlen (x) + __builtin_strlen (y);
-  char *result = __builtin_malloc (sz);
+  char *result = (char *) __builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, __builtin_strlen (x));
@@ -42,7 +42,7 @@ alloc_dup_of_concatenated_pair_2_correct (const char *x, const char *y)
   size_t len_x = __builtin_strlen (x);
   size_t len_y = __builtin_strlen (y);
   size_t sz = len_x + len_y + 1;
-  char *result = __builtin_malloc (sz);
+  char *result = (char *) __builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, len_x);
@@ -57,7 +57,8 @@ alloc_dup_of_concatenated_pair_2_incorrect (const char *x, const char *y)
   size_t len_x = __builtin_strlen (x);
   size_t len_y = __builtin_strlen (y);
   size_t sz = len_x + len_y; /* Forgetting to add space for the terminator.  */
-  char *result = __builtin_malloc (sz); /* { dg-message "capacity: 'len_x \\+ len_y' bytes" } */
+  char *result = (char *) __builtin_malloc (sz); /* { dg-message "capacity: 'len_x \\+ len_y' bytes" "" { target c } } */
+  /* { dg-message "capacity: '\\(len_x \\+ len_y\\)' bytes" "" { target c++ } .-1 } */
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, len_x);
similarity index 83%
rename from gcc/testsuite/gcc.dg/analyzer/string-ops-dup.c
rename to gcc/testsuite/c-c++-common/analyzer/string-ops-dup.c
index 44c4e9dc67e66dd1f124945404c072a4504a9f65..d7ec088f0f7d26686287c00190b5f2063df4fd1f 100644 (file)
@@ -1,5 +1,5 @@
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 /* Duplicating a string.  */
 
@@ -9,7 +9,7 @@ char *
 alloc_dup_1_correct (const char *x)
 {
   size_t sz = __builtin_strlen (x) + 1;
-  char *result = __builtin_malloc (sz);
+  char *result = (char *) __builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, __builtin_strlen (x));
@@ -24,7 +24,7 @@ alloc_dup_1_incorrect (const char *x, const char *y)
 {
   /* Forgetting to add space for the terminator here.  */
   size_t sz = __builtin_strlen (x) + 1;
-  char *result = __builtin_malloc (sz);
+  char *result = (char *) __builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, __builtin_strlen (x));
@@ -39,7 +39,7 @@ alloc_dup_2_correct (const char *x)
 {
   size_t len_x = __builtin_strlen (x);
   size_t sz = len_x + 1;
-  char *result = __builtin_malloc (sz);
+  char *result = (char *) __builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, len_x);
@@ -52,7 +52,7 @@ alloc_dup_of_concatenated_pair_2_incorrect (const char *x, const char *y)
 {
   size_t len_x = __builtin_strlen (x);
   size_t sz = len_x; /* Forgetting to add space for the terminator.  */
-  char *result = __builtin_malloc (sz); /* { dg-message "capacity: 'len_x' bytes" } */
+  char *result = (char *) __builtin_malloc (sz); /* { dg-message "capacity: 'len_x' bytes" } */
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, len_x);
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/switch-enum-pr105273-git-vreportf-2.c
rename to gcc/testsuite/c-c++-common/analyzer/switch-enum-pr105273-git-vreportf-2.c
index 336222759e32367cd77db3e9a1124db80a4ae6a5..bb1ef085691274e18e295b4084e1eb3d00cc727b 100644 (file)
@@ -34,7 +34,7 @@ static void __analyzer_vreportf(enum usage_kind kind)
 
 int main(void)
 {
-       __analyzer_vreportf(42);
+       __analyzer_vreportf((enum usage_kind) 42);
 
        return 0;
 }
similarity index 88%
rename from gcc/testsuite/gcc.dg/analyzer/symbolic-12.c
rename to gcc/testsuite/c-c++-common/analyzer/symbolic-12.c
index d7c50de9f2706ce3569d81781be72fa43b19148a..26d9d1df93a38be5ed6bf1c067eb6284d94d4bb4 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void external_fn(void);
 
@@ -10,7 +10,7 @@ struct st_1
 
 void test_1a (void *p, unsigned next_off)
 {
-  struct st_1 *r = p;
+  struct st_1 *r = (struct st_1 *) p;
 
   external_fn();
 
@@ -24,7 +24,7 @@ void test_1a (void *p, unsigned next_off)
 
 void test_1b (void *p, unsigned next_off)
 {
-  struct st_1 *r = p;
+  struct st_1 *r = (struct st_1 *) p;
 
   if (next_off >= r->size)
     return;
@@ -58,7 +58,7 @@ void test_1d (struct st_1 *r, unsigned next_off)
 
 void test_1e (void *p, unsigned next_off)
 {
-  struct st_1 *r = p;
+  struct st_1 *r = (struct st_1 *) p;
 
   while (1)
     {
@@ -79,7 +79,7 @@ struct st_2
 
 void test_2a (void *p, unsigned next_off)
 {
-  struct st_2 *r = p;
+  struct st_2 *r = (struct st_2 *) p;
 
   external_fn();
 
@@ -93,7 +93,7 @@ void test_2a (void *p, unsigned next_off)
 
 void test_2b (void *p, unsigned next_off, int idx)
 {
-  struct st_2 *r = p;
+  struct st_2 *r = (struct st_2 *) p;
 
   external_fn();
 
similarity index 57%
rename from gcc/testsuite/gcc.dg/analyzer/uninit-alloca.c
rename to gcc/testsuite/c-c++-common/analyzer/uninit-alloca.c
index 5dd3f8522d2df7f1d1ac0f5373d94bdb523d8895..d8c842171a810b218d2922022b1cc73d9974b60a 100644 (file)
@@ -2,6 +2,6 @@
 
 int test_1 (void)
 {
-  int *p = __builtin_alloca (sizeof (int)); /* { dg-message "region created on stack here" } */
+  int *p = (int *) __builtin_alloca (sizeof (int)); /* { dg-message "region created on stack here" } */
   return *p; /* { dg-warning "use of uninitialized value '\\*p'" } */
 }
similarity index 76%
rename from gcc/testsuite/gcc.dg/analyzer/untracked-2.c
rename to gcc/testsuite/c-c++-common/analyzer/untracked-2.c
index 565a9ccd58ea7cb082634a7de5353cbdd42b0fda..8c6d9d6f0235d1340d7a345f9f104ef089dc9782 100644 (file)
@@ -2,6 +2,6 @@ typedef unsigned char u8;
 extern int foo(const u8 *key, unsigned int keylen);
 int test (void)
 {
-  static const u8 default_salt[64];
+  static const u8 default_salt[64] = {};
   return foo(default_salt, 64);
 }
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/vasprintf-1.c
rename to gcc/testsuite/c-c++-common/analyzer/vasprintf-1.c
index 061cd008c133538d5e220c4c99f844a8aca3cd70..5e8ee9f233bba8055d28915a300c9d88f4b44367 100644 (file)
@@ -1,6 +1,7 @@
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
 
 extern int printf (const char *__restrict __format, ...);
 extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/write-to-const-1.c
rename to gcc/testsuite/c-c++-common/analyzer/write-to-const-1.c
index dc724e29185ad53215a8dfc5fd31fddbf477c50c..c74442af267b1751481cddb75430659817bfeb9f 100644 (file)
@@ -9,7 +9,7 @@ int test_1 (void)
 
 /* Example of writing to a subregion (an element within a const array).  */
 
-const int c2[10]; /* { dg-message "declared here" } */
+const int c2[10] = {}; /* { dg-message "declared here" } */
 int test_2 (void)
 {
   ((int*) &c2)[5] = 10; /* { dg-warning "write to 'const' object 'c2'" } */
similarity index 73%
rename from gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-1.c
rename to gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-1.c
index 092500e066fd7ddb66bb70b9bf28704216c3a7c8..46e907a856091604a524273f8f89aa1cd04eef21 100644 (file)
@@ -1,10 +1,16 @@
 #include <string.h>
 
+#ifdef __cplusplus
+#define CONST_CAST(type) const_cast<type>
+#else
+#define CONST_CAST(type)
+#endif
+
 /* PR analyzer/95007.  */
 
 void test_1 (void)
 {
-  char *s = "foo";
+  char *s = CONST_CAST(char *)("foo");
   s[0] = 'g'; /* { dg-warning "write to string literal" } */
 }
 
@@ -12,9 +18,12 @@ void test_1 (void)
 
 void test_2 (void)
 {
-  memcpy ("abc", "def", 3); /* { dg-warning "write to string literal" } */
+  // Technically irrelevant for C++ as fpermissive will warn about invalid conversion.
+  memcpy (CONST_CAST(char *)("abc"), "def", 3); /* { dg-warning "write to string literal" } */
 }
 
+/* PR c/83347.  */
+
 static char * __attribute__((noinline))
 called_by_test_3 (void)
 {
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4-disabled.c
rename to gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-4-disabled.c
index fa21af133410f865c303c8f1a06e68344e6bdb6a..868c39368e1df7880a18fbe5207741329f9d42f1 100644 (file)
@@ -16,7 +16,7 @@ void test (int flag)
   char *buf;
 
   if (flag)
-    buf = __builtin_malloc (1024);
+    buf = (char *) __builtin_malloc (1024);
   else
     buf = (char *)""; /* { dg-bogus "here" } */
 
diff --git a/gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-4.c b/gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-4.c
new file mode 100644 (file)
index 0000000..971e8f3
--- /dev/null
@@ -0,0 +1,26 @@
+typedef __SIZE_TYPE__ size_t;
+
+int getrandom (void *__buffer, size_t __length, /* { dg-line getrandom } */
+              unsigned int __flags)
+  __attribute__ ((access (__write_only__, 1, 2)));
+
+/* { dg-message "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c} getrandom } */
+/* { dg-message "parameter 1 of 'int getrandom\\(void\\*, size_t, unsigned int\\)' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c++ } getrandom } */
+
+#define GRND_RANDOM 0x02
+
+void test (int flag)
+{
+  char *buf;
+
+  if (flag)
+    buf = (char *) __builtin_malloc (1024);
+  else
+    buf = (char *)""; /* { dg-message "here" } */
+
+  if (getrandom(buf, 16, GRND_RANDOM)) /* { dg-warning "write to string literal" } */
+    __builtin_printf("%s\n", buf);
+
+  if (flag)
+    __builtin_free (buf);
+}
similarity index 59%
rename from gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-5.c
rename to gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-5.c
index 42efc49fb22ec8e44d0a04f6b109557f5495b131..a949f15323d349e4c123192abd35d33ef0a7fc7b 100644 (file)
@@ -4,11 +4,13 @@
 /* { dg-additional-options "-fanalyzer-show-duplicate-count" } */
 /* { dg-require-effective-target alloca } */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef __SIZE_TYPE__ size_t;
 
-int getrandom (void *__buffer, size_t __length, /* { dg-message "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" } */
+int getrandom (void *__buffer, size_t __length,
+              /* { dg-message "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c } .-1 } */
+              /* { dg-message "parameter 1 of 'int getrandom\\(void\\*, size_t, unsigned int\\)' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c++ } .-2 } */
               unsigned int __flags)
   __attribute__ ((access (__write_only__, 1, 2)));
 
@@ -18,9 +20,9 @@ void *test (int flag)
 {
   char *ptr;
   if (flag)
-    ptr = __builtin_malloc (1024);
+    ptr = (char *) __builtin_malloc (1024);
   else
-    ptr = __builtin_alloca (1024);
+    ptr = (char *) __builtin_alloca (1024);
 
   __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
 
index 9551d827c6569808b094c6f619acddb38a0c4f5a..848bea616df1d469a03f8d4149ddc003ccb931e2 100644 (file)
@@ -39,6 +39,9 @@ set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]]
 
 g++-dg-runtest $tests "" $DEFAULT_CXXFLAGS
 
+g++-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/analyzer/*.\[cS\]]] \
+       "" $DEFAULT_CXXFLAGS
+
 # All done.
 dg-finish
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-1.c b/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-1.c
deleted file mode 100644 (file)
index 7251665..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
-
-#include <stdint.h>
-
-void test_constant_1 (void)
-{
-  int32_t *ptr = __builtin_malloc (1); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-  __builtin_free (ptr);
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = __builtin_malloc (1);
-                  ^~~~~~~~~~~~~~~~~~~~
-  'test_constant_1': events 1-2
-    |
-    |   int32_t *ptr = __builtin_malloc (1);
-    |                  ^~~~~~~~~~~~~~~~~~~~
-    |                  |
-    |                  (1) allocated 1 byte here
-    |                  (2) assigned to 'int32_t *'
-    |
-   { dg-end-multiline-output "" } */
-
-void test_constant_2 (void)
-{
-  int32_t *ptr = __builtin_malloc (2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-  __builtin_free (ptr);
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = __builtin_malloc (2);
-                  ^~~~~~~~~~~~~~~~~~~~
-  'test_constant_2': events 1-2
-    |
-    |   int32_t *ptr = __builtin_malloc (2);
-    |                  ^~~~~~~~~~~~~~~~~~~~
-    |                  |
-    |                  (1) allocated 2 bytes here
-    |                  (2) assigned to 'int32_t *'
-    |
-   { dg-end-multiline-output "" } */
-
-void test_symbolic (int n)
-{
-  int32_t *ptr = __builtin_malloc (n * 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-  __builtin_free (ptr);
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = __builtin_malloc (n * 2);
-                  ^~~~~~~~~~~~~~~~~~~~~~~~
-  'test_symbolic': event 1
-    |
-    |   int32_t *ptr = __builtin_malloc (n * 2);
-    |                  ^~~~~~~~~~~~~~~~~~~~~~~~
-    |                  |
-    |                  (1) allocated 'n * 2' bytes and assigned to 'int32_t *'
-    |
-   { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-2.c b/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-2.c
deleted file mode 100644 (file)
index 7cadbb7..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-fine-grained" } */
-/* { dg-require-effective-target alloca } */
-
-#include <stdint.h>
-
-void test_constant_1 (void)
-{
-  int32_t *ptr = __builtin_alloca (1); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = __builtin_alloca (1);
-                  ^~~~~~~~~~~~~~~~~~~~
-  'test_constant_1': events 1-2
-    |
-    |   int32_t *ptr = __builtin_alloca (1);
-    |                  ^~~~~~~~~~~~~~~~~~~~
-    |                  |
-    |                  (1) allocated 1 byte here
-    |                  (2) assigned to 'int32_t *'
-    |
-   { dg-end-multiline-output "" } */
-
-void test_constant_2 (void)
-{
-  int32_t *ptr = __builtin_alloca (2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = __builtin_alloca (2);
-                  ^~~~~~~~~~~~~~~~~~~~
-  'test_constant_2': events 1-2
-    |
-    |   int32_t *ptr = __builtin_alloca (2);
-    |                  ^~~~~~~~~~~~~~~~~~~~
-    |                  |
-    |                  (1) allocated 2 bytes here
-    |                  (2) assigned to 'int32_t *'
-    |
-   { dg-end-multiline-output "" } */
-
-void test_symbolic (int n)
-{
-  int32_t *ptr = __builtin_alloca (n * 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = __builtin_alloca (n * 2);
-                  ^~~~~~~~~~~~~~~~~~~~~~~~
-  'test_symbolic': events 1-2
-    |
-    |   int32_t *ptr = __builtin_alloca (n * 2);
-    |                  ^~~~~~~~~~~~~~~~~~~~~~~~
-    |                  |
-    |                  (1) allocated 'n * 2' bytes here
-    |                  (2) assigned to 'int32_t *'
-    |
-   { dg-end-multiline-output "" } */
-
-/* FIXME: am getting a duplicate warning here for some reason
-   without -fanalyzer-fine-grained (PR PR analyzer/107851).  */
-
diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-3.c b/gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-3.c
deleted file mode 100644 (file)
index b3de582..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Verify that we warn for incorrect uses of "alloca" (which may be in a 
-   macro in a system header), and that the output looks correct.  */
-
-/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-fine-grained" } */
-/* { dg-require-effective-target alloca } */
-
-#include <stdint.h>
-#include "test-alloca.h"
-
-void test_constant_99 (void)
-{
-  int32_t *ptr = alloca (99); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = alloca (99);
-                  ^~~~~~
-  'test_constant_99': events 1-2
-    |
-    |   int32_t *ptr = alloca (99);
-    |                  ^~~~~~
-    |                  |
-    |                  (1) allocated 99 bytes here
-    |                  (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
-    |
-   { dg-end-multiline-output "" } */
-
-void test_symbolic (int n)
-{
-  int32_t *ptr = alloca (n * 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
-}
-
-/* { dg-begin-multiline-output "" }
-   int32_t *ptr = alloca (n * 2);
-                  ^~~~~~
-  'test_symbolic': events 1-2
-    |
-    |   int32_t *ptr = alloca (n * 2);
-    |                  ^~~~~~
-    |                  |
-    |                  (1) allocated 'n * 2' bytes here
-    |                  (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
-    |
-   { dg-end-multiline-output "" } */
index a626728946281b475cd25279061dd85a95511c50..372a13608d0961bebe7a4e6f6ac77acb09574f62 100644 (file)
@@ -1,6 +1,18 @@
 #ifndef ANALYZER_DECLS_H
 #define ANALYZER_DECLS_H
 
+#ifndef NULL
+#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#else
+#define NULL 0
+#endif
+#else
+#define NULL ((void *)0)
+#endif
+#endif
+
 /* Function decls with special meaning to the analyzer.
    None of these are actually implemented.  */
 
index af05c98fa16001bebf2a588a144ec16f28dfd538..cedf3c0466fd79ccf37b55a85badaec7bbad0d17 100644 (file)
@@ -47,6 +47,9 @@ dg-init
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
        "" $DEFAULT_CFLAGS
 
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/analyzer/*.\[cS\]]] \
+       "" $DEFAULT_CFLAGS
+
 # All done.
 dg-finish
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-11.c b/gcc/testsuite/gcc.dg/analyzer/data-model-11.c
deleted file mode 100644 (file)
index 2766324..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-int test (void)
-{
-  unsigned char *s = "abc";
-  char *t = "xyz";
-  return s[1] + t[1];
-}
index c05137bb219b3cd041a8c03a8b491f0543f9d0ea..4a01b8c656c3687955f1fb4195c9afabab8b4a8f 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-additional-options "-Wno-analyzer-too-complex -Wno-analyzer-fd-leak" } */
 // TODO: remove need for these options
+/* C only: C++ does not support transparent_union. */
+
 
 typedef __SIZE_TYPE__ size_t;
 #define NULL ((void *)0)
@@ -61,7 +63,7 @@ int main() {
   struct sockaddr_un remote;
   socklen_t len = sizeof(remote);
 
-  pollfds = calloc(1, sizeof(struct pollfd));
+  pollfds = (struct pollfd *) calloc(1, sizeof(struct pollfd));
   if (!pollfds) {
     exit(1);
   }
@@ -74,12 +76,13 @@ int main() {
 
     if (pollfds[0].revents & POLLIN) {
       nsockets++;
-      newpollfds = realloc(pollfds, nsockets * sizeof(*pollfds));
+      newpollfds = (struct pollfd *) realloc(pollfds, nsockets * sizeof(*pollfds));
       if (!newpollfds) {
         exit(1);
       }
       pollfds = newpollfds;
       pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote, &len);
+      /* { dg-error "could not convert '& remote' from 'sockaddr_un*' to '__SOCKADDR_ARG'" "G++ doesn't support transparent_union" { target c++ } .-1 } */
     }
   }
   return 0;
index 93d9987d0ba039cdfa5b365eccc8f83d4ff438a7..0121d1fb29ea5c9a69333feb308f6bacbe324046 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-additional-options "-Wno-analyzer-fd-leak" } */
 // TODO: remove need for this option
+/* C only: C++ does not support transparent_union. */
 
 typedef __SIZE_TYPE__ size_t;
 #define NULL ((void *)0)
@@ -61,7 +62,7 @@ int main() {
   struct sockaddr_un remote;
   socklen_t len = sizeof(remote);
 
-  pollfds = calloc(1, sizeof(struct pollfd));
+  pollfds = (struct pollfd *) calloc(1, sizeof(struct pollfd));
   if (!pollfds) {
     exit(1);
   }
@@ -72,11 +73,13 @@ int main() {
   }
 
   nsockets++;
-  newpollfds = realloc(pollfds, nsockets * sizeof(*pollfds));
+  newpollfds = (struct pollfd *) realloc(pollfds, nsockets * sizeof(*pollfds));
   if (!newpollfds) {
     exit(3);
   }
   pollfds = newpollfds;
   pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote, &len);
+  /* { dg-error "could not convert '& remote' from 'sockaddr_un*' to '__SOCKADDR_ARG'" "G++ doesn't support transparent_union" { target c++ } .-1 } */
+
   exit(4);
 }
index a85e743890522df32ba77b1baa6790517fb2808c..b03f510115db441a71fc6e058d31f5653a93081a 100644 (file)
@@ -1,2 +1,3 @@
 /* { dg-additional-options "-Wno-int-conversion" } */
-#include "../pr61861.c"
+/* { C only: Wno-int-conversion is not valid for C++. */
+#include "../../gcc.dg/pr61861.c"
index 148429768cd6334abd72de29c7d552035c563955..df14bea7155df95e55e447b011dddfd4a4cf003f 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "analyzer-decls.h"
 
-#define NULL ((void *) 0)
 #define PATH_SEPARATOR ':'
 #define LOCALE_ALIAS_PATH "value for LOCALE_ALIAS_PATH"
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr93457.c b/gcc/testsuite/gcc.dg/analyzer/pr93457.c
deleted file mode 100644 (file)
index b77911b..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/* { dg-do compile } */
-
-void
-p5 (const void *);
-
-void
-s5 (const void *cl)
-{
-  p5 (&cl[1]); /* { dg-warning "dereferencing 'void \\*' pointer" } */
-}
index f2a72cad01c0c38d6cd25983cf6490a32858e604..579e360a0a37ec4080e61b75eca3fefe6f2e390e 100644 (file)
@@ -1,4 +1,6 @@
 /* { dg-additional-options "-Wno-pointer-to-int-cast" } */
+/* { C only: Wno-pointer-to-int-cast is not valid for C++. */
+
 extern void my_func (int);
 typedef struct {
   int var;
@@ -6,6 +8,6 @@ typedef struct {
 extern void *_data_offs;
 void test()
 {
-  info_t *info = ((void *)((void *)1) + ((unsigned int)&_data_offs));
+  info_t *info = (info_t *) ((void *)((void *)1) + ((unsigned int)&_data_offs));
   my_func(info->var == 0);
 }
index 604b78458c7e17e3becb23b89723d4277b701f4c..f40d9eb21677fe135769f7e48204520239f6d0fe 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-Wno-incompatible-pointer-types" } */
+/* { C only: Wno-incompatible-pointer-types' is not valid for C++. */
 void foo(void)
 {
   void (*a[1]) ();
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr97568.c b/gcc/testsuite/gcc.dg/analyzer/pr97568.c
deleted file mode 100644 (file)
index 22d574b..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "analyzer-decls.h"
-
-#define NULL ((void *)0)
-
-extern int *const p1;
-
-int *const p2;
-
-int v3;
-extern int *const p3 = &v3; /* { dg-warning "'p3' initialized and declared 'extern'" } */
-
-int v4;
-int *const p4 = &v4;
-
-int main (void)
-{
-  __analyzer_describe (0, p1); /* { dg-message "INIT_VAL\\(p1\\)" } */
-  __analyzer_eval (p1 == NULL); /* { dg-message "UNKNOWN" } */
-
-  __analyzer_eval (p2 == NULL); /* { dg-message "TRUE" } */
-
-  __analyzer_describe (0, p3); /* { dg-message "&v3" } */
-  __analyzer_eval (p3 == NULL); /* { dg-message "FALSE" } */
-
-  __analyzer_describe (0, p4); /* { dg-message "&v4" } */
-  __analyzer_eval (p4 == NULL); /* { dg-message "FALSE" } */
-
-  return p1[0];
-}
index e7c2b3089c5b5444c7c4acc6d10b68bbbbc5d5a6..28914d224f509bdb3f137af9dc29e691c125bab8 100644 (file)
@@ -1,55 +1,15 @@
 /* See e.g. https://en.cppreference.com/w/c/io/fprintf
    and https://www.man7.org/linux/man-pages/man3/sprintf.3.html */
 
+/* C only: C++ fpermissive already emits errors. */
 #include "analyzer-decls.h"
 
 extern int
 sprintf(char* dst, const char* fmt, ...)
   __attribute__((__nothrow__));
 
-#define NULL ((void *)0)
-
-int
-test_passthrough (char* dst, const char* fmt)
-{
-  /* This assumes that fmt doesn't have any arguments.  */
-  return sprintf (dst, fmt);
-}
-
-void
-test_known (void)
-{
-  char buf[10];
-  int res = sprintf (buf, "foo");
-  /* TODO: ideally we would know the value of "res" is 3,
-     and known the content and strlen of "buf" after the call */
-}
 
-int
-test_null_dst (void)
-{
-  return sprintf (NULL, "hello world"); /* { dg-warning "use of NULL where non-null expected" } */
-}
-
-int
-test_null_fmt (char *dst)
-{
-  return sprintf (dst, NULL);  /* { dg-warning "use of NULL where non-null expected" } */
-}
-
-int
-test_uninit_dst (void)
-{
-  char *dst;
-  return sprintf (dst, "hello world"); /* { dg-warning "use of uninitialized value 'dst'" } */
-}
-
-int
-test_uninit_fmt_ptr (char *dst)
-{
-  const char *fmt;
-  return sprintf (dst, fmt); /* { dg-warning "use of uninitialized value 'fmt'" } */
-}
+#define NULL ((void *)0)
 
 int
 test_uninit_fmt_buf (char *dst)
@@ -66,12 +26,3 @@ test_fmt_not_terminated (char *dst)
   return sprintf (dst, fmt); /* { dg-warning "stack-based buffer over-read" } */
   /* { dg-message "while looking for null terminator for argument 2 \\('&fmt'\\) of 'sprintf'..." "event" { target *-*-* } .-1 } */
 }
-
-void
-test_strlen_1 (void)
-{
-  char buf[10];
-  sprintf (buf, "msg: %s\n", "abc");
-  __analyzer_eval (__builtin_strlen (buf) == 8); /* { dg-warning "UNKNOWN" } */
-  // TODO: ideally would be TRUE  
-}
index c1bece632ce4b705e30102c66860623a91aeb3ed..a5ee4cabcc0b05b69f523cbe846ae46604b743df 100644 (file)
@@ -1,3 +1,5 @@
+/* { C only: C++ does not allow for conversion from function pointer to 'void *' */
+
 typedef __SIZE_TYPE__ size_t;
 
 int getrandom (void *__buffer, size_t __length, /* { dg-message "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4.c b/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4.c
deleted file mode 100644 (file)
index a8f600f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-typedef __SIZE_TYPE__ size_t;
-
-int getrandom (void *__buffer, size_t __length, /* { dg-message "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" } */
-              unsigned int __flags)
-  __attribute__ ((access (__write_only__, 1, 2)));
-
-#define GRND_RANDOM 0x02
-
-void test (int flag)
-{
-  char *buf;
-
-  if (flag)
-    buf = __builtin_malloc (1024);
-  else
-    buf = (char *)""; /* { dg-message "here" } */
-
-  if (getrandom(buf, 16, GRND_RANDOM)) /* { dg-warning "write to string literal" } */
-    __builtin_printf("%s\n", buf);
-
-  if (flag)
-    __builtin_free (buf);
-}