@@ -655,6 +655,43 @@ kf_memset::impl_call_pre (const call_details &cd) const
cd.maybe_set_lhs (dest_sval);
}
+/* Handler for "bzero" and "__builtin_bzero". */
+
+class kf_bzero : public builtin_known_function
+{
+public:
+ bool matches_call_types_p (const call_details &cd) const final override
+ {
+ return (cd.num_args () == 2
+ && cd.arg_is_pointer_p (0)
+ && cd.arg_is_size_p (1));
+ }
+ enum built_in_function builtin_code () const final override
+ {
+ return BUILT_IN_BZERO;
+ }
+
+ void impl_call_pre (const call_details &cd) const final override;
+};
+
+void
+kf_bzero::impl_call_pre (const call_details &cd) const
+{
+ region_model *model = cd.get_model ();
+ region_model_manager *mgr = cd.get_manager ();
+ const svalue *dest_sval = cd.get_arg_svalue (0);
+ const svalue *size_sval = cd.get_arg_svalue (1);
+ const region *dest_reg
+ = model->deref_rvalue (dest_sval, cd.get_arg_tree (0), cd.get_ctxt ());
+
+ const region *sized_reg
+ = mgr->get_sized_region (dest_reg, NULL_TREE, size_sval);
+ model->check_region_for_write (sized_reg,
+ nullptr,
+ cd.get_ctxt ());
+ model->zero_fill_region (sized_reg, cd.get_ctxt ());
+}
+
/* A subclass of pending_diagnostic for complaining about 'putenv'
called on an auto var. */
@@ -1852,6 +1889,8 @@ register_known_functions (known_function_manager &kfm)
{
kfm.add ("alloca", make_unique<kf_alloca> ());
kfm.add ("__builtin_alloca", make_unique<kf_alloca> ());
+ kfm.add ("bzero", make_unique<kf_bzero> ());
+ kfm.add ("__builtin_bzero", make_unique<kf_bzero> ());
kfm.add ("calloc", make_unique<kf_calloc> ());
kfm.add ("__builtin_calloc", make_unique<kf_calloc> ());
kfm.add ("free", make_unique<kf_free> ());
@@ -581,6 +581,116 @@ const struct c_common_resword c_common_reswords[] =
const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
+#if ENABLE_ANALYZER
+
+extern enum cpp_ttype c_lex_with_flags (tree *, location_t *, unsigned char *,
+ int);
+
+namespace ana {
+
+/* Implementation of translation_unit::lookup_constant_by_id for use by the
+ analyzer to look up named constants in the user's source code. */
+
+tree
+c_common_translation_unit::
+lookup_constant_by_id (tree id) const
+{
+ /* Consider decls. */
+ if (tree decl = lookup_name (id))
+ if (TREE_CODE (decl) == CONST_DECL) // TEST constexpr evaluates to const_decl in c++
+ if (tree value = DECL_INITIAL (decl)) // value from enum type evaluate to their literal string
+ if (TREE_CODE (value) == INTEGER_CST) // why no REAL_TYPE ?
+ return value;
+
+ /* Consider macros. */
+ cpp_hashnode *hashnode = C_CPP_HASHNODE (id);
+ if (cpp_macro_p (hashnode))
+ if (tree value = consider_macro (hashnode->value.macro))
+ return value;
+
+ return NULL_TREE;
+}
+
+tree
+c_common_translation_unit::
+lookup_type_by_id (tree id) const
+{
+ /* lookup_name will be linked to its C or C++ implementation
+ depending on the actual FE. */
+ if (tree type_decl = lookup_name (id))
+ if (TREE_CODE (type_decl) == TYPE_DECL)
+ {
+ tree record_type = TREE_TYPE (type_decl);
+ if (TREE_CODE (record_type) == RECORD_TYPE)
+ return record_type;
+ }
+
+ return NULL_TREE;
+}
+
+tree
+c_common_translation_unit::
+lookup_global_var_by_id (tree id) const
+{
+ if (tree var_decl = lookup_name (id))
+ if (TREE_CODE (var_decl) == VAR_DECL)
+ return var_decl;
+
+ return NULL_TREE;
+}
+
+/* Attempt to get an INTEGER_CST from MACRO.
+ Only handle the simplest cases: where MACRO's definition is a single
+ token containing a number, by lexing the number again.
+ This will handle e.g.
+ #define NAME 42
+ and other bases but not negative numbers, parentheses or e.g.
+ #define NAME 1 << 7
+ as doing so would require a parser. */
+
+tree
+c_common_translation_unit::consider_macro (cpp_macro *macro) const
+{
+ if (macro->paramc > 0)
+ return NULL_TREE;
+ if (macro->kind != cmk_macro)
+ return NULL_TREE;
+ if (macro->count != 1)
+ return NULL_TREE;
+ const cpp_token &tok = macro->exp.tokens[0];
+ if (tok.type != CPP_NUMBER)
+ return NULL_TREE;
+
+ cpp_reader *old_parse_in = parse_in;
+ parse_in = cpp_create_reader (CLK_GNUC89, NULL, line_table);
+
+ pretty_printer pp;
+ pp_string (&pp, (const char *) tok.val.str.text);
+ pp_newline (&pp);
+ cpp_push_buffer (parse_in,
+ (const unsigned char *) pp_formatted_text (&pp),
+ strlen (pp_formatted_text (&pp)),
+ 0);
+
+ tree value;
+ location_t loc;
+ unsigned char cpp_flags;
+ /* c_lex_with_flags is part of c-family. */
+ c_lex_with_flags (&value, &loc, &cpp_flags, 0);
+
+ cpp_destroy (parse_in);
+ parse_in = old_parse_in;
+
+ if (value && TREE_CODE (value) == INTEGER_CST)
+ return value;
+
+ return NULL_TREE;
+}
+
+} // namespace ana
+
+#endif /* #if ENABLE_ANALYZER */
+
/* Return identifier for address space AS. */
const char *
@@ -26,7 +26,6 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h"
#include "fold-const.h"
#include "wide-int-bitmask.h"
-
/* In order for the format checking to accept the C frontend
diagnostic framework extensions, you must include this file before
diagnostic-core.h, not after. The C front end formats are a subset of those
@@ -42,6 +41,7 @@ never after.
#define GCC_DIAG_STYLE __gcc_cdiag__
#endif
#include "diagnostic-core.h"
+#include "analyzer/analyzer-language.h"
/* Usage of TREE_LANG_FLAG_?:
0: IDENTIFIER_MARKED (used by search routines).
@@ -795,6 +795,33 @@ gnu_vector_type_p (const_tree type)
return VECTOR_TYPE_P (type) && !TYPE_INDIVISIBLE_P (type);
}
+#if ENABLE_ANALYZER
+
+namespace ana {
+
+/* Concrete implementation of ana::translation_unit for the C-family FE. */
+
+class c_common_translation_unit : public translation_unit
+{
+public:
+ /* Implementation of translation_unit::lookup_constant_by_id for use by the
+ analyzer to look up named constants in the user's source code. */
+ tree lookup_constant_by_id (tree id) const final override;
+
+ tree
+ lookup_type_by_id (tree id) const final override;
+
+ tree
+ lookup_global_var_by_id (tree id) const final override;
+
+private:
+ tree consider_macro (cpp_macro *macro) const;
+};
+
+} // namespace ana
+
+#endif /* #if ENABLE_ANALYZER */
+
struct visibility_flags
{
unsigned inpragma : 1; /* True when in #pragma GCC visibility. */
@@ -72,7 +72,6 @@ along with GCC; see the file COPYING3. If not see
#include "memmodel.h"
#include "c-family/known-headers.h"
#include "bitmap.h"
-#include "analyzer/analyzer-language.h"
#include "toplev.h"
/* We need to walk over decls with incomplete struct/union/enum types
@@ -1713,109 +1712,6 @@ static bool c_parser_objc_diagnose_bad_element_prefix
(c_parser *, struct c_declspecs *);
static location_t c_parser_parse_rtl_body (c_parser *, char *);
-#if ENABLE_ANALYZER
-
-namespace ana {
-
-/* Concrete implementation of ana::translation_unit for the C frontend. */
-
-class c_translation_unit : public translation_unit
-{
-public:
- /* Implementation of translation_unit::lookup_constant_by_id for use by the
- analyzer to look up named constants in the user's source code. */
- tree lookup_constant_by_id (tree id) const final override
- {
- /* Consider decls. */
- if (tree decl = lookup_name (id))
- if (TREE_CODE (decl) == CONST_DECL)
- if (tree value = DECL_INITIAL (decl))
- if (TREE_CODE (value) == INTEGER_CST)
- return value;
-
- /* Consider macros. */
- cpp_hashnode *hashnode = C_CPP_HASHNODE (id);
- if (cpp_macro_p (hashnode))
- if (tree value = consider_macro (hashnode->value.macro))
- return value;
-
- return NULL_TREE;
- }
-
- tree
- lookup_type_by_id (tree id) const final override
- {
- if (tree type_decl = lookup_name (id))
- if (TREE_CODE (type_decl) == TYPE_DECL)
- {
- tree record_type = TREE_TYPE (type_decl);
- if (TREE_CODE (record_type) == RECORD_TYPE)
- return record_type;
- }
-
- return NULL_TREE;
- }
-
- tree
- lookup_global_var_by_id (tree id) const final override
- {
- if (tree var_decl = lookup_name (id))
- if (TREE_CODE (var_decl) == VAR_DECL)
- return var_decl;
-
- return NULL_TREE;
- }
-
-private:
- /* Attempt to get an INTEGER_CST from MACRO.
- Only handle the simplest cases: where MACRO's definition is a single
- token containing a number, by lexing the number again.
- This will handle e.g.
- #define NAME 42
- and other bases but not negative numbers, parentheses or e.g.
- #define NAME 1 << 7
- as doing so would require a parser. */
- tree consider_macro (cpp_macro *macro) const
- {
- if (macro->paramc > 0)
- return NULL_TREE;
- if (macro->kind != cmk_macro)
- return NULL_TREE;
- if (macro->count != 1)
- return NULL_TREE;
- const cpp_token &tok = macro->exp.tokens[0];
- if (tok.type != CPP_NUMBER)
- return NULL_TREE;
-
- cpp_reader *old_parse_in = parse_in;
- parse_in = cpp_create_reader (CLK_GNUC89, NULL, line_table);
-
- pretty_printer pp;
- pp_string (&pp, (const char *) tok.val.str.text);
- pp_newline (&pp);
- cpp_push_buffer (parse_in,
- (const unsigned char *) pp_formatted_text (&pp),
- strlen (pp_formatted_text (&pp)),
- 0);
-
- tree value;
- location_t loc;
- unsigned char cpp_flags;
- c_lex_with_flags (&value, &loc, &cpp_flags, 0);
-
- cpp_destroy (parse_in);
- parse_in = old_parse_in;
-
- if (value && TREE_CODE (value) == INTEGER_CST)
- return value;
-
- return NULL_TREE;
- }
-};
-
-} // namespace ana
-
-#endif /* #if ENABLE_ANALYZER */
/* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
@@ -1881,7 +1777,7 @@ c_parser_translation_unit (c_parser *parser)
#if ENABLE_ANALYZER
if (flag_analyzer)
{
- ana::c_translation_unit tu;
+ ana::c_common_translation_unit tu;
ana::on_finish_translation_unit (tu);
}
#endif
@@ -5201,6 +5201,13 @@ cp_parser_translation_unit (cp_parser* parser)
/* Make sure the declarator obstack was fully cleaned up. */
gcc_assert (obstack_next_free (&declarator_obstack)
== declarator_obstack_base);
+#if ENABLE_ANALYZER
+ if (flag_analyzer)
+ {
+ ana::c_common_translation_unit tu;
+ ana::on_finish_translation_unit (tu);
+ }
+#endif
}
/* Return the appropriate tsubst flags for parsing, possibly in N3276
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/CVE-2005-1689-dedupe-issue-2.c
rename to gcc/testsuite/c-c++-common/analyzer/CVE-2005-1689-dedupe-issue-2.c
@@ -13,10 +13,14 @@ void
recvauth_common(krb5_data common)
{
free(common.data);
- free(common.data); /* { dg-warning "double-'free' of 'common.data'" "inner warning" } */
- /* { dg-warning "double-'free' of 'inbuf_a.data' " "inbuf_a warning" { target *-*-* } .-1 } */
- /* { dg-warning "double-'free' of 'inbuf_b.data' " "inbuf_b warning" { target *-*-* } .-2 } */
- /* { dg-message "2 duplicates" "duplicates notification" { xfail *-*-* } .-3 } */
+ free(common.data); /* { dg-line double_free } */
+ /* { dg-warning "double-'free' of 'common.data'" "inner warning" { target c } double_free } */
+ /* { dg-warning "double-'free' of 'common._krb5_data::data'" "inner warning" { target c++ } double_free } */
+ /* { dg-warning "double-'free' of 'inbuf_a.data' " "inbuf_a warning" { target c } double_free } */
+ /* { dg-warning "double-'free' of 'inbuf_a._krb5_data::data' " "inbuf_a warning" { target c++ } double_free } */
+ /* { dg-warning "double-'free' of 'inbuf_b.data' " "inbuf_b warning" { target c } double_free } */
+ /* { dg-warning "double-'free' of 'inbuf_b._krb5_data::data' " "inbuf_b warning" { target c++ } double_free } */
+ /* { dg-message "2 duplicates" "duplicates notification" { xfail *-*-* } double_free } */
}
void krb5_recvauth(krb5_data inbuf_a)
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c
rename to gcc/testsuite/c-c++-common/analyzer/CVE-2005-1689-dedupe-issue.c
similarity index 71%
rename from gcc/testsuite/gcc.dg/analyzer/CVE-2005-1689-minimal.c
rename to gcc/testsuite/c-c++-common/analyzer/CVE-2005-1689-minimal.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef struct _krb5_data {
char *data;
@@ -9,7 +9,8 @@ void
test_1 (krb5_data inbuf, int flag)
{
free(inbuf.data); /* { dg-message "first 'free' here" } */
- free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" } */
+ free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'inbuf._krb5_data::data'" "" { target c++ } .-1 } */
}
void
@@ -18,7 +19,8 @@ test_2 (krb5_data inbuf, int flag)
if (flag) {
free(inbuf.data); /* { dg-message "first 'free' here" } */
}
- free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" } */
+ free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'inbuf._krb5_data::data'" "" { target c++ } .-1 } */
}
void
@@ -27,7 +29,8 @@ test_3 (krb5_data inbuf, int flag)
if (flag) {
free((char *)inbuf.data); /* { dg-message "first 'free' here" } */
}
- free((char *)inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" } */
+ free((char *)inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'inbuf._krb5_data::data'" "" { target c++ } .-1 } */
}
extern void unknown_fn (void *);
@@ -37,7 +40,8 @@ test_4 (krb5_data inbuf)
{
unknown_fn (NULL);
free(inbuf.data); /* { dg-message "first 'free' here" } */
- free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" } */
+ free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'inbuf._krb5_data::data'" "" { target c++ } .-1 } */
}
void
@@ -45,8 +49,9 @@ test_5 (krb5_data inbuf)
{
unknown_fn (&inbuf);
free(inbuf.data); /* { dg-message "first 'free' here" } */
- free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "inbuf.data" } */
- /* { dg-bogus "double-'free' of 'inbuf'" "inbuf" { target *-*-* } .-1 } */
+ free(inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "inbuf.data" { target c } } */
+ /* { dg-warning "double-'free' of 'inbuf._krb5_data::data'" "inbuf.data" { target c++ } .-1 } */
+ /* { dg-bogus "double-'free' of 'inbuf'" "inbuf" { target *-*-* } .-2 } */
}
typedef struct _padded_krb5_data {
@@ -59,7 +64,8 @@ test_6 (padded_krb5_data inbuf)
{
unknown_fn (&inbuf.data);
free((char *)inbuf.data); /* { dg-message "first 'free' here" } */
- free((char *)inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "inbuf.data" } */
+ free((char *)inbuf.data); /* { dg-warning "double-'free' of 'inbuf.data'" "inbuf.data" { target c } } */
+ /* { dg-warning "double-'free' of 'inbuf._padded_krb5_data::data'" "inbuf.data" { target c++ } .-1 } */
}
void
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/CWE-131-examples.c
rename to gcc/testsuite/c-c++-common/analyzer/CWE-131-examples.c
@@ -127,7 +127,7 @@ void example_4 (DataPacket *packet)
if (numHeaders > 100) {
ExitError("too many headers!");
}
- headers = malloc(numHeaders * sizeof(PacketHeader)); /* TODO: ideally we'd warn about possible overflow here with negative numHeaders. */
+ headers = (PacketHeader *) malloc(numHeaders * sizeof(PacketHeader)); /* TODO: ideally we'd warn about possible overflow here with negative numHeaders. */
ParsePacketHeaders(packet, headers);
}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/attr-alloc_size-3.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-alloc_size-3.c
similarity index 99%
rename from gcc/testsuite/gcc.dg/analyzer/attr-const-1.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-const-1.c
@@ -1,6 +1,6 @@
/* Verify that we handle functions with __attribute__ ((const)) correctly. */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int nonconst_fn (int);
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/attr-const-2.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-const-2.c
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/attr-const-3.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-const-3.c
@@ -3,7 +3,7 @@
/* { dg-additional-options "--param analyzer-max-svalue-depth=4" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int const_fn_1 (int) __attribute__ ((const));
new file mode 100644
@@ -0,0 +1,37 @@
+/* { dg-additional-options "-fpermissive" { target c++ } } */
+
+extern int
+my_printf (void *my_object, const char *my_format, ...)
+ __attribute__ ((format (printf, 2, 3)));
+/* { dg-message "parameter 2 of 'my_printf' marked as a format string via 'format' attribute" "attr note" { target c } .-2 } */
+/* { dg-message "parameter 2 of 'int my_printf\\(void\\*, const char\\*, \\.\\.\\.\\)' marked as a format string via 'format' attribute" "attr note" { target c++ } .-3 } */
+/* { dg-message "argument 2 of 'my_printf' must be a pointer to a null-terminated string" "arg note" { target c } .-4 } */
+/* { dg-message "argument 2 of 'int my_printf\\(void\\*, const char\\*, \\.\\.\\.\\)' must be a pointer to a null-terminated string" "arg note" { target c++ } .-5 } */
+
+int test_empty (void *my_object, const char *msg)
+{
+ return my_printf (my_object, "");
+}
+
+int test_percent_s (void *my_object, const char *msg)
+{
+ return my_printf (my_object, "%s\n", msg);
+}
+
+int
+test_unterminated_format (void *my_object)
+{
+ char fmt[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */
+ return my_printf (my_object, fmt); /* { dg-warning "stack-based buffer over-read" } */
+ /* { dg-message "while looking for null terminator for argument 2 \\('&fmt'\\) of 'my_printf'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 2 \\('& fmt'\\) of 'int my_printf\\(void\\*, const char\\*, \\.\\.\\.\\)'..." "event" { target c++ } .-2 } */
+}
+
+int
+test_uninitialized_format (void *my_object)
+{
+ char fmt[10];
+ return my_printf (my_object, fmt); /* { dg-warning "use of uninitialized value 'fmt\\\[0\\\]'" } */
+ /* { dg-message "while looking for null terminator for argument 2 \\('&fmt'\\) of 'my_printf'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 2 \\('& fmt'\\) of 'int my_printf\\(void\\*, const char\\*, \\.\\.\\.\\)'..." "event" { target c++ } .-2 } */
+}
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-1.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-1.c
@@ -71,7 +71,8 @@ void test_7 ()
{
struct foo f;
foo_release (&f); /* { dg-warning "on the stack" "analyzer" } */
- /* { dg-warning "'foo_release' called on unallocated object 'f'" "non-analyzer" { target *-*-* } .-1 } */
+ /* { dg-warning "'foo_release' called on unallocated object 'f'" "non-analyzer" { target c } .-1 } */
+ /* { dg-warning "'void foo_release\\(foo\\*\\)' called on unallocated object 'f'" "non-analyzer" { target c++ } .-2 } */
}
int test_8 (struct foo *p)
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-2.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-2.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-4.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-4.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-5.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-5.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-misuses.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-misuses.c
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/attr-malloc-pr108252.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-malloc-pr108252.c
@@ -7,7 +7,7 @@ extern void foo_release (struct foo *);
extern struct foo *foo_acquire (void)
__attribute__ ((malloc (foo_release)));
-struct {
+static struct {
/* [...snip...] */
struct foo *listen_default_ciphers;
struct foo *connect_default_ciphers;
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/attr-nonnull-pr106325.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-nonnull-pr106325.c
@@ -1,3 +1,7 @@
+#ifdef __cplusplus
+#define _Bool bool
+#endif
+
typedef long int signed_frame_t;
typedef struct Track Track;
@@ -140,7 +144,7 @@ get_position_ptr (ArrangerObject *self, ArrangerObjectPositionType pos_type)
case ARRANGER_OBJECT_POSITION_TYPE_FADE_OUT:
return &self->fade_out_pos;
}
- return (((void *)0));
+ return ((Position *)((void *)0));
}
void
@@ -182,10 +186,10 @@ arranger_object_clone (const ArrangerObject *self)
if (!self)
{
g_return_if_fail_warning ("zrythm", ((const char *)(__func__)), "self");
- return (((void *)0));
+ return ((ArrangerObject *)((void *)0));
}
/* .... */
- return (((void *)0));
+ return ((ArrangerObject *)((void *)0));
}
__attribute__((nonnull(1, 2)))
@@ -201,7 +205,7 @@ arranger_object_unsplit (ArrangerObject *r1, ArrangerObject *r2,
|| clip_editor_region == (ZRegion *)r2)
{
set_clip_editor_region = 1;
- clip_editor_set_region (((zrythm)->project->clip_editor), ((void *)0),
+ clip_editor_set_region (((zrythm)->project->clip_editor), ((ZRegion *)0),
1);
}
@@ -219,7 +223,7 @@ arranger_object_unsplit (ArrangerObject *r1, ArrangerObject *r2,
case ARRANGER_OBJECT_TYPE_REGION:
{
ZRegion *r1_region = (ZRegion *)r1;
- AutomationTrack *at = ((void *)0);
+ AutomationTrack *at = ((AutomationTrack *)0);
if (r1_region->id.type == REGION_TYPE_AUTOMATION)
{
at = region_get_automation_track (r1_region);
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/attr-tainted_args-misuses.c
rename to gcc/testsuite/c-c++-common/analyzer/attr-tainted_args-misuses.c
similarity index 88%
rename from gcc/testsuite/gcc.dg/analyzer/attribute-nonnull.c
rename to gcc/testsuite/c-c++-common/analyzer/attribute-nonnull.c
@@ -1,11 +1,13 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
#include <stdlib.h>
-extern void foo(void *ptrA, void *ptrB, void *ptrC) /* { dg-message "argument 1 of 'foo' must be non-null" } */
+extern void foo(void *ptrA, void *ptrB, void *ptrC) /* { dg-message "argument 1 of 'foo' must be non-null" "" { target c } } */
+ /* { dg-message "argument 1 of 'void foo\\(void\\*, void\\*, void\\*\\)' must be non-null" "" { target c++ } .-1 } */
__attribute__((nonnull (1, 3)));
-extern void bar(void *ptrA, void *ptrB, void *ptrC) /* { dg-message "argument 1 of 'bar' must be non-null" } */
+extern void bar(void *ptrA, void *ptrB, void *ptrC) /* { dg-message "argument 1 of 'bar' must be non-null" "" { target c } } */
+ /* { dg-message "argument 1 of 'void bar\\(void\\*, void\\*, void\\*\\)' must be non-null" "" { target c++ } .-1 } */
__attribute__((nonnull));
// TODO: complain about NULL and possible NULL args
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/bitfields-1.c
rename to gcc/testsuite/c-c++-common/analyzer/bitfields-1.c
@@ -1,4 +1,8 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+#ifdef __cplusplus
+#define _Bool bool
+#endif
typedef unsigned char u8;
typedef unsigned __INT16_TYPE__ u16;
new file mode 100644
@@ -0,0 +1,510 @@
+/* Adapted from malloc-1.c, but wrapping the pointers in a struct. */
+
+/* { dg-require-effective-target alloca } */
+/* { dg-additional-options "-fpermissive -fno-exceptions" { target c++ } } */
+
+#include <stdlib.h>
+
+extern int foo (void);
+extern int bar (void);
+extern void could_free (void *);
+extern void cant_free (const void *); /* since it's a const void *. */
+
+typedef struct boxed_ptr { void *value; } boxed_ptr;
+
+boxed_ptr
+boxed_malloc (size_t sz)
+{
+ boxed_ptr result;
+ result.value = malloc (sz);
+ return result;
+}
+
+void boxed_free (boxed_ptr ptr)
+{
+ free (ptr.value);
+}
+
+const boxed_ptr boxed_null = {NULL};
+
+void test_1 (void)
+{
+ boxed_ptr ptr;
+ ptr.value = malloc (1024);
+ free (ptr.value);
+ free (ptr.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_2 (boxed_ptr ptr)
+{
+ free (ptr.value);
+ free (ptr.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+boxed_ptr
+test_3 (void)
+{
+ boxed_ptr ptr;
+ ptr.value = malloc (sizeof (int));
+ *(int *)ptr.value = 42; /* { dg-warning "dereference of possibly-NULL 'ptr.value' \\\[CWE-690\\\]" "" { target c } } */
+ /* { dg-warning "dereference of possibly-NULL 'ptr.boxed_ptr::value' \\\[CWE-690\\\]" "" { target c++ } .-1 } */
+ return ptr;
+}
+
+boxed_ptr
+test_4 (void)
+{
+ boxed_ptr ptr;
+ ptr.value = malloc (sizeof (int));
+ int *iptr = (int *)ptr.value;
+ if (iptr)
+ *iptr = 42;
+ else
+ *iptr = 43; /* { dg-warning "dereference of NULL 'iptr' \\\[CWE-476\\\]" } */
+ return ptr;
+}
+
+int test_5 (boxed_ptr ptr)
+{
+ free (ptr.value);
+ return *(int *)ptr.value; /* { dg-warning "use after 'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "use after 'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_6 (void *ptr)
+{
+ boxed_ptr q;
+ q.value = ptr;
+ free (ptr);
+ free (q.value); /* { dg-warning "double-'free' of 'ptr'" } */
+}
+
+void test_6a (boxed_ptr ptr)
+{
+ boxed_ptr q;
+ q = ptr;
+ boxed_free (ptr);
+ free (q.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_7 (void)
+{
+ boxed_ptr ptr = boxed_malloc(4096);
+ if (!ptr.value)
+ return;
+ __builtin_memset(ptr.value, 0, 4096);
+ boxed_free(ptr);
+}
+
+boxed_ptr test_8 (void)
+{
+ boxed_ptr ptr = boxed_malloc(4096);
+ if (!ptr.value)
+ return boxed_null;
+ __builtin_memset(ptr.value, 0, 4096);
+ return ptr;
+}
+
+void test_9 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+
+ int i;
+ for (i = 0; i < 1024; i++)
+ free (ptr.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_10 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+
+ int i;
+ for (i = 0; i < 1024; i++)
+ foo ();
+
+ free (ptr.value);
+ free (ptr.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_11 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+
+ while (foo ())
+ bar ();
+
+ free (ptr.value);
+ free (ptr.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_12 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+
+ while (1)
+ {
+ free (ptr.value);
+ free (ptr.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+ }
+}
+
+void test_13 (void)
+{
+ boxed_ptr p = boxed_malloc (1024);
+ boxed_ptr q = boxed_malloc (1024);
+
+ foo ();
+ if (!q.value)
+ {
+ boxed_free (q);
+ return; /* { dg-warning "leak of 'p.value'" "" { target c } } */
+ /* { dg-warning "leak of 'p.boxed_ptr::value'" "" { target c++ } .-1 } */
+ }
+ bar ();
+ boxed_free (q);
+ boxed_free (p);
+}
+
+void test_14 (void)
+{
+ boxed_ptr p, q;
+ p = boxed_malloc (1024);
+ if (!p.value)
+ return;
+
+ q = boxed_malloc (1024);
+ if (!q.value)
+ {
+ boxed_free (p);
+ boxed_free (q);
+ /* oops: missing "return". */
+ }
+ bar ();
+ boxed_free (q); /* Although this looks like a double-'free' of q,
+ it's known to be NULL for the case where free is
+ called twice on it. */
+ free (p.value); /* { dg-warning "double-'free' of 'p.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'p.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_15 (void)
+{
+ boxed_ptr p, q;
+ p.value = NULL;
+ q.value = NULL;
+
+ p = boxed_malloc (1024);
+ if (!p.value)
+ goto fail;
+
+ foo ();
+
+ q = boxed_malloc (1024);
+ if (!q.value)
+ goto fail;
+
+ bar ();
+
+ fail:
+ boxed_free (q);
+ boxed_free (p);
+}
+
+void test_16 (void)
+{
+ boxed_ptr p, q; /* { dg-message "region created on stack here" } */
+
+ p = boxed_malloc (1024);
+ if (!p.value)
+ goto fail;
+
+ foo ();
+
+ q = boxed_malloc (1024);
+ if (!q.value)
+ goto fail;
+
+ bar ();
+
+ fail:
+ boxed_free (q); /* { dg-warning "use of uninitialized value 'q'" } */
+ boxed_free (p);
+}
+
+void test_17 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+} /* { dg-warning "leak of 'ptr.value'" "" { target c } } */
+/* { dg-warning "leak of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+
+void test_18 (void)
+{
+ boxed_ptr ptr = boxed_malloc (64);
+ ptr = boxed_null; /* { dg-warning "leak of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "leak of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_18a (void)
+{
+ boxed_ptr ptr = boxed_malloc (64);
+ ptr.value = NULL; /* { dg-warning "leak of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "leak of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_19 (void)
+{
+ boxed_ptr ptr = boxed_malloc (64);
+ free (ptr.value);
+ ptr.value = NULL;
+ free (ptr.value);
+}
+
+boxed_ptr global_ptr_20;
+
+void test_20 (void)
+{
+ global_ptr_20 = boxed_malloc (1024);
+}
+
+int *test_21 (int i)
+{
+ boxed_ptr ptr = boxed_malloc (sizeof (int));
+ if (!ptr.value)
+ abort ();
+ *(int *)ptr.value = i;
+ return (int *)ptr.value;
+}
+
+boxed_ptr test_21a (int i)
+{
+ boxed_ptr ptr = boxed_malloc (sizeof (int));
+ if (!ptr.value)
+ abort ();
+ *(int *)ptr.value = i;
+ return ptr;
+}
+
+void test_22 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+
+ int i;
+ for (i = 5; i < 10; i++)
+ foo ();
+
+ free (ptr.value);
+ free (ptr.value); /* { dg-warning "double-'free' of 'ptr.value'" "" { target c } } */
+ /* { dg-warning "double-'free' of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+}
+
+void test_24 (void)
+{
+ boxed_ptr ptr;
+ ptr.value = __builtin_alloca (sizeof (int)); /* { dg-message "region created on stack here" } */
+ free (ptr.value); /* { dg-warning "'free' of 'ptr.value' which points to memory on the stack \\\[CWE-590\\\]" "" { target c } } */
+ /* { dg-warning "'free' of 'ptr.boxed_ptr::value' which points to memory on the stack \\\[CWE-590\\\]" "" { target c++ } .-1 } */
+}
+
+void test_25 (void)
+{
+ char tmp[100]; /* { dg-message "region created on stack here" } */
+ boxed_ptr p;
+ p.value = tmp;
+ free (p.value); /* { dg-warning "'free' of '& ?tmp' which points to memory on the stack \\\[CWE-590\\\]" } */
+}
+
+char global_buffer[100]; /* { dg-message "region created here" } */
+
+void test_26 (void)
+{
+ boxed_ptr p;
+ p.value = global_buffer;
+ free (p.value); /* { dg-warning "'free' of '& ?global_buffer' which points to memory not on the heap \\\[CWE-590\\\]" } */
+}
+
+struct coord {
+ float x;
+ float y;
+};
+
+boxed_ptr test_27 (void)
+{
+ boxed_ptr p = boxed_malloc (sizeof (struct coord));
+ ((struct coord *)p.value)->x = 0.f; /* { dg-warning "dereference of possibly-NULL 'p.value' \\\[CWE-690\\\]" "" { target c } } */
+ /* { dg-warning "dereference of possibly-NULL 'p.boxed_ptr::value' \\\[CWE-690\\\]" "" { target c++ } .-1 } */
+
+ /* Only the first such usage should be reported: */
+ ((struct coord *)p.value)->y = 0.f;
+
+ return p;
+}
+
+struct link
+{
+ boxed_ptr m_ptr;
+};
+
+boxed_ptr test_29 (void)
+{
+ boxed_ptr res = boxed_malloc (sizeof (struct link));
+ if (!res.value)
+ return boxed_null;
+ ((struct link *)res.value)->m_ptr = boxed_malloc (sizeof (struct link));
+ return res;
+}
+
+void test_31 (void)
+{
+ struct link tmp;
+ boxed_ptr ptr = boxed_malloc (sizeof (struct link));
+ tmp.m_ptr = ptr;
+} /* { dg-warning "leak" } */
+
+void test_32 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+ could_free (ptr.value);
+} /* { dg-bogus "leak" } */
+
+void test_33 (void)
+{
+ boxed_ptr ptr = boxed_malloc (1024);
+ cant_free (ptr.value);
+} /* { dg-warning "leak of 'ptr.value'" "" { target c } } */
+/* { dg-warning "leak of 'ptr.boxed_ptr::value'" "" { target c++ } .-1 } */
+
+void test_34 (void)
+{
+ float *q;
+ boxed_ptr p = boxed_malloc (sizeof (struct coord));
+ if (!p.value)
+ return;
+ ((struct coord *)p.value)->x = 0.0f;
+ q = &((struct coord *)p.value)->x;
+ boxed_free (p);
+ *q = 1.0f; /* { dg-warning "use after 'free' of 'q'" } */
+};
+
+int test_35 (void)
+{
+ boxed_ptr ptr = boxed_malloc(4096);
+ if (!ptr.value)
+ return -1;
+ __builtin_memset(ptr.value, 0, 4096);
+ boxed_free(ptr);
+ return 0;
+}
+
+void test_36 (void)
+{
+ boxed_ptr ptr = boxed_malloc(4096);
+ if (!ptr.value)
+ return;
+ __builtin_memset(ptr.value, 0, 4096);
+ boxed_free(ptr);
+}
+
+boxed_ptr test_37a (void)
+{
+ boxed_ptr ptr = boxed_malloc(4096);
+ __builtin_memset(ptr.value, 0, 4096); /* { dg-warning "use of possibly-NULL 'ptr.value' where non-null expected \\\[CWE-690\\\]" "" { target c } } */
+ /* { dg-warning "use of possibly-NULL 'ptr.boxed_ptr::value' where non-null expected \\\[CWE-690\\\]" "" { target c++ } .-1 } */
+ return ptr;
+}
+
+int test_37b (void)
+{
+ boxed_ptr p = boxed_malloc(4096);
+ boxed_ptr q = boxed_malloc(4096);
+ if (p.value) {
+ __builtin_memset(p.value, 0, 4096); /* Not a bug: checked */
+ } else {
+ __builtin_memset(q.value, 0, 4096); /* { dg-warning "use of possibly-NULL 'q.value' where non-null expected \\\[CWE-690\\\]" "" { target c } } */
+ /* { dg-warning "use of possibly-NULL 'q.boxed_ptr::value' where non-null expected \\\[CWE-690\\\]" "" { target c++ } .-1 } */
+ }
+ boxed_free(p);
+ boxed_free(q);
+ return 0;
+}
+
+extern void might_use_ptr (void *ptr);
+
+void test_38(int i)
+{
+ boxed_ptr p;
+
+ p = boxed_malloc(1024);
+ if (p.value) {
+ boxed_free(p);
+ might_use_ptr(p.value); /* { dg-warning "use after 'free' of 'p.value'" "" { xfail *-*-* } } */
+ /* { dg-warning "use after 'free' of 'p.boxed_ptr::value'" "" { xfail *-*-* } .-1 } */
+ // TODO: xfail
+ }
+}
+
+boxed_ptr
+test_39 (int i)
+{
+ boxed_ptr p = boxed_malloc(sizeof(int*));
+ *(int *)p.value = i; /* { dg-warning "dereference of possibly-NULL 'p.value' \\\[CWE-690\\\]" "" { target c } } */
+ /* { dg-warning "dereference of possibly-NULL 'p.boxed_ptr::value' \\\[CWE-690\\\]" "" { target c++ } .-1 } */
+ return p;
+}
+
+boxed_ptr
+test_41 (int flag)
+{
+ boxed_ptr buffer;
+
+ if (flag) {
+ buffer = boxed_malloc(4096);
+ } else {
+ buffer = boxed_null;
+ }
+
+ ((char *)buffer.value)[0] = 'a'; /* { dg-warning "dereference of possibly-NULL 'buffer.value' \\\[CWE-690\\\]" "possibly-NULL" { target c } } */
+ /* { dg-warning "dereference of possibly-NULL 'buffer.boxed_ptr::value' \\\[CWE-690\\\]" "possibly-NULL" { target c++ } .-1 } */
+ /* { dg-warning "dereference of NULL" "NULL" { target *-*-* } .-2 } */
+
+ return buffer;
+}
+
+extern void might_take_ownership (boxed_ptr ptr);
+
+void test_45 (void)
+{
+ boxed_ptr p = boxed_malloc (1024);
+ might_take_ownership (p);
+}
+
+/* Free of function, and of label within function. */
+
+void test_50a (void)
+{
+}
+
+void test_50b (void)
+{
+ boxed_ptr ptr;
+ ptr.value = test_50a; /* { dg-warning "invalid conversion from '\[^\n\]*' to 'void\\*" "fpermissive" { target c++ } } */
+ free (ptr.value); /* { dg-warning "'free' of '&test_50a' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c } } */
+ /* { dg-warning "'free' of 'test_50a' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c++ } .-1 } */
+}
+
+void test_50c (void)
+{
+ my_label:
+ boxed_ptr ptr;
+ ptr.value = &&my_label;
+ free (ptr.value); /* { dg-warning "'free' of '&my_label' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c } } */
+ /* { dg-warning "'free' of '&& my_label' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c++ } .-1 } */
+}
+
+/* { dg-prune-output "\\\[-Wfree-nonheap-object" } */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/builtins-pr107565.c
rename to gcc/testsuite/c-c++-common/analyzer/builtins-pr107565.c
similarity index 82%
rename from gcc/testsuite/gcc.dg/analyzer/bzero-1.c
rename to gcc/testsuite/c-c++-common/analyzer/bzero-1.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern void bzero(void *s, __SIZE_TYPE__ n);
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/bzip2-arg-parse-1.c
rename to gcc/testsuite/c-c++-common/analyzer/bzip2-arg-parse-1.c
@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <stdio.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* This test file has been heavily modified from the bzip2.c original,
which has the following license boilerplate. */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-1.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-1.c
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-2.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-2.c
@@ -6,7 +6,7 @@
TODO: add some kind of test that summarization *was* used. */
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int external_fn (void *);
@@ -23,7 +23,8 @@ void test_summarized_returns_const (void)
void test_summarized_returns_const_2 (void)
{
- returns_const (); /* { dg-message "when 'returns_const' returns" } */
+ returns_const (); /* { dg-message "when 'returns_const' returns" "" { target c } } */
+ /* { dg-message "when 'int returns_const\\(\\)' returns" "" { target c++ } .-1 } */
__analyzer_dump_path (); /* { dg-message "path" } */
}
@@ -467,7 +468,7 @@ int test_returns_external_result (void)
int uses_alloca (int i)
{
- int *p = __builtin_alloca (sizeof (int));
+ int *p = (int *)__builtin_alloca (sizeof (int));
*p = i;
return *p;
}
@@ -510,7 +511,7 @@ int consume_two_ints_from_va_list (__builtin_va_list ap)
return i * j;
}
-int test_consume_two_ints_from_va_list (__builtin_va_list ap1)
+void test_consume_two_ints_from_va_list (__builtin_va_list ap1)
{
int p1, p2;
__builtin_va_list ap2;
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-3.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-3.c
@@ -4,7 +4,7 @@
call-summarization code to be used.
TODO: add some kind of test that summarization *was* used. */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* With state merging disabled, we get two summaries here. */
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-asm-x86.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-asm-x86.c
@@ -1,7 +1,7 @@
/* { dg-do compile { target x86_64-*-* } } */
/* { dg-additional-options "-fanalyzer-call-summaries --param analyzer-min-snodes-for-call-summary=0" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
int returns_asm_value (void)
{
similarity index 83%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-errno.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-errno.c
@@ -1,7 +1,7 @@
/* { dg-additional-options "-fanalyzer-call-summaries" } */
#include <errno.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void sets_errno (int x)
{
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107072.c
rename to gcc/testsuite/c-c++-common/analyzer/call-summaries-pr107072.c
@@ -8,6 +8,10 @@
/* Reduced from an example in Emacs in which string_char_and_length
was being incorrectly summarized, failing to see the write to *length. */
+#ifdef __cplusplus
+#define _Bool bool
+#endif
+
typedef long int ptrdiff_t;
typedef struct Lisp_X *Lisp_Word;
typedef Lisp_Word Lisp_Object;
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/callbacks-1.c
rename to gcc/testsuite/c-c++-common/analyzer/callbacks-1.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/callbacks-2.c
rename to gcc/testsuite/c-c++-common/analyzer/callbacks-2.c
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/callbacks-3.c
rename to gcc/testsuite/c-c++-common/analyzer/callbacks-3.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef __SIZE_TYPE__ size_t;
typedef int (*__compar_fn_t)(const void *, const void *);
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/capacity-2.c
rename to gcc/testsuite/c-c++-common/analyzer/capacity-2.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern void might_realloc (void *);
extern void cant_realloc (const void *);
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/capacity-3.c
rename to gcc/testsuite/c-c++-common/analyzer/capacity-3.c
@@ -1,7 +1,7 @@
/* { dg-require-effective-target alloca } */
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
static void __attribute__((noinline))
__analyzer_callee_1 (size_t inner_sz)
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/casts-1.c
rename to gcc/testsuite/c-c++-common/analyzer/casts-1.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct s1
{
similarity index 84%
rename from gcc/testsuite/gcc.dg/analyzer/casts-2.c
rename to gcc/testsuite/c-c++-common/analyzer/casts-2.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test_1 (int i)
{
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/clobbers-1.c
rename to gcc/testsuite/c-c++-common/analyzer/clobbers-1.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct foo
{
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/clobbers-2.c
rename to gcc/testsuite/c-c++-common/analyzer/clobbers-2.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef __SIZE_TYPE__ size_t;
extern void bzero (void *s, size_t n);
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/combined-conditionals-1.c
rename to gcc/testsuite/c-c++-common/analyzer/combined-conditionals-1.c
@@ -1,6 +1,6 @@
/* Verify that we correctly consolidate conditionals in paths. */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int foo ();
extern int bar ();
@@ -48,7 +48,7 @@ void test_6 (void)
__analyzer_dump_path (); /* { dg-message "\\(2\\) \\.\\.\\.to here" } */
}
-int test_7 (void)
+void test_7 (void)
{
if (foo () ? bar () ? baz () : 0 : 0) /* { dg-message "\\(1\\) following 'true' branch\\.\\.\\." } */
__analyzer_dump_path (); /* { dg-message "\\(2\\) \\.\\.\\.to here" } */
similarity index 53%
rename from gcc/testsuite/gcc.dg/analyzer/compound-assignment-2.c
rename to gcc/testsuite/c-c++-common/analyzer/compound-assignment-2.c
@@ -14,11 +14,12 @@ test_1 (void)
return aw1;
}
-struct array_wrapper
-test_2 (void)
+void test_2 (void)
{
struct array_wrapper aw2;
aw2.ptrs[0] = malloc (1024);
aw2.ptrs[1] = malloc (512);
-} /* { dg-warning "leak of 'aw2.ptrs.0.'" "leak of element 0" } */
-/* { dg-warning "leak of 'aw2.ptrs.1.'" "leak of element 1" { target *-*-* } .-1 } */
+} /* { dg-warning "leak of 'aw2.ptrs.0.'" "leak of element 0" { target c } } */
+/* { dg-warning "leak of 'aw2.array_wrapper::ptrs.0.'" "leak of element 0" { target c++ } .-1 } */
+/* { dg-warning "leak of 'aw2.ptrs.1.'" "leak of element 1" { target c } .-2 } */
+/* { dg-warning "leak of 'aw2.array_wrapper::ptrs.1.'" "leak of element 1" { target c++ } .-3 } */
similarity index 57%
rename from gcc/testsuite/gcc.dg/analyzer/compound-assignment-3.c
rename to gcc/testsuite/c-c++-common/analyzer/compound-assignment-3.c
@@ -17,9 +17,9 @@ test_1 (void)
return uw1;
}
-struct union_wrapper
-test_2 (void)
+void test_2 (void)
{
struct union_wrapper uw2;
uw2.u.ptr = malloc (1024);
-} /* { dg-warning "leak of 'uw2.u.ptr'" } */
+} /* { dg-warning "leak of 'uw2.u.ptr'" "" { target c } } */
+ /* { dg-warning "leak of 'uw2.union_wrapper::u.union_wrapper::<unnamed union>::ptr'" "" { target c++ } .-1 } */
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/compound-assignment-4.c
rename to gcc/testsuite/c-c++-common/analyzer/compound-assignment-4.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct coord
{
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/conditionals-3.c
rename to gcc/testsuite/c-c++-common/analyzer/conditionals-3.c
@@ -1,6 +1,6 @@
/* { dg-additional-options "-fno-analyzer-state-merge" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
static void __analyzer_only_called_when_flag_a_true (int i)
{
@@ -12,7 +12,7 @@ static void __analyzer_only_called_when_flag_b_true (int i)
__analyzer_eval (i == 17); /* { dg-warning "TRUE" } */
}
-int test_1 (int flag_a, int flag_b)
+void test_1 (int flag_a, int flag_b)
{
int i = 17;
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/conditionals-notrans.c
rename to gcc/testsuite/c-c++-common/analyzer/conditionals-notrans.c
@@ -1,5 +1,5 @@
/* { dg-additional-options "-fno-analyzer-transitivity" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test (int i, int j)
{
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/conditionals-trans.c
rename to gcc/testsuite/c-c++-common/analyzer/conditionals-trans.c
@@ -1,5 +1,5 @@
/* { dg-additional-options "-fanalyzer-transitivity" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test (int i, int j)
{
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-1.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-1.c
@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct foo
{
@@ -146,7 +146,7 @@ int test_12 (void)
/* alloca results should be unique. */
__analyzer_eval (p == q); /* { dg-warning "FALSE" } */
- return *(int *)p; /* { dg-warning "use of uninitialized value '\\*\\(int \\*\\)p" } */
+ return *(int *)p; /* { dg-warning "use of uninitialized value '\\*\\(int ?\\*\\)p" } */
}
/* Use of uninit value. */
@@ -179,7 +179,7 @@ struct coord
long y;
};
-int test_12d (struct coord c)
+void test_12d (struct coord c)
{
struct coord d;
d = c;
@@ -674,7 +674,8 @@ void test_29b (void)
__analyzer_eval (q->x == 107024); /* { dg-warning "TRUE" } */
__analyzer_eval (q->y == 107025); /* { dg-warning "TRUE" } */
- __analyzer_eval (p[10].x == 0); /* { dg-warning "use of uninitialized value 'p\\\[10\\\].x'" } */
+ __analyzer_eval (p[10].x == 0); /* { dg-warning "use of uninitialized value 'p\\\[10\\\].x'" "" { target c } } */
+ /* { dg-warning "use of uninitialized value 'p\\\[10\\\].coord::x'" "" { target c++ } .-1 } */
}
void test_29c (int len)
@@ -722,7 +723,8 @@ void test_29c (int len)
__analyzer_eval (q->x == 107024); /* { dg-warning "TRUE" } */
__analyzer_eval (q->y == 107025); /* { dg-warning "TRUE" } */
- __analyzer_eval (p[10].x == 0); /* { dg-warning "use of uninitialized value '\\*p\\\[10\\\].x'" } */
+ __analyzer_eval (p[10].x == 0); /* { dg-warning "use of uninitialized value '\\*p\\\[10\\\].x'" "" { target c } } */
+ /* { dg-warning "use of uninitialized value '\\*p\\\[10\\\].coord::x'" "" { target c++ } .-1 } */
}
void test_30 (void *ptr)
@@ -835,7 +837,7 @@ int test_38 (void)
/* Write through NULL pointer. */
-int test_38a (int i)
+void test_38a (int i)
{
int *ptr = NULL;
*ptr = i; /* { dg-warning "dereference of NULL 'ptr'" } */
@@ -849,7 +851,7 @@ int test_39 (void)
return *ptr;
}
-int test_40 (int flag)
+void test_40 (int flag)
{
int i;
if (flag)
similarity index 57%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-10.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-10.c
@@ -12,7 +12,9 @@ test (void)
if (!new_table)
return NULL;
new_table->m_f = (char **)malloc(sizeof(char **));
- *new_table->m_f = NULL; /* { dg-warning "dereference of possibly-NULL '\\*new_table.m_f'" } */
- /* { dg-message "'\\*new_table.m_f' could be NULL" "final event wording" { target *-*-* } .-1 } */
+ *new_table->m_f = NULL; /* { dg-warning "dereference of possibly-NULL '\\*new_table.m_f'" "" { target c } } */
+ /* { dg-warning "dereference of possibly-NULL '\\*new_table.foo::m_f'" "" { target c++ } .-1 } */
+ /* { dg-message "'\\*new_table.m_f' could be NULL" "final event wording" { target c } .-2 } */
+ /* { dg-message "'\\*new_table.foo::m_f' could be NULL" "final event wording" { target c++ } .-3 } */
return new_table;
}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-12.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-12.c
similarity index 67%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-13.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-13.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
-union
+static union
{
void *ptr_val;
int int_val;
@@ -14,5 +14,6 @@ void test_1 (void)
void test_2 (void)
{
global_union.ptr_val = malloc (1024); /* { dg-message "allocated here" } */
- global_union.int_val = 0; /* { dg-warning "leak of 'global_union.ptr_val' " } */
+ global_union.int_val = 0; /* { dg-warning "leak of 'global_union.ptr_val' " "" { target c } } */
+ /* { dg-warning "leak of 'global_union.<unnamed union>::ptr_val' " "" { target c++ } .-1 } */
}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-14.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-14.c
similarity index 86%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-15.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-15.c
@@ -26,7 +26,7 @@ int test_2 (const struct coord *c1, const struct coord *c2, double r_squared)
return (dx * dx) + (dy * dy) + (dz * dz) <= r_squared;
}
-int test_3 (const struct coord *c1, const struct coord *c2, struct coord *out)
+void test_3 (const struct coord *c1, const struct coord *c2, struct coord *out)
{
out->x = c1->x + c2->x;
out->y = c1->y + c2->y;
similarity index 67%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-16.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-16.c
@@ -2,7 +2,7 @@
/* Labels as values. */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern void foo (void);
@@ -40,10 +40,10 @@ void test_2 (int i)
void test_3 (int i)
{
- static const int array[] = { &&label0 - &&label0,
- &&label1 - &&label0,
- &&label2 - &&label0 };
- goto *(&&label0 + array[i]);
+ static const int array[] = { (char *)&&label0 - (char *)&&label0,
+ (char *)&&label1 - (char *)&&label0,
+ (char *)&&label2 - (char *)&&label0 };
+ goto *((int *)&&label0 + array[i]);
label0:
foo ();
@@ -52,3 +52,5 @@ void test_3 (int i)
label2:
foo ();
}
+
+/* { dg-prune-output "Wnarrowing" }*/
\ No newline at end of file
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-17.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-17.c
@@ -14,7 +14,7 @@ static const config table[2] = {
{ cb_2 }
};
-int deflate (foo_t *s, int which)
+void deflate (foo_t *s, int which)
{
(*(table[which].func))(s);
}
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-18.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-18.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test (int *p, int i, int j)
{
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-2.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-2.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-20.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-20.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-21.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-21.c
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-22.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-22.c
@@ -1,5 +1,5 @@
#include <string.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern void check_init_char (char v);
extern void check_init_int (int v);
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-23.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-23.c
@@ -1,11 +1,10 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
-#define NULL ((void *)0)
-void * __attribute__((noinline))
+char * __attribute__((noinline))
hide (void *ptr)
{
- return ptr;
+ return (char *)ptr;
}
void test_1 (void)
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-4.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-4.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-5.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-5.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-5b.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-5b.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-5c.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-5c.c
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-5d.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-5d.c
@@ -3,7 +3,7 @@
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef struct base_obj
{
similarity index 84%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-7.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-7.c
@@ -1,7 +1,7 @@
/* { dg-additional-options "-fno-analyzer-state-merge" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
-int test_40 (int flag)
+void test_40 (int flag)
{
int i;
if (flag)
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-8.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-8.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct base
{
similarity index 78%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-9.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-9.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <string.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct foo
{
@@ -11,7 +11,7 @@ struct foo
void test_1 (void)
{
- struct foo *f = calloc (1, sizeof (struct foo));
+ struct foo *f = (struct foo *) calloc (1, sizeof (struct foo));
if (f == NULL)
return;
__analyzer_eval (f->i == 0); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
@@ -23,7 +23,7 @@ void test_1 (void)
void test_2 (void)
{
- struct foo *f = malloc (sizeof (struct foo));
+ struct foo *f = (struct foo *) malloc (sizeof (struct foo));
if (f == NULL)
return;
memset (f, 0, sizeof (struct foo));
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/data-model-path-1.c
rename to gcc/testsuite/c-c++-common/analyzer/data-model-path-1.c
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-1.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-1.c
@@ -1,4 +1,4 @@
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
int test_from_pr77432 (int *a)
{
@@ -76,9 +76,11 @@ struct s4
int test_4 (struct s4 *p)
{
- if (p->m_next->m_val > 0) /* { dg-message "pointer '\\*p.m_next' is dereferenced here" } */
+ if (p->m_next->m_val > 0) /* { dg-message "pointer '\\*p.m_next' is dereferenced here" "" { target c } } */
+ /* { dg-message "pointer '\\*p.s4::m_next' is dereferenced here" "" { target c++ } .-1 } */
return -1;
- if (!p->m_next) /* { dg-warning "check of '\\*p.m_next' for NULL after already dereferencing it" } */
+ if (!p->m_next) /* { dg-warning "check of '\\*p.m_next' for NULL after already dereferencing it" "" { target c } } */
+ /* { dg-warning "check of '\\*p.s4::m_next' for NULL after already dereferencing it" "" { target c++ } .-1 } */
return -2;
return p->m_next->m_val;
}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-2.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-2.c
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-macro-pr108745.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-macro-pr108745.c
@@ -1,6 +1,6 @@
/* Reduced from ImageMagick-7.1.0-57. */
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef __builtin_va_list va_list;
typedef __SIZE_TYPE__ size_t;
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-macro.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-macro.c
@@ -1,4 +1,4 @@
-#define NULL ((void*)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
#define MY_ASSERT(COND) \
do { \
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/deref-before-check-qemu-qtest_rsp_args.c
rename to gcc/testsuite/c-c++-common/analyzer/deref-before-check-qemu-qtest_rsp_args.c
@@ -1,7 +1,7 @@
/* Reduced from qemu-7.2.0's tests/qtest/libqtest.c. */
#define TRUE 1
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
#define g_assert(expr) \
do { \
similarity index 58%
rename from gcc/testsuite/gcc.dg/analyzer/describe-1.c
rename to gcc/testsuite/c-c++-common/analyzer/describe-1.c
@@ -1,11 +1,12 @@
/* Smoketest for __analyzer_describe. */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test (int i)
{
__analyzer_describe (0, 42); /* { dg-warning "svalue: '\\(int\\)42'" } */
__analyzer_describe (0, i); /* { dg-warning "svalue: 'INIT_VAL\\(i.*\\)'" } */
- __analyzer_describe (0, &i); /* { dg-warning "svalue: '&i'" } */
+ __analyzer_describe (0, &i); /* { dg-warning "svalue: '&i'" "" { target c } } */
+ /* { dg-warning "svalue: '&int i'" "" { target c++ } .-1 } */
/* Further cases would risk overspecifying things. */
}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/disabling.c
rename to gcc/testsuite/c-c++-common/analyzer/disabling.c
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/doom-d_main-IdentifyVersion.c
rename to gcc/testsuite/c-c++-common/analyzer/doom-d_main-IdentifyVersion.c
@@ -2,6 +2,12 @@
/* { dg-additional-options "-Wno-analyzer-too-complex" } */
+#ifdef __cplusplus
+#define CONST_CAST(type, v) const_cast<type> (v)
+#else
+#define CONST_CAST(type, v) v
+#endif
+
typedef __SIZE_TYPE__ size_t;
typedef struct _IO_FILE FILE;
@@ -60,8 +66,8 @@ typedef enum
typedef enum
{
- false,
- true
+ False,
+ True
} boolean;
extern boolean devparm;
@@ -69,14 +75,14 @@ extern GameMode_t gamemode;
extern Language_t language;
extern char basedefault[1024];
int
-M_CheckParm(char* check);
+M_CheckParm(const char* check);
void
-I_Error(char* error, ...);
+I_Error(const char* error, ...);
extern char* wadfiles[20];
void
-D_AddFile(char* file)
+D_AddFile(const char* file)
{
int numwadfiles;
char* newfile;
@@ -84,7 +90,7 @@ D_AddFile(char* file)
for (numwadfiles = 0; wadfiles[numwadfiles]; numwadfiles++)
;
- newfile = malloc(strlen(file) + 1);
+ newfile = (char *)malloc(strlen(file) + 1);
strcpy(newfile, file); /* { dg-warning "use of possibly-NULL 'newfile' where non-null expected" } */
wadfiles[numwadfiles] = newfile;
@@ -107,27 +113,27 @@ IdentifyVersion(void)
char* doomwaddir;
doomwaddir = getenv("DOOMWADDIR");
if (!doomwaddir)
- doomwaddir = ".";
+ doomwaddir = CONST_CAST(char *, ".");
- doom2wad = malloc(strlen(doomwaddir) + 1 + 9 + 1);
+ doom2wad = (char *)malloc(strlen(doomwaddir) + 1 + 9 + 1);
sprintf(doom2wad, "%s/doom2.wad", doomwaddir); /* { dg-warning "possibly-NULL 'doom2wad'" } */
- doomuwad = malloc(strlen(doomwaddir) + 1 + 8 + 1);
+ doomuwad = (char *)malloc(strlen(doomwaddir) + 1 + 8 + 1);
sprintf(doomuwad, "%s/doomu.wad", doomwaddir); /* { dg-warning "possibly-NULL 'doomuwad'" } */
- doomwad = malloc(strlen(doomwaddir) + 1 + 8 + 1);
+ doomwad = (char *)malloc(strlen(doomwaddir) + 1 + 8 + 1);
sprintf(doomwad, "%s/doom.wad", doomwaddir); /* { dg-warning "possibly-NULL 'doomwad'" } */
- doom1wad = malloc(strlen(doomwaddir) + 1 + 9 + 1);
+ doom1wad = (char *)malloc(strlen(doomwaddir) + 1 + 9 + 1);
sprintf(doom1wad, "%s/doom1.wad", doomwaddir); /* { dg-warning "possibly-NULL 'doom1wad'" } */
- plutoniawad = malloc(strlen(doomwaddir) + 1 + 12 + 1);
+ plutoniawad = (char *)malloc(strlen(doomwaddir) + 1 + 12 + 1);
sprintf(plutoniawad, "%s/plutonia.wad", doomwaddir); /* { dg-warning "possibly-NULL 'plutoniawad'" } */
- tntwad = malloc(strlen(doomwaddir) + 1 + 9 + 1);
+ tntwad = (char *)malloc(strlen(doomwaddir) + 1 + 9 + 1);
sprintf(tntwad, "%s/tnt.wad", doomwaddir); /* { dg-warning "possibly-NULL 'tntwad'" } */
- doom2fwad = malloc(strlen(doomwaddir) + 1 + 10 + 1);
+ doom2fwad = (char *)malloc(strlen(doomwaddir) + 1 + 10 + 1);
sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir); /* { dg-warning "possibly-NULL 'doom2fwad'" } */
home = getenv("HOME");
@@ -137,7 +143,7 @@ IdentifyVersion(void)
if (M_CheckParm("-shdev")) {
gamemode = shareware;
- devparm = true;
+ devparm = True;
D_AddFile("devdata"
"doom1.wad");
D_AddFile("devmaps"
@@ -158,7 +164,7 @@ IdentifyVersion(void)
if (M_CheckParm("-regdev")) {
gamemode = registered;
- devparm = true;
+ devparm = True;
D_AddFile("devdata"
"doom.wad");
D_AddFile("devmaps"
@@ -181,7 +187,7 @@ IdentifyVersion(void)
if (M_CheckParm("-comdev")) {
gamemode = commercial;
- devparm = true;
+ devparm = True;
D_AddFile("devdata"
"doom2.wad");
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/doom-s_sound-pr108867.c
rename to gcc/testsuite/c-c++-common/analyzer/doom-s_sound-pr108867.c
@@ -15,14 +15,14 @@ abs(int __x) __attribute__((__nothrow__, __leaf__)) __attribute__((__const__));
typedef enum
{
- false,
- true
+ False,
+ True
} boolean;
typedef unsigned char byte;
void
-I_Error(char* error, ...);
+I_Error(const char* error, ...);
typedef enum
{
@@ -238,7 +238,7 @@ S_Init(int sfxVolume, int musicVolume)
for (i = 0; i < numChannels; i++)
channels[i].sfxinfo = 0;
- mus_paused = 0;
+ mus_paused = (boolean) 0;
for (i = 1; i < NUMSFX; i++)
S_sfx[i].lumpnum = S_sfx[i].usefulness = -1;
@@ -253,7 +253,7 @@ S_Start(void)
if (channels[cnum].sfxinfo)
S_StopChannel(cnum);
- mus_paused = 0;
+ mus_paused = (boolean) 0;
if (gamemode == commercial)
mnum = mus_runnin + gamemap - 1;
@@ -270,7 +270,7 @@ S_Start(void)
mnum = spmus[gamemap - 1];
}
- S_ChangeMusic(mnum, true);
+ S_ChangeMusic(mnum, True);
nextcleanup = 15;
}
@@ -387,7 +387,7 @@ S_PauseSound(void)
{
if (mus_playing && !mus_paused) {
I_PauseSong(mus_playing->handle);
- mus_paused = true;
+ mus_paused = True;
}
}
@@ -396,7 +396,7 @@ S_ResumeSound(void)
{
if (mus_playing && mus_paused) {
I_ResumeSong(mus_playing->handle);
- mus_paused = false;
+ mus_paused = False;
}
}
@@ -436,7 +436,7 @@ S_UpdateSounds(void* listener_p)
if (c->origin && listener_p != c->origin) {
audible =
- S_AdjustSoundParams(listener, c->origin, &volume, &sep, &pitch);
+ S_AdjustSoundParams(listener, (mobj_t *) c->origin, &volume, &sep, &pitch);
if (!audible) {
S_StopChannel(cnum);
@@ -476,7 +476,7 @@ S_SetSfxVolume(int volume)
void
S_StartMusic(int m_id)
{
- S_ChangeMusic(m_id, false);
+ S_ChangeMusic(m_id, False);
}
void
@@ -490,7 +490,7 @@ S_ChangeMusic(int musicnum, int looping)
} else
music = &S_music[musicnum];
- /* We don't know that I_Error exits, so actually a false positive;
+ /* We don't know that I_Error exits, so actually a False positive;
see PR analyzer/108867. */
if (mus_playing == music) /* { dg-warning "use of uninitialized value 'music'" } */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/double-free-lto-1-a.c
rename to gcc/testsuite/c-c++-common/analyzer/double-free-lto-1-a.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/double-free-lto-1-b.c
rename to gcc/testsuite/c-c++-common/analyzer/double-free-lto-1-b.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/double-free-lto-1.h
rename to gcc/testsuite/c-c++-common/analyzer/double-free-lto-1.h
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/dump-state.c
rename to gcc/testsuite/c-c++-common/analyzer/dump-state.c
@@ -1,7 +1,7 @@
/* Verify that __analyzer_dump_state works as expected. */
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test_1 (void)
{
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/edges-1.c
rename to gcc/testsuite/c-c++-common/analyzer/edges-1.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/edges-2.c
rename to gcc/testsuite/c-c++-common/analyzer/edges-2.c
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/equivalence.c
rename to gcc/testsuite/c-c++-common/analyzer/equivalence.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test (int p, int q, int r)
{
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/errno-1.c
rename to gcc/testsuite/c-c++-common/analyzer/errno-1.c
@@ -1,5 +1,5 @@
#include <errno.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern void external_fn (void);
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/errno-___errno.c
rename to gcc/testsuite/c-c++-common/analyzer/errno-___errno.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* According to PR 107807 comment #2, Solaris implements "errno"
like this: */
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/errno-__error.c
rename to gcc/testsuite/c-c++-common/analyzer/errno-__error.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* According to PR 107807 comment #2, OS X implements "errno"
like this: */
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/errno-global-var.c
rename to gcc/testsuite/c-c++-common/analyzer/errno-global-var.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* "errno" declared as a global var. */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/errno-pr107777.c
rename to gcc/testsuite/c-c++-common/analyzer/errno-pr107777.c
similarity index 58%
rename from gcc/testsuite/gcc.dg/analyzer/error-1.c
rename to gcc/testsuite/c-c++-common/analyzer/error-1.c
@@ -1,4 +1,5 @@
-#include "analyzer-decls.h"
+/* { dg-additional-options "-fpermissive" { target c++ } } */
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int errno;
@@ -65,30 +66,34 @@ void test_6 (int st, const char *str)
__analyzer_eval (st == 0); /* { dg-warning "TRUE" } */
}
-char *test_error_unterminated (int st)
+void test_error_unterminated (int st)
{
- char fmt[3] = "abc";
+ char fmt[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */
error (st, errno, fmt); /* { dg-warning "stack-based buffer over-read" } */
- /* { dg-message "while looking for null terminator for argument 3 \\('&fmt'\\) of 'error'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 3 \\('&fmt'\\) of 'error'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 3 \\('& fmt'\\) of 'void error\\(int, int, const char\\*, \\.\\.\\.\\)'..." "event" { target c++ } .-2 } */
}
-char *test_error_at_line_unterminated (int st, int errno)
+void test_error_at_line_unterminated (int st, int errno)
{
- char fmt[3] = "abc";
+ char fmt[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */
error_at_line (st, errno, __FILE__, __LINE__, fmt); /* { dg-warning "stack-based buffer over-read" } */
- /* { dg-message "while looking for null terminator for argument 5 \\('&fmt'\\) of 'error_at_line'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 5 \\('&fmt'\\) of 'error_at_line'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 5 \\('& fmt'\\) of 'void error_at_line\\(int, int, const char\\*, unsigned int, const char\\*, ...\\)'..." "event" { target c++ } .-2 } */
}
-char *test_error_uninitialized (int st, int errno)
+void test_error_uninitialized (int st, int errno)
{
char fmt[16];
error (st, errno, fmt); /* { dg-warning "use of uninitialized value 'fmt\\\[0\\\]'" } */
- /* { dg-message "while looking for null terminator for argument 3 \\('&fmt'\\) of 'error'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 3 \\('&fmt'\\) of 'error'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 3 \\('& fmt'\\) of 'void error\\(int, int, const char\\*, \\.\\.\\.\\)'..." "event" { target c++ } .-2 } */
}
-char *test_error_at_line_uninitialized (int st, int errno)
+void test_error_at_line_uninitialized (int st, int errno)
{
char fmt[16];
error_at_line (st, errno, __FILE__, __LINE__, fmt); /* { dg-warning "use of uninitialized value 'fmt\\\[0\\\]'" } */
- /* { dg-message "while looking for null terminator for argument 5 \\('&fmt'\\) of 'error_at_line'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 5 \\('&fmt'\\) of 'error_at_line'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 5 \\('& fmt'\\) of 'void error_at_line\\(int, int, const char\\*, unsigned int, const char\\*, ...\\)'..." "event" { target c++ } .-2 } */
}
new file mode 100644
@@ -0,0 +1,49 @@
+/* { dg-additional-options "-fno-exceptions" } */
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+typedef __SIZE_TYPE__ size_t;
+
+extern int errno;
+
+extern void free (void *);
+char *strdup (const char *)
+ __attribute__((malloc (free)));
+
+extern size_t strlen (const char *__s)
+ __attribute__ ((__nothrow__ , __leaf__))
+ __attribute__ ((__pure__))
+ __attribute__ ((__nonnull__ (1)));
+
+extern void error (int __status, int __errnum, const char *__format, ...)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+
+extern void error_at_line (int __status, int __errnum, const char *__fname,
+ unsigned int __lineno, const char *__format, ...)
+ __attribute__ ((__format__ (__printf__, 5, 6)));
+
+/* PR analyzer/99196; extract taken from
+ https://github.com/libguestfs/libguestfs/blob/f19fd566f6387ce7e4d82409528c9dde374d25e0/daemon/tar.c#L108
+ (which is GPLv2 or later). */
+
+extern char *read_whole_file (const char *error_file, size_t *out);
+
+#define EXIT_FAILURE 1
+
+char *read_error_file (const char *error_file)
+{
+ size_t len;
+ char *str;
+
+ str = read_whole_file (error_file, &len);
+ if (str == NULL) {
+ str = strdup ("(no error)");
+ if (str == NULL)
+ error (EXIT_FAILURE, errno, "strdup");
+ len = strlen (str); /* { dg-bogus "NULL" } */
+ }
+
+ /* Remove trailing \n character if any. */
+ if (len > 0 && str[len-1] == '\n')
+ str[--len] = '\0';
+
+ return str; /* caller frees */
+}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/error-3.c
rename to gcc/testsuite/c-c++-common/analyzer/error-3.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/error-uninit.c
rename to gcc/testsuite/c-c++-common/analyzer/error-uninit.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/explode-1.c
rename to gcc/testsuite/c-c++-common/analyzer/explode-1.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/explode-2.c
rename to gcc/testsuite/c-c++-common/analyzer/explode-2.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/explode-2a.c
rename to gcc/testsuite/c-c++-common/analyzer/explode-2a.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/explode-3.c
rename to gcc/testsuite/c-c++-common/analyzer/explode-3.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/factorial.c
rename to gcc/testsuite/c-c++-common/analyzer/factorial.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/fdump-analyzer-1.c
rename to gcc/testsuite/c-c++-common/analyzer/fdump-analyzer-1.c
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/feasibility-1.c
rename to gcc/testsuite/c-c++-common/analyzer/feasibility-1.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test_1 (void)
{
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/feasibility-2.c
rename to gcc/testsuite/c-c++-common/analyzer/feasibility-2.c
@@ -1,7 +1,7 @@
/* Verify that -fno-analyzer-feasibility works. */
/* { dg-additional-options "-fno-analyzer-feasibility" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test_1 (int flag)
{
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/feasibility-4.c
rename to gcc/testsuite/c-c++-common/analyzer/feasibility-4.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int rand (void);
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/feasibility-pr107582-1.c
rename to gcc/testsuite/c-c++-common/analyzer/feasibility-pr107582-1.c
@@ -6,7 +6,7 @@
#include <errno.h>
#include <unistd.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
int z;
@@ -16,7 +16,7 @@ static void func(void * o)
}
int main(int argc,
- int ** argv)
+ char ** argv)
{
struct timespec now;
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/feasibility-pr107582-2.c
rename to gcc/testsuite/c-c++-common/analyzer/feasibility-pr107582-2.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
int z;
@@ -10,7 +10,7 @@ static void func(void)
}
int main(int argc,
- int ** argv)
+ char ** argv)
{
int * x;
int ret = 0;
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/feasibility-pr107948.c
rename to gcc/testsuite/c-c++-common/analyzer/feasibility-pr107948.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void foo(int width) {
int i = 0;
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/ferror-1.c
rename to gcc/testsuite/c-c++-common/analyzer/ferror-1.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/fibonacci.c
rename to gcc/testsuite/c-c++-common/analyzer/fibonacci.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/file-1.c
rename to gcc/testsuite/c-c++-common/analyzer/file-1.c
new file mode 100644
@@ -0,0 +1,26 @@
+/* { dg-additional-options "-fno-exceptions" } */
+typedef struct FILE FILE;
+
+FILE* fopen (const char*, const char*);
+int fclose (FILE*);
+
+struct foo
+{
+ FILE *m_f;
+};
+
+void test (const char *path)
+{
+ struct foo f;
+ f.m_f = fopen (path, "r");
+
+ if (!f.m_f)
+ return; /* { dg-bogus "leak of FILE" } */
+
+ fclose (f.m_f);
+ fclose (f.m_f); /* { dg-warning "double 'fclose' of FILE 'f.m_f'" "" { target c } } */
+ /* { dg-warning "double 'fclose' of FILE 'f.foo::m_f'" "" { target c++ } .-1 } */
+}
+
+/* Swallow -Wuse-after-free issued for the same problem
+ { dg-prune-output "-Wuse-after-free" } */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/file-3.c
rename to gcc/testsuite/c-c++-common/analyzer/file-3.c
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/file-CWE-1341-example.c
rename to gcc/testsuite/c-c++-common/analyzer/file-CWE-1341-example.c
@@ -21,6 +21,7 @@
/* Checks double-fclose only, suppress CWE-415. (PR analyzer/108722). */
/* { dg-additional-options -Wno-analyzer-double-free } */
+/* { dg-additional-options "-fno-exceptions" { target c++ } } */
#include <stdio.h>
#include <stdlib.h>
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/file-meaning-1.c
rename to gcc/testsuite/c-c++-common/analyzer/file-meaning-1.c
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/file-paths-1.c
rename to gcc/testsuite/c-c++-common/analyzer/file-paths-1.c
@@ -1,4 +1,6 @@
/* { dg-additional-options "-fanalyzer-verbosity=3" } */
+/* { dg-additional-options "-fno-exceptions" { target c++ } } */
+
typedef struct FILE FILE;
@@ -6,7 +8,7 @@ FILE* fopen (const char*, const char*);
int fclose (FILE*);
char *fgets (char *, int, FILE *);
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Verify that we correctly emit CFG events in the face of buffers
similarity index 88%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-1.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-1.c
@@ -1,4 +1,5 @@
/* { dg-require-effective-target alloca } */
+/* { dg-additional-options "-fpermissive" { target c++ } } */
#include <stdlib.h>
@@ -236,7 +237,7 @@ void test_20 (void)
int *test_21 (int i)
{
- int *ptr = malloc (sizeof (int));
+ int *ptr = (int *) malloc (sizeof (int));
if (!ptr)
abort ();
*ptr = i;
@@ -269,13 +270,13 @@ int *test_23a (int n)
return ptr;
}
-int test_24 (void)
+void test_24 (void)
{
void *ptr = __builtin_alloca (sizeof (int)); /* { dg-message "region created on stack here" } */
free (ptr); /* { dg-warning "'free' of 'ptr' which points to memory on the stack \\\[CWE-590\\\]" } */
}
-int test_25 (void)
+void test_25 (void)
{
char tmp[100]; /* { dg-message "region created on stack here" } */
void *p = tmp;
@@ -285,7 +286,7 @@ int test_25 (void)
char global_buffer[100]; /* { dg-message "region created here" } */
-int test_26 (void)
+void test_26 (void)
{
void *p = global_buffer;
free (p); /* { dg-warning "'free' of 'p' which points to memory not on the heap \\\[CWE-590\\\]" } */
@@ -357,8 +358,9 @@ void test_30 (void)
{
struct link tmp;
tmp.m_ptr = (struct link *)malloc (sizeof (struct link)); /* { dg-message "allocated here" } */
-} /* { dg-warning "leak of 'tmp.m_ptr'" } */
-/* { dg-bogus "leak of '<unknown>'" "leak of unknown" { target *-*-* } .-1 } */
+} /* { dg-warning "leak of 'tmp.m_ptr'" "" { target c } } */
+/* { dg-warning "leak of 'tmp.link::m_ptr'" "" { target c++ } .-1 } */
+/* { dg-bogus "leak of '<unknown>'" "leak of unknown" { target *-*-* } .-2 } */
void test_31 (void)
{
@@ -383,7 +385,7 @@ void test_33 (void)
void test_34 (void)
{
float *q;
- struct coord *p = malloc (sizeof (struct coord));
+ struct coord *p = (struct coord *) malloc (sizeof (struct coord));
if (!p)
return;
p->x = 0.0f;
@@ -482,7 +484,7 @@ test_41 (int flag)
void test_42a (void)
{
- void *p = malloc (1024); /* { dg-message "allocated here" } */
+ char *p = (char *)malloc (1024); /* { dg-message "allocated here" } */
free (p + 64); /* this could well corrupt the heap. */
/* TODO: ^^^ we should warn about this. */
} /* { dg-warning "leak of 'p'" } */
@@ -492,7 +494,7 @@ void test_42a (void)
void test_42b (void)
{
- void *p = malloc (1024); /* { dg-message "allocated here" } */
+ char *p = (char *)malloc (1024); /* { dg-message "allocated here" } */
free (p - 64); /* this could well corrupt the heap. */
/* TODO: ^^^ we should warn about this. */
} /* { dg-warning "leak of 'p'" } */
@@ -502,16 +504,16 @@ void test_42b (void)
void test_42c (void)
{
- void *p = malloc (1024);
- void *q = p + 64;
+ char *p = (char *)malloc (1024);
+ char *q = p + 64;
free (q - 64); /* this is probably OK. */
} /* { dg-bogus "leak of 'p'" } */
void *
test_42d (void)
{
- void *p = malloc (1024);
- void *q = p + 64;
+ char *p = (char *)malloc (1024);
+ char *q = p + 64;
return q;
} /* { dg-bogus "leak of 'p'" } */
@@ -535,18 +537,19 @@ struct link global_link;
void test_43 (void)
{
- global_link.m_ptr = malloc (sizeof (struct link)); /* { dg-message "allocated here" } */
- global_link.m_ptr = NULL; /* { dg-warning "leak of 'global_link.m_ptr'" } */
+ global_link.m_ptr = (struct link *) malloc (sizeof (struct link)); /* { dg-message "allocated here" } */
+ global_link.m_ptr = NULL; /* { dg-warning "leak of 'global_link.m_ptr'" "" { target c } } */
+ /* { dg-warning "leak of 'global_link.link::m_ptr'" "" { target c++ } .-1 } */
}
struct link *global_ptr;
void test_44 (void)
{
- global_ptr = malloc (sizeof (struct link));
+ global_ptr = (struct link *) malloc (sizeof (struct link));
if (!global_ptr)
return;
- global_ptr->m_ptr = malloc (sizeof (struct link)); /* { dg-message "allocated here" } */
+ global_ptr->m_ptr = (struct link *) malloc (sizeof (struct link)); /* { dg-message "allocated here" } */
free (global_ptr); /* { dg-warning "leak of '<unknown>'" } */
/* TODO: should be more precise than just '<unknown>'. */
}
@@ -573,10 +576,10 @@ extern int maybe_alloc (char **);
int test_47 (void)
{
- char *p = ((void *)0);
+ char *p = (char *)((void *)0);
int p_size = 0;
- p = malloc (16);
+ p = (char *)malloc (16);
if (p) {
free (p);
} else {
@@ -616,13 +619,16 @@ void test_50a (void)
void test_50b (void)
{
- free (test_50a); /* { dg-warning "'free' of '&test_50a' which points to memory not on the heap \\\[CWE-590\\\]" } */
+ free (test_50a); /* { dg-warning "'free' of '&test_50a' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c } } */
+ /* { dg-warning "'free' of 'test_50a' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c++ } .-1 } */
+ /* { dg-warning "invalid conversion from '\[^\n\]*' to 'void\\*" "fpermissive" { target c++ } .-2 } */
}
void test_50c (void)
{
my_label:
- free (&&my_label); /* { dg-warning "'free' of '&my_label' which points to memory not on the heap \\\[CWE-590\\\]" } */
+ free (&&my_label); /* { dg-warning "'free' of '&my_label' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c } } */
+ /* { dg-warning "'free' of '&& my_label' which points to memory not on the heap \\\[CWE-590\\\]" "" { target c++ } .-1 } */
}
/* Double free after unconditional dereference. */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-10.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-10.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-12.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-12.c
similarity index 68%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-13.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-13.c
@@ -23,7 +23,8 @@ void test (struct foo f)
do_stuff ();
- calls_free (f.m_p); /* { dg-message "passing freed pointer 'f\\.m_p' in call to 'calls_free' from 'test'" } */
+ calls_free (f.m_p); /* { dg-message "passing freed pointer 'f\\.m_p' in call to 'calls_free' from 'test'" "" { target c } } */
+ /* { dg-message "passing freed pointer 'f\\.foo::m_p' in call to 'calls_free' from 'test'" "" { target c++ } .-1 } */
do_stuff ();
}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-13a.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-13a.c
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-double-free.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-double-free.c
@@ -189,7 +189,151 @@ void test (int i)
| | |
| | (23) second 'free' here; first 'free' was at (16)
|
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ NN | free (ptr);
+ | ~~~~~^~~~~
+ 'void test(int)': events 1-2
+ |
+ | NN | void test (int i)
+ | | ^~~~
+ | | |
+ | | (1) entry to 'test'
+ | NN | {
+ | NN | boxed_int *obj = make_boxed_int (i);
+ | | ~~~~~~~~~~~~~~~~~~
+ | | |
+ | | (2) calling 'make_boxed_int' from 'test'
+ |
+ +--> 'boxed_int* make_boxed_int(int)': events 3-4
+ |
+ | NN | make_boxed_int (int i)
+ | | ^~~~~~~~~~~~~~
+ | | |
+ | | (3) entry to 'make_boxed_int'
+ | NN | {
+ | NN | boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int));
+ | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ | | |
+ | | (4) calling 'wrapped_malloc' from 'make_boxed_int'
+ |
+ +--> 'void* wrapped_malloc(size_t)': events 5-6
+ |
+ | NN | void *wrapped_malloc (size_t size)
+ | | ^~~~~~~~~~~~~~
+ | | |
+ | | (5) entry to 'wrapped_malloc'
+ | NN | {
+ | NN | return malloc (size);
+ | | ~~~~~~~~~~~~~
+ | | |
+ | | (6) allocated here
+ |
+ <------+
+ |
+ 'boxed_int* make_boxed_int(int)': events 7-10
+ |
+ | NN | boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int));
+ | | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
+ | | |
+ | | (7) returning to 'make_boxed_int' from 'wrapped_malloc'
+ | NN | if (!result)
+ | | ~~
+ | | |
+ | | (8) assuming 'result' is non-NULL
+ | | (9) following 'false' branch (when 'result' is non-NULL)...
+ | NN | abort ();
+ | NN | result->i = i;
+ | | ~~~~~~~~~~~~~
+ | | |
+ | | (10) ...to here
+ |
+ <------+
+ |
+ 'void test(int)': events 11-12
+ |
+ | NN | boxed_int *obj = make_boxed_int (i);
+ | | ~~~~~~~~~~~~~~~^~~
+ | | |
+ | | (11) returning to 'test' from 'make_boxed_int'
+ | NN |
+ | NN | free_boxed_int (obj);
+ | | ~~~~~~~~~~~~~~~~~~~~
+ | | |
+ | | (12) calling 'free_boxed_int' from 'test'
+ |
+ +--> 'void free_boxed_int(boxed_int*)': events 13-14
+ |
+ | NN | free_boxed_int (boxed_int *bi)
+ | | ^~~~~~~~~~~~~~
+ | | |
+ | | (13) entry to 'free_boxed_int'
+ | NN | {
+ | NN | wrapped_free (bi);
+ | | ~~~~~~~~~~~~~~~~~
+ | | |
+ | | (14) calling 'wrapped_free' from 'free_boxed_int'
+ |
+ +--> 'void wrapped_free(void*)': events 15-16
+ |
+ | NN | void wrapped_free (void *ptr)
+ | | ^~~~~~~~~~~~
+ | | |
+ | | (15) entry to 'wrapped_free'
+ | NN | {
+ | NN | free (ptr);
+ | | ~~~~~~~~~~
+ | | |
+ | | (16) first 'free' here
+ |
+ <------+
+ |
+ 'void free_boxed_int(boxed_int*)': event 17
+ |
+ | NN | wrapped_free (bi);
+ | | ~~~~~~~~~~~~~^~~~
+ | | |
+ | | (17) returning to 'free_boxed_int' from 'wrapped_free'
+ |
+ <------+
+ |
+ 'void test(int)': events 18-19
+ |
+ | NN | free_boxed_int (obj);
+ | | ~~~~~~~~~~~~~~~^~~~~
+ | | |
+ | | (18) returning to 'test' from 'free_boxed_int'
+ | NN |
+ | NN | free_boxed_int (obj);
+ | | ~~~~~~~~~~~~~~~~~~~~
+ | | |
+ | | (19) passing freed pointer 'obj' in call to 'free_boxed_int' from 'test'
+ |
+ +--> 'void free_boxed_int(boxed_int*)': events 20-21
+ |
+ | NN | free_boxed_int (boxed_int *bi)
+ | | ^~~~~~~~~~~~~~
+ | | |
+ | | (20) entry to 'free_boxed_int'
+ | NN | {
+ | NN | wrapped_free (bi);
+ | | ~~~~~~~~~~~~~~~~~
+ | | |
+ | | (21) passing freed pointer 'bi' in call to 'wrapped_free' from 'free_boxed_int'
+ |
+ +--> 'void wrapped_free(void*)': events 22-23
+ |
+ | NN | void wrapped_free (void *ptr)
+ | | ^~~~~~~~~~~~
+ | | |
+ | | (22) entry to 'wrapped_free'
+ | NN | {
+ | NN | free (ptr);
+ | | ~~~~~~~~~~
+ | | |
+ | | (23) second 'free' here; first 'free' was at (16)
+ |
+ { dg-end-multiline-output "" { target c++ } } */
/* TODO: the event describing the allocation is uninteresting and probably
should be purged. */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-lto-a.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-lto-b.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-lto-c.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-8-lto.h
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-ipa-9.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-ipa-9.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-many-paths-1.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-many-paths-1.c
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-many-paths-2.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-many-paths-2.c
@@ -15,7 +15,7 @@ extern void Py_Dealloc (PyObject *op);
Py_Dealloc((PyObject *)(op)); \
} while (0)
-int test (PyObject *obj_01, PyObject *obj_02, PyObject *obj_03,
+void test (PyObject *obj_01, PyObject *obj_02, PyObject *obj_03,
PyObject *obj_04, PyObject *obj_05, PyObject *obj_06,
PyObject *obj_07, PyObject *obj_08, PyObject *obj_09,
PyObject *obj_10, PyObject *obj_11, PyObject *obj_12,
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-many-paths-3.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-many-paths-3.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-meaning-1.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-meaning-1.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-1.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-1.c
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-10.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-10.c
@@ -1,7 +1,7 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
-int test (int flag)
+void test (int flag)
{
int other_flag;
if (flag)
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-2.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-2.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-3.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-3.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-4.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-4.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-5.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-5.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-6.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-6.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-7.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-7.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-paths-8.c
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-reuse.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-reuse.c
@@ -1,7 +1,7 @@
/* { dg-require-effective-target alloca } */
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Multiple calls to malloc (without a free) should return non-equal pointers. */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-sarif-1.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-sarif-1.c
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-vs-local-1a.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-vs-local-1a.c
@@ -1,7 +1,7 @@
/* { dg-additional-options "-fno-analyzer-call-summaries -fanalyzer-transitivity" } */
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int foo (int);
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-vs-local-1b.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-vs-local-1b.c
@@ -1,7 +1,7 @@
/* { dg-additional-options "-fanalyzer-call-summaries" } */
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int foo (int);
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-vs-local-2.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-vs-local-2.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int foo (int);
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-vs-local-3.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-vs-local-3.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int foo (int);
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/malloc-vs-local-4.c
rename to gcc/testsuite/c-c++-common/analyzer/malloc-vs-local-4.c
@@ -22,7 +22,7 @@ void __attribute__((noinline)) callee_2 (int *ptr)
*ptr = 42;
}
-int test_2 (int flag)
+void test_2 (int flag)
{
int i;
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/many-disabled-diagnostics.c
rename to gcc/testsuite/c-c++-common/analyzer/many-disabled-diagnostics.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/many-unused-locals.c
rename to gcc/testsuite/c-c++-common/analyzer/many-unused-locals.c
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/memcpy-1.c
rename to gcc/testsuite/c-c++-common/analyzer/memcpy-1.c
@@ -1,9 +1,10 @@
#include <string.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Function for thwarting expansion of memcpy by optimizer. */
typedef void * (*memcpy_t) (void *dst, const void *src, size_t n);
+extern void *__memcpy_chk (void *, const void *, size_t, size_t);
static memcpy_t __attribute__((noinline))
get_memcpy (void)
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/memcpy-pr107882.c
rename to gcc/testsuite/c-c++-common/analyzer/memcpy-pr107882.c
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/memmove-1.c
rename to gcc/testsuite/c-c++-common/analyzer/memmove-1.c
@@ -1,9 +1,11 @@
#include <string.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Function for thwarting expansion of memmove by optimizer. */
typedef void * (*memmove_t) (void *dst, const void *src, size_t n);
+extern void *__memmove_chk (void *, const void *, size_t, size_t);
+
static memmove_t __attribute__((noinline))
get_memmove (void)
similarity index 99%
rename from gcc/testsuite/gcc.dg/analyzer/memset-1.c
rename to gcc/testsuite/c-c++-common/analyzer/memset-1.c
@@ -1,5 +1,5 @@
#include <string.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Zero-fill of uninitialized buffer. */
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/memset-2.c
rename to gcc/testsuite/c-c++-common/analyzer/memset-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
{
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/memset-CVE-2017-18549-1.c
rename to gcc/testsuite/c-c++-common/analyzer/memset-CVE-2017-18549-1.c
@@ -7,7 +7,7 @@
/* { dg-additional-options "-fno-analyzer-suppress-followups" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
#include <string.h>
typedef unsigned int __u32;
@@ -43,7 +43,7 @@ extern void check_uninit (u8 v);
/* Adapted from drivers/scsi/aacraid/commctrl.c */
-static int aac_send_raw_srb(/* [...snip...] */)
+static void aac_send_raw_srb(/* [...snip...] */)
{
u32 byte_count = 0;
@@ -74,7 +74,7 @@ static int aac_send_raw_srb(/* [...snip...] */)
check_uninit (reply.padding[1]); /* { dg-warning "uninitialized value" } */
}
-static int aac_send_raw_srb_fixed(/* [...snip...] */)
+static void aac_send_raw_srb_fixed(/* [...snip...] */)
{
u32 byte_count = 0;
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-Wunused-macros.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-Wunused-macros.c
@@ -3,7 +3,7 @@
/* { dg-additional-options "-Wunused-macros" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine. */
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-command-line.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-command-line.c
@@ -1,6 +1,6 @@
/* { dg-additional-options "-DO_ACCMODE=42 -DO_RDONLY=0x1 -DO_WRONLY=010" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test_sm_fd_constants (void)
{
similarity index 81%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-enum-and-macro.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-enum-and-macro.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
enum __foo {
O_ACCMODE = 1,
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-enum.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-enum.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine. */
enum {
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros-2.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros-2.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine, as macros
that can't be handled. */
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros-3.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros-3.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine, as macros
that can't be handled. */
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros-4.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros-4.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine, as macros
that can't be handled. */
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros-empty.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros-empty.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine. */
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros-gc.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros-gc.c
@@ -1,6 +1,6 @@
/* { dg-additional-options "--param ggc-min-expand=0 --param ggc-min-heapsize=0" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine. */
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros-traditional.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros-traditional.c
@@ -1,6 +1,6 @@
/* { dg-additional-options "-traditional-cpp" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine. */
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros-undef.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros-undef.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine. */
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/named-constants-via-macros.c
rename to gcc/testsuite/c-c++-common/analyzer/named-constants-via-macros.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Various constants used by the fd state machine. */
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr102671-1.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr102671-1.c
@@ -1,6 +1,16 @@
/* { dg-require-effective-target ptr_eq_long } */
/* { dg-additional-options "-O2 -Wno-shift-count-overflow" } */
+#define REGISTER register
+
+#ifdef __cplusplus
+#define _Bool bool
+#if __cplusplus >= 201703L
+#undef REGISTER
+#define REGISTER
+#endif
+#endif
+
struct lisp;
union vectorlike_header { long size; };
struct Lisp_Symbol { void *unused; };
@@ -114,7 +124,7 @@ wset_combination (struct window *w, _Bool horflag, struct lisp *val)
extern struct lisp *selected_window;
struct window *
-decode_live_window (register struct lisp *window)
+decode_live_window (REGISTER struct lisp *window)
{
if (NILP (window))
return XWINDOW (selected_window);
@@ -124,7 +134,7 @@ decode_live_window (register struct lisp *window)
}
struct window *
-decode_any_window (register struct lisp *window)
+decode_any_window (REGISTER struct lisp *window)
{
struct window *w;
if (NILP (window))
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr102671-2.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr102671-2.c
@@ -1,6 +1,10 @@
/* { dg-require-effective-target ptr_eq_long } */
/* { dg-additional-options "-O2 -Wno-shift-count-overflow" } */
+#ifdef __cplusplus
+#define _Bool bool
+#endif
+
struct lisp;
union vectorlike_header { long size; };
struct Lisp_Symbol { void *unused; };
similarity index 98%
rename from gcc/testsuite/gcc.dg/analyzer/null-deref-pr105755.c
rename to gcc/testsuite/c-c++-common/analyzer/null-deref-pr105755.c
@@ -1,6 +1,10 @@
/* { dg-require-effective-target int32plus } */
/* { dg-additional-options "-Wno-analyzer-too-complex -O2" } */
+#ifdef __cplusplus
+#define _Bool bool
+#endif
+
typedef long int ptrdiff_t;
typedef long int EMACS_INT;
typedef long int intmax_t;
similarity index 73%
rename from gcc/testsuite/gcc.dg/analyzer/null-terminated-strings-1.c
rename to gcc/testsuite/c-c++-common/analyzer/null-terminated-strings-1.c
@@ -1,6 +1,6 @@
-#include "analyzer-decls.h"
+/* { dg-additional-options "-fpermissive" { target c++ } } */
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
-#define NULL ((void *)0)
typedef __SIZE_TYPE__ size_t;
void test_terminated (void)
@@ -10,16 +10,17 @@ void test_terminated (void)
void test_unterminated (void)
{
- char buf[3] = "abc";
+ char buf[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */
__analyzer_get_strlen (buf); /* { dg-warning "stack-based buffer over-read" } */
/* { dg-message "out-of-bounds read at byte 3 but 'buf' ends at byte 3" "bad read event" { target *-*-* } .-1 } */
- /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "null terminator event" { target *-*-* } .-2 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "null terminator event" { target c } .-2 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('& buf'\\) of '(long )?unsigned int __analyzer_get_strlen\\(const char\\*\\)'..." "null terminator event" { target c++ } .-3 } */
}
void test_embedded_nuls (void)
{
/* 0123 456 78. */
- char buf[9] = "abc\0pq\0xy"; /* unterminated. */
+ char buf[9] = "abc\0pq\0xy"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "unterminated" { target c++ } } */
__analyzer_eval (__analyzer_get_strlen (buf) == 3); /* { dg-warning "TRUE" } */
__analyzer_eval (__analyzer_get_strlen (buf + 1) == 2); /* { dg-warning "TRUE" } */
__analyzer_eval (__analyzer_get_strlen (buf + 2) == 1); /* { dg-warning "TRUE" } */
@@ -28,7 +29,8 @@ void test_embedded_nuls (void)
__analyzer_eval (__analyzer_get_strlen (buf + 5) == 1); /* { dg-warning "TRUE" } */
__analyzer_eval (__analyzer_get_strlen (buf + 6) == 0); /* { dg-warning "TRUE" } */
__analyzer_get_strlen (buf + 7); /* { dg-warning "stack-based buffer over-read" } */
- /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '__analyzer_get_strlen'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '__analyzer_get_strlen'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '(long )?unsigned int __analyzer_get_strlen\\(const char\\*\\)'..." "event" { target c++ } .-2 } */
// TODO: fix the "<unknown>" here?
}
@@ -36,7 +38,8 @@ void test_before_start_of_buffer (void)
{
const char *buf = "abc";
__analyzer_get_strlen (buf - 1); /* { dg-warning "buffer under-read" } */
- /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '__analyzer_get_strlen'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '__analyzer_get_strlen'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '(long )?unsigned int __analyzer_get_strlen\\(const char\\*\\)'..." "event" { target c++ } .-2 } */
// TODO: fix the "<unknown>" here?
}
@@ -44,7 +47,8 @@ void test_after_end_of_buffer (void)
{
const char *buf = "abc";
__analyzer_get_strlen (buf + 4); /* { dg-warning "buffer over-read" } */
- /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '__analyzer_get_strlen'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '__analyzer_get_strlen'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('<unknown>'\\) of '(long )?unsigned int __analyzer_get_strlen\\(const char\\*\\)'..." "event" { target c++ } .-2 } */
// TODO: fix the "<unknown>" here?
}
@@ -55,14 +59,16 @@ void test_fully_initialized_but_unterminated (void)
buf[1] = 'b';
buf[2] = 'c';
__analyzer_get_strlen (buf); /* { dg-warning "stack-based buffer over-read" } */
- /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('& buf'\\) of '(long )?unsigned int __analyzer_get_strlen\\(const char\\*\\)'..." "event" { target c++ } .-2 } */
}
void test_uninitialized (void)
{
char buf[16];
__analyzer_get_strlen (buf); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */
- /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('& buf'\\) of '(long )?unsigned int __analyzer_get_strlen\\(const char\\*\\)'..." "event" { target c++ } .-2 } */
}
void test_partially_initialized (void)
@@ -70,14 +76,15 @@ void test_partially_initialized (void)
char buf[16];
buf[0] = 'a';
__analyzer_get_strlen (buf); /* { dg-warning "use of uninitialized value 'buf\\\[1\\\]'" } */
- /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "event" { target *-*-* } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__analyzer_get_strlen'..." "event" { target c } .-1 } */
+ /* { dg-message "while looking for null terminator for argument 1 \\('& buf'\\) of '(long )?unsigned int __analyzer_get_strlen\\(const char\\*\\)'..." "event" { target c++ } .-2 } */
}
char *test_dynamic_1 (void)
{
const char *kvstr = "NAME=value";
size_t len = __builtin_strlen (kvstr);
- char *ptr = __builtin_malloc (len + 1);
+ char *ptr = (char *)__builtin_malloc (len + 1);
if (!ptr)
return NULL;
__builtin_memcpy (ptr, kvstr, len);
@@ -91,7 +98,7 @@ char *test_dynamic_2 (void)
{
const char *kvstr = "NAME=value";
size_t len = __builtin_strlen (kvstr);
- char *ptr = __builtin_malloc (len + 1);
+ char *ptr = (char *)__builtin_malloc (len + 1);
if (!ptr)
return NULL;
__builtin_memcpy (ptr, kvstr, len);
@@ -104,7 +111,7 @@ char *test_dynamic_2 (void)
char *test_dynamic_3 (const char *src)
{
size_t len = __builtin_strlen (src);
- char *ptr = __builtin_malloc (len + 1);
+ char *ptr = (char *)__builtin_malloc (len + 1);
if (!ptr)
return NULL;
__builtin_memcpy (ptr, src, len);
@@ -117,7 +124,7 @@ char *test_dynamic_3 (const char *src)
char *test_dynamic_4 (const char *src)
{
size_t len = __builtin_strlen (src);
- char *ptr = __builtin_malloc (len + 1);
+ char *ptr = (char *)__builtin_malloc (len + 1);
if (!ptr)
return NULL;
__builtin_memcpy (ptr, src, len);
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/omp-parallel-for-1.c
rename to gcc/testsuite/c-c++-common/analyzer/omp-parallel-for-1.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/omp-parallel-for-get-min.c
rename to gcc/testsuite/c-c++-common/analyzer/omp-parallel-for-get-min.c
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/operations.c
rename to gcc/testsuite/c-c++-common/analyzer/operations.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test (int i, int j)
{
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-3.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-3.c
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-4.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-4.c
@@ -1,6 +1,12 @@
/* { dg-additional-options "-Wno-stringop-overflow -Wno-stringop-truncation" } */
#include <string.h>
+#ifdef __cplusplus
+#define CONST_CAST(type, v) const_cast<type> (v)
+#else
+#define CONST_CAST(type, v) v
+#endif
+
/* Wanalyzer-out-of-bounds tests for strpy-related overflows.
The intra-procedural tests are all caught by Wstringop-overflow.
@@ -24,7 +30,7 @@ void test2 (void)
void test3 (void)
{
- char *src = "Hello";
+ char *src = CONST_CAST(char *, "Hello");
char dst[5];
strcpy (dst, src); /* { dg-line test3 } */
@@ -35,7 +41,7 @@ void test3 (void)
void test4 (void)
{
- char *src = "Hello";
+ char *src = CONST_CAST(char *, "Hello");
char dst[6];
strcpy (dst, src);
}
similarity index 90%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-container_of.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-container_of.c
@@ -11,7 +11,7 @@ struct outer {
struct outer *container_of (struct inner *ptr_to_inner)
{
- struct outer *ptr_to_outer = ((struct outer *) (((void *) ptr_to_inner) - __builtin_offsetof(struct outer, inner_struct)));
+ struct outer *ptr_to_outer = ((struct outer *) (((char *)(void *) ptr_to_inner) - (char *)__builtin_offsetof(struct outer, inner_struct)));
return ptr_to_outer;
}
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-coreutils.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-coreutils.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-curl.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-curl.c
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-ascii.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-1-ascii.c
@@ -31,7 +31,7 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
| |
| (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
|
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
/* { dg-begin-multiline-output "" }
@@ -52,4 +52,43 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
|capacity: 40 bytes| |overflow of 4 bytes|
+------------------+ +-------------------+
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ arr[10] = x;
+ ~~~~~~~~^~~
+ event 1 (depth 0)
+ |
+ | int32_t arr[10];
+ | ^~~
+ | |
+ | (1) capacity: 40 bytes
+ |
+ +--> 'void int_arr_write_element_after_end_off_by_one(int32_t)': event 2 (depth 1)
+ |
+ | arr[10] = x;
+ | ~~~~~~~~^~~
+ | |
+ | (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
+ |
+ { dg-end-multiline-output "" { target c++ } } */
+
+/* { dg-begin-multiline-output "" }
+
+ +----------------------------------------+
+ |write from 'int32_t x' (type: 'int32_t')|
+ +----------------------------------------+
+ |
+ |
+ v
+ +------------+------------+--------------++----------------------------------------+
+ | [0] | ... | [9] || |
+ +------------+------------+--------------+| after valid range |
+ |'int32_t arr [10]' (type: 'int32_t[10]')|| |
+ +----------------------------------------++----------------------------------------+
+ |~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~||~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~|
+ | |
+ +---------+--------+ +---------+---------+
+ |capacity: 40 bytes| |overflow of 4 bytes|
+ +------------------+ +-------------------+
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-debug.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-1-debug.c
@@ -37,4 +37,29 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
|capacity: 40 bytes| |overflow of 4 bytes|
+------------------+ +-------------------+
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ +-----------+------------+---------------+---+----------------------------------------+
+ | tc0 | tc1 | tc2 |tc3| tc4 |
+ +-----------+------------+---------------+---+----------------------------------------+
+ | bytes 0-3 | bytes 4-35 | bytes 36-39 | | bytes 40-43 |
+ +-----------+------------+---------------+ +----------------------------------------+
+ +----------------------------------------+
+ |write from 'int32_t x' (type: 'int32_t')|
+ +----------------------------------------+
+ |
+ |
+ v
+ +-----------+------------+---------------+ +----------------------------------------+
+ | [0] | ... | [9] | | |
+ +-----------+------------+---------------+ | after valid range |
+ |'int32_t arr [10]' (type: 'int32_t[10]')| | |
+ +----------------------------------------+ +----------------------------------------+
+ |~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~| |~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~|
+ | |
+ +---------+--------+ +---------+---------+
+ |capacity: 40 bytes| |overflow of 4 bytes|
+ +------------------+ +-------------------+
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-emoji.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-1-emoji.c
@@ -31,7 +31,25 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
| |
| (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
|
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ arr[10] = x;
+ ~~~~~~~~^~~
+ event 1 (depth 0)
+ |
+ | int32_t arr[10];
+ | ^~~
+ | |
+ | (1) capacity: 40 bytes
+ |
+ +--> 'void int_arr_write_element_after_end_off_by_one(int32_t)': event 2 (depth 1)
+ |
+ | arr[10] = x;
+ | ~~~~~~~~^~~
+ | |
+ | (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
+ |
+ { dg-end-multiline-output "" { target c++ } } */
/* { dg-begin-multiline-output "" }
@@ -52,4 +70,24 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
│capacity: 40 bytes│ │⚠️ overflow of 4 bytes│
╰──────────────────╯ ╰──────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌────────────────────────────────────────┐
+ │write from 'int32_t x' (type: 'int32_t')│
+ └────────────────────────────────────────┘
+ │
+ │
+ v
+ ┌────────────┬────────────┬──────────────┐┌────────────────────────────────────────┐
+ │ [0] │ ... │ [9] ││ │
+ ├────────────┴────────────┴──────────────┤│ after valid range │
+ │'int32_t arr [10]' (type: 'int32_t[10]')││ │
+ └────────────────────────────────────────┘└────────────────────────────────────────┘
+ ├───────────────────┬────────────────────┤├───────────────────┬────────────────────┤
+ │ │
+ ╭─────────┴────────╮ ╭───────────┴──────────╮
+ │capacity: 40 bytes│ │⚠️ overflow of 4 bytes│
+ ╰──────────────────╯ ╰──────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-json.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-1-json.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-sarif.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-1-sarif.c
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-1-unicode.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-1-unicode.c
@@ -31,7 +31,25 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
| |
| (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
|
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ arr[10] = x;
+ ~~~~~~~~^~~
+ event 1 (depth 0)
+ |
+ | int32_t arr[10];
+ | ^~~
+ | |
+ | (1) capacity: 40 bytes
+ |
+ +--> 'void int_arr_write_element_after_end_off_by_one(int32_t)': event 2 (depth 1)
+ |
+ | arr[10] = x;
+ | ~~~~~~~~^~~
+ | |
+ | (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
+ |
+ { dg-end-multiline-output "" { target c++ } } */
/* { dg-begin-multiline-output "" }
@@ -52,4 +70,24 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
│capacity: 40 bytes│ │overflow of 4 bytes│
╰──────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌────────────────────────────────────────┐
+ │write from 'int32_t x' (type: 'int32_t')│
+ └────────────────────────────────────────┘
+ │
+ │
+ v
+ ┌────────────┬────────────┬──────────────┐┌────────────────────────────────────────┐
+ │ [0] │ ... │ [9] ││ │
+ ├────────────┴────────────┴──────────────┤│ after valid range │
+ │'int32_t arr [10]' (type: 'int32_t[10]')││ │
+ └────────────────────────────────────────┘└────────────────────────────────────────┘
+ ├───────────────────┬────────────────────┤├───────────────────┬────────────────────┤
+ │ │
+ ╭─────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 40 bytes│ │overflow of 4 bytes│
+ ╰──────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-10.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-10.c
@@ -3,9 +3,10 @@
#include <stdint.h>
#include <stdlib.h>
-int32_t int_vla_write_element_symbolic_before_start (int32_t x, size_t n)
+void int_vla_write_element_symbolic_before_start (int32_t x, size_t n)
{
- int32_t arr[n]; /* { dg-message "\\(1\\) capacity: 'n \\* 4' bytes" } */
+ int32_t arr[n]; /* { dg-message "\\(1\\) capacity: 'n \\* 4' bytes" "" { target c } } */
+ /* { dg-message "\\(1\\) capacity: '\\(n \\* 4\\)' bytes" "" { target c++ } .-1 } */
arr[-2] = 42; /* { dg-warning "stack-based buffer underwrite" } */
}
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-12.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-12.c
@@ -31,7 +31,25 @@ void test8 (size_t size, size_t offset)
│size: 'size' bytes│ │over-read of 'offset' bytes│
╰──────────────────╯ ╰───────────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌──────────────────────────────────────────────────────────────────────┐
+ │ read of 'size + offset' bytes │
+ └──────────────────────────────────────────────────────────────────────┘
+ ^ ^
+ │ │
+ │ │
+ ┌──────────────────────────────────┐┌──────────────────────────────────┐
+ │ buffer allocated on stack at (1) ││ after valid range │
+ └──────────────────────────────────┘└──────────────────────────────────┘
+ ├────────────────┬─────────────────┤├────────────────┬─────────────────┤
+ │ │
+ ╭────────────┴────────────╮ ╭─────────────────┴────────────────╮
+ │size: 'size_t size' bytes│ │over-read of 'size_t offset' bytes│
+ ╰─────────────────────────╯ ╰──────────────────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
/* { dg-begin-multiline-output "" }
@@ -50,4 +68,22 @@ void test8 (size_t size, size_t offset)
│capacity: 'size' bytes│ │overflow of 'offset' bytes│
╰──────────────────────╯ ╰──────────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌──────────────────────────────────────────────────────────────────────┐
+ │ write of 'size + offset' bytes │
+ └──────────────────────────────────────────────────────────────────────┘
+ │ │
+ │ │
+ v v
+ ┌──────────────────────────────────┐┌──────────────────────────────────┐
+ │ buffer allocated on stack at (1) ││ after valid range │
+ └──────────────────────────────────┘└──────────────────────────────────┘
+ ├────────────────┬─────────────────┤├────────────────┬─────────────────┤
+ │ │
+ ╭──────────────┴──────────────╮ ╭────────────────┴────────────────╮
+ │capacity: 'size_t size' bytes│ │overflow of 'size_t offset' bytes│
+ ╰─────────────────────────────╯ ╰─────────────────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-13.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-13.c
@@ -8,7 +8,8 @@ test_non_ascii ()
{
char buf[9];
strcpy (buf, "Liberté\n"); /* { dg-warning "stack-based buffer overflow" } */
- /* { dg-warning "'__builtin_memcpy' writing 10 bytes into a region of size 9 overflows the destination" "" { target *-*-* } .-1 } */
+ /* { dg-warning "'__builtin_memcpy' writing 10 bytes into a region of size 9 overflows the destination" "" { target c } .-1 } */
+ /* { dg-warning "'void\\* __builtin_memcpy\\(void\\*, const void\\*, (long )?unsigned int\\)' writing 10 bytes into a region of size 9 overflows the destination" "" { target c++ } .-2 } */
}
/* Example of non-ASCII UTF-8 that's short enough to fully quote, whilst
@@ -41,4 +42,32 @@ test_non_ascii ()
│capacity: 9 bytes│ │overflow of 1 byte│
╰─────────────────╯ ╰──────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌──────┬──────┬──────┬──────┬──────┬──────┬────┬────┬──────┐┌─────────────────┐
+ │ [0] │ [1] │ [2] │ [3] │ [4] │ [5] │[6] │[7] │ [8] ││ [9] │
+ ├──────┼──────┼──────┼──────┼──────┼──────┼────┼────┼──────┤├─────────────────┤
+ │ 0x4c │ 0x69 │ 0x62 │ 0x65 │ 0x72 │ 0x74 │0xc3│0xa9│ 0x0a ││ 0x00 │
+ ├──────┼──────┼──────┼──────┼──────┼──────┼────┴────┼──────┤├─────────────────┤
+ │U+004c│U+0069│U+0062│U+0065│U+0072│U+0074│ U+00e9 │U+000a││ U+0000 │
+ ├──────┼──────┼──────┼──────┼──────┼──────┼─────────┼──────┤├─────────────────┤
+ │ L │ i │ b │ e │ r │ t │ é │ ││ NUL │
+ ├──────┴──────┴──────┴──────┴──────┴──────┴─────────┴──────┴┴─────────────────┤
+ │ string literal (type: 'const char[10]') │
+ └─────────────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v
+ ┌──────┬────────────────────────────────────────────┬──────┐┌─────────────────┐
+ │ [0] │ ... │ [8] ││ │
+ ├──────┴────────────────────────────────────────────┴──────┤│after valid range│
+ │ 'char buf [9]' (type: 'char[9]') ││ │
+ └──────────────────────────────────────────────────────────┘└─────────────────┘
+ ├────────────────────────────┬─────────────────────────────┤├────────┬────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴────────╮
+ │capacity: 9 bytes│ │overflow of 1 byte│
+ ╰─────────────────╯ ╰──────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-14.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-14.c
@@ -40,7 +40,27 @@ to write to. */
│capacity: 4 bytes│ │overflow of 4 bytes│
╰─────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌────────────────────────────────┐
+ │write from 'int x' (type: 'int')│
+ └────────────────────────────────┘
+ │
+ │
+ v
+ ┌────────────────────────────────────────┐┌────────────────────────────────┐
+ │ [0] ││ │
+ ├────────────────────────────────────────┤│ after valid range │
+ │'int32_t arr_1 [1]' (type: 'int32_t[1]')││ │
+ └────────────────────────────────────────┘└────────────────────────────────┘
+ ├───────────────────┬────────────────────┤├───────────────┬────────────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 4 bytes│ │overflow of 4 bytes│
+ ╰─────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
/* The arr_2 case. */
/* { dg-begin-multiline-output "" }
@@ -62,7 +82,27 @@ to write to. */
│capacity: 8 bytes│ │overflow of 4 bytes│
╰─────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌────────────────────────────────┐
+ │write from 'int x' (type: 'int')│
+ └────────────────────────────────┘
+ │
+ │
+ v
+ ┌───────────────────┬────────────────────┐┌────────────────────────────────┐
+ │ [0] │ [1] ││ │
+ ├───────────────────┴────────────────────┤│ after valid range │
+ │'int32_t arr_2 [2]' (type: 'int32_t[2]')││ │
+ └────────────────────────────────────────┘└────────────────────────────────┘
+ ├───────────────────┬────────────────────┤├───────────────┬────────────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 8 bytes│ │overflow of 4 bytes│
+ ╰─────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
/* The arr_3 case. */
// Perhaps we should show [1] rather than ellipsize here.
@@ -85,7 +125,27 @@ to write to. */
│capacity: 12 bytes│ │overflow of 4 bytes│
╰──────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌────────────────────────────────┐
+ │write from 'int x' (type: 'int')│
+ └────────────────────────────────┘
+ │
+ │
+ v
+ ┌────────────┬────────────┬──────────────┐┌────────────────────────────────┐
+ │ [0] │ ... │ [2] ││ │
+ ├────────────┴────────────┴──────────────┤│ after valid range │
+ │'int32_t arr_3 [3]' (type: 'int32_t[3]')││ │
+ └────────────────────────────────────────┘└────────────────────────────────┘
+ ├───────────────────┬────────────────────┤├───────────────┬────────────────┤
+ │ │
+ ╭─────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 12 bytes│ │overflow of 4 bytes│
+ ╰──────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
/* The arr_4 case. */
/* { dg-begin-multiline-output "" }
@@ -107,4 +167,24 @@ to write to. */
│capacity: 16 bytes│ │overflow of 4 bytes│
╰──────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌────────────────────────────────┐
+ │write from 'int x' (type: 'int')│
+ └────────────────────────────────┘
+ │
+ │
+ v
+ ┌────────────┬────────────┬──────────────┐┌────────────────────────────────┐
+ │ [0] │ ... │ [3] ││ │
+ ├────────────┴────────────┴──────────────┤│ after valid range │
+ │'int32_t arr_4 [4]' (type: 'int32_t[4]')││ │
+ └────────────────────────────────────────┘└────────────────────────────────┘
+ ├───────────────────┬────────────────────┤├───────────────┬────────────────┤
+ │ │
+ ╭─────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 16 bytes│ │overflow of 4 bytes│
+ ╰──────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-15.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-15.c
@@ -10,7 +10,8 @@ test_non_ascii ()
{
char buf[9];
strcpy (buf, "Liberté\n"); /* { dg-warning "stack-based buffer overflow" } */
- /* { dg-warning "'__builtin_memcpy' writing 10 bytes into a region of size 9 overflows the destination" "" { target *-*-* } .-1 } */
+ /* { dg-warning "'__builtin_memcpy' writing 10 bytes into a region of size 9 overflows the destination" "" { target c } .-1 } */
+ /* { dg-warning "'void\\* __builtin_memcpy\\(void\\*, const void\\*, (long )?unsigned int\\)' writing 10 bytes into a region of size 9 overflows the destination" "" { target c++ } .-2 } */
}
/* { dg-begin-multiline-output "" }
@@ -40,4 +41,32 @@ test_non_ascii ()
│capacity: 9 bytes│ │overflow of 1 byte│
╰─────────────────╯ ╰──────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌──────┬──────┬──────┬──────┬──────┬──────┬────┬────┬──────┐┌─────────────────┐
+ │ [0] │ [1] │ [2] │ [3] │ [4] │ [5] │[6] │[7] │ [8] ││ [9] │
+ ├──────┼──────┼──────┼──────┼──────┼──────┼────┼────┼──────┤├─────────────────┤
+ │ 0x4c │ 0x69 │ 0x62 │ 0x65 │ 0x72 │ 0x74 │0xc3│0xa9│ 0x0a ││ 0x00 │
+ ├──────┼──────┼──────┼──────┼──────┼──────┼────┴────┼──────┤├─────────────────┤
+ │U+004c│U+0069│U+0062│U+0065│U+0072│U+0074│ U+00e9 │U+000a││ U+0000 │
+ ├──────┼──────┼──────┼──────┼──────┼──────┼─────────┼──────┤├─────────────────┤
+ │ L │ i │ b │ e │ r │ t │ é │ ││ NUL │
+ ├──────┴──────┴──────┴──────┴──────┴──────┴─────────┴──────┴┴─────────────────┤
+ │ string literal (type: 'const char[10]') │
+ └─────────────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v
+ ┌──────┬────────────────────────────────────────────┬──────┐┌─────────────────┐
+ │ [0] │ ... │ [8] ││ │
+ ├──────┴────────────────────────────────────────────┴──────┤│after valid range│
+ │ 'char buf [9]' (type: 'char[9]') ││ │
+ └──────────────────────────────────────────────────────────┘└─────────────────┘
+ ├────────────────────────────┬─────────────────────────────┤├────────┬────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴────────╮
+ │capacity: 9 bytes│ │overflow of 1 byte│
+ ╰─────────────────╯ ╰──────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-16.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-16.c
@@ -1,12 +1,12 @@
/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
#include <string.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
char *test_fixed_size_heap_2_invalid (void)
{
char str[] = "abc";
- char *p = __builtin_malloc (strlen (str)); /* { dg-message "\\(1\\) capacity: 3 bytes" } */
+ char *p = (char *) __builtin_malloc (strlen (str)); /* { dg-message "\\(1\\) capacity: 3 bytes" } */
if (!p)
return NULL;
strcpy (p, str); /* { dg-warning "heap-based buffer overflow" } */
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-17.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-17.c
@@ -31,4 +31,26 @@ void test (void)
╭─────────┴────────╮ ╭─────────┴─────────╮
│capacity: 10 bytes│ │overflow of 3 bytes│
╰──────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ ┌────┬────┬────┬────┬─────┐┌────┬────┬─────────┐
+ │[0] │[1] │[2] │[3] │ [4] ││[5] │[6] │ [7] │
+ ├────┼────┼────┼────┼─────┤├────┼────┼─────────┤
+ │' ' │'w' │'o' │'r' │ 'l' ││'d' │'!' │ NUL │
+ ├────┴────┴────┴────┴─────┴┴────┴────┴─────────┤
+ │ string literal (type: 'const char[8]') │
+ └──────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │
+ v v v v v v v v
+ ┌────┬──────────────────────────────────────┬─────┐┌───────────────────┐
+ │[0] │ ... │ [9] ││ │
+ ├────┴──────────────────────────────────────┴─────┤│ after valid range │
+ │ 'char buf [10]' (type: 'char[10]') ││ │
+ └─────────────────────────────────────────────────┘└───────────────────┘
+ ├────────────────────────┬────────────────────────┤├─────────┬─────────┤
+ │ │
+ ╭─────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 10 bytes│ │overflow of 3 bytes│
+ ╰──────────────────╯ ╰───────────────────╯
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 51%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-18.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-18.c
@@ -35,4 +35,30 @@ void test (void)
╭─────────┴────────╮ ╭─────────┴─────────╮
│capacity: 11 bytes│ │overflow of 5 bytes│
╰──────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ ┌───────┬───────────┐┌────┬────┬────┬────┬───────┐
+ │ [0] │ [1] ││[2] │[3] │[4] │[5] │ [6] │
+ ├───────┼───────────┤├────┼────┼────┼────┼───────┤
+ │ 0xe3 │ 0x83 ││0xa1│0xe3│0x82│0xa4│ 0x00 │
+ ├───────┴───────────┴┴────┼────┴────┴────┼───────┤
+ │ U+30e1 │ U+30a4 │U+0000 │
+ ├─────────────────────────┼──────────────┼───────┤
+ │ メ │ イ │ NUL │
+ ├─────────────────────────┴──────────────┴───────┤
+ │ string literal (type: 'const char[7]') │
+ └────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │
+ v v v v v v v
+ ┌──────┬──────────────────────┬───────────┐┌───────────────────────────┐
+ │ [0] │ ... │ [10] ││ │
+ ├──────┴──────────────────────┴───────────┤│ after valid range │
+ │ 'char buf [11]' (type: 'char[11]') ││ │
+ └─────────────────────────────────────────┘└───────────────────────────┘
+ ├────────────────────┬────────────────────┤├─────────────┬─────────────┤
+ │ │
+ ╭─────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 11 bytes│ │overflow of 5 bytes│
+ ╰──────────────────╯ ╰───────────────────╯
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 55%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-19.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-19.c
@@ -42,4 +42,26 @@ test_long_string ()
╭─────────┴─────────╮ ╭──────────┴──────────╮
│capacity: 100 bytes│ │overflow of 350 bytes│
╰───────────────────╯ ╰─────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ ┌───┬───┬───┬───┬───┬───┬────────┬─────┬─────┬─────┬─────┬─────┬─────┐
+ │[0]│[1]│[2]│[3]│[4]│[5]│ │[440]│[441]│[442]│[443]│[444]│[445]│
+ ├───┼───┼───┼───┼───┼───┤ ... ├─────┼─────┼─────┼─────┼─────┼─────┤
+ │'L'│'o'│'r'│'e'│'m'│' '│ │ 'o' │ 'r' │ 'u' │ 'm' │ '.' │ NUL │
+ ├───┴───┴───┴───┴───┴───┴────────┴─────┴─────┴─────┴─────┴─────┴─────┤
+ │ string literal (type: 'const char[446]') │
+ └────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v v v v v v
+ ┌───┬──────────────────────────┬─────┐┌────────────────────────────────────┐
+ │[0]│ ... │[99] ││ │
+ ├───┴──────────────────────────┴─────┤│ after valid range │
+ │'char buf [100]' (type: 'char[100]')││ │
+ └────────────────────────────────────┘└────────────────────────────────────┘
+ ├─────────────────┬──────────────────┤├─────────────────┬──────────────────┤
+ │ │
+ ╭─────────┴─────────╮ ╭──────────┴──────────╮
+ │capacity: 100 bytes│ │overflow of 350 bytes│
+ ╰───────────────────╯ ╰─────────────────────╯
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-2.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-2.c
@@ -5,7 +5,8 @@
void int_vla_write_element_after_end_off_by_one(int32_t x, size_t n)
{
- int32_t arr[n]; /* { dg-message "\\(1\\) capacity: 'n \\* 4' bytes" } */
+ int32_t arr[n]; /* { dg-message "\\(1\\) capacity: 'n \\* 4' bytes" "" { target c } } */
+ /* { dg-message "\\(1\\) capacity: '\\(n \\* 4\\)' bytes" "" { target c++ } .-1 } */
arr[n] = x; /* { dg-warning "stack-based buffer overflow" } */
}
@@ -27,4 +28,22 @@ void int_vla_write_element_after_end_off_by_one(int32_t x, size_t n)
│capacity: 'n * 4' bytes│ │overflow of 4 bytes│
╰───────────────────────╯ ╰───────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌────────────────────────────────────────┐
+ │write from 'int32_t x' (type: 'int32_t')│
+ └────────────────────────────────────────┘
+ │
+ │
+ v
+ ┌────────────────────────────────┐┌────────────────────────────────────────┐
+ │buffer allocated on stack at (1)││ after valid range │
+ └────────────────────────────────┘└────────────────────────────────────────┘
+ ├───────────────┬────────────────┤├───────────────────┬────────────────────┤
+ │ │
+ ╭───────────┴───────────╮ ╭─────────┴─────────╮
+ │capacity: 'n * 4' bytes│ │overflow of 4 bytes│
+ ╰───────────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 52%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-4.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-4.c
@@ -17,7 +17,9 @@ test_long_string ()
{
char buf[100];
strcpy (buf, LOREM_IPSUM); /* { dg-warning "stack-based buffer overflow" } */
- /* { dg-warning "'__builtin_memcpy' writing 446 bytes into a region of size 100 overflows the destination" "" { target *-*-* } .-1 } */
+ /* { dg-warning "'__builtin_memcpy' writing 446 bytes into a region of size 100 overflows the destination" "" { target c } .-1 } */
+ /* { dg-warning "'void\\* __builtin_memcpy\\(void\\*, const void\\*, (long )?unsigned int\\)' writing 446 bytes into a region of size 100 overflows the destination" "" { target c++ } .-2 } */
+
}
/* { dg-begin-multiline-output "" }
@@ -43,4 +45,28 @@ test_long_string ()
│capacity: 100 bytes│ │overflow of 346 bytes│
╰───────────────────╯ ╰─────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌───┬───┬───┬───┬───┬───┬──────────────┬─────┬─────┬─────┬─────┬─────┬─────┐
+ │[0]│[1]│[2]│[3]│[4]│[5]│ │[440]│[441]│[442]│[443]│[444]│[445]│
+ ├───┼───┼───┼───┼───┼───┤ ... ├─────┼─────┼─────┼─────┼─────┼─────┤
+ │'L'│'o'│'r'│'e'│'m'│' '│ │ 'o' │ 'r' │ 'u' │ 'm' │ '.' │ NUL │
+ ├───┴───┴───┴───┴───┴───┴──────────────┴─────┴─────┴─────┴─────┴─────┴─────┤
+ │ string literal (type: 'const char[446]') │
+ └──────────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v v v v v v
+ ┌───┬────────────────────┬───────────┐┌────────────────────────────────────┐
+ │[0]│ ... │ [99] ││ │
+ ├───┴────────────────────┴───────────┤│ after valid range │
+ │'char buf [100]' (type: 'char[100]')││ │
+ └────────────────────────────────────┘└────────────────────────────────────┘
+ ├─────────────────┬──────────────────┤├─────────────────┬──────────────────┤
+ │ │
+ ╭─────────┴─────────╮ ╭──────────┴──────────╮
+ │capacity: 100 bytes│ │overflow of 346 bytes│
+ ╰───────────────────╯ ╰─────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
new file mode 100644
@@ -0,0 +1,69 @@
+/* { dg-additional-options "-fdiagnostics-text-art-charset=ascii" } */
+/* { dg-skip-if "" { powerpc-ibm-aix* } } */
+
+#include <string.h>
+
+void
+test_non_ascii ()
+{
+ char buf[5];
+ strcpy (buf, "文字化け"); /* { dg-warning "stack-based buffer overflow" } */
+ /* { dg-warning "'__builtin_memcpy' writing 13 bytes into a region of size 5 overflows the destination" "" { target c } .-1 } */
+ /* { dg-warning "'void\\* __builtin_memcpy\\(void\\*, const void\\*, (long )?unsigned int\\)' writing 13 bytes into a region of size 5 overflows the destination" "" { target c++ } .-2 } */
+
+}
+
+/* Without unicode support, we shouldn't show the printable unicode chars. */
+
+/* { dg-begin-multiline-output "" }
+
+ +-----+-----+-----+----+----++----+----+----+----+----+----+----+------+
+ | [0] | [1] | [2] |[3] |[4] ||[5] |[6] |[7] |[8] |[9] |[10]|[11]| [12] |
+ +-----+-----+-----+----+----++----+----+----+----+----+----+----+------+
+ |0xe6 |0x96 |0x87 |0xe5|0xad||0x97|0xe5|0x8c|0x96|0xe3|0x81|0x91| 0x00 |
+ +-----+-----+-----+----+----++----+----+----+----+----+----+----+------+
+ | U+6587 | U+5b57 | U+5316 | U+3051 |U+0000|
+ +-----------------+---------------+--------------+--------------+------+
+ | string literal (type: 'char[13]') |
+ +----------------------------------------------------------------------+
+ | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
+ v v v v v v v v v v v v v
+ +-----+----------------+----++-----------------------------------------+
+ | [0] | ... |[4] || |
+ +-----+----------------+----+| after valid range |
+ | 'buf' (type: 'char[5]') || |
+ +---------------------------++-----------------------------------------+
+ |~~~~~~~~~~~~~+~~~~~~~~~~~~~||~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~|
+ | |
+ +--------+--------+ +---------+---------+
+ |capacity: 5 bytes| |overflow of 8 bytes|
+ +-----------------+ +-------------------+
+
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ +-----+-----+-----+-----+--------++----+----+----+----+----+----+----+------+
+ | [0] | [1] | [2] | [3] | [4] ||[5] |[6] |[7] |[8] |[9] |[10]|[11]| [12] |
+ +-----+-----+-----+-----+--------++----+----+----+----+----+----+----+------+
+ |0xe6 |0x96 |0x87 |0xe5 | 0xad ||0x97|0xe5|0x8c|0x96|0xe3|0x81|0x91| 0x00 |
+ +-----+-----+-----+-----+--------++----+----+----+----+----+----+----+------+
+ | U+6587 | U+5b57 | U+5316 | U+3051 |U+0000|
+ +-----------------+--------------------+--------------+--------------+------+
+ | string literal (type: 'const char[13]') |
+ +---------------------------------------------------------------------------+
+ | | | | | | | | | | | | |
+ | | | | | | | | | | | | |
+ v v v v v v v v v v v v v
+ +-----+-----------------+--------++-----------------------------------------+
+ | [0] | ... | [4] || |
+ +-----+-----------------+--------+| after valid range |
+ |'char buf [5]' (type: 'char[5]')|| |
+ +--------------------------------++-----------------------------------------+
+ |~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~||~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~|
+ | |
+ +--------+--------+ +---------+---------+
+ |capacity: 5 bytes| |overflow of 8 bytes|
+ +-----------------+ +-------------------+
+
+ { dg-end-multiline-output "" { target c++ } } */
new file mode 100644
@@ -0,0 +1,72 @@
+/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
+/* { dg-skip-if "" { powerpc-ibm-aix* } } */
+
+#include <string.h>
+
+void
+test_non_ascii ()
+{
+ char buf[5];
+ strcpy (buf, "文字化け"); /* { dg-warning "stack-based buffer overflow" } */
+ /* { dg-warning "'__builtin_memcpy' writing 13 bytes into a region of size 5 overflows the destination" "" { target c } .-1 } */
+ /* { dg-warning "'void\\* __builtin_memcpy\\(void\\*, const void\\*, (long )?unsigned int\\)' writing 13 bytes into a region of size 5 overflows the destination" "" { target c++ } .-2 } */
+}
+
+/* With unicode support, we should show the printable unicode chars. */
+
+/* { dg-begin-multiline-output "" }
+
+ ┌─────┬─────┬─────┬────┬────┐┌────┬────┬────┬────┬────┬────┬────┬──────┐
+ │ [0] │ [1] │ [2] │[3] │[4] ││[5] │[6] │[7] │[8] │[9] │[10]│[11]│ [12] │
+ ├─────┼─────┼─────┼────┼────┤├────┼────┼────┼────┼────┼────┼────┼──────┤
+ │0xe6 │0x96 │0x87 │0xe5│0xad││0x97│0xe5│0x8c│0x96│0xe3│0x81│0x91│ 0x00 │
+ ├─────┴─────┴─────┼────┴────┴┴────┼────┴────┴────┼────┴────┴────┼──────┤
+ │ U+6587 │ U+5b57 │ U+5316 │ U+3051 │U+0000│
+ ├─────────────────┼───────────────┼──────────────┼──────────────┼──────┤
+ │ 文 │ 字 │ 化 │ け │ NUL │
+ ├─────────────────┴───────────────┴──────────────┴──────────────┴──────┤
+ │ string literal (type: 'char[13]') │
+ └──────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v v v v
+ ┌─────┬────────────────┬────┐┌─────────────────────────────────────────┐
+ │ [0] │ ... │[4] ││ │
+ ├─────┴────────────────┴────┤│ after valid range │
+ │ 'buf' (type: 'char[5]') ││ │
+ └───────────────────────────┘└─────────────────────────────────────────┘
+ ├─────────────┬─────────────┤├────────────────────┬────────────────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 5 bytes│ │overflow of 8 bytes│
+ ╰─────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌─────┬─────┬─────┬─────┬────────┐┌────┬────┬────┬────┬────┬────┬────┬──────┐
+ │ [0] │ [1] │ [2] │ [3] │ [4] ││[5] │[6] │[7] │[8] │[9] │[10]│[11]│ [12] │
+ ├─────┼─────┼─────┼─────┼────────┤├────┼────┼────┼────┼────┼────┼────┼──────┤
+ │0xe6 │0x96 │0x87 │0xe5 │ 0xad ││0x97│0xe5│0x8c│0x96│0xe3│0x81│0x91│ 0x00 │
+ ├─────┴─────┴─────┼─────┴────────┴┴────┼────┴────┴────┼────┴────┴────┼──────┤
+ │ U+6587 │ U+5b57 │ U+5316 │ U+3051 │U+0000│
+ ├─────────────────┼────────────────────┼──────────────┼──────────────┼──────┤
+ │ 文 │ 字 │ 化 │ け │ NUL │
+ ├─────────────────┴────────────────────┴──────────────┴──────────────┴──────┤
+ │ string literal (type: 'const char[13]') │
+ └───────────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v v v v
+ ┌─────┬─────────────────┬────────┐┌─────────────────────────────────────────┐
+ │ [0] │ ... │ [4] ││ │
+ ├─────┴─────────────────┴────────┤│ after valid range │
+ │'char buf [5]' (type: 'char[5]')││ │
+ └────────────────────────────────┘└─────────────────────────────────────────┘
+ ├───────────────┬────────────────┤├────────────────────┬────────────────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 5 bytes│ │overflow of 8 bytes│
+ ╰─────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 50%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-6.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-6.c
@@ -28,7 +28,8 @@ test_bad_memcpy ()
/* { dg-warning "stack-based buffer underwrite" "" { target *-*-* } .-1 } */
/* { dg-warning "buffer under-read" "" { target *-*-* } .-2 } */
/* { dg-warning "buffer over-read" "" { target *-*-* } .-3 } */
- /* { dg-warning "'memcpy' writing 4096 bytes into a region of size 0 overflows the destination" "" { target *-*-* } .-4 } */
+ /* { dg-warning "'memcpy' writing 4096 bytes into a region of size 0 overflows the destination" "" { target c } .-4 } */
+ /* { dg-warning "'void\\* memcpy\\(void\\*, const void\\*, size_t\\)' writing 4096 bytes into a region of size 0 overflows the destination" "" { target c++ } .-5 } */
}
/* { dg-begin-multiline-output "" }
@@ -50,7 +51,27 @@ test_bad_memcpy ()
│under-read of 100 bytes│ │size: 446 bytes│ │over-read of 3550 bytes│
╰───────────────────────╯ ╰───────────────╯ ╰───────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌───────────────────────────────────────────────────────────────────────────────┐
+ │ read of 4096 bytes │
+ └───────────────────────────────────────────────────────────────────────────────┘
+ ^ ^ ^ ^ ^
+ │ │ │ │ │
+ │ │ │ │ │
+ ┌──────────────────┐┌────────────┬────────────┬──────────────┐┌─────────────────┐
+ │ ││ [0] │ ... │ [445] ││ │
+ │before valid range│├────────────┴────────────┴──────────────┤│after valid range│
+ │ ││string literal (type: 'const char[446]')││ │
+ └──────────────────┘└────────────────────────────────────────┘└─────────────────┘
+ ├────────┬─────────┤├───────────────────┬────────────────────┤├────────┬────────┤
+ │ │ │
+ ╭────────┴──────────────╮ ╭───────┴───────╮ ╭───────────┴───────────╮
+ │under-read of 100 bytes│ │size: 446 bytes│ │over-read of 3550 bytes│
+ ╰───────────────────────╯ ╰───────────────╯ ╰───────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
/* { dg-begin-multiline-output "" }
@@ -74,7 +95,27 @@ test_bad_memcpy ()
│underwrite of 50 bytes│
╰──────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌───────────────────────────────────────────────────────────────────────────┐
+ │ write of 4096 bytes │
+ └───────────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │
+ │ │ │ │ │
+ v v v v v
+ ┌──────────────────┐┌───────────┬───────────┬────────────┐┌─────────────────┐
+ │ ││ [0] │ ... │ [99] ││ │
+ │before valid range│├───────────┴───────────┴────────────┤│after valid range│
+ │ ││'char buf [100]' (type: 'char[100]')││ │
+ └──────────────────┘└────────────────────────────────────┘└─────────────────┘
+ ├────────┬─────────┤├─────────────────┬──────────────────┤├────────┬────────┤
+ │ │ │
+ ╭────────┴─────────────╮ ╭─────────┴─────────╮ ╭───────────┴──────────╮
+ │underwrite of 50 bytes│ │capacity: 100 bytes│ │overflow of 3946 bytes│
+ ╰──────────────────────╯ ╰───────────────────╯ ╰──────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
/* The read and write diagrams are each emitted twice: once for the "before"
and once for the "after" diagnostic. */
@@ -98,7 +139,27 @@ test_bad_memcpy ()
│under-read of 100 bytes│ │size: 446 bytes│ │over-read of 3550 bytes│
╰───────────────────────╯ ╰───────────────╯ ╰───────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌───────────────────────────────────────────────────────────────────────────────┐
+ │ read of 4096 bytes │
+ └───────────────────────────────────────────────────────────────────────────────┘
+ ^ ^ ^ ^ ^
+ │ │ │ │ │
+ │ │ │ │ │
+ ┌──────────────────┐┌────────────┬────────────┬──────────────┐┌─────────────────┐
+ │ ││ [0] │ ... │ [445] ││ │
+ │before valid range│├────────────┴────────────┴──────────────┤│after valid range│
+ │ ││string literal (type: 'const char[446]')││ │
+ └──────────────────┘└────────────────────────────────────────┘└─────────────────┘
+ ├────────┬─────────┤├───────────────────┬────────────────────┤├────────┬────────┤
+ │ │ │
+ ╭────────┴──────────────╮ ╭───────┴───────╮ ╭───────────┴───────────╮
+ │under-read of 100 bytes│ │size: 446 bytes│ │over-read of 3550 bytes│
+ ╰───────────────────────╯ ╰───────────────╯ ╰───────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
/* { dg-begin-multiline-output "" }
@@ -122,4 +183,24 @@ test_bad_memcpy ()
│underwrite of 50 bytes│
╰──────────────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌───────────────────────────────────────────────────────────────────────────┐
+ │ write of 4096 bytes │
+ └───────────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │
+ │ │ │ │ │
+ v v v v v
+ ┌──────────────────┐┌───────────┬───────────┬────────────┐┌─────────────────┐
+ │ ││ [0] │ ... │ [99] ││ │
+ │before valid range│├───────────┴───────────┴────────────┤│after valid range│
+ │ ││'char buf [100]' (type: 'char[100]')││ │
+ └──────────────────┘└────────────────────────────────────┘└─────────────────┘
+ ├────────┬─────────┤├─────────────────┬──────────────────┤├────────┬────────┤
+ │ │ │
+ ╭────────┴─────────────╮ ╭─────────┴─────────╮ ╭───────────┴──────────╮
+ │underwrite of 50 bytes│ │capacity: 100 bytes│ │overflow of 3946 bytes│
+ ╰──────────────────────╯ ╰───────────────────╯ ╰──────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
new file mode 100644
@@ -0,0 +1,62 @@
+/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
+/* { dg-skip-if "" { powerpc-ibm-aix* } } */
+
+#include <string.h>
+
+void
+test_string_with_control_chars ()
+{
+ char buf[8];
+ strcpy (buf, "\tone\n\ttwo\n"); /* { dg-warning "stack-based buffer overflow" } */
+ /* { dg-warning "'__builtin_memcpy' writing 11 bytes into a region of size 8 overflows the destination" "" { target c } .-1 } */
+ /* { dg-warning "'void\\* __builtin_memcpy\\(void\\*, const void\\*, (long )?unsigned int\\)' writing 11 bytes into a region of size 8 overflows the destination" "" { target c++ } .-2 } */
+}
+
+/* { dg-begin-multiline-output "" }
+
+ ┌──────┬──────┬──────┬─────┬─────┬─────┬─────┬─────┐┌─────┬─────┬──────┐
+ │ [0] │ [1] │ [2] │ [3] │ [4] │ [5] │ [6] │ [7] ││ [8] │ [9] │ [10] │
+ ├──────┼──────┼──────┼─────┼─────┼─────┼─────┼─────┤├─────┼─────┼──────┤
+ │ 0x09 │ 'o' │ 'n' │ 'e' │0x0a │0x09 │ 't' │ 'w' ││ 'o' │0x0a │ NUL │
+ ├──────┴──────┴──────┴─────┴─────┴─────┴─────┴─────┴┴─────┴─────┴──────┤
+ │ string literal (type: 'char[11]') │
+ └──────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v v
+ ┌──────┬─────────────────────────────────────┬─────┐┌──────────────────┐
+ │ [0] │ ... │ [7] ││ │
+ ├──────┴─────────────────────────────────────┴─────┤│after valid range │
+ │ 'buf' (type: 'char[8]') ││ │
+ └──────────────────────────────────────────────────┘└──────────────────┘
+ ├────────────────────────┬─────────────────────────┤├────────┬─────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 8 bytes│ │overflow of 3 bytes│
+ ╰─────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌──────┬──────┬──────┬─────┬─────┬─────┬─────┬─────┐┌─────┬─────┬──────┐
+ │ [0] │ [1] │ [2] │ [3] │ [4] │ [5] │ [6] │ [7] ││ [8] │ [9] │ [10] │
+ ├──────┼──────┼──────┼─────┼─────┼─────┼─────┼─────┤├─────┼─────┼──────┤
+ │ 0x09 │ 'o' │ 'n' │ 'e' │0x0a │0x09 │ 't' │ 'w' ││ 'o' │0x0a │ NUL │
+ ├──────┴──────┴──────┴─────┴─────┴─────┴─────┴─────┴┴─────┴─────┴──────┤
+ │ string literal (type: 'const char[11]') │
+ └──────────────────────────────────────────────────────────────────────┘
+ │ │ │ │ │ │ │ │ │ │ │
+ │ │ │ │ │ │ │ │ │ │ │
+ v v v v v v v v v v v
+ ┌──────┬─────────────────────────────────────┬─────┐┌──────────────────┐
+ │ [0] │ ... │ [7] ││ │
+ ├──────┴─────────────────────────────────────┴─────┤│after valid range │
+ │ 'char buf [8]' (type: 'char[8]') ││ │
+ └──────────────────────────────────────────────────┘└──────────────────┘
+ ├────────────────────────┬─────────────────────────┤├────────┬─────────┤
+ │ │
+ ╭────────┴────────╮ ╭─────────┴─────────╮
+ │capacity: 8 bytes│ │overflow of 3 bytes│
+ ╰─────────────────╯ ╰───────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 54%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-9.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-9.c
@@ -39,4 +39,27 @@ int32_t struct_arr_read_x_element_before_start_far(void)
│under-read of 4 bytes│ │2380 bytes│ │size: 240 bytes│
╰─────────────────────╯ ╰──────────╯ ╰───────────────╯
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+
+ ┌───────────────────────────┐
+ │read of 'int32_t' (4 bytes)│
+ └───────────────────────────┘
+ ^
+ │
+ │
+ ┌───────────────────────────┐ ┌───────────┬───────────┬─────────────┐
+ │ │ │ [0] │ ... │ [9] │
+ │ before valid range │ ├───────────┴───────────┴─────────────┤
+ │ │ │'st arr [10]' (type: 'struct st[10]')│
+ └───────────────────────────┘ └─────────────────────────────────────┘
+ ├─────────────┬─────────────┤├┬─┤├──────────────────┬──────────────────┤
+ │ │ │
+ │ ╭─────┴────╮ ╭───────┴───────╮
+ │ │2380 bytes│ │size: 240 bytes│
+ │ ╰──────────╯ ╰───────────────╯
+ ╭──────────┴──────────╮
+ │under-read of 4 bytes│
+ ╰─────────────────────╯
+
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 64%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-multiline-1.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-multiline-1.c
@@ -34,4 +34,22 @@ void int_arr_write_element_after_end_off_by_one(int32_t x)
| |
| (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
|
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ arr[10] = x;
+ ~~~~~~~~^~~
+ event 1 (depth 0)
+ |
+ | int32_t arr[10];
+ | ^~~
+ | |
+ | (1) capacity: 40 bytes
+ |
+ +--> 'void int_arr_write_element_after_end_off_by_one(int32_t)': event 2 (depth 1)
+ |
+ | arr[10] = x;
+ | ~~~~~~~~^~~
+ | |
+ | (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
+ |
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 62%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-multiline-2.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-multiline-2.c
@@ -29,4 +29,20 @@ void int_vla_write_element_after_end_off_by_one(int32_t x, size_t n)
| |
| (2) write of 4 bytes at offset 'n * 4' exceeds the buffer
|
- { dg-end-multiline-output "" } */
+ { dg-end-multiline-output "" { target c } } */
+/* { dg-begin-multiline-output "" }
+ arr[n] = x;
+ ~~~~~~~^~~
+ 'void int_vla_write_element_after_end_off_by_one(int32_t, size_t)': events 1-2 (depth 1)
+ |
+ | int32_t arr[n];
+ | ^~~
+ | |
+ | (1) capacity: '(n * 4)' bytes
+ |
+ | arr[n] = x;
+ | ~~~~~~~~~~
+ | |
+ | (2) write of 4 bytes at offset '(n * 4)' exceeds the buffer
+ |
+ { dg-end-multiline-output "" { target c++ } } */
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-pr110387.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-pr110387.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-read-char-arr.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-read-char-arr.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-read-int-arr.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-read-int-arr.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-read-struct-arr.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-read-struct-arr.c
similarity index 95%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-realloc-grow.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-realloc-grow.c
@@ -21,7 +21,7 @@ fread_file (FILE *stream, int flags, size_t *length)
char *buf = NULL;
size_t alloc = BUFSIZ;
- if (!(buf = malloc (alloc)))
+ if (!(buf = (char *)malloc (alloc)))
return NULL; /* errno is ENOMEM. */
{
@@ -44,7 +44,7 @@ fread_file (FILE *stream, int flags, size_t *length)
else
alloc = PTRDIFF_MAX;
- if (!(new_buf = realloc (buf, alloc)))
+ if (!(new_buf = (char *)realloc (buf, alloc)))
{
save_errno = errno;
break;
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-write-char-arr.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-write-char-arr.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-write-int-arr.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-write-int-arr.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-write-struct-arr.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-write-struct-arr.c
similarity index 91%
rename from gcc/testsuite/gcc.dg/analyzer/out-of-bounds-zero.c
rename to gcc/testsuite/c-c++-common/analyzer/out-of-bounds-zero.c
@@ -32,7 +32,7 @@ void test3 (void)
void test4 (void)
{
- int32_t *buf = malloc (sizeof (int32_t));
+ int32_t *buf = (int32_t *)malloc (sizeof (int32_t));
if (!buf)
return;
@@ -43,7 +43,7 @@ void test4 (void)
void test5 (void)
{
- int32_t *buf = malloc (0);
+ int32_t *buf = (int32_t *)malloc (0);
if (!buf)
return;
@@ -57,7 +57,7 @@ void test5 (void)
void test6 (void)
{
- int32_t *buf = malloc (0);
+ int32_t *buf = (int32_t *)malloc (0);
if (!buf)
return;
similarity index 83%
rename from gcc/testsuite/gcc.dg/analyzer/params-2.c
rename to gcc/testsuite/c-c++-common/analyzer/params-2.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
static void ensure_equal (int a, int b)
{
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/params.c
rename to gcc/testsuite/c-c++-common/analyzer/params.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
static int __analyzer_called_function(int j)
{
similarity index 81%
rename from gcc/testsuite/gcc.dg/analyzer/paths-1.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-1.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct foo
{
similarity index 81%
rename from gcc/testsuite/gcc.dg/analyzer/paths-1a.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-1a.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
union foo
{
similarity index 87%
rename from gcc/testsuite/gcc.dg/analyzer/paths-2.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-2.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
int test (int a)
{
similarity index 94%
rename from gcc/testsuite/gcc.dg/analyzer/paths-3.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-3.c
@@ -1,7 +1,7 @@
/* { dg-additional-options "-fanalyzer-transitivity" } */
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
int test_1 (int a, int b)
{
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/paths-4.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-4.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
struct state
{
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/paths-5.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-5.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test (int *p, int n)
{
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/paths-6.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-6.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
/* Verify that ordering of writes doesn't matter when merging states. */
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/paths-7.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-7.c
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int foo (int);
similarity index 85%
rename from gcc/testsuite/gcc.dg/analyzer/paths-8.c
rename to gcc/testsuite/c-c++-common/analyzer/paths-8.c
@@ -1,4 +1,4 @@
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
static void __attribute__((noinline))
__analyzer_callee_1 (void)
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/pattern-test-1.c
rename to gcc/testsuite/c-c++-common/analyzer/pattern-test-1.c
similarity index 77%
rename from gcc/testsuite/gcc.dg/analyzer/pattern-test-2.c
rename to gcc/testsuite/c-c++-common/analyzer/pattern-test-2.c
@@ -1,6 +1,10 @@
/* { dg-additional-options "-fanalyzer-checker=pattern-test -O2" } */
// TODO: run this at every optimization level
+#ifdef __cplusplus
+#define _Bool bool
+#endif
+
extern void foo(void *);
extern void bar(void *);
@@ -26,7 +30,8 @@ void test_2 (void *p, void *q)
foo(p);
/* { dg-warning "pattern match on 'p != 0'" "p != 0" { target *-*-* } cond_2 } */
- /* { dg-warning "pattern match on 'p == 0 | q == 0 != 0'" "tmp1 | tmp2 != 0" { target *-*-* } cond_2 } */
+ /* { dg-warning "pattern match on 'p == 0 | q == 0 != 0'" "tmp1 | tmp2 != 0" { target c } cond_2 } */
+ /* { dg-warning "pattern match on '\\(\\(p == 0\\) | \\(q == 0\\)\\) != false'" "tmp1 | tmp2 != 0" { target c++ } cond_2 } */
/* { dg-warning "pattern match on 'q != 0'" "q != 0" { target *-*-* } cond_2 } */
}
@@ -42,6 +47,7 @@ void test_3 (void *p, void *q)
foo(p);
/* { dg-warning "pattern match on 'p == 0'" "p == 0" { target *-*-* } cond_3 } */
- /* { dg-warning "pattern match on 'p == 0 & q == 0 == 0'" "tmp1 & tmp2 == 0" { target *-*-* } cond_3 } */
+ /* { dg-warning "pattern match on 'p == 0 & q == 0 == 0'" "tmp1 & tmp2 == 0" { target c } cond_3 } */
+ /* { dg-warning "pattern match on '\\(\\(p == 0\\) & \\(q == 0\\)\\) == false'" "tmp1 & tmp2 == 0" { target c++ } cond_3 } */
/* { dg-warning "pattern match on 'q == 0'" "q == 0" { target *-*-* } cond_3 } */
}
similarity index 77%
rename from gcc/testsuite/gcc.dg/analyzer/phi-2.c
rename to gcc/testsuite/c-c++-common/analyzer/phi-2.c
@@ -20,7 +20,7 @@ void mbochs_close(struct list_head *dmabufs,
while (&dmabuf->next != dmabufs)
{
dmabuf = tmp;
- tmp = ((struct mbochs_dmabuf *)((void *)(tmp->next.next) - __builtin_offsetof(struct mbochs_dmabuf, next)));
+ tmp = ((struct mbochs_dmabuf *)((char *)(void *)(tmp->next.next) - (char *)__builtin_offsetof(struct mbochs_dmabuf, next)));
}
/* [...snip...] */
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/pipe-1.c
rename to gcc/testsuite/c-c++-common/analyzer/pipe-1.c
@@ -1,6 +1,7 @@
/* { dg-additional-options "-fno-analyzer-suppress-followups" } */
+/* { dg-additional-options "-fno-exceptions" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int pipe(int pipefd[2]);
extern int close(int fd);
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c
rename to gcc/testsuite/c-c++-common/analyzer/pipe-glibc.c
@@ -1,6 +1,7 @@
/* Example of pipe usage from glibc manual. */
/* { dg-skip-if "" { "avr-*-*" } } */
+/* { dg-additional-options "-fno-exceptions" } */
#include <sys/types.h>
#include <unistd.h>
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/pipe-manpages.c
rename to gcc/testsuite/c-c++-common/analyzer/pipe-manpages.c
@@ -26,6 +26,8 @@ the source, must acknowledge the copyright and authors of this work.
*/
+/* { dg-additional-options "-fno-exceptions" } */
+
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/pipe-pr107486.c
rename to gcc/testsuite/c-c++-common/analyzer/pipe-pr107486.c
similarity index 88%
rename from gcc/testsuite/gcc.dg/analyzer/pipe-void-return.c
rename to gcc/testsuite/c-c++-common/analyzer/pipe-void-return.c
@@ -1,4 +1,5 @@
/* { dg-additional-options "-fno-analyzer-suppress-followups" } */
+/* { dg-additional-options "-fno-exceptions" } */
extern void pipe(int pipefd[2]);
extern int close(int fd);
similarity index 92%
rename from gcc/testsuite/gcc.dg/analyzer/pipe2-1.c
rename to gcc/testsuite/c-c++-common/analyzer/pipe2-1.c
@@ -1,6 +1,7 @@
/* { dg-additional-options "-fno-analyzer-suppress-followups" } */
+/* { dg-additional-options "-fno-exceptions" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
extern int pipe2(int pipefd[2], int flags);
extern int close(int fd);
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/pointer-merging.c
rename to gcc/testsuite/c-c++-common/analyzer/pointer-merging.c
similarity index 93%
rename from gcc/testsuite/gcc.dg/analyzer/pr93032-mztools-simplified.c
rename to gcc/testsuite/c-c++-common/analyzer/pr93032-mztools-simplified.c
@@ -1,7 +1,7 @@
/* { dg-do "compile" } */
/* Minimal replacement of system headers. */
-#define NULL ((void *) 0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef struct _IO_FILE FILE;
extern FILE *fopen(const char *__restrict __filename,
const char *__restrict __modes);
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/pr93290.c
rename to gcc/testsuite/c-c++-common/analyzer/pr93290.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/analyzer/pr93352.c
rename to gcc/testsuite/c-c++-common/analyzer/pr93352.c
similarity index 89%
rename from gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility-2.c
rename to gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-feasibility-2.c
@@ -4,13 +4,12 @@
/* { dg-do "compile" } */
-#include "analyzer-decls.h"
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
#define PATH_SEPARATOR ':'
#define LOCALE_ALIAS_PATH "value for LOCALE_ALIAS_PATH"
-const char *
-_nl_expand_alias (void)
+void _nl_expand_alias (void)
{
static const char *locale_alias_path;
similarity index 97%
rename from gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-feasibility-3.c
rename to gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-feasibility-3.c
@@ -25,7 +25,7 @@
/* Minimal version of system headers. */
typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *)0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef struct _IO_FILE FILE;
extern FILE *fopen (const char *__restrict __filename,
similarity index 96%
rename from gcc/testsuite/gcc.dg/analyzer/pr93355-localealias-simplified.c
rename to gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-simplified.c
@@ -23,7 +23,7 @@
USA. */
/* Minimal version of system headers. */
-#define NULL ((void *) 0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef struct _IO_FILE FILE;
extern FILE *fopen(const char *__restrict __filename,
const char *__restrict __modes);
deleted file mode 100644
@@ -1,31 +0,0 @@
-extern int
-my_printf (void *my_object, const char *my_format, ...)
- __attribute__ ((format (printf, 2, 3)));
-/* { dg-message "parameter 2 of 'my_printf' marked as a format string via 'format' attribute" "attr note" { target *-*-* } .-2 } */
-/* { dg-message "argument 2 of 'my_printf' must be a pointer to a null-terminated string" "arg note" { target *-*-* } .-3 } */
-
-int test_empty (void *my_object, const char *msg)
-{
- return my_printf (my_object, "");
-}
-
-int test_percent_s (void *my_object, const char *msg)
-{
- return my_printf (my_object, "%s\n", msg);
-}
-
-int
-test_unterminated_format (void *my_object)
-{
- char fmt[3] = "abc";
- return my_printf (my_object, fmt); /* { dg-warning "stack-based buffer over-read" } */
- /* { dg-message "while looking for null terminator for argument 2 \\('&fmt'\\) of 'my_printf'..." "event" { target *-*-* } .-1 } */
-}
-
-int
-test_uninitialized_format (void *my_object)
-{
- char fmt[10];
- return my_printf (my_object, fmt); /* { dg-warning "use of uninitialized value 'fmt\\\[0\\\]'" } */
- /* { dg-message "while looking for null terminator for argument 2 \\('&fmt'\\) of 'my_printf'..." "event" { target *-*-* } .-1 } */
-}
@@ -1,5 +1,7 @@
/* { dg-additional-options "-fgimple" } */
+/* C only: -fgimple is no valid for C++. */
+
typedef long long int i64;
int __GIMPLE (ssa)
@@ -1,4 +1,9 @@
-#define NULL ((void*)0)
+/* C only: C++ exceptions cause a false positive va-leak to be
+ emitted at line 42.
+ Therefore this test has been duplicated as
+ c-c++-common/analyzer/error-2-noexcept.c */
+
+#include "analyzer-decls.h"
typedef __SIZE_TYPE__ size_t;
extern int errno;
@@ -3,6 +3,8 @@
conjured_svalues whilst handling a long chain of external
function calls. */
+/* C only: -Wno-implicit-function-declaration and -Wno-int-conversion are not valid in C++. */
+
/* { dg-additional-options "-Wno-implicit-function-declaration -Wno-int-conversion -Wno-analyzer-too-complex" } */
#define NULL ((void *)0)
@@ -1,3 +1,8 @@
+/* C only: C++ exceptions cause a false positive file-leak to be
+ emitted at line 19.
+ Therefore this test has been duplicated as
+ c-c++-common/analyzer/file-2-noexcept.c */
+
typedef struct FILE FILE;
FILE* fopen (const char*, const char*);
@@ -17,7 +22,7 @@ void test (const char *path)
return; /* { dg-bogus "leak of FILE" } */
fclose (f.m_f);
- fclose (f.m_f); /* { dg-warning "double 'fclose' of FILE 'f.m_f'" } */
+ fclose (f.m_f); /* { dg-warning "double 'fclose' of FILE 'f.m_f'" "" { target c } } */
}
/* Swallow -Wuse-after-free issued for the same problem
deleted file mode 100644
@@ -1,41 +0,0 @@
-/* { dg-additional-options "-fdiagnostics-text-art-charset=ascii" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
-
-#include <string.h>
-
-void
-test_non_ascii ()
-{
- char buf[5];
- strcpy (buf, "文字化け"); /* { dg-warning "stack-based buffer overflow" } */
- /* { dg-warning "'__builtin_memcpy' writing 13 bytes into a region of size 5 overflows the destination" "" { target *-*-* } .-1 } */
-}
-
-/* Without unicode support, we shouldn't show the printable unicode chars. */
-
-/* { dg-begin-multiline-output "" }
-
- +-----+-----+-----+----+----++----+----+----+----+----+----+----+------+
- | [0] | [1] | [2] |[3] |[4] ||[5] |[6] |[7] |[8] |[9] |[10]|[11]| [12] |
- +-----+-----+-----+----+----++----+----+----+----+----+----+----+------+
- |0xe6 |0x96 |0x87 |0xe5|0xad||0x97|0xe5|0x8c|0x96|0xe3|0x81|0x91| 0x00 |
- +-----+-----+-----+----+----++----+----+----+----+----+----+----+------+
- | U+6587 | U+5b57 | U+5316 | U+3051 |U+0000|
- +-----------------+---------------+--------------+--------------+------+
- | string literal (type: 'char[13]') |
- +----------------------------------------------------------------------+
- | | | | | | | | | | | | |
- | | | | | | | | | | | | |
- v v v v v v v v v v v v v
- +-----+----------------+----++-----------------------------------------+
- | [0] | ... |[4] || |
- +-----+----------------+----+| after valid range |
- | 'buf' (type: 'char[5]') || |
- +---------------------------++-----------------------------------------+
- |~~~~~~~~~~~~~+~~~~~~~~~~~~~||~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~|
- | |
- +--------+--------+ +---------+---------+
- |capacity: 5 bytes| |overflow of 8 bytes|
- +-----------------+ +-------------------+
-
- { dg-end-multiline-output "" } */
deleted file mode 100644
@@ -1,43 +0,0 @@
-/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
-
-#include <string.h>
-
-void
-test_non_ascii ()
-{
- char buf[5];
- strcpy (buf, "文字化け"); /* { dg-warning "stack-based buffer overflow" } */
- /* { dg-warning "'__builtin_memcpy' writing 13 bytes into a region of size 5 overflows the destination" "" { target *-*-* } .-1 } */
-}
-
-/* With unicode support, we should show the printable unicode chars. */
-
-/* { dg-begin-multiline-output "" }
-
- ┌─────┬─────┬─────┬────┬────┐┌────┬────┬────┬────┬────┬────┬────┬──────┐
- │ [0] │ [1] │ [2] │[3] │[4] ││[5] │[6] │[7] │[8] │[9] │[10]│[11]│ [12] │
- ├─────┼─────┼─────┼────┼────┤├────┼────┼────┼────┼────┼────┼────┼──────┤
- │0xe6 │0x96 │0x87 │0xe5│0xad││0x97│0xe5│0x8c│0x96│0xe3│0x81│0x91│ 0x00 │
- ├─────┴─────┴─────┼────┴────┴┴────┼────┴────┴────┼────┴────┴────┼──────┤
- │ U+6587 │ U+5b57 │ U+5316 │ U+3051 │U+0000│
- ├─────────────────┼───────────────┼──────────────┼──────────────┼──────┤
- │ 文 │ 字 │ 化 │ け │ NUL │
- ├─────────────────┴───────────────┴──────────────┴──────────────┴──────┤
- │ string literal (type: 'char[13]') │
- └──────────────────────────────────────────────────────────────────────┘
- │ │ │ │ │ │ │ │ │ │ │ │ │
- │ │ │ │ │ │ │ │ │ │ │ │ │
- v v v v v v v v v v v v v
- ┌─────┬────────────────┬────┐┌─────────────────────────────────────────┐
- │ [0] │ ... │[4] ││ │
- ├─────┴────────────────┴────┤│ after valid range │
- │ 'buf' (type: 'char[5]') ││ │
- └───────────────────────────┘└─────────────────────────────────────────┘
- ├─────────────┬─────────────┤├────────────────────┬────────────────────┤
- │ │
- ╭────────┴────────╮ ╭─────────┴─────────╮
- │capacity: 5 bytes│ │overflow of 8 bytes│
- ╰─────────────────╯ ╰───────────────────╯
-
- { dg-end-multiline-output "" } */
deleted file mode 100644
@@ -1,37 +0,0 @@
-/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
-/* { dg-skip-if "" { powerpc-ibm-aix* } } */
-
-#include <string.h>
-
-void
-test_string_with_control_chars ()
-{
- char buf[8];
- strcpy (buf, "\tone\n\ttwo\n"); /* { dg-warning "stack-based buffer overflow" } */
- /* { dg-warning "'__builtin_memcpy' writing 11 bytes into a region of size 8 overflows the destination" "" { target *-*-* } .-1 } */
-}
-
-/* { dg-begin-multiline-output "" }
-
- ┌──────┬──────┬──────┬─────┬─────┬─────┬─────┬─────┐┌─────┬─────┬──────┐
- │ [0] │ [1] │ [2] │ [3] │ [4] │ [5] │ [6] │ [7] ││ [8] │ [9] │ [10] │
- ├──────┼──────┼──────┼─────┼─────┼─────┼─────┼─────┤├─────┼─────┼──────┤
- │ 0x09 │ 'o' │ 'n' │ 'e' │0x0a │0x09 │ 't' │ 'w' ││ 'o' │0x0a │ NUL │
- ├──────┴──────┴──────┴─────┴─────┴─────┴─────┴─────┴┴─────┴─────┴──────┤
- │ string literal (type: 'char[11]') │
- └──────────────────────────────────────────────────────────────────────┘
- │ │ │ │ │ │ │ │ │ │ │
- │ │ │ │ │ │ │ │ │ │ │
- v v v v v v v v v v v
- ┌──────┬─────────────────────────────────────┬─────┐┌──────────────────┐
- │ [0] │ ... │ [7] ││ │
- ├──────┴─────────────────────────────────────┴─────┤│after valid range │
- │ 'buf' (type: 'char[8]') ││ │
- └──────────────────────────────────────────────────┘└──────────────────┘
- ├────────────────────────┬─────────────────────────┤├────────┬─────────┤
- │ │
- ╭────────┴────────╮ ╭─────────┴─────────╮
- │capacity: 8 bytes│ │overflow of 3 bytes│
- ╰─────────────────╯ ╰───────────────────╯
-
- { dg-end-multiline-output "" } */
@@ -1,3 +1,5 @@
+/* C only: K&R C syntax is not supported in C++. */
+
/* Integration test to ensure we issue FILE * leak diagnostics for
this particular non-trivial case.
Adapted from zlib/contrib/minizip/mztools.c, with all #includes
@@ -9,7 +11,7 @@
/* Minimal replacement of system headers. */
typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *) 0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef struct _IO_FILE FILE;
extern FILE *fopen(const char *__restrict __filename,
@@ -160,7 +162,7 @@ uLong* bytesRecovered;
dataSize = uncpsize;
}
if (dataSize > 0) {
- char* data = malloc(dataSize);
+ char* data = (char *)malloc(dataSize);
if (data != NULL) {
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
@@ -1,3 +1,5 @@
+/* C only: K&R C syntax is not supported in C++. */
+
/* Integration test to ensure we issue FILE * leak diagnostics for
this particular non-trivial case.
Adapted from zlib/contrib/minizip/mztools.c, with all #includes
@@ -9,7 +11,7 @@
/* Minimal replacement of system headers. */
typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *) 0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
typedef struct _IO_FILE FILE;
extern FILE *fopen(const char *__restrict __filename,
@@ -160,7 +162,7 @@ uLong* bytesRecovered;
dataSize = uncpsize;
}
if (dataSize > 0) {
- char* data = malloc(dataSize);
+ char* data = (char *)malloc(dataSize);
if (data != NULL) {
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
@@ -1,3 +1,5 @@
+/* C only: K&R C syntax is not supported in C++. */
+
/* Integration test to ensure we issue a FILE * leak diagnostic for
this particular non-trivial case.
Adapted from intl/localealias.c, with all #includes removed. */
@@ -28,7 +30,7 @@
/* Minimal version of system headers. */
typedef __SIZE_TYPE__ size_t;
-#define NULL ((void *) 0)
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
#define PATH_SEPARATOR ':'
typedef struct _IO_FILE FILE;