aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/region-model.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2023-06-26 09:57:21 -0700
committerIan Lance Taylor <iant@golang.org>2023-06-26 09:57:21 -0700
commitaa1e672b5d99102b03eb5fb9c51609c45f62bff7 (patch)
tree886212591b1c9d127eaaf234a4a2e22452ea384a /gcc/analyzer/region-model.cc
parent97e31a0a2a2d2273687fcdb4e5416aab1a2186e1 (diff)
parent3a39a31b8ae9c6465434aefa657f7fcc86f905c0 (diff)
downloadgcc-devel/gccgo.zip
gcc-devel/gccgo.tar.gz
gcc-devel/gccgo.tar.bz2
Merge from trunk revision 3a39a31b8ae9c6465434aefa657f7fcc86f905c0.devel/gccgo
Diffstat (limited to 'gcc/analyzer/region-model.cc')
-rw-r--r--gcc/analyzer/region-model.cc52
1 files changed, 35 insertions, 17 deletions
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 598196a..6bc60f8 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -507,7 +507,7 @@ public:
bool terminate_path_p () const final override { return true; }
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
switch (m_pkind)
{
@@ -638,7 +638,7 @@ public:
return OPT_Wanalyzer_shift_count_negative;
}
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
return warning_at (rich_loc, get_controlling_option (),
"shift by negative count (%qE)", m_count_cst);
@@ -685,7 +685,7 @@ public:
return OPT_Wanalyzer_shift_count_overflow;
}
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
return warning_at (rich_loc, get_controlling_option (),
"shift by count (%qE) >= precision of type (%qi)",
@@ -1736,7 +1736,7 @@ check_external_function_for_access_attr (const gcall *call,
tree ptr_tree = gimple_call_arg (call, access->ptrarg);
const svalue *ptr_sval = get_rvalue (ptr_tree, &my_ctxt);
const region *reg = deref_rvalue (ptr_sval, ptr_tree, &my_ctxt);
- check_region_for_write (reg, &my_ctxt);
+ check_region_for_write (reg, nullptr, &my_ctxt);
/* We don't use the size arg for now. */
}
}
@@ -2522,8 +2522,8 @@ region_model::deref_rvalue (const svalue *ptr_sval, tree ptr_tree,
const poisoned_svalue *poisoned_sval
= as_a <const poisoned_svalue *> (ptr_sval);
enum poison_kind pkind = poisoned_sval->get_poison_kind ();
- ctxt->warn (make_unique<poisoned_value_diagnostic>
- (ptr, pkind, NULL, NULL));
+ ctxt->warn (::make_unique<poisoned_value_diagnostic>
+ (ptr, pkind, nullptr, nullptr));
}
}
}
@@ -2576,7 +2576,7 @@ public:
return OPT_Wanalyzer_write_to_const;
}
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
auto_diagnostic_group d;
bool warned;
@@ -2644,7 +2644,7 @@ public:
return OPT_Wanalyzer_write_to_string_literal;
}
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
return warning_at (rich_loc, get_controlling_option (),
"write to string literal");
@@ -2742,6 +2742,15 @@ region_model::get_capacity (const region *reg) const
/* Look through sized regions to get at the capacity
of the underlying regions. */
return get_capacity (reg->get_parent_region ());
+ case RK_STRING:
+ {
+ /* "Capacity" here means "size". */
+ const string_region *string_reg = as_a <const string_region *> (reg);
+ tree string_cst = string_reg->get_string_cst ();
+ return m_mgr->get_or_create_int_cst (size_type_node,
+ TREE_STRING_LENGTH (string_cst));
+ }
+ break;
}
if (const svalue *recorded = get_dynamic_extents (reg))
@@ -2781,11 +2790,14 @@ region_model::get_string_size (const region *reg) const
/* If CTXT is non-NULL, use it to warn about any problems accessing REG,
using DIR to determine if this access is a read or write.
- Return TRUE if an UNKNOWN_SVALUE needs be created. */
+ Return TRUE if an UNKNOWN_SVALUE needs be created.
+ If SVAL_HINT is non-NULL, use it as a hint in diagnostics
+ about the value that would be written to REG. */
bool
region_model::check_region_access (const region *reg,
enum access_direction dir,
+ const svalue *sval_hint,
region_model_context *ctxt) const
{
/* Fail gracefully if CTXT is NULL. */
@@ -2794,7 +2806,7 @@ region_model::check_region_access (const region *reg,
bool need_unknown_sval = false;
check_region_for_taint (reg, dir, ctxt);
- if (!check_region_bounds (reg, dir, ctxt))
+ if (!check_region_bounds (reg, dir, sval_hint, ctxt))
need_unknown_sval = true;
switch (dir)
@@ -2815,9 +2827,10 @@ region_model::check_region_access (const region *reg,
void
region_model::check_region_for_write (const region *dest_reg,
+ const svalue *sval_hint,
region_model_context *ctxt) const
{
- check_region_access (dest_reg, DIR_WRITE, ctxt);
+ check_region_access (dest_reg, DIR_WRITE, sval_hint, ctxt);
}
/* If CTXT is non-NULL, use it to warn about any problems reading from REG.
@@ -2827,7 +2840,7 @@ bool
region_model::check_region_for_read (const region *src_reg,
region_model_context *ctxt) const
{
- return check_region_access (src_reg, DIR_READ, ctxt);
+ return check_region_access (src_reg, DIR_READ, NULL, ctxt);
}
/* Concrete subclass for casts of pointers that lead to trailing bytes. */
@@ -2863,7 +2876,7 @@ public:
return OPT_Wanalyzer_allocation_size;
}
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
diagnostic_metadata m;
m.add_cwe (131);
@@ -3203,7 +3216,7 @@ region_model::set_value (const region *lhs_reg, const svalue *rhs_sval,
check_region_size (lhs_reg, rhs_sval, ctxt);
- check_region_for_write (lhs_reg, ctxt);
+ check_region_for_write (lhs_reg, rhs_sval, ctxt);
m_store.set_value (m_mgr->get_store_manager(), lhs_reg, rhs_sval,
ctxt ? ctxt->get_uncertainty () : NULL);
@@ -3836,7 +3849,12 @@ region_model::get_representative_path_var_1 (const svalue *sval,
/* Prevent infinite recursion. */
if (visited->contains (sval))
- return path_var (NULL_TREE, 0);
+ {
+ if (sval->get_kind () == SK_CONSTANT)
+ return path_var (sval->maybe_get_constant (), 0);
+ else
+ return path_var (NULL_TREE, 0);
+ }
visited->add (sval);
/* Handle casts by recursion into get_representative_path_var. */
@@ -4941,7 +4959,7 @@ public:
return same_tree_p (m_arg, ((const float_as_size_arg &) other).m_arg);
}
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
diagnostic_metadata m;
bool warned = warning_meta (rich_loc, m, get_controlling_option (),
@@ -5303,7 +5321,7 @@ public:
return OPT_Wanalyzer_exposure_through_uninit_copy;
}
- bool emit (rich_location *rich_loc) final override
+ bool emit (rich_location *rich_loc, logger *) final override
{
diagnostic_metadata m;
/* CWE-200: Exposure of Sensitive Information to an Unauthorized Actor. */