From: benjamin priour Date: Sat, 9 Sep 2023 16:03:56 +0000 (+0200) Subject: analyzer: Move gcc.dg/analyzer tests to c-c++-common (2) [PR96395] X-Git-Tag: basepoints/gcc-15~6316 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50b5199cff690891726877e1c00ac53dfb7cc1c8;p=thirdparty%2Fgcc.git analyzer: Move gcc.dg/analyzer tests to c-c++-common (2) [PR96395] 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 --- diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index a351e5cd214b..da1ec7c41b9e 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -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 diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-1.c b/gcc/testsuite/c-c++-common/analyzer/allocation-size-1.c 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 003914ed96cd..05efc4f8028a 100644 --- a/gcc/testsuite/gcc.dg/analyzer/allocation-size-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/allocation-size-1.c @@ -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 } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-2.c b/gcc/testsuite/c-c++-common/analyzer/allocation-size-2.c 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 eb770f73d4a4..ff4cb5634695 100644 --- a/gcc/testsuite/gcc.dg/analyzer/allocation-size-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/allocation-size-2.c @@ -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; } diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-3.c b/gcc/testsuite/c-c++-common/analyzer/allocation-size-3.c 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 6751441dd18f..4e99e881dff7 100644 --- a/gcc/testsuite/gcc.dg/analyzer/allocation-size-3.c +++ b/gcc/testsuite/c-c++-common/analyzer/allocation-size-3.c @@ -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); } diff --git a/gcc/testsuite/gcc.dg/analyzer/allocation-size-4.c b/gcc/testsuite/c-c++-common/analyzer/allocation-size-4.c 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 a56b25b4374d..7d07ba67316c 100644 --- a/gcc/testsuite/gcc.dg/analyzer/allocation-size-4.c +++ b/gcc/testsuite/c-c++-common/analyzer/allocation-size-4.c @@ -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 } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-0.c 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 f21cd3778241..24fe84deb14f 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c +++ b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-0.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-1.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 6d6e70a8ae11..e13437052584 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-1.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-2.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 3d3316af1f9a..0fd865485df9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-2.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-3.c b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-3.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 fb87d16f8334..ac699ec544e1 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-3.c +++ b/gcc/testsuite/c-c++-common/analyzer/analyzer-verbosity-3.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-1.c b/gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-1.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 eb3c6955e116..650d3f55b3f7 100644 --- a/gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-1.c @@ -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'; diff --git a/gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-2.c b/gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-2.c 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 7b787f959dcb..47f0ba44d005 100644 --- a/gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-2.c @@ -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) diff --git a/gcc/testsuite/gcc.dg/analyzer/call-summaries-malloc.c b/gcc/testsuite/c-c++-common/analyzer/call-summaries-malloc.c 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 87173a08d064..15c4c2e8fccc 100644 --- a/gcc/testsuite/gcc.dg/analyzer/call-summaries-malloc.c +++ b/gcc/testsuite/c-c++-common/analyzer/call-summaries-malloc.c @@ -6,11 +6,11 @@ #include #include -#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); diff --git a/gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158-2.c b/gcc/testsuite/c-c++-common/analyzer/call-summaries-pr107158-2.c 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 c2e9e2ba9f26..4561e10cafd0 100644 --- a/gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/call-summaries-pr107158-2.c @@ -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); diff --git a/gcc/testsuite/gcc.dg/analyzer/capacity-1.c b/gcc/testsuite/c-c++-common/analyzer/capacity-1.c 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 2d1248332966..ae31cedfe47a 100644 --- a/gcc/testsuite/gcc.dg/analyzer/capacity-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/capacity-1.c @@ -1,7 +1,7 @@ /* { dg-require-effective-target alloca } */ #include -#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 index 000000000000..0ab006d505ff --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/compound-assignment-1.c @@ -0,0 +1,72 @@ +#include + +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 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 '.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 '.ptr_wrapper::ptr'" "" { target c++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/dot-output.c b/gcc/testsuite/c-c++-common/analyzer/dot-output.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 03405cdf4a09..b1badd7e49d3 100644 --- a/gcc/testsuite/gcc.dg/analyzer/dot-output.c +++ b/gcc/testsuite/c-c++-common/analyzer/dot-output.c @@ -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++) diff --git a/gcc/testsuite/gcc.dg/analyzer/escaping-1.c b/gcc/testsuite/c-c++-common/analyzer/escaping-1.c 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 2dfd02b9ede5..b3896564ef87 100644 --- a/gcc/testsuite/gcc.dg/analyzer/escaping-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/escaping-1.c @@ -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 } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/expect-1.c b/gcc/testsuite/c-c++-common/analyzer/expect-1.c 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 e538f77741df..c2f72b4ba710 100644 --- a/gcc/testsuite/gcc.dg/analyzer/expect-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/expect-1.c @@ -1,4 +1,4 @@ -#define NULL ((void*)0) +#include "../../gcc.dg/analyzer/analyzer-decls.h" void *test_1 (void) { diff --git a/gcc/testsuite/gcc.dg/analyzer/fgets-1.c b/gcc/testsuite/c-c++-common/analyzer/fgets-1.c 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 e93d24c9de80..e67bb18a4919 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fgets-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/fgets-1.c @@ -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 index 000000000000..cdbbe00289a0 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/file-pr58237-noexcept.c @@ -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. */ +} diff --git a/gcc/testsuite/gcc.dg/analyzer/file-uninit-1.c b/gcc/testsuite/c-c++-common/analyzer/file-uninit-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/file-uninit-1.c rename to gcc/testsuite/c-c++-common/analyzer/file-uninit-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/fileno-1.c b/gcc/testsuite/c-c++-common/analyzer/fileno-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/fileno-1.c rename to gcc/testsuite/c-c++-common/analyzer/fileno-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/first-field-1.c b/gcc/testsuite/c-c++-common/analyzer/first-field-1.c 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 8b71e1abcae8..c11707d9aa62 100644 --- a/gcc/testsuite/gcc.dg/analyzer/first-field-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/first-field-1.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" typedef struct base_obj { diff --git a/gcc/testsuite/gcc.dg/analyzer/first-field-2.c b/gcc/testsuite/c-c++-common/analyzer/first-field-2.c 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 2fb98d3c9d72..8661e6e9efd0 100644 --- a/gcc/testsuite/gcc.dg/analyzer/first-field-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/first-field-2.c @@ -3,7 +3,7 @@ #include #include -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" typedef struct base_obj base_obj; typedef struct string_obj string_obj; diff --git a/gcc/testsuite/gcc.dg/analyzer/flex-with-call-summaries.c b/gcc/testsuite/c-c++-common/analyzer/flex-with-call-summaries.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/flex-with-call-summaries.c rename to gcc/testsuite/c-c++-common/analyzer/flex-with-call-summaries.c diff --git a/gcc/testsuite/gcc.dg/analyzer/flex-without-call-summaries.c b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c 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 5b4a9868c2f2..5369f7685c28 100644 --- a/gcc/testsuite/gcc.dg/analyzer/flex-without-call-summaries.c +++ b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c @@ -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) ); diff --git a/gcc/testsuite/gcc.dg/analyzer/flexible-array-member-1.c b/gcc/testsuite/c-c++-common/analyzer/flexible-array-member-1.c 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 2df085a43f23..82dbcec53592 100644 --- a/gcc/testsuite/gcc.dg/analyzer/flexible-array-member-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/flexible-array-member-1.c @@ -1,5 +1,6 @@ #include #include +#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); diff --git a/gcc/testsuite/gcc.dg/analyzer/fold-string-to-char.c b/gcc/testsuite/c-c++-common/analyzer/fold-string-to-char.c 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 46139216bbac..4eb08c072902 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fold-string-to-char.c +++ b/gcc/testsuite/c-c++-common/analyzer/fold-string-to-char.c @@ -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 index 000000000000..82087f2fe25a --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/fopen-2.c @@ -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 } */ +} + diff --git a/gcc/testsuite/gcc.dg/analyzer/fread-1.c b/gcc/testsuite/c-c++-common/analyzer/fread-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/fread-1.c rename to gcc/testsuite/c-c++-common/analyzer/fread-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/fread-2.c b/gcc/testsuite/c-c++-common/analyzer/fread-2.c 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 02a5e31cec63..d74d0555d23e 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fread-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/fread-2.c @@ -1,6 +1,6 @@ /* { dg-additional-options "-fdump-analyzer-untracked" } */ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" struct S { diff --git a/gcc/testsuite/gcc.dg/analyzer/fread-pr108661.c b/gcc/testsuite/c-c++-common/analyzer/fread-pr108661.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/fread-pr108661.c rename to gcc/testsuite/c-c++-common/analyzer/fread-pr108661.c diff --git a/gcc/testsuite/gcc.dg/analyzer/function-ptr-1.c b/gcc/testsuite/c-c++-common/analyzer/function-ptr-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/function-ptr-1.c rename to gcc/testsuite/c-c++-common/analyzer/function-ptr-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/function-ptr-2.c b/gcc/testsuite/c-c++-common/analyzer/function-ptr-2.c 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 fd25e3be40be..0a1e845d6c55 100644 --- a/gcc/testsuite/gcc.dg/analyzer/function-ptr-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/function-ptr-2.c @@ -1,5 +1,5 @@ #include -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" typedef void (*fn_ptr_t) (void *); diff --git a/gcc/testsuite/gcc.dg/analyzer/function-ptr-3.c b/gcc/testsuite/c-c++-common/analyzer/function-ptr-3.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/function-ptr-3.c rename to gcc/testsuite/c-c++-common/analyzer/function-ptr-3.c diff --git a/gcc/testsuite/gcc.dg/analyzer/function-ptr-4.c b/gcc/testsuite/c-c++-common/analyzer/function-ptr-4.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/function-ptr-4.c rename to gcc/testsuite/c-c++-common/analyzer/function-ptr-4.c diff --git a/gcc/testsuite/gcc.dg/analyzer/getc-1.c b/gcc/testsuite/c-c++-common/analyzer/getc-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/getc-1.c rename to gcc/testsuite/c-c++-common/analyzer/getc-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/getchar-1.c b/gcc/testsuite/c-c++-common/analyzer/getchar-1.c 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 0cc984bd2b34..157877dd4fb8 100644 --- a/gcc/testsuite/gcc.dg/analyzer/getchar-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/getchar-1.c @@ -1,7 +1,7 @@ /* { dg-skip-if "" { powerpc*-*-aix* } } */ #include -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" int test_1 (void) { diff --git a/gcc/testsuite/gcc.dg/analyzer/gzio-2.c b/gcc/testsuite/c-c++-common/analyzer/gzio-2.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/gzio-2.c rename to gcc/testsuite/c-c++-common/analyzer/gzio-2.c diff --git a/gcc/testsuite/gcc.dg/analyzer/gzio-3.c b/gcc/testsuite/c-c++-common/analyzer/gzio-3.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/gzio-3.c rename to gcc/testsuite/c-c++-common/analyzer/gzio-3.c diff --git a/gcc/testsuite/gcc.dg/analyzer/gzio-3a.c b/gcc/testsuite/c-c++-common/analyzer/gzio-3a.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/gzio-3a.c rename to gcc/testsuite/c-c++-common/analyzer/gzio-3a.c diff --git a/gcc/testsuite/gcc.dg/analyzer/gzio.c b/gcc/testsuite/c-c++-common/analyzer/gzio.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/gzio.c rename to gcc/testsuite/c-c++-common/analyzer/gzio.c diff --git a/gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c b/gcc/testsuite/c-c++-common/analyzer/imprecise-floating-point-1.c 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 7fe09fb826b9..cbe26589db00 100644 --- a/gcc/testsuite/gcc.dg/analyzer/imprecise-floating-point-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/imprecise-floating-point-1.c @@ -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; diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-2.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-2.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-2.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-2.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-3.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-3.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-3.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-3.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-limited-buggy.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-limited-buggy.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-limited-buggy.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-limited-buggy.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-limited.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-limited.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-limited.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-limited.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-unlimited-buggy.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-unlimited-buggy.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-unlimited-buggy.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-unlimited-buggy.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-unlimited.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-unlimited.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-4-unlimited.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-4-unlimited.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-5.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-5.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-5.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-5.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-alloca.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-alloca.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-alloca.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-alloca.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-inlining.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-inlining.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-inlining.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-inlining.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-1.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-1.c 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 e236dd48712d..21f38946678e 100644 --- a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-1.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-2.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-2.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 2c69dd508f0d..be4fb6cfd689 100644 --- a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-multiline-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-multiline-2.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-1.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-1.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-1a.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-1a.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-1a.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-1a.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-2.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-2.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-pr108935-2.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-pr108935-2.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion-variadic.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion-variadic.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion-variadic.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion-variadic.c diff --git a/gcc/testsuite/gcc.dg/analyzer/infinite-recursion.c b/gcc/testsuite/c-c++-common/analyzer/infinite-recursion.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/infinite-recursion.c rename to gcc/testsuite/c-c++-common/analyzer/infinite-recursion.c diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-1-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-1-multiline.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 79621f10e9be..cda5a7d38b98 100644 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-1-multiline.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-1-multiline.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-1-no-undo.c b/gcc/testsuite/c-c++-common/analyzer/inlining-1-no-undo.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 bad0f68fec05..d0d1b82d0427 100644 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-1-no-undo.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-1-no-undo.c @@ -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 index 000000000000..ed33e78bb419 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-1.c @@ -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 } */ +} diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-2-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-2-multiline.c 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 0a006b3a58fe..7a259a8b9976 100644 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-2-multiline.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-2-multiline.c @@ -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 index 000000000000..1561bee91f2d --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-2.c @@ -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 } */ +} diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-5-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-5-multiline.c 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 21b8fb978c89..8fefe380e9a2 100644 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-5-multiline.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-5-multiline.c @@ -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 index 000000000000..7b08c4bd5c48 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-5.c @@ -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 } */ +} diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-6-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-6-multiline.c 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 9cec6146f372..3fbf854cd926 100644 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-6-multiline.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-6-multiline.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-6.c b/gcc/testsuite/c-c++-common/analyzer/inlining-6.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/inlining-6.c rename to gcc/testsuite/c-c++-common/analyzer/inlining-6.c diff --git a/gcc/testsuite/gcc.dg/analyzer/inlining-7-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-7-multiline.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 956c6b90bb07..78fe4d4a6bf4 100644 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-7-multiline.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-7-multiline.c @@ -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 index 000000000000..960944fa8f73 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-7.c @@ -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 } */ +} diff --git a/gcc/testsuite/gcc.dg/analyzer/invalid-shift-1.c b/gcc/testsuite/c-c++-common/analyzer/invalid-shift-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/invalid-shift-1.c rename to gcc/testsuite/c-c++-common/analyzer/invalid-shift-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/isatty-1.c b/gcc/testsuite/c-c++-common/analyzer/isatty-1.c 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 3bb12c0db25b..c5d376da498f 100644 --- a/gcc/testsuite/gcc.dg/analyzer/isatty-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/isatty-1.c @@ -2,7 +2,7 @@ /* { dg-skip-if "" { "avr-*-*" } } */ #include -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" extern int isatty(int fd); extern int close(int fd); diff --git a/gcc/testsuite/gcc.dg/analyzer/leak-2.c b/gcc/testsuite/c-c++-common/analyzer/leak-2.c 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 bba3e816db76..d12850cdc6a5 100644 --- a/gcc/testsuite/gcc.dg/analyzer/leak-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/leak-2.c @@ -1,8 +1,9 @@ #include +#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'" } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/leak-3.c b/gcc/testsuite/c-c++-common/analyzer/leak-3.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/leak-3.c rename to gcc/testsuite/c-c++-common/analyzer/leak-3.c diff --git a/gcc/testsuite/gcc.dg/analyzer/leak-4.c b/gcc/testsuite/c-c++-common/analyzer/leak-4.c 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 75090e6be83b..ba5f2d26f4b4 100644 --- a/gcc/testsuite/gcc.dg/analyzer/leak-4.c +++ b/gcc/testsuite/c-c++-common/analyzer/leak-4.c @@ -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 ''" "leak of unknown" { target *-*-* } .-1 } */ /* TODO: rather than '', 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" } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c b/gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c 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 0172c9b324c7..1b657697ef40 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1-with-iter-obj.c @@ -1,6 +1,6 @@ #include -#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. */ diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c b/gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1.c 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 d49ed1304888..92ce3dc6a5d2 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-0-up-to-n-by-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-0-up-to-n-by-1.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(int n) { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-2.c b/gcc/testsuite/c-c++-common/analyzer/loop-2.c 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 f106722c2474..274d5080a51e 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-2.c @@ -1,5 +1,5 @@ /* { dg-additional-options "-fno-analyzer-state-purge" } */ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" struct s { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-2a.c b/gcc/testsuite/c-c++-common/analyzer/loop-2a.c 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 16b64497cb7d..212acf42dc7a 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-2a.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-2a.c @@ -1,5 +1,5 @@ /* { dg-additional-options "-fno-analyzer-state-purge" } */ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" union u { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-3.c b/gcc/testsuite/c-c++-common/analyzer/loop-3.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/loop-3.c rename to gcc/testsuite/c-c++-common/analyzer/loop-3.c diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-4.c b/gcc/testsuite/c-c++-common/analyzer/loop-4.c 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 b66a34594376..dd3104eeb2a7 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-4.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-4.c @@ -1,6 +1,6 @@ /* Example of nested loops. */ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(void) { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c b/gcc/testsuite/c-c++-common/analyzer/loop-n-down-to-1-by-1.c 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 553cd2f15dc4..1ab8abec8937 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-n-down-to-1-by-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-n-down-to-1-by-1.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(int n) { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c b/gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-1.c 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 3513bf423474..092cc9719067 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-1.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(int start, int end, int step) { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c b/gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-step.c 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 2692c503b5c9..f929f7ac60f9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-start-down-to-end-by-step.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-start-down-to-end-by-step.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(int start, int end, int step) { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c b/gcc/testsuite/c-c++-common/analyzer/loop-start-to-end-by-step.c 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 3fc1362d1cf9..71d9619db0c0 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-start-to-end-by-step.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-start-to-end-by-step.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(int start, int end, int step) { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c b/gcc/testsuite/c-c++-common/analyzer/loop-start-up-to-end-by-1.c 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 5e21890bfea1..629f592d453b 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop-start-up-to-end-by-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop-start-up-to-end-by-1.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(int start, int end) { diff --git a/gcc/testsuite/gcc.dg/analyzer/loop.c b/gcc/testsuite/c-c++-common/analyzer/loop.c similarity index 95% rename from gcc/testsuite/gcc.dg/analyzer/loop.c rename to gcc/testsuite/c-c++-common/analyzer/loop.c index c4cfd88c9122..33ac96c06e29 100644 --- a/gcc/testsuite/gcc.dg/analyzer/loop.c +++ b/gcc/testsuite/c-c++-common/analyzer/loop.c @@ -1,4 +1,4 @@ -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" void test(void) { diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-3.c b/gcc/testsuite/c-c++-common/analyzer/malloc-3.c 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 5afb6b3b0f7b..f4e647b25aa2 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-3.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-3.c @@ -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; } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-5.c b/gcc/testsuite/c-c++-common/analyzer/malloc-5.c 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 b75135f26a3f..3b2a4527ab58 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-5.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-5.c @@ -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); diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-CWE-401-example.c b/gcc/testsuite/c-c++-common/analyzer/malloc-CWE-401-example.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-401-example.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-CWE-401-example.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-CWE-415-examples.c b/gcc/testsuite/c-c++-common/analyzer/malloc-CWE-415-examples.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-415-examples.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-CWE-415-examples.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-CWE-416-examples.c b/gcc/testsuite/c-c++-common/analyzer/malloc-CWE-416-examples.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-CWE-416-examples.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-CWE-416-examples.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-CWE-590-examples.c b/gcc/testsuite/c-c++-common/analyzer/malloc-CWE-590-examples.c 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 9434f2df75f0..11ab017c12ae 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-CWE-590-examples.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-CWE-590-examples.c @@ -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 } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c b/gcc/testsuite/c-c++-common/analyzer/malloc-callbacks.c 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 cf3927fcaeaf..ccd6c01194f3 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-callbacks.c @@ -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" } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-dce.c b/gcc/testsuite/c-c++-common/analyzer/malloc-dce.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-dce.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-dce.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-dedupe-1.c b/gcc/testsuite/c-c++-common/analyzer/malloc-dedupe-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-dedupe-1.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-dedupe-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-in-loop.c b/gcc/testsuite/c-c++-common/analyzer/malloc-in-loop.c 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 a8c85a9c6188..b10715770243 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-in-loop.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-in-loop.c @@ -1,5 +1,5 @@ #include -#include "analyzer-decls.h" +#include "../../gcc.dg/analyzer/analyzer-decls.h" extern void foo (int *); diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-1.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-1.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-1.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-1.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-11.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-11.c 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 b65ff9165e4d..60501034bc32 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-11.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-11.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-2.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-2.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-2.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-2.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-3.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-3.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-3.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-3.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-4.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-4.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 82d50bd3c936..bd03d607872e 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-4.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-4.c @@ -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'" } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-5.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-5.c 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 c66ecb5c5635..ca8e6a511f5e 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-5.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-5.c @@ -2,7 +2,7 @@ static int *calls_malloc(void) { - return malloc(sizeof(int)); + return (int *) malloc(sizeof(int)); } int *test(void) diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-6.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-6.c similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-6.c rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-6.c diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-7.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-7.c 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 0742370d2f91..1fe70ddc8b2c 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-7.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-7.c @@ -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); } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-unchecked.c 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 320044753a18..5bc8e57827b6 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-unchecked.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-unchecked.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c b/gcc/testsuite/c-c++-common/analyzer/malloc-macro-inline-events.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 9134bb4781e5..d00d076b209a 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-inline-events.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-macro-inline-events.c @@ -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++ } } */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c b/gcc/testsuite/c-c++-common/analyzer/malloc-macro-separate-events.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 c56419eeb5a5..647b29c3aa40 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-macro-separate-events.c +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-macro-separate-events.c @@ -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/gcc.dg/analyzer/malloc-macro.h b/gcc/testsuite/c-c++-common/analyzer/malloc-macro.h similarity index 100% rename from gcc/testsuite/gcc.dg/analyzer/malloc-macro.h rename to gcc/testsuite/c-c++-common/analyzer/malloc-macro.h 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 index 000000000000..f914ed6216fa --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/malloc-paths-9-noexcept.c @@ -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 + +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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c b/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.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 1e4613cd1b10..1151d622519b 100644 --- a/gcc/testsuite/gcc.dg/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c +++ b/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c @@ -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; iContexts, entry); Free(entry->Name); - WuFreeContext(entry->Value); + WuFreeContext((WU_CONTEXT*)entry->Value); Free(entry); } ReleaseList(Expired); diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-1.c b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-1.c 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 93b379c173ab..868b8ee9b410 100644 --- a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-1.c @@ -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. */ diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-2.c b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-2.c 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 336f624441c7..e69614612fdb 100644 --- a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-2.c @@ -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)); diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-5.c 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 568f9cad199c..4d15b163f400 100644 --- a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-5.c +++ b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-5.c @@ -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); diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-11.c b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-11.c 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 f8eb1580eb35..d68ac8f25ba9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-11.c +++ b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-11.c @@ -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); diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-3.c 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 064f3fad47e2..43df9564a76a 100644 --- a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-3.c +++ b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-3.c @@ -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; diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-8.c b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-8.c 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 24d87357e2d4..81cd4ff3c4b1 100644 --- a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-8.c +++ b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-8.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/phi-1.c b/gcc/testsuite/c-c++-common/analyzer/phi-1.c 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 09260033fef6..7818935b9534 100644 --- a/gcc/testsuite/gcc.dg/analyzer/phi-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/phi-1.c @@ -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); diff --git a/gcc/testsuite/gcc.dg/analyzer/pr100615.c b/gcc/testsuite/c-c++-common/analyzer/pr100615.c similarity index 96% rename from gcc/testsuite/gcc.dg/analyzer/pr100615.c rename to gcc/testsuite/c-c++-common/analyzer/pr100615.c index 7a06f987d413..f4b29f47fe67 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr100615.c +++ b/gcc/testsuite/c-c++-common/analyzer/pr100615.c @@ -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__)) diff --git a/gcc/testsuite/gcc.dg/analyzer/pr103526.c b/gcc/testsuite/c-c++-common/analyzer/pr103526.c similarity index 85% rename from gcc/testsuite/gcc.dg/analyzer/pr103526.c rename to gcc/testsuite/c-c++-common/analyzer/pr103526.c index 39d60fd853e1..0388fc1df999 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr103526.c +++ b/gcc/testsuite/c-c++-common/analyzer/pr103526.c @@ -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 index 000000000000..4ff7a5b3ba8b --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/pr109577-noexcept.c @@ -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 index 000000000000..6ab14fb82c7c --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-feasibility-noexcept.c @@ -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; +} diff --git a/gcc/testsuite/gcc.dg/analyzer/pr94362-1.c b/gcc/testsuite/c-c++-common/analyzer/pr94362-1.c 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 1302cedb856e..a184636073f2 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr94362-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/pr94362-1.c @@ -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); } diff --git a/gcc/testsuite/gcc.dg/analyzer/pr97074.c b/gcc/testsuite/c-c++-common/analyzer/pr97074.c similarity index 87% rename from gcc/testsuite/gcc.dg/analyzer/pr97074.c rename to gcc/testsuite/c-c++-common/analyzer/pr97074.c index ccb3b61bd415..2dee9090bba7 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr97074.c +++ b/gcc/testsuite/c-c++-common/analyzer/pr97074.c @@ -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 index 000000000000..ac0d3dd6df53 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/pr99193-1-noexcept.c @@ -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; +} diff --git a/gcc/testsuite/c-c++-common/analyzer/pr99193-2.c b/gcc/testsuite/c-c++-common/analyzer/pr99193-2.c index 12326ef61f1c..f033a264dc82 100644 --- a/gcc/testsuite/c-c++-common/analyzer/pr99193-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/pr99193-2.c @@ -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) diff --git a/gcc/testsuite/c-c++-common/analyzer/realloc-1.c b/gcc/testsuite/c-c++-common/analyzer/realloc-1.c index 75e0b10e964b..04925cfe5adc 100644 --- a/gcc/testsuite/c-c++-common/analyzer/realloc-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/realloc-1.c @@ -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__)) diff --git a/gcc/testsuite/gcc.dg/analyzer/scope-1.c b/gcc/testsuite/c-c++-common/analyzer/scope-1.c 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 f8acffa18e41..09e62d46df35 100644 --- a/gcc/testsuite/gcc.dg/analyzer/scope-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/scope-1.c @@ -3,7 +3,7 @@ int test_1 (void) { { - int *q = malloc (1024); + int *q = (int *) malloc (1024); } return 42; /* { dg-warning "leak of 'q'" } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-2.c b/gcc/testsuite/c-c++-common/analyzer/setjmp-2.c 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 f5d9c53e2393..731a17293fc7 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-2.c +++ b/gcc/testsuite/c-c++-common/analyzer/setjmp-2.c @@ -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 -#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) { diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-5.c b/gcc/testsuite/c-c++-common/analyzer/setjmp-5.c 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 4787fa38032b..3133a473d51a 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-5.c +++ b/gcc/testsuite/c-c++-common/analyzer/setjmp-5.c @@ -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 -#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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-9.c b/gcc/testsuite/c-c++-common/analyzer/setjmp-9.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 c2b00e3b95c5..f7e940ea605b 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-9.c +++ b/gcc/testsuite/c-c++-common/analyzer/setjmp-9.c @@ -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 -#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 } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/signal-4a.c b/gcc/testsuite/c-c++-common/analyzer/signal-4a.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 4ee6f0e7d0e0..b5c6012ec2ec 100644 --- a/gcc/testsuite/gcc.dg/analyzer/signal-4a.c +++ b/gcc/testsuite/c-c++-common/analyzer/signal-4a.c @@ -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++ } } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/signal-4b.c b/gcc/testsuite/c-c++-common/analyzer/signal-4b.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 5a2ccb1def48..d2b5db7b2760 100644 --- a/gcc/testsuite/gcc.dg/analyzer/signal-4b.c +++ b/gcc/testsuite/c-c++-common/analyzer/signal-4b.c @@ -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 index 0f07818dcdd2..000000000000 --- a/gcc/testsuite/gcc.dg/analyzer/compound-assignment-1.c +++ /dev/null @@ -1,70 +0,0 @@ -#include - -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 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 '.ptr'" } */ - /* TODO: show the allocation point; improve above message. */ -} - -void test_5b (void) -{ - called_by_test_5b (); -} diff --git a/gcc/testsuite/gcc.dg/analyzer/file-pr58237.c b/gcc/testsuite/gcc.dg/analyzer/file-pr58237.c index ecc7144198b6..e186ce430699 100644 --- a/gcc/testsuite/gcc.dg/analyzer/file-pr58237.c +++ b/gcc/testsuite/gcc.dg/analyzer/file-pr58237.c @@ -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]; diff --git a/gcc/testsuite/gcc.dg/analyzer/fopen-1.c b/gcc/testsuite/gcc.dg/analyzer/fopen-1.c index e5b00e93b6da..f59d9efd3e19 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fopen-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/fopen-1.c @@ -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 index a9797eace191..000000000000 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-1.c +++ /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 index da06fa29d87b..000000000000 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-2.c +++ /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 index 5104be0c615c..000000000000 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-5.c +++ /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 index fe0404253b67..000000000000 --- a/gcc/testsuite/gcc.dg/analyzer/inlining-7.c +++ /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\\)" } */ -} diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-4.c b/gcc/testsuite/gcc.dg/analyzer/malloc-4.c index 908bb28ee500..058ae174effc 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-4.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-4.c @@ -1,4 +1,5 @@ /* { dg-additional-options "-Wno-incompatible-pointer-types" } */ +/* C only: Wno-incompatible-pointer-types is not valid for C++. */ #include @@ -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'" } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c index a3cacc07fab5..83eec292e85d 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-9.c @@ -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 diff --git a/gcc/testsuite/gcc.dg/analyzer/pr103892.c b/gcc/testsuite/gcc.dg/analyzer/pr103892.c index e9775b69ad0b..95d4b17d18ba 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr103892.c +++ b/gcc/testsuite/gcc.dg/analyzer/pr103892.c @@ -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]); diff --git a/gcc/testsuite/gcc.dg/analyzer/pr109577.c b/gcc/testsuite/gcc.dg/analyzer/pr109577.c index a6af6f7019f0..74d1629f3c73 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr109577.c +++ b/gcc/testsuite/gcc.dg/analyzer/pr109577.c @@ -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. */ } diff --git a/gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility.c b/gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility.c index c7b49d28cbe1..11d2b616d42d 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility.c +++ b/gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility.c @@ -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. @@ -22,10 +26,10 @@ 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, diff --git a/gcc/testsuite/gcc.dg/analyzer/pr99193-1.c b/gcc/testsuite/gcc.dg/analyzer/pr99193-1.c index 459357cf1381..ed19caf255c3 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr99193-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/pr99193-1.c @@ -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);