]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: Move gcc.dg/analyzer tests to c-c++-common (2) [PR96395]
authorbenjamin priour <vultkayn@gcc.gnu.org>
Sat, 9 Sep 2023 16:03:56 +0000 (18:03 +0200)
committerbenjamin priour <vultkayn@gcc.gnu.org>
Sat, 9 Sep 2023 16:22:52 +0000 (18:22 +0200)
Second batch of moving tests from under gcc.dg/analyzer into
c-c++-common/analyzer.

Prior to this patch the analyzer was not unwrapping ordering
binop_svalue, such as LT_EXPR, when evaluating conditions.

Therefore when an ordering conditional was stored, the analyzer
was missing out on some constraints, which led to false positives.

gcc/analyzer/ChangeLog:

PR analyzer/96395
* region-model.cc
(region_model::add_constraints_from_binop): binop_svalues around
LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR are now unwrapped.

gcc/testsuite/ChangeLog:

PR analyzer/96395
* gcc.dg/analyzer/allocation-size-1.c: Moved to...
* c-c++-common/analyzer/allocation-size-1.c: ...here.
* gcc.dg/analyzer/allocation-size-2.c: Moved to...
* c-c++-common/analyzer/allocation-size-2.c: ...here.
* gcc.dg/analyzer/allocation-size-3.c: Moved to...
* c-c++-common/analyzer/allocation-size-3.c: ...here.
* gcc.dg/analyzer/allocation-size-4.c: Moved to...
* c-c++-common/analyzer/allocation-size-4.c: ...here.
* gcc.dg/analyzer/analyzer-verbosity-0.c: Moved to...
* c-c++-common/analyzer/analyzer-verbosity-0.c: ...here.
* gcc.dg/analyzer/analyzer-verbosity-1.c: Moved to...
* c-c++-common/analyzer/analyzer-verbosity-1.c: ...here.
* gcc.dg/analyzer/analyzer-verbosity-2.c: Moved to...
* c-c++-common/analyzer/analyzer-verbosity-2.c: ...here.
* gcc.dg/analyzer/analyzer-verbosity-3.c: Moved to...
* c-c++-common/analyzer/analyzer-verbosity-3.c: ...here.
* gcc.dg/analyzer/attr-alloc_size-1.c: Moved to...
* c-c++-common/analyzer/attr-alloc_size-1.c: ...here.
* gcc.dg/analyzer/attr-alloc_size-2.c: Moved to...
* c-c++-common/analyzer/attr-alloc_size-2.c: ...here.
* gcc.dg/analyzer/call-summaries-malloc.c: Moved to...
* c-c++-common/analyzer/call-summaries-malloc.c: ...here.
* gcc.dg/analyzer/call-summaries-pr107158-2.c: Moved to...
* c-c++-common/analyzer/call-summaries-pr107158-2.c: ...here.
* gcc.dg/analyzer/capacity-1.c: Moved to...
* c-c++-common/analyzer/capacity-1.c: ...here.
* gcc.dg/analyzer/dot-output.c: Moved to...
* c-c++-common/analyzer/dot-output.c: ...here.
* gcc.dg/analyzer/escaping-1.c: Moved to...
* c-c++-common/analyzer/escaping-1.c: ...here.
* gcc.dg/analyzer/expect-1.c: Moved to...
* c-c++-common/analyzer/expect-1.c: ...here.
* gcc.dg/analyzer/fgets-1.c: Moved to...
* c-c++-common/analyzer/fgets-1.c: ...here.
* gcc.dg/analyzer/file-uninit-1.c: Moved to...
* c-c++-common/analyzer/file-uninit-1.c: ...here.
* gcc.dg/analyzer/fileno-1.c: Moved to...
* c-c++-common/analyzer/fileno-1.c: ...here.
* gcc.dg/analyzer/first-field-1.c: Moved to...
* c-c++-common/analyzer/first-field-1.c: ...here.
* gcc.dg/analyzer/first-field-2.c: Moved to...
* c-c++-common/analyzer/first-field-2.c: ...here.
* gcc.dg/analyzer/flex-with-call-summaries.c: Moved to...
* c-c++-common/analyzer/flex-with-call-summaries.c: ...here.
* gcc.dg/analyzer/flex-without-call-summaries.c: Moved to...
* c-c++-common/analyzer/flex-without-call-summaries.c: ...here.
* gcc.dg/analyzer/flexible-array-member-1.c: Moved to...
* c-c++-common/analyzer/flexible-array-member-1.c: ...here.
* gcc.dg/analyzer/fold-string-to-char.c: Moved to...
* c-c++-common/analyzer/fold-string-to-char.c: ...here.
* gcc.dg/analyzer/fread-1.c: Moved to...
* c-c++-common/analyzer/fread-1.c: ...here.
* gcc.dg/analyzer/fread-2.c: Moved to...
* c-c++-common/analyzer/fread-2.c: ...here.
* gcc.dg/analyzer/fread-pr108661.c: Moved to...
* c-c++-common/analyzer/fread-pr108661.c: ...here.
* gcc.dg/analyzer/function-ptr-1.c: Moved to...
* c-c++-common/analyzer/function-ptr-1.c: ...here.
* gcc.dg/analyzer/function-ptr-2.c: Moved to...
* c-c++-common/analyzer/function-ptr-2.c: ...here.
* gcc.dg/analyzer/function-ptr-3.c: Moved to...
* c-c++-common/analyzer/function-ptr-3.c: ...here.
* gcc.dg/analyzer/function-ptr-4.c: Moved to...
* c-c++-common/analyzer/function-ptr-4.c: ...here.
* gcc.dg/analyzer/getc-1.c: Moved to...
* c-c++-common/analyzer/getc-1.c: ...here.
* gcc.dg/analyzer/getchar-1.c: Moved to...
* c-c++-common/analyzer/getchar-1.c: ...here.
* gcc.dg/analyzer/gzio-2.c: Moved to...
* c-c++-common/analyzer/gzio-2.c: ...here.
* gcc.dg/analyzer/gzio-3.c: Moved to...
* c-c++-common/analyzer/gzio-3.c: ...here.
* gcc.dg/analyzer/gzio-3a.c: Moved to...
* c-c++-common/analyzer/gzio-3a.c: ...here.
* gcc.dg/analyzer/gzio.c: Moved to...
* c-c++-common/analyzer/gzio.c: ...here.
* gcc.dg/analyzer/imprecise-floating-point-1.c: Moved to...
* c-c++-common/analyzer/imprecise-floating-point-1.c: ...here.
* gcc.dg/analyzer/infinite-recursion-2.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-2.c: ...here.
* gcc.dg/analyzer/infinite-recursion-3.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-3.c: ...here.
* gcc.dg/analyzer/infinite-recursion-4-limited-buggy.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-4-limited-buggy.c: ...here.
* gcc.dg/analyzer/infinite-recursion-4-limited.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-4-limited.c: ...here.
* gcc.dg/analyzer/infinite-recursion-4-unlimited-buggy.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-4-unlimited-buggy.c: ...here.
* gcc.dg/analyzer/infinite-recursion-4-unlimited.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-4-unlimited.c: ...here.
* gcc.dg/analyzer/infinite-recursion-5.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-5.c: ...here.
* gcc.dg/analyzer/infinite-recursion-alloca.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-alloca.c: ...here.
* gcc.dg/analyzer/infinite-recursion-inlining.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-inlining.c: ...here.
* gcc.dg/analyzer/infinite-recursion-multiline-1.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-multiline-1.c: ...here.
* gcc.dg/analyzer/infinite-recursion-multiline-2.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-multiline-2.c: ...here.
* gcc.dg/analyzer/infinite-recursion-pr108935-1.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-pr108935-1.c: ...here.
* gcc.dg/analyzer/infinite-recursion-pr108935-1a.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-pr108935-1a.c: ...here.
* gcc.dg/analyzer/infinite-recursion-pr108935-2.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-pr108935-2.c: ...here.
* gcc.dg/analyzer/infinite-recursion-variadic.c: Moved to...
* c-c++-common/analyzer/infinite-recursion-variadic.c: ...here.
* gcc.dg/analyzer/infinite-recursion.c: Moved to...
* c-c++-common/analyzer/infinite-recursion.c: ...here.
* gcc.dg/analyzer/inlining-1-multiline.c: Moved to...
* c-c++-common/analyzer/inlining-1-multiline.c: ...here.
* gcc.dg/analyzer/inlining-1-no-undo.c: Moved to...
* c-c++-common/analyzer/inlining-1-no-undo.c: ...here.
* gcc.dg/analyzer/inlining-2-multiline.c: Moved to...
* c-c++-common/analyzer/inlining-2-multiline.c: ...here.
* gcc.dg/analyzer/inlining-5-multiline.c: Moved to...
* c-c++-common/analyzer/inlining-5-multiline.c: ...here.
* gcc.dg/analyzer/inlining-6-multiline.c: Moved to...
* c-c++-common/analyzer/inlining-6-multiline.c: ...here.
* gcc.dg/analyzer/inlining-6.c: Moved to...
* c-c++-common/analyzer/inlining-6.c: ...here.
* gcc.dg/analyzer/inlining-7-multiline.c: Moved to...
* c-c++-common/analyzer/inlining-7-multiline.c: ...here.
* gcc.dg/analyzer/invalid-shift-1.c: Moved to...
* c-c++-common/analyzer/invalid-shift-1.c: ...here.
* gcc.dg/analyzer/isatty-1.c: Moved to...
* c-c++-common/analyzer/isatty-1.c: ...here.
* gcc.dg/analyzer/leak-2.c: Moved to...
* c-c++-common/analyzer/leak-2.c: ...here.
* gcc.dg/analyzer/leak-3.c: Moved to...
* c-c++-common/analyzer/leak-3.c: ...here.
* gcc.dg/analyzer/leak-4.c: Moved to...
* c-c++-common/analyzer/leak-4.c: ...here.
* gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c: Moved to...
* c-c++-common/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c: ...here.
* gcc.dg/analyzer/loop-0-up-to-n-by-1.c: Moved to...
* c-c++-common/analyzer/loop-0-up-to-n-by-1.c: ...here.
* gcc.dg/analyzer/loop-2.c: Moved to...
* c-c++-common/analyzer/loop-2.c: ...here.
* gcc.dg/analyzer/loop-2a.c: Moved to...
* c-c++-common/analyzer/loop-2a.c: ...here.
* gcc.dg/analyzer/loop-3.c: Moved to...
* c-c++-common/analyzer/loop-3.c: ...here.
* gcc.dg/analyzer/loop-4.c: Moved to...
* c-c++-common/analyzer/loop-4.c: ...here.
* gcc.dg/analyzer/loop-n-down-to-1-by-1.c: Moved to...
* c-c++-common/analyzer/loop-n-down-to-1-by-1.c: ...here.
* gcc.dg/analyzer/loop-start-down-to-end-by-1.c: Moved to...
* c-c++-common/analyzer/loop-start-down-to-end-by-1.c: ...here.
* gcc.dg/analyzer/loop-start-down-to-end-by-step.c: Moved to...
* c-c++-common/analyzer/loop-start-down-to-end-by-step.c: ...here.
* gcc.dg/analyzer/loop-start-to-end-by-step.c: Moved to...
* c-c++-common/analyzer/loop-start-to-end-by-step.c: ...here.
* gcc.dg/analyzer/loop-start-up-to-end-by-1.c: Moved to...
* c-c++-common/analyzer/loop-start-up-to-end-by-1.c: ...here.
* gcc.dg/analyzer/loop.c: Moved to...
* c-c++-common/analyzer/loop.c: ...here.
* gcc.dg/analyzer/malloc-3.c: Moved to...
* c-c++-common/analyzer/malloc-3.c: ...here.
* gcc.dg/analyzer/malloc-5.c: Moved to...
* c-c++-common/analyzer/malloc-5.c: ...here.
* gcc.dg/analyzer/malloc-CWE-401-example.c: Moved to...
* c-c++-common/analyzer/malloc-CWE-401-example.c: ...here.
* gcc.dg/analyzer/malloc-CWE-415-examples.c: Moved to...
* c-c++-common/analyzer/malloc-CWE-415-examples.c: ...here.
* gcc.dg/analyzer/malloc-CWE-416-examples.c: Moved to...
* c-c++-common/analyzer/malloc-CWE-416-examples.c: ...here.
* gcc.dg/analyzer/malloc-CWE-590-examples.c: Moved to...
* c-c++-common/analyzer/malloc-CWE-590-examples.c: ...here.
* gcc.dg/analyzer/malloc-callbacks.c: Moved to...
* c-c++-common/analyzer/malloc-callbacks.c: ...here.
* gcc.dg/analyzer/malloc-dce.c: Moved to...
* c-c++-common/analyzer/malloc-dce.c: ...here.
* gcc.dg/analyzer/malloc-dedupe-1.c: Moved to...
* c-c++-common/analyzer/malloc-dedupe-1.c: ...here.
* gcc.dg/analyzer/malloc-in-loop.c: Moved to...
* c-c++-common/analyzer/malloc-in-loop.c: ...here.
* gcc.dg/analyzer/malloc-ipa-1.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-1.c: ...here.
* gcc.dg/analyzer/malloc-ipa-11.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-11.c: ...here.
* gcc.dg/analyzer/malloc-ipa-2.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-2.c: ...here.
* gcc.dg/analyzer/malloc-ipa-3.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-3.c: ...here.
* gcc.dg/analyzer/malloc-ipa-4.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-4.c: ...here.
* gcc.dg/analyzer/malloc-ipa-5.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-5.c: ...here.
* gcc.dg/analyzer/malloc-ipa-6.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-6.c: ...here.
* gcc.dg/analyzer/malloc-ipa-7.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-7.c: ...here.
* gcc.dg/analyzer/malloc-ipa-8-unchecked.c: Moved to...
* c-c++-common/analyzer/malloc-ipa-8-unchecked.c: ...here.
* gcc.dg/analyzer/malloc-macro-inline-events.c: Moved to...
* c-c++-common/analyzer/malloc-macro-inline-events.c: ...here.
* gcc.dg/analyzer/malloc-macro-separate-events.c: Moved to...
* c-c++-common/analyzer/malloc-macro-separate-events.c: ...here.
* gcc.dg/analyzer/malloc-macro.h: Moved to...
* c-c++-common/analyzer/malloc-macro.h: ...here.
* gcc.dg/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c: Moved to...
* c-c++-common/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c: ...here.
* gcc.dg/analyzer/out-of-bounds-1.c: Moved to...
* c-c++-common/analyzer/out-of-bounds-1.c: ...here.
* gcc.dg/analyzer/out-of-bounds-2.c: Moved to...
* c-c++-common/analyzer/out-of-bounds-2.c: ...here.
* gcc.dg/analyzer/out-of-bounds-5.c: Moved to...
* c-c++-common/analyzer/out-of-bounds-5.c: ...here.
* gcc.dg/analyzer/out-of-bounds-diagram-11.c: Moved to...
* c-c++-common/analyzer/out-of-bounds-diagram-11.c: ...here.
* gcc.dg/analyzer/out-of-bounds-diagram-3.c: Moved to...
* c-c++-common/analyzer/out-of-bounds-diagram-3.c: ...here.
* gcc.dg/analyzer/out-of-bounds-diagram-8.c: Moved to...
* c-c++-common/analyzer/out-of-bounds-diagram-8.c: ...here.
* gcc.dg/analyzer/phi-1.c: Moved to...
* c-c++-common/analyzer/phi-1.c: ...here.
* gcc.dg/analyzer/pr100615.c: Moved to...
* c-c++-common/analyzer/pr100615.c: ...here.
* gcc.dg/analyzer/pr103526.c: Moved to...
* c-c++-common/analyzer/pr103526.c: ...here.
* gcc.dg/analyzer/pr94362-1.c: Moved to...
* c-c++-common/analyzer/pr94362-1.c: ...here.
* gcc.dg/analyzer/pr97074.c: Moved to...
* c-c++-common/analyzer/pr97074.c: ...here.
* c-c++-common/analyzer/pr99193-2.c: Added include.
* c-c++-common/analyzer/realloc-1.c: Added include.
* gcc.dg/analyzer/scope-1.c: Moved to...
* c-c++-common/analyzer/scope-1.c: ...here.
* gcc.dg/analyzer/setjmp-2.c: Moved to...
* c-c++-common/analyzer/setjmp-2.c: ...here.
* gcc.dg/analyzer/setjmp-5.c: Moved to...
* c-c++-common/analyzer/setjmp-5.c: ...here.
* gcc.dg/analyzer/setjmp-9.c: Moved to...
* c-c++-common/analyzer/setjmp-9.c: ...here.
* gcc.dg/analyzer/signal-4a.c: Moved to...
* c-c++-common/analyzer/signal-4a.c: ...here.
* gcc.dg/analyzer/signal-4b.c: Moved to...
* c-c++-common/analyzer/signal-4b.c: ...here.
* gcc.dg/analyzer/file-pr58237.c: C only.
* gcc.dg/analyzer/fopen-1.c: C only.
* gcc.dg/analyzer/malloc-4.c: C only.
* gcc.dg/analyzer/malloc-paths-9.c: C only.
* gcc.dg/analyzer/pr103892.c: C only.
* gcc.dg/analyzer/pr109577.c: C only.
* gcc.dg/analyzer/pr93355-localealias-feasibility.c: C only.
* gcc.dg/analyzer/pr99193-1.c: C only.
* gcc.dg/analyzer/compound-assignment-1.c: Removed.
* gcc.dg/analyzer/inlining-1.c: Removed.
* gcc.dg/analyzer/inlining-2.c: Removed.
* gcc.dg/analyzer/inlining-5.c: Removed.
* gcc.dg/analyzer/inlining-7.c: Removed.
* c-c++-common/analyzer/compound-assignment-1.c: New test.
* c-c++-common/analyzer/file-pr58237-noexcept.c: Duplicate of
gcc.dg/analyzer/file-pr58237.c with exceptions disabled.
* c-c++-common/analyzer/fopen-2.c: C++ compatible parts from
gcc.dg/analyzer/fopen-1.c.
* c-c++-common/analyzer/inlining-1.c: New test.
* c-c++-common/analyzer/inlining-2.c: New test.
* c-c++-common/analyzer/inlining-5.c: New test.
* c-c++-common/analyzer/inlining-7.c: New test.
* c-c++-common/analyzer/malloc-paths-9-noexcept.c: Duplicate of
gcc.dg/analyzer/malloc-paths-9.c with exceptions disabled.
* c-c++-common/analyzer/pr109577-noexcept.c: Duplicate of
gcc.dg/analyzer/pr109577.c with exceptions disabled.
* c-c++-common/analyzer/pr93355-localealias-feasibility-noexcept.c:
Duplicate of gcc.dg/analyzer/pr93355-localealias-feasibility.c with
exceptions disabled.
* c-c++-common/analyzer/pr99193-1-noexcept.c: Duplicate of
gcc.dg/analyzer/pr99193-1.c with exceptions disabled.

Signed-off-by: benjamin priour <vultkayn@gcc.gnu.org>
146 files changed:
gcc/analyzer/region-model.cc
gcc/testsuite/c-c++-common/analyzer/allocation-size-1.c [moved from gcc/testsuite/gcc.dg/analyzer/allocation-size-1.c with 73% similarity]
gcc/testsuite/c-c++-common/analyzer/allocation-size-2.c [moved from gcc/testsuite/gcc.dg/analyzer/allocation-size-2.c with 81% similarity]
gcc/testsuite/c-c++-common/analyzer/allocation-size-3.c [moved from gcc/testsuite/gcc.dg/analyzer/allocation-size-3.c with 66% similarity]
gcc/testsuite/c-c++-common/analyzer/allocation-size-4.c [moved from gcc/testsuite/gcc.dg/analyzer/allocation-size-4.c with 64% similarity]
gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-0.c [moved from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c with 53% similarity]
gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-1.c [moved from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c with 52% similarity]
gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-2.c [moved from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c with 51% similarity]
gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-3.c [moved from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-3.c with 51% similarity]
gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-1.c [moved from gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-1.c with 82% similarity]
gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-2.c [moved from gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-2.c with 88% similarity]
gcc/testsuite/c-c++-common/analyzer/call-summaries-malloc.c [moved from gcc/testsuite/gcc.dg/analyzer/call-summaries-malloc.c with 79% similarity]
gcc/testsuite/c-c++-common/analyzer/call-summaries-pr107158-2.c [moved from gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158-2.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/capacity-1.c [moved from gcc/testsuite/gcc.dg/analyzer/capacity-1.c with 94% similarity]
gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/dot-output.c [moved from gcc/testsuite/gcc.dg/analyzer/dot-output.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/escaping-1.c [moved from gcc/testsuite/gcc.dg/analyzer/escaping-1.c with 60% similarity]
gcc/testsuite/c-c++-common/analyzer/expect-1.c [moved from gcc/testsuite/gcc.dg/analyzer/expect-1.c with 91% similarity]
gcc/testsuite/c-c++-common/analyzer/fgets-1.c [moved from gcc/testsuite/gcc.dg/analyzer/fgets-1.c with 90% similarity]
gcc/testsuite/c-c++-common/analyzer/file-pr58237-noexcept.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/file-uninit-1.c [moved from gcc/testsuite/gcc.dg/analyzer/file-uninit-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/fileno-1.c [moved from gcc/testsuite/gcc.dg/analyzer/fileno-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/first-field-1.c [moved from gcc/testsuite/gcc.dg/analyzer/first-field-1.c with 91% similarity]
gcc/testsuite/c-c++-common/analyzer/first-field-2.c [moved from gcc/testsuite/gcc.dg/analyzer/first-field-2.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/flex-with-call-summaries.c [moved from gcc/testsuite/gcc.dg/analyzer/flex-with-call-summaries.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c [moved from gcc/testsuite/gcc.dg/analyzer/flex-without-call-summaries.c with 99% similarity]
gcc/testsuite/c-c++-common/analyzer/flexible-array-member-1.c [moved from gcc/testsuite/gcc.dg/analyzer/flexible-array-member-1.c with 70% similarity]
gcc/testsuite/c-c++-common/analyzer/fold-string-to-char.c [moved from gcc/testsuite/gcc.dg/analyzer/fold-string-to-char.c with 72% similarity]
gcc/testsuite/c-c++-common/analyzer/fopen-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/fread-1.c [moved from gcc/testsuite/gcc.dg/analyzer/fread-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/fread-2.c [moved from gcc/testsuite/gcc.dg/analyzer/fread-2.c with 91% similarity]
gcc/testsuite/c-c++-common/analyzer/fread-pr108661.c [moved from gcc/testsuite/gcc.dg/analyzer/fread-pr108661.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/function-ptr-1.c [moved from gcc/testsuite/gcc.dg/analyzer/function-ptr-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/function-ptr-2.c [moved from gcc/testsuite/gcc.dg/analyzer/function-ptr-2.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/function-ptr-3.c [moved from gcc/testsuite/gcc.dg/analyzer/function-ptr-3.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/function-ptr-4.c [moved from gcc/testsuite/gcc.dg/analyzer/function-ptr-4.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/getc-1.c [moved from gcc/testsuite/gcc.dg/analyzer/getc-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/getchar-1.c [moved from gcc/testsuite/gcc.dg/analyzer/getchar-1.c with 86% similarity]
gcc/testsuite/c-c++-common/analyzer/gzio-2.c [moved from gcc/testsuite/gcc.dg/analyzer/gzio-2.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/gzio-3.c [moved from gcc/testsuite/gcc.dg/analyzer/gzio-3.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/gzio-3a.c [moved from gcc/testsuite/gcc.dg/analyzer/gzio-3a.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/gzio.c [moved from gcc/testsuite/gcc.dg/analyzer/gzio.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/imprecise-floating-point-1.c [moved from gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c with 80% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-2.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-2.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-3.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-3.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-limited-buggy.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-limited-buggy.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-limited.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-limited.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-unlimited-buggy.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-unlimited-buggy.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-unlimited.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-unlimited.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-5.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-5.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-alloca.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-alloca.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-inlining.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-inlining.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-1.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-1.c with 56% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-2.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-2.c with 51% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-1.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-1a.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-1a.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-2.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-2.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion-variadic.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-variadic.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/infinite-recursion.c [moved from gcc/testsuite/gcc.dg/analyzer/infinite-recursion.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-1-multiline.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-1-multiline.c with 53% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-1-no-undo.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-1-no-undo.c with 60% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/inlining-2-multiline.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-2-multiline.c with 55% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/inlining-5-multiline.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-5-multiline.c with 54% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/inlining-6-multiline.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-6-multiline.c with 54% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-6.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-6.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-7-multiline.c [moved from gcc/testsuite/gcc.dg/analyzer/inlining-7-multiline.c with 52% similarity]
gcc/testsuite/c-c++-common/analyzer/inlining-7.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/invalid-shift-1.c [moved from gcc/testsuite/gcc.dg/analyzer/invalid-shift-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/isatty-1.c [moved from gcc/testsuite/gcc.dg/analyzer/isatty-1.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-2.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-2.c with 62% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-3.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-3.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/leak-4.c [moved from gcc/testsuite/gcc.dg/analyzer/leak-4.c with 61% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c with 97% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-2.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-2.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-2a.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-2a.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-3.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-3.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-4.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-4.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-n-down-to-1-by-1.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-1.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-step.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-start-to-end-by-step.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/loop-start-up-to-end-by-1.c [moved from gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/loop.c [moved from gcc/testsuite/gcc.dg/analyzer/loop.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-3.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-3.c with 80% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-5.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-5.c with 85% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-CWE-401-example.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-401-example.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-CWE-415-examples.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-415-examples.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-CWE-416-examples.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-416-examples.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-CWE-590-examples.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-590-examples.c with 92% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-callbacks.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c with 89% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-dce.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-dce.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-dedupe-1.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-dedupe-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-in-loop.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-in-loop.c with 89% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-1.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-1.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-11.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-11.c with 52% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-2.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-2.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-3.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-3.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-4.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-4.c with 85% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-5.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-5.c with 87% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-6.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-6.c with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-7.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-7.c with 76% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-unchecked.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c with 55% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-macro-inline-events.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c with 57% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-macro-separate-events.c [moved from gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-macro.h [moved from gcc/testsuite/gcc.dg/analyzer/malloc-macro.h with 100% similarity]
gcc/testsuite/c-c++-common/analyzer/malloc-paths-9-noexcept.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c [moved from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c with 86% similarity]
gcc/testsuite/c-c++-common/analyzer/out-of-bounds-1.c [moved from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-1.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/out-of-bounds-2.c [moved from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-2.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/out-of-bounds-5.c [moved from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c with 82% similarity]
gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-11.c [moved from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-11.c with 95% similarity]
gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-3.c [moved from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c with 91% similarity]
gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-8.c [moved from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-8.c with 89% similarity]
gcc/testsuite/c-c++-common/analyzer/phi-1.c [moved from gcc/testsuite/gcc.dg/analyzer/phi-1.c with 88% similarity]
gcc/testsuite/c-c++-common/analyzer/pr100615.c [moved from gcc/testsuite/gcc.dg/analyzer/pr100615.c with 96% similarity]
gcc/testsuite/c-c++-common/analyzer/pr103526.c [moved from gcc/testsuite/gcc.dg/analyzer/pr103526.c with 85% similarity]
gcc/testsuite/c-c++-common/analyzer/pr109577-noexcept.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-feasibility-noexcept.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/pr94362-1.c [moved from gcc/testsuite/gcc.dg/analyzer/pr94362-1.c with 83% similarity]
gcc/testsuite/c-c++-common/analyzer/pr97074.c [moved from gcc/testsuite/gcc.dg/analyzer/pr97074.c with 87% similarity]
gcc/testsuite/c-c++-common/analyzer/pr99193-1-noexcept.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/analyzer/pr99193-2.c
gcc/testsuite/c-c++-common/analyzer/realloc-1.c
gcc/testsuite/c-c++-common/analyzer/scope-1.c [moved from gcc/testsuite/gcc.dg/analyzer/scope-1.c with 90% similarity]
gcc/testsuite/c-c++-common/analyzer/setjmp-2.c [moved from gcc/testsuite/gcc.dg/analyzer/setjmp-2.c with 55% similarity]
gcc/testsuite/c-c++-common/analyzer/setjmp-5.c [moved from gcc/testsuite/gcc.dg/analyzer/setjmp-5.c with 52% similarity]
gcc/testsuite/c-c++-common/analyzer/setjmp-9.c [moved from gcc/testsuite/gcc.dg/analyzer/setjmp-9.c with 55% similarity]
gcc/testsuite/c-c++-common/analyzer/signal-4a.c [moved from gcc/testsuite/gcc.dg/analyzer/signal-4a.c with 53% similarity]
gcc/testsuite/c-c++-common/analyzer/signal-4b.c [moved from gcc/testsuite/gcc.dg/analyzer/signal-4b.c with 52% similarity]
gcc/testsuite/gcc.dg/analyzer/compound-assignment-1.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/file-pr58237.c
gcc/testsuite/gcc.dg/analyzer/fopen-1.c
gcc/testsuite/gcc.dg/analyzer/inlining-1.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/inlining-2.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/inlining-5.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/inlining-7.c [deleted file]
gcc/testsuite/gcc.dg/analyzer/malloc-4.c
gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c
gcc/testsuite/gcc.dg/analyzer/pr103892.c
gcc/testsuite/gcc.dg/analyzer/pr109577.c
gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility.c
gcc/testsuite/gcc.dg/analyzer/pr99193-1.c

index a351e5cd214b7d650cadcaeb3fd0f64e1ea6a621..da1ec7c41b9e4437e10fc6df2cc19d5d560b0d4b 100644 (file)
@@ -4458,6 +4458,10 @@ region_model::add_constraints_from_binop (const svalue *outer_lhs,
 
     case EQ_EXPR:
     case NE_EXPR:
+    case GE_EXPR:
+    case GT_EXPR:
+    case LE_EXPR:
+    case LT_EXPR:
       {
        /* ...and "(inner_lhs OP inner_rhs) == 0"
           then (inner_lhs OP inner_rhs) must have the same
similarity index 73%
rename from gcc/testsuite/gcc.dg/analyzer/allocation-size-1.c
rename to gcc/testsuite/c-c++-common/analyzer/allocation-size-1.c
index 003914ed96cd15729e807cddf98ba75b5c0d4756..05efc4f8028afcb235adae03d7b83e1d81223df3 100644 (file)
@@ -6,18 +6,19 @@
 
 void test_1 (void)
 {
-  int16_t *ptr = malloc (21 * sizeof (int16_t));
+  int16_t *ptr = (int16_t *) malloc (21 * sizeof (int16_t));
   free (ptr);
 }
 
 void test_2 (void)
 {
-  int32_t *ptr = malloc (21 * sizeof (int16_t)); /* { dg-line malloc2 } */
+  int32_t *ptr = (int32_t *) malloc (21 * sizeof (int16_t)); /* { dg-line malloc2 } */
   free (ptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc2 } */
   /* { dg-message "42 bytes" "note" { target *-*-* } malloc2 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } malloc2 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } malloc2 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } malloc2 } */
 }
 
 void test_3 (void)
@@ -34,7 +35,8 @@ void test_4 (void)
   free (iptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } assign4 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } assign4 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } assign4 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } assign4 } */
 }
 
 void test_5 (void)
@@ -67,7 +69,8 @@ void test_6 (void)
   free (iptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } assign6 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } assign6 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } assign6 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } assign6 } */
 }
 
 void test_7 (void)
@@ -94,7 +97,7 @@ void *create_buffer (int32_t n)
 
 void test_8 (void) 
 {
-  int32_t *buf = create_buffer(4 * sizeof (int));
+  int32_t *buf = (int32_t *) create_buffer(4 * sizeof (int));
   free (buf);
 }
 
@@ -106,22 +109,23 @@ void test_9 (void)
      impl_region_model_context::warn. To ensure that the indentation
      in the diagnostic is right, the warning has to be emitted on an EN
      that is after the return edge.  */
-  int32_t *buf = create_buffer(42); /* { dg-warning "" "" { xfail *-*-* } } */
+  int32_t *buf = (int32_t *) create_buffer(42); /* { dg-warning "" "" { xfail *-*-* } } */
   free (buf);
 }
 
 void test_10 (int32_t n)
 {
-  char *ptr = malloc (7 * n);
+  char *ptr = (char *) malloc (7 * n);
   free (ptr);
 }
 
 void test_11 ()
 {
   /* 3.0 is folded to an int before the analyzer runs.  */
-  int32_t *ptr = malloc (3.0); /* { dg-line malloc11 } */
+  int32_t *ptr = (int32_t *) malloc (3.0); /* { dg-line malloc11 } */
   free (ptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc11 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } malloc11 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } malloc11 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } malloc11 } */
 }
similarity index 81%
rename from gcc/testsuite/gcc.dg/analyzer/allocation-size-2.c
rename to gcc/testsuite/c-c++-common/analyzer/allocation-size-2.c
index eb770f73d4a48923957576b5122da08c7074bed2..ff4cb563469554a39f1ba55c5f0c686819cb95f8 100644 (file)
@@ -9,18 +9,19 @@
 
 void test_1 (int32_t n)
 {
-  int16_t *ptr = malloc (n * sizeof (int16_t));
+  int16_t *ptr = (int16_t *)malloc (n * sizeof (int16_t));
   free (ptr);
 }
 
 void test_2 (int32_t n)
 {
-  int32_t *ptr = malloc (n * sizeof (int16_t)); /* { dg-line malloc2 } */
+  int32_t *ptr = (int32_t *)malloc (n * sizeof (int16_t)); /* { dg-line malloc2 } */
   free (ptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc2 } */
   /* { dg-message "'\[a-z0-9\\*\\(\\)\\s\]*' bytes" "note" { target *-*-* } malloc2 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4" "note" { target *-*-* } malloc2 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4" "note" { target c } malloc2 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4" "note" { target c++ } malloc2 } */
 }
 
 void test_3 (int32_t n)
@@ -37,7 +38,8 @@ void test_4 (int32_t n)
   free (iptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } assign4 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } assign4 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } assign4 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } assign4 } */
 }
 
 void test_5 (void)
@@ -78,7 +80,7 @@ void *create_buffer(int32_t n)
 
 void test_7(int32_t n)
 {
-  int32_t *buf = create_buffer(n * sizeof (int32_t));
+  int32_t *buf = (int32_t *)create_buffer(n * sizeof (int32_t));
   free (buf);
 }
 
@@ -90,7 +92,7 @@ void test_8(int32_t n)
      impl_region_model_context::warn. To ensure that the indentation
      in the diagnostic is right, the warning has to be emitted on an EN
      that is after the return edge.  */
-  int32_t *buf = create_buffer(n * sizeof(int16_t)); /* { dg-warning "" "" { xfail *-*-* } } */
+  int32_t *buf = (int32_t *)create_buffer(n * sizeof(int16_t)); /* { dg-warning "" "" { xfail *-*-* } } */
   free (buf);
 }
 
@@ -136,7 +138,8 @@ void test_12 (void)
   else
     free (ptr);
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } assign12 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } assign12 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } assign12 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } assign12 } */
 }
 
 void test_13 (void)
@@ -162,6 +165,6 @@ int *test_14 (size_t n)
   /* n is an initial_svalue and guarded such that there is no equiv_class
      for n itself but only for a binop_svalue containing n.  */
   if (n % sizeof (int) == 0)
-    ptr = malloc (n);
+    ptr = (int *)malloc (n);
   return ptr;
 }
similarity index 66%
rename from gcc/testsuite/gcc.dg/analyzer/allocation-size-3.c
rename to gcc/testsuite/c-c++-common/analyzer/allocation-size-3.c
index 6751441dd18f7ee764ef8fe09df5bb6a454d206e..4e99e881dff7d236fc819d5d51f0980ddbd3d4ff 100644 (file)
@@ -21,31 +21,34 @@ void test_1 (void)
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc1 } */
   /* { dg-message "3 bytes" "note" { target *-*-* } malloc1 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } malloc1 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } malloc1 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } malloc1 } */
 }
 
 void test_2 (void)
 {
-  int32_t *ptr = malloc (10 + sizeof(int32_t)); /* { dg-line malloc2 } */
+  int32_t *ptr = (int32_t *) malloc (10 + sizeof(int32_t)); /* { dg-line malloc2 } */
   free (ptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc2 } */
   /* { dg-message "14 bytes" "note" { target *-*-* } malloc2 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } malloc2 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } malloc2 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } malloc2 } */
 }
 
 void test_3 (int32_t n)
 {
-  int32_t *ptr = malloc (n + sizeof (int32_t)); /* { dg-line malloc3 } */
+  int32_t *ptr = (int32_t *) malloc (n + sizeof (int32_t)); /* { dg-line malloc3 } */
   free (ptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc3 } */
   /* { dg-message "'\[a-z0-9\\+\\(\\)\\s\]*' bytes" "note" { target *-*-* } malloc3 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } malloc3 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } malloc3 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } malloc3 } */
 }
 
 void test_4 (int32_t n, int32_t m)
 {
-  int32_t *ptr = malloc ((n + m) * sizeof (int32_t));
+  int32_t *ptr = (int32_t *) malloc ((n + m) * sizeof (int32_t));
   free (ptr);
 }
similarity index 64%
rename from gcc/testsuite/gcc.dg/analyzer/allocation-size-4.c
rename to gcc/testsuite/c-c++-common/analyzer/allocation-size-4.c
index a56b25b4374d7dec8817f68812ae91649756fd80..7d07ba67316cf46ee962a0eab5027fdb585f2eae 100644 (file)
@@ -20,31 +20,32 @@ struct var_len {
 
 void test_1 (void)
 {
-  struct base *ptr = malloc (5 * sizeof (struct base));
+  struct base *ptr = (struct base *) malloc (5 * sizeof (struct base));
   free (ptr);
 }
 
 void test_2 (void)
 {
-  int32_t *ptr = malloc (5 * sizeof (struct base));  /* { dg-line malloc2 } */
+  int32_t *ptr = (int32_t *) malloc (5 * sizeof (struct base));  /* { dg-line malloc2 } */
   free (ptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc2 } */
   /* { dg-message "\\d+ bytes" "note" { target *-*-* } malloc2 } */
-  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target *-*-* } malloc2 } */
+  /* { dg-message "'int32_t \\*' (\\\{aka '(long )?int \\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c } malloc2 } */
+  /* { dg-message "'int32_t\\*' (\\\{aka '(long )?int\\*'\\\})? here; 'sizeof \\(int32_t (\\\{aka (long )?int\\\})?\\)' is '4'" "note" { target c++ } malloc2 } */
 }
 
 void test_3 (void)
 {
   /* Even though 10 bytes is not a multiple of 4, we do not warn to prevent
      a false positive in case s is the base struct of a struct inheritance.  */
-  struct base *ptr = malloc (10);
+  struct base *ptr = (struct base *) malloc (10);
   free (ptr);
 }
 
 void test_4 (void)
 {
-  struct var_len *ptr = malloc (10);
+  struct var_len *ptr = (struct var_len *) malloc (10);
   free (ptr);
 }
 
@@ -52,10 +53,11 @@ void test_5 (void)
 {
   /* For constant sizes, we warn if the buffer
      is too small to hold a single struct.  */
-  struct base *ptr = malloc (1);  /* { dg-line malloc5 } */
+  struct base *ptr = (struct base *) malloc (1);  /* { dg-line malloc5 } */
   free (ptr);
 
   /* { dg-warning "allocated buffer size is not a multiple of the pointee's size \\\[CWE-131\\\]" "warning" { target *-*-* } malloc5 } */
   /* { dg-message "allocated 1 byte here" "note" { target *-*-* } malloc5 } */
-  /* { dg-message "'struct base \\*' here; 'sizeof \\(struct base\\)' is '\\d+'" "note" { target *-*-* } malloc5 } */
+  /* { dg-message "'struct base \\*' here; 'sizeof \\(struct base\\)' is '\\d+'" "note" { target c } malloc5 } */
+  /* { dg-message "'base\\*' here; 'sizeof \\(base\\)' is '\\d+'" "note" { target c++ } malloc5 } */
 }
similarity index 53%
rename from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c
rename to gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-0.c
index f21cd37782415b5e21306adc2101e2631db8e07e..24fe84deb14f871473b7527e08091563e1031703 100644 (file)
@@ -58,7 +58,46 @@ void test_1 (void *ptr, int a, int b)
            |      |   |
            |      |   (5) second 'free' here; first 'free' was at (2)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_1(void*, int, int)': event 1
+    |
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~^~~~~
+    |      |                  |
+    |      |                  (1) calling 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': event 2
+           |
+           |   NN |   free (ptr);
+           |      |   ~~~~~^~~~~
+           |      |        |
+           |      |        (2) first 'free' here
+           |
+    <------+
+    |
+  'void test_1(void*, int, int)': events 3-4
+    |
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~^~~~~
+    |      |                  |
+    |      |                  (3) returning to 'test_1' from 'calls_free_1'
+    |......
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~~~~~~
+    |      |                  |
+    |      |                  (4) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': event 5
+           |
+           |   NN |   free (ptr);
+           |      |   ~~~~~^~~~~
+           |      |        |
+           |      |        (5) second 'free' here; first 'free' was at (2)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 void calls_free_2 (void *ptr)
 {
@@ -128,7 +167,46 @@ void test_2 (void *ptr, int a, int b)
            |      |   |
            |      |   (5) second 'free' here; first 'free' was at (2)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_2(void*, int, int)': event 1
+    |
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~^~~~~
+    |      |                    |
+    |      |                    (1) calling 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': event 2
+           |
+           |   NN |   free (ptr);
+           |      |   ~~~~~^~~~~
+           |      |        |
+           |      |        (2) first 'free' here
+           |
+    <------+
+    |
+  'void test_2(void*, int, int)': events 3-4
+    |
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~^~~~~
+    |      |                    |
+    |      |                    (3) returning to 'test_2' from 'calls_free_2'
+    |......
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~~~~~~
+    |      |                    |
+    |      |                    (4) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': event 5
+           |
+           |   NN |   free (ptr);
+           |      |   ~~~~~^~~~~
+           |      |        |
+           |      |        (5) second 'free' here; first 'free' was at (2)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 // TODO: range cases
 
@@ -160,4 +238,20 @@ void test_3 (void *ptr)
     |      |   |
     |      |   (2) second 'free' here; first 'free' was at (1)
     |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_3(void*)': events 1-2
+    |
+    |   NN |   free (ptr);
+    |      |   ~~~~~^~~~~
+    |      |        |
+    |      |        (1) first 'free' here
+    |   NN |   called_by_test_3 ();
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~
+    |      |        |
+    |      |        (2) second 'free' here; first 'free' was at (1)
+    |
+  { dg-end-multiline-output "" { target c++ } } */
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c
rename to gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-1.c
index 6d6e70a8ae11f2e13fcebee7796896915acfc447..e13437052584ff4d5bf4fa7463bcf6b5c256dbfa 100644 (file)
@@ -73,7 +73,61 @@ void test_1 (void *ptr, int a, int b)
            |      |   |
            |      |   (8) second 'free' here; first 'free' was at (4)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_1(void*, int, int)': events 1-2
+    |
+    |   NN | void test_1 (void *ptr, int a, int b)
+    |      |      ^~~~~~
+    |      |      |
+    |      |      (1) entry to 'test_1'
+    |......
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~~~~~~
+    |      |                  |
+    |      |                  (2) calling 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': events 3-4
+           |
+           |   NN | void calls_free_1 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (3) entry to 'calls_free_1'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (4) first 'free' here
+           |
+    <------+
+    |
+  'void test_1(void*, int, int)': events 5-6
+    |
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~^~~~~
+    |      |                  |
+    |      |                  (5) returning to 'test_1' from 'calls_free_1'
+    |......
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~~~~~~
+    |      |                  |
+    |      |                  (6) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': events 7-8
+           |
+           |   NN | void calls_free_1 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (7) entry to 'calls_free_1'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (8) second 'free' here; first 'free' was at (4)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 void calls_free_2 (void *ptr)
 {
@@ -158,7 +212,61 @@ void test_2 (void *ptr, int a, int b)
            |      |   |
            |      |   (8) second 'free' here; first 'free' was at (4)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_2(void*, int, int)': events 1-2
+    |
+    |   NN | void test_2 (void *ptr, int a, int b)
+    |      |      ^~~~~~
+    |      |      |
+    |      |      (1) entry to 'test_2'
+    |......
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~~~~~~
+    |      |                    |
+    |      |                    (2) calling 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': events 3-4
+           |
+           |   NN | void calls_free_2 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (3) entry to 'calls_free_2'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (4) first 'free' here
+           |
+    <------+
+    |
+  'void test_2(void*, int, int)': events 5-6
+    |
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~^~~~~
+    |      |                    |
+    |      |                    (5) returning to 'test_2' from 'calls_free_2'
+    |......
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~~~~~~
+    |      |                    |
+    |      |                    (6) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': events 7-8
+           |
+           |   NN | void calls_free_2 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (7) entry to 'calls_free_2'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (8) second 'free' here; first 'free' was at (4)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 /* The call/return to this function shouldn't appear in the path.  */
 
@@ -188,4 +296,20 @@ void test_3 (void *ptr)
     |      |   |
     |      |   (2) second 'free' here; first 'free' was at (1)
     |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_3(void*)': events 1-2
+    |
+    |   NN |   free (ptr);
+    |      |   ~~~~~^~~~~
+    |      |        |
+    |      |        (1) first 'free' here
+    |   NN |   called_by_test_3 ();
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~
+    |      |        |
+    |      |        (2) second 'free' here; first 'free' was at (1)
+    |
+  { dg-end-multiline-output "" { target c++ } } */
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c
rename to gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-2.c
index 3d3316af1f9a4123b8d3c29e45ccb5e432951186..0fd865485df9832dac95cfb34ac0baddb7af06fe 100644 (file)
@@ -84,7 +84,72 @@ void test_1 (void *ptr, int a, int b)
            |      |   |
            |      |   (12) second 'free' here; first 'free' was at (6)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_1(void*, int, int)': events 1-4
+    |
+    |   NN | void test_1 (void *ptr, int a, int b)
+    |      |      ^~~~~~
+    |      |      |
+    |      |      (1) entry to 'test_1'
+    |   NN | {
+    |   NN |   if (a)
+    |      |   ~~  
+    |      |   |
+    |      |   (2) following 'true' branch (when 'a != 0')...
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~~~~~~
+    |      |                  |
+    |      |                  (3) ...to here
+    |      |                  (4) calling 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': events 5-6
+           |
+           |   NN | void calls_free_1 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (5) entry to 'calls_free_1'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (6) first 'free' here
+           |
+    <------+
+    |
+  'void test_1(void*, int, int)': events 7-10
+    |
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~^~~~~
+    |      |                  |
+    |      |                  (7) returning to 'test_1' from 'calls_free_1'
+    |   NN | 
+    |   NN |   if (b)
+    |      |   ~~              
+    |      |   |
+    |      |   (8) following 'false' branch (when 'b == 0')...
+    |......
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~~~~~~
+    |      |                  |
+    |      |                  (9) ...to here
+    |      |                  (10) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': events 11-12
+           |
+           |   NN | void calls_free_1 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (11) entry to 'calls_free_1'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (12) second 'free' here; first 'free' was at (6)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 void calls_free_2 (void *ptr)
 {
@@ -187,7 +252,79 @@ void test_2 (void *ptr, int a, int b)
            |      |   |
            |      |   (12) second 'free' here; first 'free' was at (6)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_2(void*, int, int)': events 1-4
+    |
+    |   NN | void test_2 (void *ptr, int a, int b)
+    |      |      ^~~~~~
+    |      |      |
+    |      |      (1) entry to 'test_2'
+    |   NN | {
+    |   NN |   switch (a)
+    |      |   ~~~~~~
+    |      |   |
+    |      |   (2) following 'case 3:' branch...
+    |......
+    |   NN |     case 3:
+    |      |     ~~~~
+    |      |     |
+    |      |     (3) ...to here
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~~~~~~
+    |      |                    |
+    |      |                    (4) calling 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': events 5-6
+           |
+           |   NN | void calls_free_2 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (5) entry to 'calls_free_2'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (6) first 'free' here
+           |
+    <------+
+    |
+  'void test_2(void*, int, int)': events 7-10
+    |
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~^~~~~
+    |      |                    |
+    |      |                    (7) returning to 'test_2' from 'calls_free_2'
+    |......
+    |   NN |   switch (b)
+    |      |   ~~~~~~            
+    |      |   |
+    |      |   (8) following 'default:' branch...
+    |   NN |     {
+    |   NN |     default:
+    |      |     ~~~~~~~         
+    |      |     |
+    |      |     (9) ...to here
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~~~~~~
+    |      |                    |
+    |      |                    (10) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': events 11-12
+           |
+           |   NN | void calls_free_2 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (11) entry to 'calls_free_2'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (12) second 'free' here; first 'free' was at (6)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 // TODO: range cases
 
@@ -219,4 +356,20 @@ void test_3 (void *ptr)
     |      |   |
     |      |   (2) second 'free' here; first 'free' was at (1)
     |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_3(void*)': events 1-2
+    |
+    |   NN |   free (ptr);
+    |      |   ~~~~~^~~~~
+    |      |        |
+    |      |        (1) first 'free' here
+    |   NN |   called_by_test_3 ();
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~
+    |      |        |
+    |      |        (2) second 'free' here; first 'free' was at (1)
+    |
+  { dg-end-multiline-output "" { target c++ } } */
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-3.c
rename to gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-3.c
index fb87d16f8334ef7b20462ff8072efc62618ec18d..ac699ec544e158e41286147c3f8ea7f929023872 100644 (file)
@@ -84,7 +84,72 @@ void test_1 (void *ptr, int a, int b)
            |      |   |
            |      |   (12) second 'free' here; first 'free' was at (6)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_1(void*, int, int)': events 1-4
+    |
+    |   NN | void test_1 (void *ptr, int a, int b)
+    |      |      ^~~~~~
+    |      |      |
+    |      |      (1) entry to 'test_1'
+    |   NN | {
+    |   NN |   if (a)
+    |      |   ~~  
+    |      |   |
+    |      |   (2) following 'true' branch (when 'a != 0')...
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~~~~~~
+    |      |                  |
+    |      |                  (3) ...to here
+    |      |                  (4) calling 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': events 5-6
+           |
+           |   NN | void calls_free_1 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (5) entry to 'calls_free_1'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (6) first 'free' here
+           |
+    <------+
+    |
+  'void test_1(void*, int, int)': events 7-10
+    |
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~^~~~~
+    |      |                  |
+    |      |                  (7) returning to 'test_1' from 'calls_free_1'
+    |   NN | 
+    |   NN |   if (b)
+    |      |   ~~              
+    |      |   |
+    |      |   (8) following 'false' branch (when 'b == 0')...
+    |......
+    |   NN |     calls_free_1 (ptr);
+    |      |     ~~~~~~~~~~~~~~~~~~
+    |      |                  |
+    |      |                  (9) ...to here
+    |      |                  (10) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
+    |
+    +--> 'void calls_free_1(void*)': events 11-12
+           |
+           |   NN | void calls_free_1 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (11) entry to 'calls_free_1'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (12) second 'free' here; first 'free' was at (6)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 void calls_free_2 (void *ptr)
 {
@@ -187,7 +252,79 @@ void test_2 (void *ptr, int a, int b)
            |      |   |
            |      |   (12) second 'free' here; first 'free' was at (6)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_2(void*, int, int)': events 1-4
+    |
+    |   NN | void test_2 (void *ptr, int a, int b)
+    |      |      ^~~~~~
+    |      |      |
+    |      |      (1) entry to 'test_2'
+    |   NN | {
+    |   NN |   switch (a)
+    |      |   ~~~~~~
+    |      |   |
+    |      |   (2) following 'case 3:' branch...
+    |......
+    |   NN |     case 3:
+    |      |     ~~~~
+    |      |     |
+    |      |     (3) ...to here
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~~~~~~
+    |      |                    |
+    |      |                    (4) calling 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': events 5-6
+           |
+           |   NN | void calls_free_2 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (5) entry to 'calls_free_2'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (6) first 'free' here
+           |
+    <------+
+    |
+  'void test_2(void*, int, int)': events 7-10
+    |
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~^~~~~
+    |      |                    |
+    |      |                    (7) returning to 'test_2' from 'calls_free_2'
+    |......
+    |   NN |   switch (b)
+    |      |   ~~~~~~            
+    |      |   |
+    |      |   (8) following 'default:' branch...
+    |   NN |     {
+    |   NN |     default:
+    |      |     ~~~~~~~         
+    |      |     |
+    |      |     (9) ...to here
+    |   NN |       calls_free_2 (ptr);
+    |      |       ~~~~~~~~~~~~~~~~~~
+    |      |                    |
+    |      |                    (10) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
+    |
+    +--> 'void calls_free_2(void*)': events 11-12
+           |
+           |   NN | void calls_free_2 (void *ptr)
+           |      |      ^~~~~~~~~~~~
+           |      |      |
+           |      |      (11) entry to 'calls_free_2'
+           |   NN | {
+           |   NN |   free (ptr);
+           |      |   ~~~~~~~~~~
+           |      |        |
+           |      |        (12) second 'free' here; first 'free' was at (6)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
 
 // TODO: range cases
 
@@ -219,4 +356,20 @@ void test_3 (void *ptr)
     |      |   |
     |      |   (2) second 'free' here; first 'free' was at (1)
     |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_3(void*)': events 1-2
+    |
+    |   NN |   free (ptr);
+    |      |   ~~~~~^~~~~
+    |      |        |
+    |      |        (1) first 'free' here
+    |   NN |   called_by_test_3 ();
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~
+    |      |        |
+    |      |        (2) second 'free' here; first 'free' was at (1)
+    |
+  { dg-end-multiline-output "" { target c++ } } */
similarity index 82%
rename from gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-1.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-1.c
index eb3c6955e1162b15797c0d69f7063db109c9c4db..650d3f55b3f746181baaf5767b9ce2dea3858dc3 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef __SIZE_TYPE__ size_t;
 
@@ -7,7 +7,7 @@ extern void* (*my_alloc_2)(size_t, size_t) __attribute__ ((alloc_size (1, 2)));
 
 int test_one_arg_concrete_int_ptr (void)
 {
-  int *x = my_alloc (1); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+  int *x = (int *) my_alloc (1); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
   __analyzer_dump_capacity (x); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)1'" } */
   x[0] = 0; /* { dg-warning "buffer overflow" } */
   return 0;
@@ -15,7 +15,7 @@ int test_one_arg_concrete_int_ptr (void)
 
 void test_one_arg_concrete (void)
 {
-  char *p = my_alloc (10);
+  char *p = (char *) my_alloc (10);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)10'" } */
   p[0] = 'a';
   p[9] = 'b';
@@ -25,13 +25,13 @@ void test_one_arg_concrete (void)
 
 void test_one_arg_symbolic (size_t sz)
 {
-  char *p = my_alloc (sz);
+  char *p = (char *) my_alloc (sz);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(sz" } */
 }
 
 void test_two_args_concrete (void)
 {
-  char *p = my_alloc_2 (2, 5);
+  char *p = (char *) my_alloc_2 (2, 5);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)10'" } */
   p[0] = 'a';
   p[9] = 'b';
@@ -41,19 +41,19 @@ void test_two_args_concrete (void)
 
 void test_two_args_symbolic_first (size_t sz)
 {
-  char *p = my_alloc_2 (sz, 5);
+  char *p = (char *) my_alloc_2 (sz, 5);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(INIT_VAL\\(sz\[^\n\r\]*\\*\\(size_t\\)5\\)'" } */
 }
 
 void test_two_args_symbolic_second (size_t sz)
 {
-  char *p = my_alloc_2 (5, sz);
+  char *p = (char *) my_alloc_2 (5, sz);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(INIT_VAL\\(sz\[^\n\r\]*\\*\\(size_t\\)5\\)'" } */
 }
 
 void test_two_args_symbolic_both (size_t a, size_t b)
 {
-  char *p = my_alloc_2 (a, b);
+  char *p = (char *) my_alloc_2 (a, b);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(INIT_VAL\\(a\[^\n\r\]*\\*INIT_VAL\\(b" } */
 }
 
@@ -62,7 +62,7 @@ typedef void* (*my_alloc_2_t)(size_t, size_t) __attribute__ ((alloc_size (1, 2))
 
 void test_one_arg_concrete_fnptr (my_alloc_t fnptr)
 {
-  char *p = fnptr (10);
+  char *p = (char *) fnptr (10);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)10'" } */
   p[0] = 'a';
   p[9] = 'b';
@@ -72,7 +72,7 @@ void test_one_arg_concrete_fnptr (my_alloc_t fnptr)
 
 void test_two_args_concrete_fnptr (my_alloc_2_t fnptr)
 {
-  char *p = fnptr (2, 5);
+  char *p = (char *) fnptr (2, 5);
   __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)10'" } */
   p[0] = 'a';
   p[9] = 'b';
similarity index 88%
rename from gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-2.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-2.c
index 7b787f959dcbbda754e48637322afb300ed52986..47f0ba44d0055845baf0daca1449d66fa702cb4c 100644 (file)
@@ -6,7 +6,7 @@ void *xirealloc (void *p, idx_t s)
 char *
 test_cast_1 (char *buf, idx_t buf_count)
 {
-  return xirealloc (buf, buf_count + 1);
+  return (char *) xirealloc (buf, buf_count + 1);
 }
 
 void *alloc_cast_2 (signed char x, signed char y)
similarity index 79%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-malloc.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-malloc.c
index 87173a08d064c025ced7765d8d829cb4250a4697..15c4c2e8fccc35b55282c9e49e59c84b6d07c797 100644 (file)
@@ -6,11 +6,11 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 int *malloc_int (int i)
 {
-  int *res = malloc (sizeof (int));
+  int *res = (int *) malloc (sizeof (int));
   if (!res)
     return NULL;
   *res = i;
@@ -34,7 +34,8 @@ void test_malloc_int (int x)
 
 void test_leak (int x)
 {
-  int *p = malloc_int (x); /* { dg-message "when 'malloc_int' returns pointer to heap-allocated buffer" } */
+  int *p = malloc_int (x); /* { dg-message "when 'malloc_int' returns pointer to heap-allocated buffer" "" { target c } } */
+  /* { dg-message "when 'int\\* malloc_int\\(int\\)' returns pointer to heap-allocated buffer" "" { target c++ } .-1 } */
 } /* { dg-message "leak of 'p'" } */
 
 void *wrapped_malloc (size_t sz)
@@ -64,14 +65,14 @@ void test_use_after_free (void)
 
 void test_use_without_check (size_t sz)
 {
-  char *buf = wrapped_malloc (sz); /* { dg-message "this call could return NULL" } */
+  char *buf = (char *) wrapped_malloc (sz); /* { dg-message "this call could return NULL" } */
   memset (buf, 'x', sz); /* { dg-warning "use of possibly-NULL 'buf' where non-null expected" } */
   wrapped_free (buf);
 }
 
 void test_out_of_bounds (size_t sz)
 {
-  char *buf = wrapped_malloc (sz);
+  char *buf = (char *) wrapped_malloc (sz);
   if (!buf)
     return;
   memset (buf, 'x', sz);
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158-2.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-pr107158-2.c
index c2e9e2ba9f2674c4eff3716944f6ecf2283b2f80..4561e10cafd03100353d2d7450867e0d6d38bfef 100644 (file)
@@ -1,4 +1,9 @@
 /* { dg-additional-options "-fanalyzer-call-summaries -Wno-analyzer-too-complex" } */
+/* { dg-skip-if "c++98 has no noreturn attribute" { c++98_only } } */
+
+#ifdef __cplusplus
+#define _Noreturn [[noreturn]]
+#endif
 
 typedef __SIZE_TYPE__ size_t;
 typedef struct _IO_FILE FILE;
@@ -36,7 +41,7 @@ _Noreturn static 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);
@@ -48,7 +53,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 94%
rename from gcc/testsuite/gcc.dg/analyzer/capacity-1.c
rename to gcc/testsuite/c-c++-common/analyzer/capacity-1.c
index 2d12483329664264f0968ba91cb067c493d83bc4..ae31cedfe47a3c0704a95d18c2cadf609a0e08c9 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-require-effective-target alloca } */
 
 #include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef unsigned __INT32_TYPE__ u32;
 
@@ -89,7 +89,7 @@ struct s
 static struct s * __attribute__((noinline))
 alloc_s (size_t num)
 {
-  struct s *p = malloc (sizeof(struct s) + num);
+  struct s *p = (struct s *) malloc (sizeof(struct s) + num);
   return p;
 }
 
diff --git a/gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c b/gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c
new file mode 100644 (file)
index 0000000..0ab006d
--- /dev/null
@@ -0,0 +1,72 @@
+#include <stdlib.h>
+
+struct ptr_wrapper
+{
+  int *ptr;
+};
+
+struct ptr_wrapper
+test_1 (void)
+{
+  struct ptr_wrapper r;
+  r.ptr = (int *) malloc (sizeof (int));
+  return r;
+}
+
+struct ptr_wrapper
+test_2 (void)
+{
+  struct ptr_wrapper r, s;
+  r.ptr = (int *) malloc (sizeof (int));
+  s = r;
+  return s;
+}
+
+struct nested
+{
+  struct ptr_wrapper w;
+};
+
+struct nested
+test_3 (void)
+{
+  struct nested n;
+  n.w.ptr = (int *) malloc (sizeof (int));
+  return n;
+}
+
+void test_4 (void)
+{
+  struct ptr_wrapper r;
+  r.ptr = (int *) malloc (sizeof (int)); /* { dg-message "allocated here" } */
+} /* { dg-warning "leak of 'r.ptr'" "" { target c } } */
+/* { dg-warning "leak of 'r.ptr_wrapper::ptr'" "" { target c++ } .-1 } */
+/* { dg-bogus "leak of '<unknown>'" "unknown leak" { target *-*-* } .-1 } */
+
+static struct ptr_wrapper __attribute__((noinline))
+called_by_test_5a (void)
+{
+  struct ptr_wrapper r;
+  r.ptr = (int *) malloc (sizeof (int)); /* { dg-message "allocated here" } */
+  return r;
+}
+
+void test_5a (void)
+{
+  struct ptr_wrapper q = called_by_test_5a ();  
+} /* { dg-warning "leak of 'q.ptr'" "" { target c } } */
+/* { dg-warning "leak of 'q.ptr_wrapper::ptr'" "" { target c++ } .-1 } */
+
+static struct ptr_wrapper __attribute__((noinline))
+called_by_test_5b (void)
+{
+  struct ptr_wrapper r;
+  r.ptr = (int *) malloc (sizeof (int));
+  return r; /* { dg-warning "leak of '<return-value>.ptr'" "" { target c } } */
+  /* TODO: show the allocation point; improve above messages. C++ does show it.  */
+}
+
+void test_5b (void)
+{
+  called_by_test_5b ();
+} /* { dg-warning "leak of '<anonymous>.ptr_wrapper::ptr'" "" { target c++ } } */
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/dot-output.c
rename to gcc/testsuite/c-c++-common/analyzer/dot-output.c
index 03405cdf4a0963ee2ad9130eb647995df144a776..b1badd7e49d335ba36bdff0d014511b50669eab9 100644 (file)
@@ -14,7 +14,7 @@ int some_call (int i, char ch)
 int *test (int *buf, int n, int *out)
 {
   int i;
-  int *result = malloc (sizeof (int) * n);
+  int *result = (int *) malloc (sizeof (int) * n);
   
   /* A loop, to ensure we have phi nodes.  */
   for (i = 0; i < n; i++)
similarity index 60%
rename from gcc/testsuite/gcc.dg/analyzer/escaping-1.c
rename to gcc/testsuite/c-c++-common/analyzer/escaping-1.c
index 2dfd02b9ede5f6cb7385758dfa7465759caa6371..b3896564ef87e6183771170e4a0751f53d61f5c4 100644 (file)
@@ -1,6 +1,4 @@
-#include "analyzer-decls.h"
-
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern void unknown_fn (void *);
 
@@ -15,13 +13,16 @@ static void test_1 (void)
   __analyzer_dump_escaped (); /* { dg-warning "escaped: 0: " } */
 
   unknown_fn (&local_1);
-  __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" } */
+  __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" "" { target c } } */
+  /* { dg-warning "escaped: 1: 'int local_1'" "" { target c++ } .-1 } */
 
   /* Should be idempotent.  */
   unknown_fn (&local_1);
-  __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" } */
+  __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" "" { target c } } */
+  /* { dg-warning "escaped: 1: 'int local_1'" "" { target c++ } .-1 } */
 
   /* Escape a static global.  */
   unknown_fn (&only_used_by_test_1);
-  __analyzer_dump_escaped (); /* { dg-warning "escaped: 2: 'local_1', 'only_used_by_test_1'" } */
+  __analyzer_dump_escaped (); /* { dg-warning "escaped: 2: 'local_1', 'only_used_by_test_1'" "" { target c } } */
+  /* { dg-warning "escaped: 2: 'int local_1', 'int only_used_by_test_1'" "" { target c++ } .-1 } */
 }
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/expect-1.c
rename to gcc/testsuite/c-c++-common/analyzer/expect-1.c
index e538f77741dff860ecbd1e93d2c4d8e4d901a6b5..c2f72b4ba710d97053963fd9b28fd4a455cba57f 100644 (file)
@@ -1,4 +1,4 @@
-#define NULL ((void*)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void *test_1 (void)
 {
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/fgets-1.c
rename to gcc/testsuite/c-c++-common/analyzer/fgets-1.c
index e93d24c9de805217a44e87ac24eed92e5d5213e4..e67bb18a491907aaaa53b9ee036a46b8cab49e54 100644 (file)
@@ -1,6 +1,6 @@
 /* { dg-do "compile" } */
 
-#define NULL ((void *) 0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef struct _IO_FILE FILE;
 
 extern char *fgets(char *__restrict __s, int __n,
diff --git a/gcc/testsuite/c-c++-common/analyzer/file-pr58237-noexcept.c b/gcc/testsuite/c-c++-common/analyzer/file-pr58237-noexcept.c
new file mode 100644 (file)
index 0000000..cdbbe00
--- /dev/null
@@ -0,0 +1,82 @@
+/* { dg-additional-options "-fno-exceptions" } */
+typedef struct FILE   FILE;
+
+FILE* fopen (const char*, const char*);
+int   fclose (FILE*);
+char *fgets (char *, int, FILE *);
+
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+void f0(const char *str)
+{
+  FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */
+  // ideally warning should be located at the end of the function
+  char buf[10];
+  fgets(buf, 10, fp);
+} /* { dg-warning "leak of FILE 'fp'" } */
+
+void f1(const char *str)
+{
+  FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */
+  // ideally warning should be located at the end of the function
+  char buf[10];
+
+  while (fgets(buf, 10, fp) != NULL)
+    {
+      /* Do something with buf */
+    }
+} /* { dg-warning "leak of FILE 'fp'" } */
+
+void f2(const char *str, int flag)
+{
+  FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */
+  // ideally warning should be located at the end of the function
+  char buf[10];
+
+  while (fgets(buf, 10, fp) != NULL)
+    {
+      /* Do something with buf */
+    }
+  if (flag) /* { dg-message "when 'flag == 0'" } */
+    fclose(fp);
+} /* { dg-warning "leak of FILE 'fp'" } */
+
+extern void called_by_f3( FILE * fp);
+
+void f3(const char *str)
+{
+  FILE * fp = fopen(str, "r");
+  char buf[10];
+
+  while (fgets(buf, 10, fp) != NULL)
+    {
+      /* Do something with buf */
+    }
+  /* Not sure if fclose executed by called_by_f3 or not. Say nothing */
+  called_by_f3(fp);
+}
+
+void f4(const char *str)
+{
+  FILE * fp = fopen(str, "r");
+  char buf[10];
+
+  while (fgets(buf, 10, fp) != NULL)
+    {
+      /* Do something with buf */
+    }
+  /* Nothing to say here. */
+  fclose(fp);
+}
+
+int main(int argc, const char * argv[])
+{
+  FILE * fp = fopen(argv[0], "r");
+  char buf[10];
+
+  while (fgets(buf, 10, fp) != NULL)
+    {
+      /* Do something with buf */
+    }
+  /* Nothing to say here, because we are in main. */
+}
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/first-field-1.c
rename to gcc/testsuite/c-c++-common/analyzer/first-field-1.c
index 8b71e1abcae81c2e510ff2865e099c563c8af54a..c11707d9aa62b1d67c592a3962b39ceb8718f18d 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef struct base_obj
 {
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/first-field-2.c
rename to gcc/testsuite/c-c++-common/analyzer/first-field-2.c
index 2fb98d3c9d728bddf2f7cf5546c7730fbde8c00f..8661e6e9efd0367a1eaee1e73c5459b2a87ca388 100644 (file)
@@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef struct base_obj base_obj;
 typedef struct string_obj string_obj;
similarity index 99%
rename from gcc/testsuite/gcc.dg/analyzer/flex-without-call-summaries.c
rename to gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c
index 5b4a9868c2f29bea9ea17d6ad42aa5d900ca23aa..5369f7685c286d69e89adcf41d005f6fd4f48195 100644 (file)
@@ -878,7 +878,8 @@ static int yy_get_next_buffer (void)
                                else
                                        b->yy_buf_size *= 2;
 
-                               b->yy_ch_buf = (char *)  /* { dg-warning "leak of '\\*b.yy_ch_buf'" } */
+                               b->yy_ch_buf = (char *)  /* { dg-warning "leak of '\\*b.yy_ch_buf'" "" { target c } } */
+                                                        /* { dg-warning "leak of '\\*b.yy_buffer_state::yy_ch_buf'" "" { target c++ } .-1 } */
                                        /* Include room in for 2 EOB chars. */
                                        yyrealloc( (void *) b->yy_ch_buf,
                                                         (yy_size_t) (b->yy_buf_size + 2)  );
similarity index 70%
rename from gcc/testsuite/gcc.dg/analyzer/flexible-array-member-1.c
rename to gcc/testsuite/c-c++-common/analyzer/flexible-array-member-1.c
index 2df085a43f2331f452718b9d9b1d7a4c04237bcc..82dbcec535925fdbd2065ed8361d7a1e9faea83a 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <string.h>
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct str {
   size_t len;
@@ -9,7 +10,7 @@ struct str {
 struct str *
 test_const_size (void)
 {
-  struct str *str = malloc(sizeof(str) + 10);
+  struct str *str = (struct str *) malloc(sizeof(str) + 10);
   if (str) {
     str->len = 10;
     memset(str->data, 'x', 10);
@@ -22,11 +23,12 @@ struct str *
 test_const_size_oob_1 (void)
 {
   /* Forgetting to add space for the trailing array.  */
-  struct str *str = malloc(sizeof(str));
+  struct str *str = (struct str *) malloc(sizeof(str));
   if (str) {
     str->len = 10;
     memset(str->data, 'x', 10); /* { dg-warning "heap-based buffer overflow" "Wanalyzer-out-of-bounds" } */
-    /* { dg-warning "'memset' writing 10 bytes into a region of size 0 overflows the destination" "Wstringop-overflow" { target *-*-* } .-1 } */
+    /* { dg-warning "'memset' writing 10 bytes into a region of size 0 overflows the destination" "Wstringop-overflow" { target c } .-1 } */
+    /* { dg-warning "'void\\* memset\\(void\\*, int, size_t\\)' writing 10 bytes into a region of size 0 overflows the destination" "Wstringop-overflow" { target c++ } .-2 } */
     return str;
   }
   return NULL;
@@ -35,12 +37,14 @@ test_const_size_oob_1 (void)
 struct str *
 test_const_size_oob_2 (void)
 {
-  struct str *str = malloc(sizeof(str) + 10);
+  struct str *str = (struct str *) malloc(sizeof(str) + 10);
   if (str) {
     str->len = 10;
     /* Using the wrong size here.  */
     memset(str->data, 'x', 11); /* { dg-warning "heap-based buffer overflow" "Wanalyzer-out-of-bounds" } */
-    /* { dg-warning "'memset' writing 11 bytes into a region of size 10 overflows the destination" "Wstringop-overflow" { target *-*-* } .-1 } */
+    /* { dg-warning "'memset' writing 11 bytes into a region of size 10 overflows the destination" "Wstringop-overflow" { target c } .-1 } */
+    /* { dg-warning "'void\\* memset\\(void\\*, int, size_t\\)' writing 11 bytes into a region of size 10 overflows the destination" "Wstringop-overflow" { target c++ } .-2 } */
+
     return str;
   }
   return NULL;
@@ -49,7 +53,7 @@ test_const_size_oob_2 (void)
 struct str *
 test_symbolic_size (size_t len)
 {
-  struct str *str = malloc(sizeof(str) + len);
+  struct str *str = (struct str *) malloc(sizeof(str) + len);
   if (str) {
     str->len = len;
     memset(str->data, 'x', len);
@@ -62,7 +66,7 @@ struct str *
 test_symbolic_size_oob (size_t len)
 {
   /* Forgetting to add space for the trailing array.  */
-  struct str *str = malloc(sizeof(str));
+  struct str *str = (struct str *) malloc(sizeof(str));
   if (str) {
     str->len = len;
     memset(str->data, 'x', len); /* { dg-warning "heap-based buffer overflow" "PR analyzer/98247" { xfail *-*-* } } */
@@ -75,7 +79,7 @@ test_symbolic_size_oob (size_t len)
 struct str *
 test_symbolic_size_with_terminator (size_t len)
 {
-  struct str *str = malloc(sizeof(str) + len + 1);
+  struct str *str = (struct str *) malloc(sizeof(str) + len + 1);
   if (str) {
     str->len = len;
     memset(str->data, 'x', len);
@@ -89,7 +93,7 @@ struct str *
 test_symbolic_size_with_terminator_oob (size_t len)
 {
   /* Forgetting to add 1 for the terminator.  */
-  struct str *str = malloc(sizeof(str) + len);
+  struct str *str = (struct str *) malloc(sizeof(str) + len);
   if (str) {
     str->len = len;
     memset(str->data, 'x', len);
similarity index 72%
rename from gcc/testsuite/gcc.dg/analyzer/fold-string-to-char.c
rename to gcc/testsuite/c-c++-common/analyzer/fold-string-to-char.c
index 46139216bbac36f2a922deb57943194b89c6f33d..4eb08c072902bc8bd465190de830cebc1cb602af 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test_1 (void)
 {
diff --git a/gcc/testsuite/c-c++-common/analyzer/fopen-2.c b/gcc/testsuite/c-c++-common/analyzer/fopen-2.c
new file mode 100644 (file)
index 0000000..82087f2
--- /dev/null
@@ -0,0 +1,52 @@
+typedef struct FILE FILE;
+FILE *fopen (const char *pathname, const char *mode);
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+FILE *
+test_passthrough (const char *pathname, const char *mode)
+{
+  return fopen (pathname, mode);
+}
+
+FILE *
+test_null_pathname (const char *pathname, const char *mode)
+{
+  return fopen (NULL, mode);
+}
+
+FILE *
+test_null_mode (const char *pathname)
+{
+  return fopen (pathname, NULL);
+}
+
+FILE *
+test_simple_r (void)
+{
+  return fopen ("foo.txt", "r");
+}
+
+FILE *
+test_swapped_args (void)
+{
+  return fopen ("r", "foo.txt"); /* TODO: would be nice to detect this.  */
+}
+
+FILE *
+test_uninitialized_pathname (const char *mode)
+{
+  char buf[10];
+  return fopen (buf, mode); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */  
+  /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of 'fopen'..." "event" { target c } .-1 } */
+  /* { dg-message "while looking for null terminator for argument 1 \\('& buf'\\) of 'FILE\\* fopen\\(const char\\*, const char\\*\\)'..." "event" { target c++ } .-2 } */
+}
+
+FILE *
+test_uninitialized_mode (const char *filename)
+{
+  char buf[10];
+  return fopen (filename, buf); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */  
+  /* { dg-message "while looking for null terminator for argument 2 \\('&buf'\\) of 'fopen'..." "event" { target c } .-1 } */
+  /* { dg-message "while looking for null terminator for argument 2 \\('& buf'\\) of 'FILE\\* fopen\\(const char\\*, const char\\*\\)'..." "event" { target c++ } .-2 } */
+}
+
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/fread-2.c
rename to gcc/testsuite/c-c++-common/analyzer/fread-2.c
index 02a5e31cec63dc1134ccd33040b3a990f79d4101..d74d0555d23e81dff8bcc2d7e5980ad9ef882f2f 100644 (file)
@@ -1,6 +1,6 @@
 /* { dg-additional-options "-fdump-analyzer-untracked" } */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct S
 {
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/function-ptr-2.c
rename to gcc/testsuite/c-c++-common/analyzer/function-ptr-2.c
index fd25e3be40bebd6c2ec8e85286353d4038e402d0..0a1e845d6c55f89ee3a0a532bdcd588ec1efdcea 100644 (file)
@@ -1,5 +1,5 @@
 #include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 typedef void (*fn_ptr_t) (void *);
 
similarity index 86%
rename from gcc/testsuite/gcc.dg/analyzer/getchar-1.c
rename to gcc/testsuite/c-c++-common/analyzer/getchar-1.c
index 0cc984bd2b3412a604252549810547e8508c41ed..157877dd4fb8f2c3225525c9322a8e5e980f26f5 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
 #include <stdio.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 int test_1 (void)
 {
similarity index 80%
rename from gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c
rename to gcc/testsuite/c-c++-common/analyzer/imprecise-floating-point-1.c
index 7fe09fb826b96f41d2dd3c2448636645ac22782a..cbe26589db0099a66d7492e651add65fdcc256f8 100644 (file)
@@ -10,7 +10,7 @@
 
 void test_1 (float f)
 {
-  int *ptr = malloc (sizeof (int) * f); /* { dg-line test_1 } */
+  int *ptr = (int *)malloc (sizeof (int) * f); /* { dg-line test_1 } */
   free (ptr);
 
   /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_1 } */
@@ -20,11 +20,11 @@ void test_1 (float f)
 
 void test_2 (int n)
 {
-  int *ptr = malloc (n * 3.1); /* { dg-line test_2 } */
+  int *ptr = (int *)malloc (n * 3.1); /* { dg-line test_2 } */
   free (ptr);
 
   /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_2 } */
-  /* { dg-message "operand '\(\\d|e|f|\\.|\\+|\)+' is of type 'double'" "note" { target *-*-* } test_2 } */
+  /* { dg-message "operand '\(\\d|e|f|l|\\.|\\+|\)+' is of type '\(long \)?double'" "note" { target *-*-* } test_2 } */
   /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_2 } */
 }
 
@@ -45,17 +45,17 @@ void test_3 (float f)
 
 void test_4 (int n)
 {
-  int *ptr = calloc(1.7 * n, sizeof (int)); /* { dg-line test_4 } */
+  int *ptr = (int *)calloc(1.7 * n, sizeof (int)); /* { dg-line test_4 } */
   free (ptr);
 
   /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_4 } */
-  /* { dg-message "operand '\(\\d|e|f|\\.|\\+|\)+' is of type 'double'" "note" { target *-*-* } test_4 } */
+  /* { dg-message "operand '\(\\d|e|f|l|\\.|\\+|\)+' is of type '\(long \)?double'" "note" { target *-*-* } test_4 } */
   /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_4 } */
 }
 
 int test_5 (float f)
 {
-  int *ptr = __builtin_alloca (sizeof (int) * f); /* { dg-line test_5 } */
+  int *ptr = (int *)__builtin_alloca (sizeof (int) * f); /* { dg-line test_5 } */
   *ptr = 4;
   return *ptr;
 
@@ -66,7 +66,7 @@ int test_5 (float f)
 
 int test_6 (float f)
 {
-  int *ptr = __builtin_alloca (1.7f * f * 2.3f); /* { dg-line test_6 } */
+  int *ptr = (int *)__builtin_alloca (1.7f * f * 2.3f); /* { dg-line test_6 } */
   *ptr = 4;
   return *ptr;
 
similarity index 56%
rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-1.c
rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-1.c
index e236dd48712dbbf61949cccaa4c82c32fb5ed8d8..21f38946678eebe7d79dac59498f8c1dd5c0ec4a 100644 (file)
@@ -38,4 +38,33 @@ void foo (int flag)
            |      (5) recursive entry to 'foo'; previously entered at (1)
            |      (6) apparently infinite recursion
            |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+     foo (flag);
+     ~~~~^~~~~~
+  'void foo(int)': events 1-4 (depth 1)
+    |
+    | void foo (int flag)
+    |      ^~~
+    |      |
+    |      (1) initial entry to 'foo'
+    |
+    |   if (flag)
+    |   ~~  
+    |   |
+    |   (2) following 'true' branch (when 'flag != 0')...
+    |     foo (flag);
+    |     ~~~~~~~~~~
+    |         |
+    |         (3) ...to here
+    |         (4) calling 'foo' from 'foo'
+    |
+    +--> 'void foo(int)': events 5-6 (depth 2)
+           |
+           | void foo (int flag)
+           |      ^~~
+           |      |
+           |      (5) recursive entry to 'foo'; previously entered at (1)
+           |      (6) apparently infinite recursion
+           |
+   { dg-end-multiline-output "" { target c++ } } */
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-2.c
rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-2.c
index 2c69dd508f0df59a23f4441b995105b78e122672..be4fb6cfd689d81dfe5a5b2fb4a5060f68ad2c51 100644 (file)
@@ -52,7 +52,43 @@ void mutual_2 (void)
                   |      (5) recursive entry to 'mutual_2'; previously entered at (1)
                   |      (6) apparently infinite chain of mutually-recursive function calls, consuming 2 stack frames per recursion
                   |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   mutual_2 ();
+   ~~~~~~~~~^~
+  'void mutual_2()': events 1-2 (depth 1)
+    |
+    | void mutual_2 (void)
+    |      ^~~~~~~~
+    |      |
+    |      (1) initial entry to 'mutual_2'
+    |
+    |   mutual_1 ();
+    |   ~~~~~~~~~~~
+    |            |
+    |            (2) calling 'mutual_1' from 'mutual_2'
+    |
+    +--> 'void mutual_1()': events 3-4 (depth 2)
+           |
+           | void mutual_1 (void)
+           |      ^~~~~~~~
+           |      |
+           |      (3) entry to 'mutual_1'
+           |
+           |   mutual_2 ();
+           |   ~~~~~~~~~~~
+           |            |
+           |            (4) calling 'mutual_2' from 'mutual_1'
+           |
+           +--> 'void mutual_2()': events 5-6 (depth 3)
+                  |
+                  | void mutual_2 (void)
+                  |      ^~~~~~~~
+                  |      |
+                  |      (5) recursive entry to 'mutual_2'; previously entered at (1)
+                  |      (6) apparently infinite chain of mutually-recursive function calls, consuming 2 stack frames per recursion
+                  |
+   { dg-end-multiline-output "" { target c++ } } */
 
 
 /* { dg-begin-multiline-output "" }
@@ -90,4 +126,40 @@ void mutual_2 (void)
                   |      (5) recursive entry to 'mutual_1'; previously entered at (1)
                   |      (6) apparently infinite chain of mutually-recursive function calls, consuming 2 stack frames per recursion
                   |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   mutual_1 ();
+   ~~~~~~~~~^~
+  'void mutual_1()': events 1-2 (depth 1)
+    |
+    | void mutual_1 (void)
+    |      ^~~~~~~~
+    |      |
+    |      (1) initial entry to 'mutual_1'
+    |
+    |   mutual_2 ();
+    |   ~~~~~~~~~~~
+    |            |
+    |            (2) calling 'mutual_2' from 'mutual_1'
+    |
+    +--> 'void mutual_2()': events 3-4 (depth 2)
+           |
+           | void mutual_2 (void)
+           |      ^~~~~~~~
+           |      |
+           |      (3) entry to 'mutual_2'
+           |
+           |   mutual_1 ();
+           |   ~~~~~~~~~~~
+           |            |
+           |            (4) calling 'mutual_1' from 'mutual_2'
+           |
+           +--> 'void mutual_1()': events 5-6 (depth 3)
+                  |
+                  | void mutual_1 (void)
+                  |      ^~~~~~~~
+                  |      |
+                  |      (5) recursive entry to 'mutual_1'; previously entered at (1)
+                  |      (6) apparently infinite chain of mutually-recursive function calls, consuming 2 stack frames per recursion
+                  |
+   { dg-end-multiline-output "" { target c++ } } */
similarity index 53%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-1-multiline.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-1-multiline.c
index 79621f10e9be2cd8a17f541023d846bd40ff42b1..cda5a7d38b98d3e28b7a71c9e43a5f1ff7f6335f 100644 (file)
@@ -53,4 +53,43 @@ void bar (void *q)
            |   |
            |   (5) second 'free' here; first 'free' was at (3)
            |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   __builtin_free (p);
+   ~~~~~~~~~~~~~~~^~~
+  'void bar(void*)': events 1-2 (depth 1)
+    |
+    | void bar (void *q)
+    |      ^~~
+    |      |
+    |      (1) entry to 'bar'
+    |
+    |   foo (q);
+    |       ~
+    |       |
+    |       (2) inlined call to 'foo' from 'bar'
+    |
+    +--> 'void foo(void*)': event 3 (depth 2)
+           |
+           |   __builtin_free (p);
+           |   ~~~~~~~~~~~~~~~^~~
+           |                  |
+           |                  (3) first 'free' here
+           |
+    <------+
+    |
+  'void bar(void*)': event 4 (depth 1)
+    |
+    |   foo (q);
+    |       ^
+    |       |
+    |       (4) inlined call to 'foo' from 'bar'
+    |
+    +--> 'void foo(void*)': event 5 (depth 2)
+           |
+           |   __builtin_free (p);
+           |   ~~~~~~~~~~~~~~~^~~
+           |                  |
+           |                  (5) second 'free' here; first 'free' was at (3)
+           |
+   { dg-end-multiline-output "" { target c++ } } */
similarity index 60%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-1-no-undo.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-1-no-undo.c
index bad0f68fec05e1ab387031fb852a6b942bca98fd..d0d1b82d0427cc2b45321a866150ebab26f11b54 100644 (file)
@@ -7,8 +7,10 @@
 void foo (void *p)
 {
   __builtin_free (p); /* { dg-warning "double-'free' of 'q'" "warning" } */
-  /* { dg-message "\\(1\\) first 'free' here \\(fndecl 'bar', depth 1\\)" "1st free message" { target *-*-* } .-1 } */
-  /* { dg-message "\\(2\\) second 'free' here; first 'free' was at \\(1\\) \\(fndecl 'bar', depth 1\\)" "2nd free message" { target *-*-* } .-2 } */
+  /* { dg-message "\\(1\\) first 'free' here \\(fndecl 'bar', depth 1\\)" "1st free message" { target c } .-1 } */
+  /* { dg-message "\\(1\\) first 'free' here \\(fndecl 'void bar\\(void\\*\\)', depth 1\\)" "1st free message" { target c++ } .-2 } */
+  /* { dg-message "\\(2\\) second 'free' here; first 'free' was at \\(1\\) \\(fndecl 'bar', depth 1\\)" "2nd free message" { target c } .-3 } */
+  /* { dg-message "\\(2\\) second 'free' here; first 'free' was at \\(1\\) \\(fndecl 'void bar\\(void\\*\\)', depth 1\\)" "2nd free message" { target c++ } .-4 } */
 }
 
 void bar (void *q)
diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-1.c b/gcc/testsuite/c-c++-common/analyzer/inlining-1.c
new file mode 100644 (file)
index 0000000..ed33e78
--- /dev/null
@@ -0,0 +1,22 @@
+/* Verify that we can reconstruct fndecl and stack depth information
+   after early inlining.  */
+
+/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
+
+void foo (void *p)
+{
+  __builtin_free (p); /* { dg-warning "double-'free' of 'q'" "warning" } */
+  /* { dg-message "\\(3\\) first 'free' here \\(fndecl 'foo', depth 2\\)" "1st free message" { target c } .-1 } */
+  /* { dg-message "\\(3\\) first 'free' here \\(fndecl 'void foo\\(void\\*\\)', depth 2\\)" "1st free message" { target c++ } .-2 } */
+  /* { dg-message "\\(5\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl 'foo', depth 2\\)" "2nd free message" { target c } .-3 } */
+  /* { dg-message "\\(5\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl 'void foo\\(void\\*\\)', depth 2\\)" "2nd free message" { target c++ } .-4 } */
+}
+
+void bar (void *q) /* { dg-message "\\(1\\) entry to 'bar' \\(fndecl 'bar', depth 1\\)" "" { target c } } */
+/* { dg-message "\\(1\\) entry to 'bar' \\(fndecl 'void bar\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+{
+  foo (q); /* { dg-message "\\(2\\) inlined call to 'foo' from 'bar' \\(fndecl 'bar', depth 1\\)" "" { target c } } */
+  /* { dg-message "\\(2\\) inlined call to 'foo' from 'bar' \\(fndecl 'void bar\\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+  foo (q); /* { dg-message "\\(4\\) inlined call to 'foo' from 'bar' \\(fndecl 'bar', depth 1\\)" "" { target c } } */
+  /* { dg-message "\\(4\\) inlined call to 'foo' from 'bar' \\(fndecl 'void bar\\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+}
similarity index 55%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-2-multiline.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-2-multiline.c
index 0a006b3a58fe7bde81453f4599e9d492d0b472c6..7a259a8b9976190b7d01d36c78c367499035ee81 100644 (file)
@@ -43,4 +43,32 @@ void bar (void *q)
            |   |
            |   (4) second 'free' here; first 'free' was at (3)
            |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   __builtin_free (p);
+   ~~~~~~~~~~~~~~~^~~
+  'void bar(void*)': events 1-2 (depth 1)
+    |
+    | void bar (void *q)
+    |      ^~~
+    |      |
+    |      (1) entry to 'bar'
+    |
+    |   __analyzer_foo (q);
+    |                  ~
+    |                  |
+    |                  (2) inlined call to '__analyzer_foo' from 'bar'
+    |
+    +--> 'void __analyzer_foo(void*)': events 3-4 (depth 2)
+           |
+           |   __builtin_free (p);
+           |   ~~~~~~~~~~~~~~~^~~
+           |                  |
+           |                  (3) first 'free' here
+           |
+           |   __builtin_free (p);
+           |   ~~~~~~~~~~~~~~~~~~
+           |                  |
+           |                  (4) second 'free' here; first 'free' was at (3)
+           |
+   { dg-end-multiline-output "" { target c++ } } */
diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-2.c b/gcc/testsuite/c-c++-common/analyzer/inlining-2.c
new file mode 100644 (file)
index 0000000..1561bee
--- /dev/null
@@ -0,0 +1,21 @@
+/* Verify that we can reconstruct fndecl and stack depth information
+   after early inlining.  */
+
+/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
+
+static void __analyzer_foo (void *p)
+{
+  __builtin_free (p); /* { dg-message "\\(3\\) first 'free' here \\(fndecl '__analyzer_foo', depth 2\\)" "1st free message" { target c } } */
+  /* { dg-message "\\(3\\) first 'free' here \\(fndecl 'void __analyzer_foo\\(void\\*\\)', depth 2\\)" "1st free message" { target c++ } .-1 } */
+
+  __builtin_free (p); /* { dg-warning "double-'free' of 'q'" "warning" } */
+  /* { dg-message "\\(4\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl '__analyzer_foo', depth 2\\)" "2nd free message" { target c } .-1 } */
+  /* { dg-message "\\(4\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl 'void __analyzer_foo\\(void\\*\\)', depth 2\\)" "2nd free message" { target c++ } .-2 } */
+}
+
+void bar (void *q) /* { dg-message "\\(1\\) entry to 'bar' \\(fndecl 'bar', depth 1\\)" "" { target c } } */
+/* { dg-message "\\(1\\) entry to 'bar' \\(fndecl 'void bar\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+{
+  __analyzer_foo (q); /* { dg-message "\\(2\\) inlined call to '__analyzer_foo' from 'bar' \\(fndecl 'bar', depth 1\\)" "" { target c } } */
+  /* { dg-message "\\(2\\) inlined call to '__analyzer_foo' from 'bar' \\(fndecl 'void bar\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+}
similarity index 54%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-5-multiline.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-5-multiline.c
index 21b8fb978c89ad226b62eb823c4b4d1fc91a9a4b..8fefe380e9a2b19fa002404a562ff99603c3cf8f 100644 (file)
@@ -56,4 +56,38 @@ outer (void *r)
                   |   |
                   |   (5) second 'free' here; first 'free' was at (3)
                   |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   __builtin_free (p);
+   ~~~~~~~~~~~~~~~^~~
+  'void outer(void*)': events 1-2 (depth 1)
+    |
+    | outer (void *r)
+    | ^~~~~
+    | |
+    | (1) entry to 'outer'
+    |
+    |   middle (r);
+    |          ~
+    |          |
+    |          (2) inlined call to 'middle' from 'outer'
+    |
+    +--> 'void middle(void*)': events 3-4 (depth 2)
+           |
+           |   __builtin_free (q);
+           |   ~~~~~~~~~~~~~~~^~~
+           |                  |
+           |                  (3) first 'free' here
+           |   inner (q);
+           |         ~         
+           |         |
+           |         (4) inlined call to 'inner' from 'middle'
+           |
+           +--> 'void inner(void*)': event 5 (depth 3)
+                  |
+                  |   __builtin_free (p);
+                  |   ~~~~~~~~~~~~~~~^~~
+                  |                  |
+                  |                  (5) second 'free' here; first 'free' was at (3)
+                  |
+   { dg-end-multiline-output "" { target c++ } } */
diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-5.c b/gcc/testsuite/c-c++-common/analyzer/inlining-5.c
new file mode 100644 (file)
index 0000000..7b08c4b
--- /dev/null
@@ -0,0 +1,29 @@
+/* Verify that we can reconstruct fndecl and stack depth information
+   after early inlining.  */
+
+/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
+
+static inline void
+inner (void *p)
+{
+  __builtin_free (p); /* { dg-warning "double-'free' of 'r'" } */
+  /* { dg-message "\\(5\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl 'inner', depth 3\\)" "2nd free message" { target c } .-1 } */
+  /* { dg-message "\\(5\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl 'void inner\\(void\\*\\)', depth 3\\)" "2nd free message" { target c++ } .-2 } */
+}
+
+static inline void
+middle (void *q)
+{
+  __builtin_free (q); /* { dg-message "\\(3\\) first 'free' here \\(fndecl 'middle', depth 2\\)" "1st free message" { target c } } */
+  /* { dg-message "\\(3\\) first 'free' here \\(fndecl 'void middle\\(void\\*\\)', depth 2\\)" "1st free message" { target c++ } .-1 } */
+  inner (q); /* { dg-message "\\(4\\) inlined call to 'inner' from 'middle' \\(fndecl 'middle', depth 2\\)" "" { target c } } */
+  /* { dg-message "\\(4\\) inlined call to 'inner' from 'middle' \\(fndecl 'void middle\\(void\\*\\)', depth 2\\)" "" { target c++ } .-1 } */
+}
+
+void
+outer (void *r) /* { dg-message "\\(1\\) entry to 'outer' \\(fndecl 'outer', depth 1\\)" "" { target c } } */
+/* { dg-message "\\(1\\) entry to 'outer' \\(fndecl 'void outer\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+{
+  middle (r); /* { dg-message "\\(2\\) inlined call to 'middle' from 'outer' \\(fndecl 'outer', depth 1\\)" "" { target c } } */
+  /* { dg-message "\\(2\\) inlined call to 'middle' from 'outer' \\(fndecl 'void outer\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+}
similarity index 54%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-6-multiline.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-6-multiline.c
index 9cec6146f3721bb28ea24854a6e072be5c81d2e3..3fbf854cd926d5da9741d23fe8a3145d660ec3f6 100644 (file)
@@ -61,4 +61,43 @@ outer (void *r)
            |   |
            |   (5) second 'free' here; first 'free' was at (4)
            |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   __builtin_free (q);
+   ~~~~~~~~~~~~~~~^~~
+  'void outer(void*)': events 1-2 (depth 1)
+    |
+    | outer (void *r)
+    | ^~~~~
+    | |
+    | (1) entry to 'outer'
+    |
+    |   middle (r);
+    |          ~
+    |          |
+    |          (2) inlined call to 'middle' from 'outer'
+    |
+    +--> 'void middle(void*)': event 3 (depth 2)
+           |
+           |   inner (q);
+           |         ^
+           |         |
+           |         (3) inlined call to 'inner' from 'middle'
+           |
+           +--> 'void inner(void*)': event 4 (depth 3)
+                  |
+                  |   __builtin_free (p);
+                  |   ~~~~~~~~~~~~~~~^~~
+                  |                  |
+                  |                  (4) first 'free' here
+                  |
+           <------+
+           |
+         'void middle(void*)': event 5 (depth 2)
+           |
+           |   __builtin_free (q);
+           |   ~~~~~~~~~~~~~~~^~~
+           |                  |
+           |                  (5) second 'free' here; first 'free' was at (4)
+           |
+   { dg-end-multiline-output "" { target c++ } } */
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/inlining-7-multiline.c
rename to gcc/testsuite/c-c++-common/analyzer/inlining-7-multiline.c
index 956c6b90bb0715cba9a63b1e7d91a01ccb163218..78fe4d4a6bf4fa1fc5965c47bc250867592cb3c0 100644 (file)
@@ -125,4 +125,85 @@ depth_1 (void *p1)
                                        |   |
                                        |   (11) second 'free' here; first 'free' was at (7)
                                        |
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   __builtin_free (p);
+   ~~~~~~~~~~~~~~~^~~
+  'void depth_1(void*)': events 1-2 (depth 1)
+    |
+    | depth_1 (void *p1)
+    | ^~~~~~~
+    | |
+    | (1) entry to 'depth_1'
+    |
+    |   depth_2 (p1);
+    |           ~
+    |           |
+    |           (2) inlined call to 'depth_2' from 'depth_1'
+    |
+    +--> 'void depth_2(void*)': event 3 (depth 2)
+           |
+           |   depth_3 (p2);
+           |           ^
+           |           |
+           |           (3) inlined call to 'depth_3' from 'depth_2'
+           |
+           +--> 'void depth_3(void*)': event 4 (depth 3)
+                  |
+                  |   depth_4 (p3);
+                  |           ^
+                  |           |
+                  |           (4) inlined call to 'depth_4' from 'depth_3'
+                  |
+                  +--> 'void depth_4(void*)': event 5 (depth 4)
+                         |
+                         |   depth_5 (p4);
+                         |           ^
+                         |           |
+                         |           (5) inlined call to 'depth_5' from 'depth_4'
+                         |
+                         +--> 'void depth_5(void*)': event 6 (depth 5)
+                                |
+                                |   depth_6 (p5);
+                                |           ^
+                                |           |
+                                |           (6) inlined call to 'depth_6' from 'depth_5'
+                                |
+                                +--> 'void depth_6(void*)': event 7 (depth 6)
+                                       |
+                                       |   __builtin_free (p);
+                                       |   ~~~~~~~~~~~~~~~^~~
+                                       |                  |
+                                       |                  (7) first 'free' here
+                                       |
+                  <--------------------+
+                  |
+                'void depth_3(void*)': event 8 (depth 3)
+                  |
+                  |   depth_4 (p3);
+                  |           ^
+                  |           |
+                  |           (8) inlined call to 'depth_4' from 'depth_3'
+                  |
+                  +--> 'void depth_4(void*)': event 9 (depth 4)
+                         |
+                         |   depth_5 (p4);
+                         |           ^
+                         |           |
+                         |           (9) inlined call to 'depth_5' from 'depth_4'
+                         |
+                         +--> 'void depth_5(void*)': event 10 (depth 5)
+                                |
+                                |   depth_6 (p5);
+                                |           ^
+                                |           |
+                                |           (10) inlined call to 'depth_6' from 'depth_5'
+                                |
+                                +--> 'void depth_6(void*)': event 11 (depth 6)
+                                       |
+                                       |   __builtin_free (p);
+                                       |   ~~~~~~~~~~~~~~~^~~
+                                       |                  |
+                                       |                  (11) second 'free' here; first 'free' was at (7)
+                                       |
+   { dg-end-multiline-output "" { target c++ } } */
diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-7.c b/gcc/testsuite/c-c++-common/analyzer/inlining-7.c
new file mode 100644 (file)
index 0000000..960944f
--- /dev/null
@@ -0,0 +1,60 @@
+/* Verify that we can reconstruct fndecl and stack depth information
+   after early inlining.  */
+
+/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
+
+/* We want the reconstructed call/return hierarchy to show
+   that two calls happen at depth_3, without any spurious events
+   popping the stack back any further.  */
+
+static inline void
+depth_6 (void *p)
+{
+  __builtin_free (p); /* { dg-warning "double-'free' of 'p1'" "warning" } */
+ /* { dg-message "\\(7\\) first 'free' here \\(fndecl 'depth_6', depth 6\\)" "1st free message" { target c } .-1 } */
+ /* { dg-message "\\(7\\) first 'free' here \\(fndecl 'void depth_6\\(void\\*\\)', depth 6\\)" "1st free message" { target c++ } .-2 } */
+ /* { dg-message "\\(11\\) second 'free' here; first 'free' was at \\(7\\) \\(fndecl 'depth_6', depth 6\\)" "2nd free message" { target c } .-3 } */
+ /* { dg-message "\\(11\\) second 'free' here; first 'free' was at \\(7\\) \\(fndecl 'void depth_6\\(void\\*\\)', depth 6\\)" "2nd free message" { target c++ } .-4 } */
+}
+
+static inline void
+depth_5 (void *p5)
+{
+  depth_6 (p5); /* { dg-message "\\(6\\) inlined call to 'depth_6' from 'depth_5' \\(fndecl 'depth_5', depth 5\\)" "event 6" { target c } } */
+  /* { dg-message "\\(6\\) inlined call to 'depth_6' from 'depth_5' \\(fndecl 'void depth_5\\(void\\*\\)', depth 5\\)" "event 6" { target c++ } .-1 } */
+  /* { dg-message "\\(10\\) inlined call to 'depth_6' from 'depth_5' \\(fndecl 'depth_5', depth 5\\)" "event 10" { target c } .-2 } */
+  /* { dg-message "\\(10\\) inlined call to 'depth_6' from 'depth_5' \\(fndecl 'void depth_5\\(void\\*\\)', depth 5\\)" "event 10" { target c++ } .-3 } */
+}
+
+static inline void
+depth_4 (void *p4)
+{
+  depth_5 (p4); /* { dg-message "\\(5\\) inlined call to 'depth_5' from 'depth_4' \\(fndecl 'depth_4', depth 4\\)" "event 5" { target c } } */
+  /* { dg-message "\\(5\\) inlined call to 'depth_5' from 'depth_4' \\(fndecl 'void depth_4\\(void\\*\\)', depth 4\\)" "event 5" { target c++ } .-1 } */
+  /* { dg-message "\\(9\\) inlined call to 'depth_5' from 'depth_4' \\(fndecl 'depth_4', depth 4\\)" "event 9" { target c } .-2 } */
+  /* { dg-message "\\(9\\) inlined call to 'depth_5' from 'depth_4' \\(fndecl 'void depth_4\\(void\\*\\)', depth 4\\)" "event 9" { target c++ } .-3 } */
+}
+
+static inline void
+depth_3 (void *p3)
+{
+  depth_4 (p3); /* { dg-message "\\(4\\) inlined call to 'depth_4' from 'depth_3' \\(fndecl 'depth_3', depth 3\\)" "" { target c } } */
+  /* { dg-message "\\(4\\) inlined call to 'depth_4' from 'depth_3' \\(fndecl 'void depth_3\\(void\\*\\)', depth 3\\)" "" { target c++ } .-1 } */
+  depth_4 (p3); /* { dg-message "\\(8\\) inlined call to 'depth_4' from 'depth_3' \\(fndecl 'depth_3', depth 3\\)" "" { target c } } */
+  /* { dg-message "\\(8\\) inlined call to 'depth_4' from 'depth_3' \\(fndecl 'void depth_3\\(void\\*\\)', depth 3\\)" "" { target c++ } .-1 } */
+}
+
+static inline void
+depth_2 (void *p2)
+{
+  depth_3 (p2); /* { dg-message "\\(3\\) inlined call to 'depth_3' from 'depth_2' \\(fndecl 'depth_2', depth 2\\)" "" { target c } } */
+  /* { dg-message "\\(3\\) inlined call to 'depth_3' from 'depth_2' \\(fndecl 'void depth_2\\(void\\*\\)', depth 2\\)" "" { target c++ } .-1 } */
+}
+
+void
+depth_1 (void *p1) /* { dg-message "\\(1\\) entry to 'depth_1' \\(fndecl 'depth_1', depth 1\\)" "" { target c } } */
+/* { dg-message "\\(1\\) entry to 'depth_1' \\(fndecl 'void depth_1\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+{
+  depth_2 (p1); /* { dg-message "\\(2\\) inlined call to 'depth_2' from 'depth_1' \\(fndecl 'depth_1', depth 1\\)" "" { target c } } */
+  /* { dg-message "\\(2\\) inlined call to 'depth_2' from 'depth_1' \\(fndecl 'void depth_1\\(void\\*\\)', depth 1\\)" "" { target c++ } .-1 } */
+}
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/isatty-1.c
rename to gcc/testsuite/c-c++-common/analyzer/isatty-1.c
index 3bb12c0db25b708e0763d584d6b20717371a955a..c5d376da498f4793906651a4ac15b51f03c13716 100644 (file)
@@ -2,7 +2,7 @@
 /* { dg-skip-if "" { "avr-*-*" } } */
 
 #include <errno.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern int isatty(int fd);
 extern int close(int fd);
similarity index 62%
rename from gcc/testsuite/gcc.dg/analyzer/leak-2.c
rename to gcc/testsuite/c-c++-common/analyzer/leak-2.c
index bba3e816db76bfd3c3fa6c3db2730e7a9c15e180..d12850cdc6a547dca8806cbbedaa1b955da472d5 100644 (file)
@@ -1,8 +1,9 @@
 #include <stdlib.h>
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void *ptr;
 
-void *test (void)
+void test (void)
 {
   ptr = malloc (1024);
   ptr = NULL; /* { dg-warning "leak of 'ptr'" } */
similarity index 61%
rename from gcc/testsuite/gcc.dg/analyzer/leak-4.c
rename to gcc/testsuite/c-c++-common/analyzer/leak-4.c
index 75090e6be83b19002b5b913ff3657a7ca800572b..ba5f2d26f4b40a825350e98dd70db9539e4d2fee 100644 (file)
@@ -11,7 +11,7 @@ struct s1
 
 void test_1 (void)
 {
-  struct s1 *a = malloc (sizeof (struct s1));
+  struct s1 *a = (struct s1 *) malloc (sizeof (struct s1));
   if (!a)
     return;
   a->ptr = malloc (1024); /* { dg-message "allocated here" } */
@@ -32,25 +32,30 @@ void test_2a (void)
 {
   struct s2 arr[5];
   arr[3].m_arr[4] = malloc (1024); /* { dg-message "allocated here" } */
-} /* { dg-warning "leak of 'arr\\\[3\\\].m_arr\\\[4\\\]'" } */
+} /* { dg-warning "leak of 'arr\\\[3\\\].m_arr\\\[4\\\]'" "" { target c } } */
+/* { dg-warning "leak of 'arr\\\[3\\\].s2::m_arr\\\[4\\\]'" "" { target c++ } .-1 } */
 
 void test_2b (int i)
 {
   struct s2 arr[5];
   arr[3].m_arr[i] = malloc (1024); /* { dg-message "allocated here" } */
-} /* { dg-warning "leak of 'arr\\\[3\\\].m_arr\\\[i\\\]'" } */
+} /* { dg-warning "leak of 'arr\\\[3\\\].m_arr\\\[i\\\]'" "" { target c } } */
+/* { dg-warning "leak of 'arr\\\[3\\\].s2::m_arr\\\[i\\\]'" "" { target c++ } .-1 } */
 
 void test_2c (int i)
 {
   struct s2 arr[5];
   arr[i].m_arr[4] = malloc (1024); /* { dg-message "allocated here" } */
-} /* { dg-warning "leak of 'arr\\\[i\\\].m_arr\\\[4\\\]'" } */
+} /* { dg-warning "leak of 'arr\\\[i\\\].m_arr\\\[4\\\]'" "" { target c } } */
+/* { dg-warning "leak of 'arr\\\[i\\\].s2::m_arr\\\[4\\\]'" "" { target c++ } .-1 } */
+
 
 void test_2d (int i, int j)
 {
   struct s2 arr[5];
   arr[i].m_arr[j] = malloc (1024); /* { dg-message "allocated here" } */
-} /* { dg-warning "leak of 'arr\\\[i\\\].m_arr\\\[j\\\]'" } */
+} /* { dg-warning "leak of 'arr\\\[i\\\].m_arr\\\[j\\\]'" "" { target c } } */
+/* { dg-warning "leak of 'arr\\\[i\\\].s2::m_arr\\\[j\\\]'" "" { target c++ } .-1 } */
 
 
 /* Example involving fields.  */
@@ -63,9 +68,10 @@ struct s3
 
 void test_3 (void)
 {
-  struct s3 *a = malloc (sizeof (struct s3));
-  a->m_right = malloc (sizeof (struct s3)); /* { dg-warning "dereference of possibly-NULL 'a'" } */
-  a->m_right->m_left = malloc (sizeof (struct s3)); /* { dg-warning "dereference of possibly-NULL '\\*a.m_right'" } */
+  struct s3 *a = (struct s3 *) malloc (sizeof (struct s3));
+  a->m_right = (struct s3 *) malloc (sizeof (struct s3)); /* { dg-warning "dereference of possibly-NULL 'a'" } */
+  a->m_right->m_left = (struct s3 *) malloc (sizeof (struct s3)); /* { dg-warning "dereference of possibly-NULL '\\*a.m_right'" "" { target c } } */
+  /* { dg-warning "dereference of possibly-NULL '\\*a.s3::m_right'" "" { target c++ } .-1 } */
 } /* { dg-warning "leak of 'a'" "leak of a" } */
 /* { dg-warning "leak of '<unknown>'" "leak of unknown" { target *-*-* } .-1 } */
 /* TODO: rather than '<unknown>', we should print 'a->m_right'
@@ -87,7 +93,7 @@ struct s4_sub
 static struct s4_sub *
 make_s4_sub (void)
 {
-  struct s4_sub *sub = malloc (sizeof (struct s4_sub)); /* { dg-message "allocated here" } */
+  struct s4_sub *sub = (struct s4_sub *) malloc (sizeof (struct s4_sub)); /* { dg-message "allocated here" } */
   if (!sub)
     return NULL;
   sub->m_buffer = malloc (1024); /* { dg-message "allocated here" } */
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c
index 0172c9b324c7c4a31d45f5aa71bb488f8e734d01..1b657697ef407b6d4c12f00ae520cd4d8c14217b 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdlib.h>
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct iter
 {
@@ -45,7 +45,7 @@ void test(int n)
   struct iter *it = iter_new (0, n, 1);
   while (!iter_done_p (it))
     {
-      __analyzer_eval (it->val < n); /* { dg-warning "TRUE" "true" { xfail *-*-* } } */
+      __analyzer_eval (it->val < n); /* { dg-warning "TRUE" "true" } */
       /* { dg-bogus "UNKNOWN" "unknown" { xfail *-*-* } .-1 } */
       /* TODO(xfail^^^): ideally we ought to figure out i > 0 after 1st iteration.  */
 
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1.c
index d49ed130488801bfc00b6dee1d3310eaf507c670..92ce3dc6a5d283bbaf11a7a44bb71e759f781f07 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(int n)
 {
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/loop-2.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-2.c
index f106722c247417ff03bac6c4ade5c2e9e6c9d572..274d5080a51e3352d6fb602f755e88922dea1531 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-additional-options "-fno-analyzer-state-purge" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 struct s
 {
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/loop-2a.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-2a.c
index 16b64497cb7d33657beaeca8b027b3e420416897..212acf42dc7a1ef6c9f3142a9c3c72db403abd7e 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-additional-options "-fno-analyzer-state-purge" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 union u
 {
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/loop-4.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-4.c
index b66a3459437679125b728c15ce294391324b8947..dd3104eeb2a7597c1eaeb326b8e505b58422dfb0 100644 (file)
@@ -1,6 +1,6 @@
 /* Example of nested loops.  */
 
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(void)
 {
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-n-down-to-1-by-1.c
index 553cd2f15dc40746a7e488530865b2227810d640..1ab8abec8937720e42e432175f02ebae9eae6246 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(int n)
 {
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-1.c
index 3513bf423474a2290beac6c170eb3b3a6fe29ed5..092cc97190678ce13f1add91959f8a395780a53f 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(int start, int end, int step)
 {
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-step.c
index 2692c503b5c94b9277364224d2fe680eb96aeebe..f929f7ac60f97c024f22778463ff7e9697b7cf9b 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(int start, int end, int step)
 {
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-start-to-end-by-step.c
index 3fc1362d1cf9a5927343ebc64c2852ecc7ebc79f..71d9619db0c08e9723c80d4ea4738b9464e3242e 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(int start, int end, int step)
 {
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c
rename to gcc/testsuite/c-c++-common/analyzer/loop-start-up-to-end-by-1.c
index 5e21890bfea108775ec801d829c4ecc000a7f10b..629f592d453b0bebda722c370858d14cec65d4ed 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(int start, int end)
 {
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/loop.c
rename to gcc/testsuite/c-c++-common/analyzer/loop.c
index c4cfd88c9122bec02d7f76b2fd666d9a4704b331..33ac96c06e2945dcc5a0dbea9d24dc3a883fd1c4 100644 (file)
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void test(void)
 {
similarity index 80%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-3.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-3.c
index 5afb6b3b0f7b62210365f830b9d40ab618978fb2..f4e647b25aa2cef0596bcef63fe1c1300b3fdf6a 100644 (file)
@@ -2,7 +2,8 @@
 
 /* Don't complain about leaks due to exiting from "main".  */
 
-void main (void)
+int main (void)
 {
   void *p = malloc (1024);
+  return 0;
 }
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-5.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-5.c
index b75135f26a3fcbed04271a7f7a0119ccc2fe71a4..3b2a4527ab58773e8c84301f4f26e69666b94221 100644 (file)
@@ -5,7 +5,7 @@ void test (void)
   void *p = malloc (sizeof (int));
   if (!p)
     return;
-  int *q = p;
+  int *q = (int *) p;
   if (!q)
     return;
   free (q);
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-590-examples.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-CWE-590-examples.c
index 9434f2df75f06bca38310bab248be203ce2c6831..11ab017c12aeaf486af1221e7773d68c1ce4c1d1 100644 (file)
@@ -33,7 +33,8 @@ void foo_1(){
   /* do something interesting with bar */
 
   /* ... */
-  free(bar); /* { dg-warning "'free' of '&bar' which points to memory on the stack" } */
+  free(bar); /* { dg-warning "'free' of '&bar' which points to memory on the stack" "" { target c } } */
+  /* { dg-warning "'free' of '& bar' which points to memory on the stack" "" { target c++ } .-1 } */
 }
 
 record_t bar[MAX_SIZE]; //Global var
@@ -41,5 +42,6 @@ void foo_2(){
 
   /* do something interesting with bar */
   /* ... */
-  free(bar); /* { dg-warning "'free' of '&bar' which points to memory not on the heap" } */
+  free(bar); /* { dg-warning "'free' of '&bar' which points to memory not on the heap" "" { target c } } */
+  /* { dg-warning "'free' of '& bar' which points to memory not on the heap" "" { target c++ } .-1 } */
 }
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-callbacks.c
index cf3927fcaeaf475bd2621237045f84bae3bafbc4..ccd6c01194f3012ffa89b886c4f90f15bfad8dea 100644 (file)
@@ -54,16 +54,16 @@ void test_3 (void *ptr)
 int *test_4 (void)
 {
   allocator_t alloc_fn = get_malloc ();
-  int *ptr = alloc_fn (sizeof (int)); /* { dg-message "this call could return NULL" } */
+  int *ptr = (int *) alloc_fn (sizeof (int)); /* { dg-message "this call could return NULL" } */
   *ptr = 42; /* { dg-warning "dereference of possibly-NULL 'ptr'" } */
   return ptr;
 }
 
-int *test_5 (void)
+void test_5 (void)
 {
   allocator_t alloc_fn = get_alloca ();
   deallocator_t dealloc_fn = get_free ();
-  int *ptr = alloc_fn (sizeof (int)); /* dg-message "region created on stack here" } */
+  int *ptr = (int *) alloc_fn (sizeof (int)); /* dg-message "region created on stack here" } */
   dealloc_fn (ptr); /* { dg-warning "'free' of 'ptr' which points to memory on the stack" } */
 }
 
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-in-loop.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-in-loop.c
index a8c85a9c61885ec829e686e7879463696001e39a..b10715770243cffd46d5c91208f8a611c2b07d03 100644 (file)
@@ -1,5 +1,5 @@
 #include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern void foo (int *);
 
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-11.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-11.c
index b65ff9165e4da5c1bd730e8bc306a3618e18f2b4..60501034bc320dda3fa08ff9907f25a33097a7b9 100644 (file)
@@ -93,4 +93,70 @@ void test (void *ptr)
            |      |   (11) ...to here
            |      |   (12) second 'free' here; first 'free' was at (6)
            |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (victim);
+      |   ~~~~~^~~~~~~~
+  'void test(void*)': events 1-2
+    |
+    |   NN | void test (void *ptr)
+    |      |      ^~~~
+    |      |      |
+    |      |      (1) entry to 'test'
+    |......
+    |   NN |   may_call_free (ptr);
+    |      |   ~~~~~~~~~~~~~~~~~~~
+    |      |                 |
+    |      |                 (2) calling 'may_call_free' from 'test'
+    |
+    +--> 'void may_call_free(void*)': events 3-6
+           |
+           |   NN | may_call_free (void *victim)
+           |      | ^~~~~~~~~~~~~
+           |      | |
+           |      | (3) entry to 'may_call_free'
+           |   NN | {
+           |   NN |   if (some_condition ())
+           |      |   ~~
+           |      |   |
+           |      |   (4) following 'false' branch...
+           |......
+           |   NN |   free (victim);
+           |      |   ~~~~~~~~~~~~~
+           |      |        |
+           |      |        (5) ...to here
+           |      |        (6) first 'free' here
+           |
+    <------+
+    |
+  'void test(void*)': events 7-8
+    |
+    |   NN |   may_call_free (ptr);
+    |      |   ~~~~~~~~~~~~~~^~~~~
+    |      |                 |
+    |      |                 (7) returning to 'test' from 'may_call_free'
+    |......
+    |   NN |   may_call_free (ptr);
+    |      |   ~~~~~~~~~~~~~~~~~~~
+    |      |                 |
+    |      |                 (8) passing freed pointer 'ptr' in call to 'may_call_free' from 'test'
+    |
+    +--> 'void may_call_free(void*)': events 9-12
+           |
+           |   NN | may_call_free (void *victim)
+           |      | ^~~~~~~~~~~~~
+           |      | |
+           |      | (9) entry to 'may_call_free'
+           |   NN | {
+           |   NN |   if (some_condition ())
+           |      |   ~~
+           |      |   |
+           |      |   (10) following 'false' branch...
+           |......
+           |   NN |   free (victim);
+           |      |   ~~~~~~~~~~~~~
+           |      |        |
+           |      |        (11) ...to here
+           |      |        (12) second 'free' here; first 'free' was at (6)
+           |
+  { dg-end-multiline-output "" { target c++ } } */
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-4.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-4.c
index 82d50bd3c9367966a9075bc68e4c660025caf311..bd03d607872e10e4ca7052378fa8a3b254339a91 100644 (file)
@@ -7,7 +7,7 @@ static void calls_free(int *q)
 
 void test(void *p)
 {
-  calls_free(p);
+  calls_free((int *) p);
 
   free(p); /* { dg-warning "double-'free' of 'p'" } */
 }
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-5.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-5.c
index c66ecb5c5635257db7852fd10a2ad1179180b8d8..ca8e6a511f5ef60bada39a0a10309584696b4a60 100644 (file)
@@ -2,7 +2,7 @@
 
 static int *calls_malloc(void)
 {
-  return malloc(sizeof(int));
+  return (int *) malloc(sizeof(int));
 }
 
 int *test(void)
similarity index 76%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-7.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-7.c
index 0742370d2f91d776c7c060603381fe58a2843c27..1fe70ddc8b2c95ce7168d3a3d6aa23733bc235c6 100644 (file)
@@ -10,8 +10,8 @@ static void maybe_calls_free_1(int *q, int flag)
 
 void test_1(void *p)
 {
-  maybe_calls_free_1(p, 1);
-  maybe_calls_free_1(p, 1); 
+  maybe_calls_free_1((int *) p, 1);
+  maybe_calls_free_1((int *) p, 1); 
 }
 
 /**************************************************************************/
@@ -24,6 +24,6 @@ static void maybe_calls_free_2(int *q, int flag)
 
 void test_2(void *p)
 {
-  maybe_calls_free_2(p, 0);
-  maybe_calls_free_2(p, 0);
+  maybe_calls_free_2((int *) p, 0);
+  maybe_calls_free_2((int *) p, 0);
 }
similarity index 55%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-unchecked.c
index 320044753a183e94b46f4d7ad4998a83cc9336bc..5bc8e57827b6fcfb3205de82c2ea051d9386e72c 100644 (file)
@@ -64,4 +64,45 @@ make_boxed_int (int i)
     |      |             |
     |      |             (6) 'result' could be NULL: unchecked value from (4)
     |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   result->i = i;
+      |   ~~~~~~~~~~^~~
+  'boxed_int* make_boxed_int(int)': events 1-2
+    |
+    |   NN | make_boxed_int (int i)
+    |      | ^~~~~~~~~~~~~~
+    |      | |
+    |      | (1) entry to 'make_boxed_int'
+    |   NN | {
+    |   NN |   boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int));
+    |      |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    |      |                                                   |
+    |      |                                                   (2) calling 'wrapped_malloc' from 'make_boxed_int'
+    |
+    +--> 'void* wrapped_malloc(size_t)': events 3-4
+           |
+           |   NN | void *wrapped_malloc (size_t size)
+           |      |       ^~~~~~~~~~~~~~
+           |      |       |
+           |      |       (3) entry to 'wrapped_malloc'
+           |   NN | {
+           |   NN |   return malloc (size);
+           |      |          ~~~~~~~~~~~~~
+           |      |                 |
+           |      |                 (4) this call could return NULL
+           |
+    <------+
+    |
+  'boxed_int* make_boxed_int(int)': events 5-6
+    |
+    |   NN |   boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int));
+    |      |                                    ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
+    |      |                                                   |
+    |      |                                                   (5) possible return of NULL to 'make_boxed_int' from 'wrapped_malloc'
+    |   NN |   result->i = i;
+    |      |   ~~~~~~~~~~~~~                     
+    |      |             |
+    |      |             (6) 'result' could be NULL: unchecked value from (4)
+    |
+  { dg-end-multiline-output "" { target c++ } } */
similarity index 57%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-macro-inline-events.c
index 9134bb4781e5549f448889e498c3c2de062e185d..d00d076b209af4652092b2510cf6c320d371af56 100644 (file)
@@ -7,7 +7,7 @@
 
 /* { dg-warning "double-'free' of 'ptr'" "" { target *-*-* } 2 } */
 
-int test (void *ptr)
+void test (void *ptr)
 {
   WRAPPED_FREE (ptr); /* { dg-message "in expansion of macro 'WRAPPED_FREE'" } */
   WRAPPED_FREE (ptr); /* { dg-message "in expansion of macro 'WRAPPED_FREE'" } */
@@ -37,5 +37,31 @@ int test (void *ptr)
     |   NN |   WRAPPED_FREE (ptr);
     |      |   ^~~~~~~~~~~~
     |
-     { dg-end-multiline-output "" } */
+     { dg-end-multiline-output "" { target c } } */
+  /* { dg-begin-multiline-output "" }
+   NN | #define WRAPPED_FREE(PTR) free(PTR)
+      |                           ~~~~^~~~~
+   NN |   WRAPPED_FREE (ptr);
+      |   ^~~~~~~~~~~~
+  'void test(void*)': event 1
+    |
+    |
+    |   NN | #define WRAPPED_FREE(PTR) free(PTR)
+    |      |                           ~~~~^~~~~
+    |      |                               |
+    |      |                               (1) first 'free' here
+    |   NN |   WRAPPED_FREE (ptr);
+    |      |   ^~~~~~~~~~~~
+    |
+  'void test(void*)': event 2
+    |
+    |
+    |   NN | #define WRAPPED_FREE(PTR) free(PTR)
+    |      |                           ~~~~^~~~~
+    |      |                               |
+    |      |                               (2) second 'free' here; first 'free' was at (1)
+    |   NN |   WRAPPED_FREE (ptr);
+    |      |   ^~~~~~~~~~~~
+    |
+     { dg-end-multiline-output "" { target c++ } } */
 }
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-macro-separate-events.c
index c56419eeb5a5e1ea087406aa92fdd7b6f396a526..647b29c3aa40c4dfffa04ce85e17515001e0320a 100644 (file)
@@ -8,7 +8,7 @@
 /* { dg-message "first 'free' here" "1st free event" { target *-*-* } 2 } */
 /* { dg-message "second 'free' here" "2nd free event" { target *-*-* } 2 } */
 
-int test (void *ptr)
+void test (void *ptr)
 {
   WRAPPED_FREE (ptr); /* { dg-message "in expansion of macro 'WRAPPED_FREE'" } */
   WRAPPED_FREE (ptr); /* { dg-message "in expansion of macro 'WRAPPED_FREE'" } */
diff --git a/gcc/testsuite/c-c++-common/analyzer/malloc-paths-9-noexcept.c b/gcc/testsuite/c-c++-common/analyzer/malloc-paths-9-noexcept.c
new file mode 100644 (file)
index 0000000..f914ed6
--- /dev/null
@@ -0,0 +1,435 @@
+/* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fno-exceptions" } */
+/* { dg-enable-nn-line-numbers "" } */
+
+#include <stdlib.h>
+
+void test_1 (void)
+{
+  void *ptr = malloc (1024);
+  free (ptr);
+  free (ptr); /* { dg-warning "double-'free' of 'ptr'"  } */
+}
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ^~~~~~~~~~
+  'test_1': events 1-3
+    |
+    |   NN |   void *ptr = malloc (1024);
+    |      |               ^~~~~~~~~~~~~
+    |      |               |
+    |      |               (1) allocated here
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~   
+    |      |   |
+    |      |   (2) first 'free' here
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~   
+    |      |   |
+    |      |   (3) second 'free' here; first 'free' was at (2)
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   free (ptr);
+      |   ~~~~~^~~~~
+  'void test_1()': events 1-3
+    |
+    |   NN |   void *ptr = malloc (1024);
+    |      |               ~~~~~~~^~~~~~
+    |      |                      |
+    |      |                      (1) allocated here
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~          
+    |      |        |
+    |      |        (2) first 'free' here
+    |   NN |   free (ptr);
+    |      |   ~~~~~~~~~~          
+    |      |        |
+    |      |        (3) second 'free' here; first 'free' was at (2)
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+void test_2 (int x, int y)
+{
+  void *ptr = malloc (1024);
+  if (x)
+    free (ptr);
+  if (y)
+    free (ptr); /* { dg-warning "double-'free' of 'ptr'"  } */
+} /* { dg-warning "leak of 'ptr'"  } */
+
+/* "double-'free' of 'ptr'".  */
+/* { dg-begin-multiline-output "" }
+   NN |     free (ptr);
+      |     ^~~~~~~~~~
+  'test_2': events 1-7
+    |
+    |   NN |   void *ptr = malloc (1024);
+    |      |               ^~~~~~~~~~~~~
+    |      |               |
+    |      |               (1) allocated here
+    |   NN |   if (x)
+    |      |      ~         
+    |      |      |
+    |      |      (2) following 'true' branch (when 'x != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~ 
+    |      |     |
+    |      |     (3) ...to here
+    |      |     (4) first 'free' here
+    |   NN |   if (y)
+    |      |      ~         
+    |      |      |
+    |      |      (5) following 'true' branch (when 'y != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~ 
+    |      |     |
+    |      |     (6) ...to here
+    |      |     (7) second 'free' here; first 'free' was at (4)
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |     free (ptr);
+      |     ~~~~~^~~~~
+  'void test_2(int, int)': events 1-7
+    |
+    |   NN |   void *ptr = malloc (1024);
+    |      |               ~~~~~~~^~~~~~
+    |      |                      |
+    |      |                      (1) allocated here
+    |   NN |   if (x)
+    |      |   ~~                  
+    |      |   |
+    |      |   (2) following 'true' branch (when 'x != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~        
+    |      |          |
+    |      |          (3) ...to here
+    |      |          (4) first 'free' here
+    |   NN |   if (y)
+    |      |   ~~                  
+    |      |   |
+    |      |   (5) following 'true' branch (when 'y != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~        
+    |      |          |
+    |      |          (6) ...to here
+    |      |          (7) second 'free' here; first 'free' was at (4)
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+/* "leak of 'ptr'.  */
+/* { dg-begin-multiline-output "" }
+   NN | }
+      | ^
+  'test_2': events 1-6
+    |
+    |   NN |   void *ptr = malloc (1024);
+    |      |               ^~~~~~~~~~~~~
+    |      |               |
+    |      |               (1) allocated here
+    |   NN |   if (x)
+    |      |      ~         
+    |      |      |
+    |      |      (2) following 'false' branch (when 'x == 0')...
+    |   NN |     free (ptr);
+    |   NN |   if (y)
+    |      |      ~         
+    |      |      |
+    |      |      (3) ...to here
+    |      |      (4) following 'false' branch (when 'y == 0')...
+    |   NN |     free (ptr);
+    |   NN | }
+    |      | ~              
+    |      | |
+    |      | (5) ...to here
+    |      | (6) 'ptr' leaks here; was allocated at (1)
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN | }
+      | ^
+  'void test_2(int, int)': events 1-6
+    |
+    |   NN |   void *ptr = malloc (1024);
+    |      |               ~~~~~~~^~~~~~
+    |      |                      |
+    |      |                      (1) allocated here
+    |   NN |   if (x)
+    |      |   ~~                  
+    |      |   |
+    |      |   (2) following 'false' branch (when 'x == 0')...
+    |   NN |     free (ptr);
+    |   NN |   if (y)
+    |      |   ~~                  
+    |      |   |
+    |      |   (3) ...to here
+    |      |   (4) following 'false' branch (when 'y == 0')...
+    |   NN |     free (ptr);
+    |   NN | }
+    |      | ~                     
+    |      | |
+    |      | (5) ...to here
+    |      | (6) 'ptr' leaks here; was allocated at (1)
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+int test_3 (int x, int y)
+{
+  int *ptr = (int *)malloc (sizeof (int));
+  *ptr = 42; /* { dg-warning "dereference of possibly-NULL 'ptr'" } */
+  if (x)
+    free (ptr);
+
+  *ptr = 19; /* { dg-warning "use after 'free' of 'ptr'" } */
+  // TODO: two warnings here:  one is from sm-malloc, the other from region model
+
+  if (y)
+    free (ptr); /* No double-'free' warning: we've already attempted
+                  to dereference it above.  */
+  return *ptr; /* { dg-warning "use after 'free' of 'ptr'" "use-after-free" } */
+  /* { dg-warning "leak of 'ptr'" "leak" { target *-*-* } .-1 } */
+}
+
+/* "dereference of possibly-NULL 'ptr'".  */
+/* { dg-begin-multiline-output "" }
+   NN |   *ptr = 42;
+      |   ~~~~~^~~~
+  'test_3': events 1-2
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ^~~~~~~~~~~~~~~~~~~~~
+    |      |                     |
+    |      |                     (1) this call could return NULL
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~          
+    |      |        |
+    |      |        (2) 'ptr' could be NULL: unchecked value from (1)
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   *ptr = 42;
+      |   ~~~~~^~~~
+  'int test_3(int, int)': events 1-2
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ~~~~~~~^~~~~~~~~~~~~~
+    |      |                            |
+    |      |                            (1) this call could return NULL
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~                 
+    |      |        |
+    |      |        (2) 'ptr' could be NULL: unchecked value from (1)
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+/* "use after 'free' of 'ptr'".  */
+/* { dg-begin-multiline-output "" }
+   NN |   *ptr = 19;
+      |   ~~~~~^~~~
+  'test_3': events 1-6
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ^~~~~~~~~~~~~~~~~~~~~
+    |      |                     |
+    |      |                     (1) allocated here
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~          
+    |      |        |
+    |      |        (2) assuming 'ptr' is non-NULL
+    |   NN |   if (x)
+    |      |      ~               
+    |      |      |
+    |      |      (3) following 'true' branch (when 'x != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~       
+    |      |     |
+    |      |     (4) ...to here
+    |      |     (5) freed here
+    |   NN | 
+    |   NN |   *ptr = 19;
+    |      |   ~~~~~~~~~          
+    |      |        |
+    |      |        (6) use after 'free' of 'ptr'; freed at (5)
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   *ptr = 19;
+      |   ~~~~~^~~~
+  'int test_3(int, int)': events 1-6
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ~~~~~~~^~~~~~~~~~~~~~
+    |      |                            |
+    |      |                            (1) allocated here
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~                 
+    |      |        |
+    |      |        (2) assuming 'ptr' is non-NULL
+    |   NN |   if (x)
+    |      |   ~~                        
+    |      |   |
+    |      |   (3) following 'true' branch (when 'x != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~              
+    |      |          |
+    |      |          (4) ...to here
+    |      |          (5) freed here
+    |   NN | 
+    |   NN |   *ptr = 19;
+    |      |   ~~~~~~~~~                 
+    |      |        |
+    |      |        (6) use after 'free' of 'ptr'; freed at (5)
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+/* "use after 'free' of 'ptr'".  */
+/* { dg-begin-multiline-output "" }
+   NN |   return *ptr;
+      |          ^~~~
+  'test_3': events 1-8
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ^~~~~~~~~~~~~~~~~~~~~
+    |      |                     |
+    |      |                     (1) allocated here
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~          
+    |      |        |
+    |      |        (2) assuming 'ptr' is non-NULL
+    |   NN |   if (x)
+    |      |      ~               
+    |      |      |
+    |      |      (3) following 'false' branch (when 'x == 0')...
+    |......
+    |   NN |   *ptr = 19;
+    |      |   ~~~~~~~~~          
+    |      |        |
+    |      |        (4) ...to here
+    |......
+    |   NN |   if (y)
+    |      |      ~               
+    |      |      |
+    |      |      (5) following 'true' branch (when 'y != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~       
+    |      |     |
+    |      |     (6) ...to here
+    |      |     (7) freed here
+    |   NN |      
+    |   NN |   return *ptr;
+    |      |          ~~~~        
+    |      |          |
+    |      |          (8) use after 'free' of 'ptr'; freed at (7)
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   return *ptr;
+      |           ^~~
+  'int test_3(int, int)': events 1-8
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ~~~~~~~^~~~~~~~~~~~~~
+    |      |                            |
+    |      |                            (1) allocated here
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~                 
+    |      |        |
+    |      |        (2) assuming 'ptr' is non-NULL
+    |   NN |   if (x)
+    |      |   ~~                        
+    |      |   |
+    |      |   (3) following 'false' branch (when 'x == 0')...
+    |......
+    |   NN |   *ptr = 19;
+    |      |   ~~~~~~~~~                 
+    |      |        |
+    |      |        (4) ...to here
+    |......
+    |   NN |   if (y)
+    |      |   ~~                        
+    |      |   |
+    |      |   (5) following 'true' branch (when 'y != 0')...
+    |   NN |     free (ptr);
+    |      |     ~~~~~~~~~~              
+    |      |          |
+    |      |          (6) ...to here
+    |      |          (7) freed here
+    |   NN |      
+    |   NN |   return *ptr;
+    |      |           ~~~               
+    |      |           |
+    |      |           (8) use after 'free' of 'ptr'; freed at (7)
+    |
+   { dg-end-multiline-output "" { target c++ } } */
+
+/* "leak of 'ptr'".  */
+/* { dg-begin-multiline-output "" }
+   NN |   return *ptr;
+      |          ^~~~
+  'test_3': events 1-7
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ^~~~~~~~~~~~~~~~~~~~~
+    |      |                     |
+    |      |                     (1) allocated here
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~          
+    |      |        |
+    |      |        (2) assuming 'ptr' is non-NULL
+    |   NN |   if (x)
+    |      |      ~               
+    |      |      |
+    |      |      (3) following 'false' branch (when 'x == 0')...
+    |......
+    |   NN |   *ptr = 19;
+    |      |   ~~~~~~~~~          
+    |      |        |
+    |      |        (4) ...to here
+    |......
+    |   NN |   if (y)
+    |      |      ~               
+    |      |      |
+    |      |      (5) following 'false' branch (when 'y == 0')...
+    |......
+    |   NN |   return *ptr;
+    |      |          ~~~~        
+    |      |          |
+    |      |          (6) ...to here
+    |      |          (7) 'ptr' leaks here; was allocated at (1)
+    |
+   { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   return *ptr;
+      |           ^~~
+  'int test_3(int, int)': events 1-7
+    |
+    |   NN |   int *ptr = (int *)malloc (sizeof (int));
+    |      |                     ~~~~~~~^~~~~~~~~~~~~~
+    |      |                            |
+    |      |                            (1) allocated here
+    |   NN |   *ptr = 42;
+    |      |   ~~~~~~~~~                 
+    |      |        |
+    |      |        (2) assuming 'ptr' is non-NULL
+    |   NN |   if (x)
+    |      |   ~~                        
+    |      |   |
+    |      |   (3) following 'false' branch (when 'x == 0')...
+    |......
+    |   NN |   *ptr = 19;
+    |      |   ~~~~~~~~~                 
+    |      |        |
+    |      |        (4) ...to here
+    |......
+    |   NN |   if (y)
+    |      |   ~~                        
+    |      |   |
+    |      |   (5) following 'false' branch (when 'y == 0')...
+    |......
+    |   NN |   return *ptr;
+    |      |           ~~~               
+    |      |           |
+    |      |           (6) ...to here
+    |      |           (7) 'ptr' leaks here; was allocated at (1)
+    |
+   { dg-end-multiline-output "" { target c++ } } */
similarity index 86%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c
index 1e4613cd1b1019e809b227f5fd02caae70999792..1151d622519bd2990fdee85dc0f3049beeec477c 100644 (file)
@@ -1,6 +1,5 @@
 /* Reduced from SoftEtherVPN's src/Cedar/WebUI.c.   */
-
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef int (COMPARE)(void *p1, void *p2);
 typedef unsigned int UINT;
 typedef unsigned long int UINT64;
@@ -28,7 +27,11 @@ struct LIST
 
 #define        LIST_DATA(o, i)         (((o) != NULL) ? ((o)->p[(i)]) : NULL)
 #define        LIST_NUM(o)                     (((o) != NULL) ? (o)->num_item : 0)
-
+#ifdef __cplusplus
+#ifndef _Bool
+typedef bool _Bool;
+#endif
+#endif
 
 struct STRMAP_ENTRY
 {
@@ -65,10 +68,10 @@ void WuExpireSessionKey(WEBUI *wu)
 
        for(i=0; i<LIST_NUM(Expired); i++)
        {
-               STRMAP_ENTRY *entry = LIST_DATA(Expired, i);
+               STRMAP_ENTRY *entry = (STRMAP_ENTRY*)LIST_DATA(Expired, i);
                Delete(wu->Contexts, entry);
                Free(entry->Name);
-               WuFreeContext(entry->Value);
+               WuFreeContext((WU_CONTEXT*)entry->Value);
                Free(entry);
        }
        ReleaseList(Expired);
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-1.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-1.c
index 93b379c173ab3d9e550c782bc43aa897ef107930..868b8ee9b410c2d0616005069f56b93b983cea90 100644 (file)
@@ -54,7 +54,7 @@ void test3 (void)
 
 void test4 (void)
 {
-  int *arr = malloc (4 * sizeof (int));
+  int *arr = (int *)malloc (4 * sizeof (int));
   if (!arr)
     return;
   
@@ -66,7 +66,7 @@ void test4 (void)
 
 void test5 (void)
 {
-  int *arr = malloc (4 * sizeof (int));
+  int *arr = (int *)malloc (4 * sizeof (int));
   if (!arr)
     return;
   
@@ -99,7 +99,7 @@ void test6 (void)
 
 extern int is_valid (void);
 
-int returnChunkSize (void *ptr)
+int returnChunkSize (int *ptr)
 {
   /* If chunk info is valid, return the size of usable memory,
      else, return -1 to indicate an error.  */
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-2.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-2.c
index 336f624441c755b57c94e383bab46504327e5bfd..e69614612fdb8d623f79624d44a6fb3bedb8ee63 100644 (file)
@@ -54,7 +54,7 @@ void test3 (void)
 void test4 (void)
 {
   int n = 4;
-  int *arr = malloc (n * sizeof (int));
+  int *arr = (int *)malloc (n * sizeof (int));
   if (!arr)
     return;
   memset (arr, 0, n * sizeof(int));
@@ -69,7 +69,7 @@ void test4 (void)
 void test5 (void)
 {
   int n = 4;
-  int *arr = malloc (n * sizeof (int));
+  int *arr = (int *)malloc (n * sizeof (int));
   if (!arr)
     return;
   memset (arr, 0, n * sizeof(int));
similarity index 82%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-5.c
index 568f9cad199cceeaaf14771521e26f3096b68de6..4d15b163f4003db167bf61b9329884453552b55a 100644 (file)
@@ -9,7 +9,7 @@
 
 void test1 (size_t size)
 {
-  char *buf = __builtin_malloc (size);
+  char *buf = (char *)__builtin_malloc (size);
   if (!buf) return;
 
   buf[size] = '\0'; /* { dg-warning "heap-based buffer overflow" } */
@@ -18,7 +18,7 @@ void test1 (size_t size)
 
 void test2 (size_t size)
 {
-  char *buf = __builtin_malloc (size);
+  char *buf = (char *)__builtin_malloc (size);
   if (!buf) return;
 
   buf[size + 1] = '\0'; /* { dg-warning "heap-based buffer overflow" } */
@@ -27,7 +27,7 @@ void test2 (size_t size)
 
 void test3 (size_t size, size_t op)
 {
-  char *buf = __builtin_malloc (size);
+  char *buf = (char *)__builtin_malloc (size);
   if (!buf) return;
 
   buf[size + op] = '\0'; /* { dg-warning "heap-based buffer overflow" } */
@@ -36,26 +36,26 @@ void test3 (size_t size, size_t op)
 
 void test4 (size_t size, unsigned short s)
 {
-  char *buf = __builtin_alloca (size);
+  char *buf = (char *)__builtin_alloca (size);
   buf[size + s] = '\0'; /* { dg-warning "stack-based buffer overflow" } */
 }
 
 void test5 (size_t size)
 {
-  int32_t *buf = __builtin_alloca (4 * size);
+  int32_t *buf = (int32_t *)__builtin_alloca (4 * size);
   buf[size] = 42; /* { dg-warning "stack-based buffer overflow" } */
 }
 
 void test6 (size_t size)
 {
-  int32_t *buf = __builtin_alloca (4 * size);
+  int32_t *buf = (int32_t *)__builtin_alloca (4 * size);
   memset (buf, 0, 4 * size);
   int32_t last = *(buf + 4 * size); /* { dg-warning "stack-based buffer over-read" } */
 }
 
 void test7 (size_t size)
 {
-  int32_t *buf = __builtin_alloca (4 * size + 3); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+  int32_t *buf = (int32_t *)__builtin_alloca (4 * size + 3); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
   buf[size] = 42; /* { dg-warning "stack-based buffer overflow" } */
 }
 
@@ -91,7 +91,7 @@ void test10 (size_t size)
 
 void test11 (size_t size)
 {
-  int32_t *buf = __builtin_alloca (4 * size + 5); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+  int32_t *buf = (int32_t *)__builtin_alloca (4 * size + 5); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
   buf[size] = 42;
 }
 
@@ -129,7 +129,7 @@ char *test98 (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);
@@ -144,7 +144,7 @@ char *test99 (const char *x, const char *y)
   size_t len_y = __builtin_strlen (y);
   /* BUG (root cause): forgot to add 1 for terminator.  */
   size_t sz = len_x + len_y;
-  char *result = __builtin_malloc (sz);
+  char *result = (char *)__builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, len_x);
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-11.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-11.c
index f8eb1580eb3568ef2d68c554d17e6d52576e677a..d68ac8f25ba9dda19d7efffe83e89129737612f7 100644 (file)
@@ -7,7 +7,7 @@
 
 void test6 (size_t size)
 {
-  int32_t *buf = __builtin_alloca (4 * size);
+  int32_t *buf = (int32_t *) __builtin_alloca (4 * size);
   memset (buf, 0, 4 * size);
   int32_t last = *(buf + 4 * size); /* { dg-warning "stack-based buffer over-read" } */
 }
@@ -38,7 +38,7 @@ void test6 (size_t size)
 
 void test7 (size_t size)
 {
-  int32_t *buf = __builtin_alloca (4 * size + 3); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
+  int32_t *buf = (int32_t *) __builtin_alloca (4 * size + 3); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
   buf[size] = 42; /* { dg-warning "stack-based buffer overflow" } */
 }
 
@@ -71,7 +71,7 @@ char *test99 (const char *x, const char *y)
   size_t len_y = __builtin_strlen (y);
   /* BUG (root cause): forgot to add 1 for terminator.  */
   size_t sz = len_x + len_y;
-  char *result = __builtin_malloc (sz);
+  char *result = (char *) __builtin_malloc (sz);
   if (!result)
     return NULL;
   __builtin_memcpy (result, x, len_x);
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-3.c
index 064f3fad47e2bbfff03aa781f78800f31c64a79a..43df9564a76a006072cf21ee1bb037e10b494316 100644 (file)
@@ -16,7 +16,8 @@ struct str *
 make_str_badly (const char *src)
 {
   size_t len = strlen(src);
-  struct str *str = malloc(sizeof(str) + len); /* { dg-message "\\(1\\) capacity: 'len \\+ 8' bytes" } */
+  struct str *str = (struct str *) malloc(sizeof(str) + len); /* { dg-message "\\(1\\) capacity: 'len \\+ 8' bytes" "" { target c } } */
+  /* { dg-message "\\(1\\) capacity: '\\(len \\+ 8\\)' bytes" "" { target c++ } .-1 } */
   if (!str)
     return NULL;
   str->len = len;
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-8.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-8.c
index 24d87357e2d44aff85a06c0d2265edd3fdc17699..81cd4ff3c4b18ed454294b73cc427591b7d28e42 100644 (file)
@@ -7,7 +7,8 @@
 
 void test2 (size_t size)
 {
-  int32_t *buf = __builtin_malloc (size * sizeof(int32_t)); /* { dg-message "\\(1\\) capacity: 'size \\* 4' bytes" } */
+  int32_t *buf = (int32_t *) __builtin_malloc (size * sizeof(int32_t)); /* { dg-message "\\(1\\) capacity: 'size \\* 4' bytes" "" { target c } } */
+  /* { dg-message "\\(1\\) capacity: '\\(size \\* 4\\)' bytes" "" { target c++ } .-1 } */
   if (!buf) return;
 
   buf[size + 1] = 42; /* { dg-warning "heap-based buffer overflow" } */
similarity index 88%
rename from gcc/testsuite/gcc.dg/analyzer/phi-1.c
rename to gcc/testsuite/c-c++-common/analyzer/phi-1.c
index 09260033fef6bdcfa1714ffe7efab92b85d0437e..7818935b9534bac1c97f80719cdb0909abc2596d 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-do "compile" } */
 
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *) 0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern const char *foo (void);
 extern size_t bar (void);
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/pr100615.c
rename to gcc/testsuite/c-c++-common/analyzer/pr100615.c
index 7a06f987d4138ffd2c3b17e38a75544ce4999011..f4b29f47fe67205fdf78d1f4f1ec4f913b64eedf 100644 (file)
@@ -3,7 +3,7 @@
    which is MIT-licensed.  */
 
 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__))
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/pr103526.c
rename to gcc/testsuite/c-c++-common/analyzer/pr103526.c
index 39d60fd853e1cfa02f489b71bf10d86f0d6b5182..0388fc1df9994d5b10545207fe08be9bbe3a2cb8 100644 (file)
@@ -17,9 +17,9 @@ game_new(void)
 
        tmp.word = teststr;
        wordlen = strlen(tmp.word);
-       if ((tmp.word_state = malloc(wordlen+1)) == NULL)
+       if ((tmp.word_state = (char *) malloc(wordlen+1)) == NULL)
                goto err;
-       if ((rval = malloc(sizeof(*rval))) == NULL)
+       if ((rval = (struct game_state *) malloc(sizeof(*rval))) == NULL)
                goto err;
        memcpy(rval, &tmp, sizeof(*rval));
 
diff --git a/gcc/testsuite/c-c++-common/analyzer/pr109577-noexcept.c b/gcc/testsuite/c-c++-common/analyzer/pr109577-noexcept.c
new file mode 100644 (file)
index 0000000..4ff7a5b
--- /dev/null
@@ -0,0 +1,2 @@
+/* { dg-additional-options "-fno-exceptions" } */
+#include "../../gcc.dg/analyzer/pr109577.c"
diff --git a/gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-feasibility-noexcept.c b/gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-feasibility-noexcept.c
new file mode 100644 (file)
index 0000000..6ab14fb
--- /dev/null
@@ -0,0 +1,85 @@
+/* Simplified version of test to ensure we issue a FILE * leak diagnostic,
+   reproducing a feasibility issue.
+   Adapted from intl/localealias.c, with all #includes removed.  */
+
+/* { dg-do "compile" } */
+/* { dg-additional-options "-fno-exceptions" } */
+
+/* Handle aliases for locale names.
+   Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Library General Public License as published
+   by the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
+   USA.  */
+
+
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+/* Minimal version of system headers.  */
+typedef __SIZE_TYPE__ size_t;
+
+typedef struct _IO_FILE FILE;
+extern FILE *fopen (const char *__restrict __filename,
+                   const char *__restrict __modes);
+extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+extern int fclose (FILE *__stream);
+
+extern int isspace (int) __attribute__((__nothrow__, __leaf__));
+
+/* Cleaned-up body of localealias.c follows.  */
+
+size_t
+read_alias_file (const char *fname, int fname_len)
+{
+  FILE *fp;
+  size_t added;
+  char buf[400];
+  char *alias;
+  char *value;
+  char *cp;
+
+  fp = fopen (fname, "r"); /* { dg-message "opened here" } */
+  if (fp == NULL)
+    return 0;
+
+  if (fread (buf, sizeof buf, 1, fp) != 1)
+    {
+      fclose (fp);
+      return 0;
+    }
+
+  cp = buf;
+
+  /* Ignore leading white space.  */
+  while (isspace ((unsigned char)cp[0]))
+    ++cp;
+
+  if (cp[0] != '\0' && cp[0] != '#')
+    {
+      alias = cp++;
+      while (cp[0] != '\0' && !isspace ((unsigned char)cp[0]))
+       ++cp;
+      if (cp[0] != '\0')
+       *cp++ = '\0';
+
+      while (isspace ((unsigned char)cp[0]))
+       ++cp;
+
+      if (cp[0] != '\0')
+       return 42; /* { dg-warning "leak of FILE 'fp'" } */
+    }
+
+  fclose(fp);
+
+  return 0;
+}
similarity index 83%
rename from gcc/testsuite/gcc.dg/analyzer/pr94362-1.c
rename to gcc/testsuite/c-c++-common/analyzer/pr94362-1.c
index 1302cedb856ee51be1cd07b83b381d4106765716..a184636073f24de98091b54a7fac20a1ead7d17d 100644 (file)
@@ -17,7 +17,7 @@ sk_EVP_PKEY_ASN1_METHOD_value(const struct stack_st_EVP_PKEY_ASN1_METHOD *sk,
                               int idx);
 extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
 static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {&hmac_asn1_meth};
-static struct stack_st_EVP_PKEY_ASN1_METHOD *app_methods = ((void *)0);
+static struct stack_st_EVP_PKEY_ASN1_METHOD *app_methods = (struct stack_st_EVP_PKEY_ASN1_METHOD *) ((void *)0);
 
 int EVP_PKEY_asn1_get_count(void) {
   int num = (sizeof(standard_methods) / sizeof((standard_methods)[0]));
@@ -29,7 +29,7 @@ int EVP_PKEY_asn1_get_count(void) {
 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) {
   int num = (sizeof(standard_methods) / sizeof((standard_methods)[0]));
   if (idx < 0)
-    return ((void *)0);
+    return (const EVP_PKEY_ASN1_METHOD *) ((void *)0);
   if (idx < num)
     return standard_methods[idx];
   idx -= num;
@@ -39,7 +39,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) {
 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str,
                                                    int len) {
   int i;
-  const EVP_PKEY_ASN1_METHOD *ameth = ((void *)0);
+  const EVP_PKEY_ASN1_METHOD *ameth = (const EVP_PKEY_ASN1_METHOD *) ((void *)0);
 
   if (pe) {
     ENGINE *e;
@@ -48,7 +48,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str,
       *pe = e;
       return ameth;
     }
-    *pe = ((void *)0);
+    *pe = (ENGINE *) ((void *)0);
   }
   for (i = EVP_PKEY_asn1_get_count(); i-- > 0;) {
     ameth = EVP_PKEY_asn1_get0(i);
@@ -56,5 +56,5 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str,
       continue;
     return ameth;
   }
-  return ((void *)0);
+  return (const EVP_PKEY_ASN1_METHOD *) ((void *)0);
 }
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/pr97074.c
rename to gcc/testsuite/c-c++-common/analyzer/pr97074.c
index ccb3b61bd415b2836e7d5b359add8349bf3ab70c..2dee9090bba75bebce35b0fbd99671ea002e70b1 100644 (file)
@@ -1,5 +1,4 @@
-#include "analyzer-decls.h"
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 void *x, *y;
 
diff --git a/gcc/testsuite/c-c++-common/analyzer/pr99193-1-noexcept.c b/gcc/testsuite/c-c++-common/analyzer/pr99193-1-noexcept.c
new file mode 100644 (file)
index 0000000..ac0d3dd
--- /dev/null
@@ -0,0 +1,68 @@
+/* { dg-additional-options "-Wno-analyzer-too-complex" } */
+/* { dg-additional-options "-fno-exceptions" } */
+
+/* Verify absence of false positive from -Wanalyzer-mismatching-deallocation
+   on realloc(3).
+   Based on https://github.com/libguestfs/libguestfs/blob/f19fd566f6387ce7e4d82409528c9dde374d25e0/daemon/command.c#L115
+   which is GPLv2 or later.  */
+
+typedef __SIZE_TYPE__ size_t;
+typedef __builtin_va_list va_list;
+
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+extern void *malloc (size_t __size)
+  __attribute__ ((__nothrow__ , __leaf__))
+  __attribute__ ((__malloc__))
+  __attribute__ ((__alloc_size__ (1)));
+extern void perror (const char *__s);
+extern void *realloc (void *__ptr, size_t __size)
+  __attribute__ ((__nothrow__ , __leaf__))
+  __attribute__ ((__warn_unused_result__))
+  __attribute__ ((__alloc_size__ (2)));
+
+extern void guestfs_int_cleanup_free (void *ptr);
+extern int commandrvf (char **stdoutput, char **stderror, unsigned flags,
+                       char const* const *argv);
+#define CLEANUP_FREE __attribute__((cleanup(guestfs_int_cleanup_free))) 
+
+int
+commandrf (char **stdoutput, char **stderror, unsigned flags,
+           const char *name, ...)
+{
+  va_list args;
+  CLEANUP_FREE const char **argv = NULL;
+  char *s;
+  int i, r;
+
+  /* Collect the command line arguments into an array. */
+  i = 2;
+  argv = (const char **) malloc (sizeof (char *) * i);
+
+ if (argv == NULL) {
+    perror ("malloc");
+    return -1;
+  }
+  argv[0] = (char *) name;
+  argv[1] = NULL;
+
+  __builtin_va_start (args, name);
+
+  while ((s = __builtin_va_arg (args, char *)) != NULL) {
+    const char **p = (const char **) realloc (argv, sizeof (char *) * (++i)); /* { dg-bogus "'free'" } */
+    if (p == NULL) {
+      perror ("realloc");
+      __builtin_va_end (args);
+      return -1;
+    }
+    argv = p;
+    argv[i-2] = s;
+    argv[i-1] = NULL;
+  }
+
+  __builtin_va_end (args);
+
+  r = commandrvf (stdoutput, stderror, flags, argv);
+
+  return r;
+}
index 12326ef61f1c3d1f020d54d11a5c788156385b80..f033a264dc82d36a78a20cbfd4f1f1f28886a55f 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)
index 75e0b10e964b06aea062704f7272da6b8de5bd13..04925cfe5adc4b618dc37007de2c98f15c225802 100644 (file)
@@ -2,7 +2,7 @@
 
 typedef __SIZE_TYPE__ size_t;
 
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern void *malloc (size_t __size)
   __attribute__ ((__nothrow__ , __leaf__))
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/scope-1.c
rename to gcc/testsuite/c-c++-common/analyzer/scope-1.c
index f8acffa18e4124a46850fbbbfe183a5530275dbc..09e62d46df3555690d7fc2efd4288b228b2a930c 100644 (file)
@@ -3,7 +3,7 @@
 int test_1 (void)
 {
   {
-    int *q = malloc (1024);
+    int *q = (int *) malloc (1024);
   }
 
   return 42; /* { dg-warning "leak of 'q'" } */
similarity index 55%
rename from gcc/testsuite/gcc.dg/analyzer/setjmp-2.c
rename to gcc/testsuite/c-c++-common/analyzer/setjmp-2.c
index f5d9c53e2393e78cf2e3316985a0fe203860142a..731a17293fc75b4c55642dadcf9bd899d93af4d5 100644 (file)
@@ -2,9 +2,9 @@
 /* { dg-enable-nn-line-numbers "" } */
 /* { dg-require-effective-target indirect_jumps } */
 
-#include "test-setjmp.h"
+#include "../../gcc.dg/analyzer/test-setjmp.h"
 #include <stddef.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern void foo (int);
 
@@ -81,7 +81,54 @@ void test_2 (void)
     |      |       |
     |      |       (8) here
     |
-    { dg-end-multiline-output "" } */
+    { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |       __analyzer_dump_path ();
+      |       ~~~~~~~~~~~~~~~~~~~~~^~
+  'void test_2()': event 1
+    |
+    |   NN |   i = SETJMP(env);
+    |      |       ^~~~~~
+    |      |       |
+    |      |       (1) 'setjmp' called here
+    |
+  'void test_2()': events 2-4
+    |
+    |   NN |   if (i != 0)
+    |      |   ^~
+    |      |   |
+    |      |   (2) following 'false' branch (when 'i == 0')...
+    |......
+    |   NN |     longjmp (env, 1);
+    |      |     ~~~~~~~~~~~~~~~~
+    |      |             |
+    |      |             (3) ...to here
+    |      |             (4) rewinding within 'test_2' from 'longjmp'...
+    |
+  'void test_2()': event 5
+    |
+    |   NN |   i = SETJMP(env);
+    |      |       ^~~~~~
+    |      |       |
+    |      |       (5) ...to 'setjmp' (saved at (1))
+    |
+  'void test_2()': events 6-8
+    |
+    |   NN |   if (i != 0)
+    |      |   ^~
+    |      |   |
+    |      |   (6) following 'true' branch (when 'i != 0')...
+    |   NN |     {
+    |   NN |       foo (2);
+    |      |       ~~~~~~~
+    |      |           |
+    |      |           (7) ...to here
+    |   NN |       __analyzer_dump_path ();
+    |      |       ~~~~~~~~~~~~~~~~~~~~~~~
+    |      |                            |
+    |      |                            (8) here
+    |
+    { dg-end-multiline-output "" { target c++ } } */
 
 void test_3 (void)
 {
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/setjmp-5.c
rename to gcc/testsuite/c-c++-common/analyzer/setjmp-5.c
index 4787fa38032b9196b72f326398a4c562e488734b..3133a473d51aa799500ea6856d411547b7b49c07 100644 (file)
@@ -2,9 +2,9 @@
 /* { dg-enable-nn-line-numbers "" } */
 /* { dg-require-effective-target indirect_jumps } */
 
-#include "test-setjmp.h"
+#include "../../gcc.dg/analyzer/test-setjmp.h"
 #include <stddef.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 static jmp_buf env;
 
@@ -72,4 +72,55 @@ void outer (void)
     |      |   |
     |      |   (7) 'longjmp' called after enclosing function of 'setjmp' returned at (5)
     |
-    { dg-end-multiline-output "" } */
+    { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   longjmp (env, 42);
+      |   ~~~~~~~~^~~~~~~~~
+  'void outer()': events 1-2
+    |
+    |   NN | void outer (void)
+    |      |      ^~~~~
+    |      |      |
+    |      |      (1) entry to 'outer'
+    |......
+    |   NN |   inner ();
+    |      |   ~~~~~~~~
+    |      |         |
+    |      |         (2) calling 'inner' from 'outer'
+    |
+    +--> 'void inner()': event 3
+           |
+           |   NN | static void inner (void)
+           |      |             ^~~~~
+           |      |             |
+           |      |             (3) entry to 'inner'
+           |
+         'void inner()': event 4
+           |
+           |   NN |   SETJMP (env);
+           |      |   ^~~~~~
+           |      |   |
+           |      |   (4) 'setjmp' called here
+           |
+         'void inner()': event 5
+           |
+           |   NN | }
+           |      | ^
+           |      | |
+           |      | (5) stack frame is popped here, invalidating saved environment
+           |
+    <------+
+    |
+  'void outer()': events 6-7
+    |
+    |   NN |   inner ();
+    |      |   ~~~~~~^~
+    |      |         |
+    |      |         (6) returning to 'outer' from 'inner'
+    |   NN | 
+    |   NN |   longjmp (env, 42);
+    |      |   ~~~~~~~~~~~~~~~~~
+    |      |           |
+    |      |           (7) 'longjmp' called after enclosing function of 'setjmp' returned at (5)
+    |
+    { dg-end-multiline-output "" { target c++ } } */
similarity index 55%
rename from gcc/testsuite/gcc.dg/analyzer/setjmp-9.c
rename to gcc/testsuite/c-c++-common/analyzer/setjmp-9.c
index c2b00e3b95c5bb1a70f73a11776da2d22cb94add..f7e940ea605bce84d5166829c14a7c9010ca59d9 100644 (file)
@@ -2,9 +2,9 @@
 /* { dg-enable-nn-line-numbers "" } */
 /* { dg-require-effective-target indirect_jumps } */
 
-#include "test-setjmp.h"
+#include "../../gcc.dg/analyzer/test-setjmp.h"
 #include <stddef.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
 
 extern int foo (int) __attribute__ ((__pure__));
 
@@ -39,6 +39,71 @@ void outer (void)
   foo (3);
 }
 
+/* { dg-begin-multiline-output "" }
+   NN |       __analyzer_dump_path ();
+      |       ~~~~~~~~~~~~~~~~~~~~~^~
+  'void outer()': event 1
+    |
+    |   NN | void outer (void)
+    |      |      ^~~~~
+    |      |      |
+    |      |      (1) entry to 'outer'
+    |
+  'void outer()': event 2
+    |
+    |   NN |   i = SETJMP(env);
+    |      |       ^~~~~~
+    |      |       |
+    |      |       (2) 'setjmp' called here
+    |
+  'void outer()': events 3-5
+    |
+    |   NN |   if (i != 0)
+    |      |   ^~
+    |      |   |
+    |      |   (3) following 'false' branch (when 'i == 0')...
+    |......
+    |   NN |       inner ();
+    |      |       ~~~~~~~~
+    |      |             |
+    |      |             (4) ...to here
+    |      |             (5) calling 'inner' from 'outer'
+    |
+    +--> 'void inner()': events 6-7
+           |
+           |   NN | static void inner (void)
+           |      |             ^~~~~
+           |      |             |
+           |      |             (6) entry to 'inner'
+           |......
+           |   NN |   longjmp (env, unknown_val);
+           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~
+           |      |           |
+           |      |           (7) rewinding from 'longjmp' in 'inner'...
+           |
+    <------+
+    |
+  'void outer()': event 8
+    |
+    |   NN |   i = SETJMP(env);
+    |      |       ^~~~~~
+    |      |       |
+    |      |       (8) ...to 'setjmp' in 'outer' (saved at (2))
+    |
+  'void outer()': events 9-11
+    |
+    |   NN |   if (i != 0)
+    |      |   ^~
+    |      |   |
+    |      |   (9) following 'true' branch (when 'i != 0')...
+    |......
+    |   NN |       __analyzer_dump_path ();
+    |      |       ~~~~~~~~~~~~~~~~~~~~~~~
+    |      |                            |
+    |      |                            (10) ...to here
+    |      |                            (11) here
+    |
+    { dg-end-multiline-output "" { target c++ } } */
 /* { dg-begin-multiline-output "" }
    NN |       __analyzer_dump_path ();
       |       ^~~~~~~~~~~~~~~~~~~~~~~
@@ -109,4 +174,4 @@ void outer (void)
     |      |       |
     |      |       (11) here
     |
-    { dg-end-multiline-output "" } */
+    { dg-end-multiline-output "" { target c } } */
similarity index 53%
rename from gcc/testsuite/gcc.dg/analyzer/signal-4a.c
rename to gcc/testsuite/c-c++-common/analyzer/signal-4a.c
index 4ee6f0e7d0e0204acd5c12a40fb6837ffcc46a70..b5c6012ec2ec853fbc920c891604175edaebad31 100644 (file)
@@ -12,7 +12,8 @@ extern void body_of_program(void);
 
 void custom_logger(const char *msg)
 {
-  fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" } */
+  fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" "" { target c } } */
+  /* { dg-warning "call to 'int fprintf\\(FILE\\*, const char\\*, ...\\)' from within signal handler" "" { target c++ } .-1 } */
 }
 
 static void int_handler(int signum)
@@ -73,4 +74,49 @@ void test (void)
                   |      |   |
                   |      |   (7) call to 'fprintf' from within signal handler
                   |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   fprintf(stderr, "LOG: %s", msg);
+      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
+  'void test()': events 1-2
+    |
+    |   NN | void test (void)
+    |      |      ^~~~
+    |      |      |
+    |      |      (1) entry to 'test'
+    |......
+    |   NN |   signal(SIGINT, int_handler);
+    |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    |      |         |
+    |      |         (2) registering 'void int_handler(int)' as signal handler
+    |
+  event 3
+    |
+    |cc1plus:
+    | (3): later on, when the signal is delivered to the process
+    |
+    +--> 'void int_handler(int)': events 4-5
+           |
+           |   NN | static void int_handler(int signum)
+           |      |             ^~~~~~~~~~~
+           |      |             |
+           |      |             (4) entry to 'int_handler'
+           |   NN | {
+           |   NN |   custom_logger("got signal");
+           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+           |      |                |
+           |      |                (5) calling 'custom_logger' from 'int_handler'
+           |
+           +--> 'void custom_logger(const char*)': events 6-7
+                  |
+                  |   NN | void custom_logger(const char *msg)
+                  |      |      ^~~~~~~~~~~~~
+                  |      |      |
+                  |      |      (6) entry to 'custom_logger'
+                  |   NN | {
+                  |   NN |   fprintf(stderr, "LOG: %s", msg);
+                  |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+                  |      |          |
+                  |      |          (7) call to 'int fprintf(FILE*, const char*, ...)' from within signal handler
+                  |
+  { dg-end-multiline-output "" { target c++ } } */
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/signal-4b.c
rename to gcc/testsuite/c-c++-common/analyzer/signal-4b.c
index 5a2ccb1def48cd7f4cb3f5532a4f2081d1f24689..d2b5db7b2760ef5db69bf2ca1e69ac637d2b9240 100644 (file)
@@ -12,7 +12,8 @@ extern void body_of_program(void);
 
 void custom_logger(const char *msg)
 {
-  fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" } */
+  fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" "" { target c } } */
+  /* { dg-warning "call to 'int fprintf\\(FILE\\*, const char\\*, ...\\)' from within signal handler" "" { target c++ } .-1 } */
 }
 
 static void int_handler(int signum)
@@ -88,4 +89,61 @@ void test (void)
                   |      |   |
                   |      |   (9) call to 'fprintf' from within signal handler
                   |
-  { dg-end-multiline-output "" } */
+  { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+   NN |   fprintf(stderr, "LOG: %s", msg);
+      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
+  'void test()': events 1-2
+    |
+    |   NN | void test (void)
+    |      |      ^~~~
+    |      |      |
+    |      |      (1) entry to 'test'
+    |   NN | {
+    |   NN |   __analyzer_register_handler ();
+    |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    |      |                               |
+    |      |                               (2) calling '__analyzer_register_handler' from 'test'
+    |
+    +--> 'void __analyzer_register_handler()': events 3-4
+           |
+           |   NN | static void __analyzer_register_handler ()
+           |      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
+           |      |             |
+           |      |             (3) entry to '__analyzer_register_handler'
+           |   NN | {
+           |   NN |   signal(SIGINT, int_handler);
+           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+           |      |         |
+           |      |         (4) registering 'void int_handler(int)' as signal handler
+           |
+  event 5
+    |
+    |cc1plus:
+    | (5): later on, when the signal is delivered to the process
+    |
+    +--> 'void int_handler(int)': events 6-7
+           |
+           |   NN | static void int_handler(int signum)
+           |      |             ^~~~~~~~~~~
+           |      |             |
+           |      |             (6) entry to 'int_handler'
+           |   NN | {
+           |   NN |   custom_logger("got signal");
+           |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+           |      |                |
+           |      |                (7) calling 'custom_logger' from 'int_handler'
+           |
+           +--> 'void custom_logger(const char*)': events 8-9
+                  |
+                  |   NN | void custom_logger(const char *msg)
+                  |      |      ^~~~~~~~~~~~~
+                  |      |      |
+                  |      |      (8) entry to 'custom_logger'
+                  |   NN | {
+                  |   NN |   fprintf(stderr, "LOG: %s", msg);
+                  |      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+                  |      |          |
+                  |      |          (9) call to 'int fprintf(FILE*, const char*, ...)' from within signal handler
+                  |
+  { dg-end-multiline-output "" { target c++ } } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/compound-assignment-1.c b/gcc/testsuite/gcc.dg/analyzer/compound-assignment-1.c
deleted file mode 100644 (file)
index 0f07818..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-#include <stdlib.h>
-
-struct ptr_wrapper
-{
-  int *ptr;
-};
-
-struct ptr_wrapper
-test_1 (void)
-{
-  struct ptr_wrapper r;
-  r.ptr = malloc (sizeof (int));
-  return r;
-}
-
-struct ptr_wrapper
-test_2 (void)
-{
-  struct ptr_wrapper r, s;
-  r.ptr = malloc (sizeof (int));
-  s = r;
-  return s;
-}
-
-struct nested
-{
-  struct ptr_wrapper w;
-};
-
-struct nested
-test_3 (void)
-{
-  struct nested n;
-  n.w.ptr = malloc (sizeof (int));
-  return n;
-}
-
-void test_4 (void)
-{
-  struct ptr_wrapper r;
-  r.ptr = malloc (sizeof (int)); /* { dg-message "allocated here" } */
-} /* { dg-warning "leak of 'r.ptr'" } */
-/* { dg-bogus "leak of '<unknown>'" "unknown leak" { target *-*-* } .-1 } */
-
-static struct ptr_wrapper __attribute__((noinline))
-called_by_test_5a (void)
-{
-  struct ptr_wrapper r;
-  r.ptr = malloc (sizeof (int)); /* { dg-message "allocated here" } */
-  return r;
-}
-
-void test_5a (void)
-{
-  struct ptr_wrapper q = called_by_test_5a ();  
-} /* { dg-warning "leak of 'q.ptr'" } */
-
-static struct ptr_wrapper __attribute__((noinline))
-called_by_test_5b (void)
-{
-  struct ptr_wrapper r;
-  r.ptr = malloc (sizeof (int));
-  return r; /* { dg-warning "leak of '<return-value>.ptr'" } */
-  /* TODO: show the allocation point; improve above message.  */
-}
-
-void test_5b (void)
-{
-  called_by_test_5b ();
-}
index ecc7144198b608ba05cdf8fce764504b2a432c51..e186ce430699c6d2a410b4d071618dbb414ba471 100644 (file)
@@ -1,14 +1,19 @@
+/* C only: C++ exceptions double the fopen leak warnings.
+   Therefore this test has been duplicated as
+   c-c++-common/analyzer/file-pr58237-noexcept.c  */
+
 typedef struct FILE   FILE;
 
 FILE* fopen (const char*, const char*);
 int   fclose (FILE*);
 char *fgets (char *, int, FILE *);
 
-#define NULL ((void *)0)
+#include "analyzer-decls.h"
 
 void f0(const char *str)
 {
   FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */
+  // ideally warning should be located at the end of the function
   char buf[10];
   fgets(buf, 10, fp);
 } /* { dg-warning "leak of FILE 'fp'" } */
@@ -16,6 +21,7 @@ void f0(const char *str)
 void f1(const char *str)
 {
   FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */
+  // ideally warning should be located at the end of the function
   char buf[10];
 
   while (fgets(buf, 10, fp) != NULL)
@@ -27,6 +33,7 @@ void f1(const char *str)
 void f2(const char *str, int flag)
 {
   FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */
+  // ideally warning should be located at the end of the function
   char buf[10];
 
   while (fgets(buf, 10, fp) != NULL)
@@ -65,7 +72,7 @@ void f4(const char *str)
   fclose(fp);
 }
 
-void main(int argc, const char * argv[])
+int main(int argc, const char * argv[])
 {
   FILE * fp = fopen(argv[0], "r");
   char buf[10];
index e5b00e93b6da44950b5236fbb77b8660627bd5c8..f59d9efd3e1959ea00077b1b069d09bc1348164c 100644 (file)
@@ -1,36 +1,9 @@
+/* C only: C++ FE fpermissive already emits an error for initializer
+   string too long.
+   C++ compatible parts have been moved into c-c++-common/analyzer/fopen-2.c  */
+
 typedef struct FILE FILE;
 FILE *fopen (const char *pathname, const char *mode);
-#define NULL ((void *)0)
-
-FILE *
-test_passthrough (const char *pathname, const char *mode)
-{
-  return fopen (pathname, mode);
-}
-
-FILE *
-test_null_pathname (const char *pathname, const char *mode)
-{
-  return fopen (NULL, mode);
-}
-
-FILE *
-test_null_mode (const char *pathname)
-{
-  return fopen (pathname, NULL);
-}
-
-FILE *
-test_simple_r (void)
-{
-  return fopen ("foo.txt", "r");
-}
-
-FILE *
-test_swapped_args (void)
-{
-  return fopen ("r", "foo.txt"); /* TODO: would be nice to detect this.  */
-}
 
 FILE *
 test_unterminated_pathname (const char *mode)
@@ -47,20 +20,3 @@ test_unterminated_mode (const char *filename)
   return fopen (filename, buf);  /* { dg-warning "stack-based buffer over-read" } */
   /* { dg-message "while looking for null terminator for argument 2 \\('&buf'\\) of 'fopen'..." "event" { target *-*-* } .-1 } */
 }
-
-FILE *
-test_uninitialized_pathname (const char *mode)
-{
-  char buf[10];
-  return fopen (buf, mode); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */  
-  /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of 'fopen'..." "event" { target *-*-* } .-1 } */
-}
-
-FILE *
-test_uninitialized_mode (const char *filename)
-{
-  char buf[10];
-  return fopen (filename, buf); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */  
-  /* { dg-message "while looking for null terminator for argument 2 \\('&buf'\\) of 'fopen'..." "event" { target *-*-* } .-1 } */
-}
-
diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-1.c b/gcc/testsuite/gcc.dg/analyzer/inlining-1.c
deleted file mode 100644 (file)
index a9797ea..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Verify that we can reconstruct fndecl and stack depth information
-   after early inlining.  */
-
-/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
-
-void foo (void *p)
-{
-  __builtin_free (p); /* { dg-warning "double-'free' of 'q'" "warning" } */
-  /* { dg-message "\\(3\\) first 'free' here \\(fndecl 'foo', depth 2\\)" "1st free message" { target *-*-* } .-1 } */
-  /* { dg-message "\\(5\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl 'foo', depth 2\\)" "2nd free message" { target *-*-* } .-2 } */
-}
-
-void bar (void *q) /* { dg-message "\\(1\\) entry to 'bar' \\(fndecl 'bar', depth 1\\)" } */
-{
-  foo (q); /* { dg-message "\\(2\\) inlined call to 'foo' from 'bar' \\(fndecl 'bar', depth 1\\)" } */
-  foo (q); /* { dg-message "\\(4\\) inlined call to 'foo' from 'bar' \\(fndecl 'bar', depth 1\\)" } */
-}
diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-2.c b/gcc/testsuite/gcc.dg/analyzer/inlining-2.c
deleted file mode 100644 (file)
index da06fa2..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Verify that we can reconstruct fndecl and stack depth information
-   after early inlining.  */
-
-/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
-
-static void __analyzer_foo (void *p)
-{
-  __builtin_free (p); /* { dg-message "\\(3\\) first 'free' here \\(fndecl '__analyzer_foo', depth 2\\)" "1st free message" } */
-
-  __builtin_free (p); /* { dg-warning "double-'free' of 'q'" "warning" } */
-  /* { dg-message "\\(4\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl '__analyzer_foo', depth 2\\)" "2nd free message" { target *-*-* } .-1 } */
-}
-
-void bar (void *q) /* { dg-message "\\(1\\) entry to 'bar' \\(fndecl 'bar', depth 1\\)" } */
-{
-  __analyzer_foo (q); /* { dg-message "\\(2\\) inlined call to '__analyzer_foo' from 'bar' \\(fndecl 'bar', depth 1\\)" } */
-}
diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-5.c b/gcc/testsuite/gcc.dg/analyzer/inlining-5.c
deleted file mode 100644 (file)
index 5104be0..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Verify that we can reconstruct fndecl and stack depth information
-   after early inlining.  */
-
-/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
-
-static inline void
-inner (void *p)
-{
-  __builtin_free (p); /* { dg-warning "double-'free' of 'r'" } */
-  /* { dg-message "\\(5\\) second 'free' here; first 'free' was at \\(3\\) \\(fndecl 'inner', depth 3\\)" "2nd free message" { target *-*-* } .-1 } */
-}
-
-static inline void
-middle (void *q)
-{
-  __builtin_free (q); /* { dg-message "\\(3\\) first 'free' here \\(fndecl 'middle', depth 2\\)" "1st free message" } */
-  inner (q); /* { dg-message "\\(4\\) inlined call to 'inner' from 'middle' \\(fndecl 'middle', depth 2\\)" } */
-}
-
-void
-outer (void *r) /* { dg-message "\\(1\\) entry to 'outer' \\(fndecl 'outer', depth 1\\)" } */
-{
-  middle (r); /* { dg-message "\\(2\\) inlined call to 'middle' from 'outer' \\(fndecl 'outer', depth 1\\)" } */
-}
diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-7.c b/gcc/testsuite/gcc.dg/analyzer/inlining-7.c
deleted file mode 100644 (file)
index fe04042..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Verify that we can reconstruct fndecl and stack depth information
-   after early inlining.  */
-
-/* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
-
-/* We want the reconstructed call/return hierarchy to show
-   that two calls happen at depth_3, without any spurious events
-   popping the stack back any further.  */
-
-static inline void
-depth_6 (void *p)
-{
-  __builtin_free (p); /* { dg-warning "double-'free' of 'p1'" "warning" } */
- /* { dg-message "\\(7\\) first 'free' here \\(fndecl 'depth_6', depth 6\\)" "1st free message" { target *-*-* } .-1 } */
- /* { dg-message "\\(11\\) second 'free' here; first 'free' was at \\(7\\) \\(fndecl 'depth_6', depth 6\\)" "2nd free message" { target *-*-* } .-2 } */
-}
-
-static inline void
-depth_5 (void *p5)
-{
-  depth_6 (p5); /* { dg-message "\\(6\\) inlined call to 'depth_6' from 'depth_5' \\(fndecl 'depth_5', depth 5\\)" "event 6" } */
-  /* { dg-message "\\(10\\) inlined call to 'depth_6' from 'depth_5' \\(fndecl 'depth_5', depth 5\\)" "event 10" { target *-*-* } .-1 } */
-}
-
-static inline void
-depth_4 (void *p4)
-{
-  depth_5 (p4); /* { dg-message "\\(5\\) inlined call to 'depth_5' from 'depth_4' \\(fndecl 'depth_4', depth 4\\)" "event 5" } */
-  /* { dg-message "\\(9\\) inlined call to 'depth_5' from 'depth_4' \\(fndecl 'depth_4', depth 4\\)" "event 9" { target *-*-* } .-1 } */
-}
-
-static inline void
-depth_3 (void *p3)
-{
-  depth_4 (p3); /* { dg-message "\\(4\\) inlined call to 'depth_4' from 'depth_3' \\(fndecl 'depth_3', depth 3\\)" } */
-  depth_4 (p3); /* { dg-message "\\(8\\) inlined call to 'depth_4' from 'depth_3' \\(fndecl 'depth_3', depth 3\\)" } */
-}
-
-static inline void
-depth_2 (void *p2)
-{
-  depth_3 (p2); /* { dg-message "\\(3\\) inlined call to 'depth_3' from 'depth_2' \\(fndecl 'depth_2', depth 2\\)" } */
-}
-
-void
-depth_1 (void *p1) /* { dg-message "\\(1\\) entry to 'depth_1' \\(fndecl 'depth_1', depth 1\\)" } */
-{
-  depth_2 (p1); /* { dg-message "\\(2\\) inlined call to 'depth_2' from 'depth_1' \\(fndecl 'depth_1', depth 1\\)" } */
-}
index 908bb28ee500c970738b14e5161c307f7b278439..058ae174effc2cdc314cee44ac5907b3d4efd1cf 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-Wno-incompatible-pointer-types" } */
+/* C only: Wno-incompatible-pointer-types is not valid for C++. */
 
 #include <stdlib.h>
 
@@ -7,7 +8,7 @@ struct bar;
 void *hv (struct foo **tm)
 {
   void *p = __builtin_malloc (4);
-  *tm = p;
+  *tm = (struct foo *) p;
   if (!p)
     abort ();
   return p;
@@ -16,5 +17,5 @@ void *hv (struct foo **tm)
 void a5 (void)
 {
   struct bar *qb = NULL;
-  hv (&qb);
+  hv ((struct foo **) &qb);
 } /* { dg-warning "leak of 'qb'" } */
index a3cacc07fab5e9a607bab3c358f4bc26ea17ffbd..83eec292e85da4798023791975f96c2e4da7a26b 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
 /* { dg-enable-nn-line-numbers "" } */
+/* C only: C++ exceptions mess up events. Therefore this test has been duplicated
+   as c-c++-common/analyzer/malloc-paths-9-noexcept.c */
 
 #include <stdlib.h>
 
index e9775b69ad0bf76d0b5879c624881672f5495e5d..95d4b17d18baf5e22ac720a8eeb6ea4818b4fdec 100644 (file)
@@ -1,5 +1,9 @@
 /* { dg-additional-options "-O2" } */
 
+/* C only: C++ FE optimizes argstr_get_word completely away
+   and therefore the number of SN diminishes compared to C,
+   making the analysis bails out early.  */
+
 extern void free (void *__ptr) __attribute__ ((__nothrow__ , __leaf__));
 
 enum pipecmd_tag
@@ -10,7 +14,7 @@ enum pipecmd_tag
 
 struct pipecmd {
  enum pipecmd_tag tag;
- union {
+ union pipecmd_union_t {
   struct pipecmd_process {
    int argc;
    int argv_max;
@@ -24,22 +28,30 @@ struct pipecmd {
  } u;
 };
 
+#ifdef __cplusplus
+typedef pipecmd::pipecmd_union_t::pipecmd_process pipecmd_process_t;
+typedef pipecmd::pipecmd_union_t::pipecmd_sequence pipecmd_sequence_t;
+#else
+typedef struct pipecmd_process pipecmd_process_t;
+typedef struct pipecmd_sequence pipecmd_sequence_t;
+#endif
+
 static char *argstr_get_word (const char **argstr)
 {
  while (**argstr) {
   switch (**argstr) {
    case ' ':
    case '\t':
-    return (void *) 0;
+    return (char *) ((void *) 0);
   }
  }
- return (void *) 0;
+ return (char *) ((void *) 0);
 }
 
 struct pipecmd *pipecmd_new_argstr (const char *argstr)
 {
  argstr_get_word (&argstr);
- return (void *) 0;
+ return (struct pipecmd *) ((void *) 0);
 }
 
 void pipecmd_free (struct pipecmd *cmd)
@@ -51,7 +63,7 @@ void pipecmd_free (struct pipecmd *cmd)
 
  switch (cmd->tag) {
   case PIPECMD_PROCESS: {
-   struct pipecmd_process *cmdp = &cmd->u.process;
+   pipecmd_process_t *cmdp = &cmd->u.process;
 
    for (i = 0; i < cmdp->argc; ++i)
     free (cmdp->argv[i]);
@@ -61,7 +73,7 @@ void pipecmd_free (struct pipecmd *cmd)
   }
 
   case PIPECMD_SEQUENCE: {
-   struct pipecmd_sequence *cmds = &cmd->u.sequence;
+   pipecmd_sequence_t *cmds = &cmd->u.sequence;
 
    for (i = 0; i < cmds->ncommands; ++i)
     pipecmd_free (cmds->commands[i]);
index a6af6f7019f0e4d2f18159021ef43548c2e7e0f9..74d1629f3c735addd6b6a28fa4672a9a3f53445f 100644 (file)
@@ -1,9 +1,13 @@
+/* C only: C++ exceptions cause a malloc leak after "safer" returns.
+   Therefore this test has been duplicated as
+   c-c++-common/analyzer/pr109577-noexcept.c  */
+
 void *malloc (unsigned long);
 
 double *
 unsafe (unsigned long n)
 {
-  return malloc (n * sizeof (double));
+  return (double *) malloc (n * sizeof (double));
 }
 
 double *
@@ -12,5 +16,5 @@ safer (unsigned long n)
   unsigned long nbytes;
   if (__builtin_mul_overflow (n, sizeof (double), &nbytes))
     return 0;
-  return malloc (nbytes);
+  return (double *) malloc (nbytes); /* Exceptions enabled cause a leak here. */
 }
index c7b49d28cbe170ae90a2ce1a867cfb4eb81b4039..11d2b616d42dd433731bde8e9791801901869525 100644 (file)
@@ -4,6 +4,10 @@
 
 /* { dg-do "compile" } */
 
+/* C only: C++ exceptions cause another fopen leak warning to be emitted at line 54.
+   Therefore this test has been duplicated as
+   c-c++-common/analyzer/pr93355-localealias-feasibility-noexcept.c  */
+
 /* Handle aliases for locale names.
    Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
    USA.  */
 
-/* Minimal version of system headers.  */
 
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+/* Minimal version of system headers.  */
 typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
 
 typedef struct _IO_FILE FILE;
 extern FILE *fopen (const char *__restrict __filename,
index 459357cf13813e987e728c60f9f0c6cbab72d3bf..ed19caf255c3d02636ac8c035111f3ff20a77f8a 100644 (file)
@@ -1,5 +1,9 @@
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 
+/* C only: C++ exceptions cause a Wanalyzer-va-list-leak warning to be emitted
+   at the end of commandrf. Therefore this test has been duplicated as
+   c-c++-common/analyzer/pr99193-1-noexcept.c  */
+
 /* Verify absence of false positive from -Wanalyzer-mismatching-deallocation
    on realloc(3).
    Based on https://github.com/libguestfs/libguestfs/blob/f19fd566f6387ce7e4d82409528c9dde374d25e0/daemon/command.c#L115
@@ -8,7 +12,7 @@
 typedef __SIZE_TYPE__ size_t;
 typedef __builtin_va_list va_list;
 
-#define NULL ((void *)0)
+#include "analyzer-decls.h"
 
 extern void *malloc (size_t __size)
   __attribute__ ((__nothrow__ , __leaf__))
@@ -36,7 +40,7 @@ commandrf (char **stdoutput, char **stderror, unsigned flags,
 
   /* Collect the command line arguments into an array. */
   i = 2;
-  argv = malloc (sizeof (char *) * i);
+  argv = (const char **) malloc (sizeof (char *) * i);
 
  if (argv == NULL) {
     perror ("malloc");
@@ -48,7 +52,7 @@ commandrf (char **stdoutput, char **stderror, unsigned flags,
   __builtin_va_start (args, name);
 
   while ((s = __builtin_va_arg (args, char *)) != NULL) {
-    const char **p = realloc (argv, sizeof (char *) * (++i)); /* { dg-bogus "'free'" } */
+    const char **p = (const char **) realloc (argv, sizeof (char *) * (++i)); /* { dg-bogus "'free'" } */
     if (p == NULL) {
       perror ("realloc");
       __builtin_va_end (args);