* c++: Fix null this pointer [PR 98624]
@ 2021-01-19 19:35 Nathan Sidwell
0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2021-01-19 19:35 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 179 bytes --]
There's no need for this function to have an object, so make it
static and avoid UB.
gcc/cp/
* module.cc (trees_out::write_location): Make static.
--
Nathan Sidwell
[-- Attachment #2: pr98624.diff --]
[-- Type: text/x-patch, Size: 477 bytes --]
diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc
index 1fd0bcfe3eb..3b224b616c1 100644
--- i/gcc/cp/module.cc
+++ w/gcc/cp/module.cc
@@ -3727,7 +3727,7 @@ class GTY((chain_next ("%h.parent"), for_user)) module_state {
static cpp_macro *deferred_macro (cpp_reader *, location_t, cpp_hashnode *);
public:
- void write_location (bytes_out &, location_t);
+ static void write_location (bytes_out &, location_t);
location_t read_location (bytes_in &) const;
public:
^ permalink raw reply [flat|nested] 2+ messages in thread
* c++: Fix null this pointer [PR 98624]
@ 2021-01-21 19:42 Nathan Sidwell
0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2021-01-21 19:42 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 453 bytes --]
One may not use a null this pointer to invoke a static member
function. This fixes the remaining ubsan errors found with an
ubsan bootstrap.
PR c++/98624
gcc/cp/
* module.cc (depset::hash::find_dependencies): Add
module arg.
(trees_out::core_vals): Check state before calling
write_location.
(sort_cluster, module_state::write): Adjust
find_dependencies call.
--
Nathan Sidwell
[-- Attachment #2: pr98624-2.diff --]
[-- Type: text/x-patch, Size: 4170 bytes --]
diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc
index 8f9c7940ef8..6741ae03ee7 100644
--- i/gcc/cp/module.cc
+++ w/gcc/cp/module.cc
@@ -2567,7 +2567,7 @@ public:
void add_class_entities (vec<tree, va_gc> *);
public:
- void find_dependencies ();
+ void find_dependencies (module_state *);
bool finalize_dependencies ();
vec<depset *> connect ();
};
@@ -5898,7 +5898,8 @@ trees_out::core_vals (tree t)
if (!DECL_TEMPLATE_PARM_P (t))
WT (t->decl_minimal.context);
- state->write_location (*this, t->decl_minimal.locus);
+ if (state)
+ state->write_location (*this, t->decl_minimal.locus);
}
if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON))
@@ -6001,7 +6002,8 @@ trees_out::core_vals (tree t)
if (CODE_CONTAINS_STRUCT (code, TS_EXP))
{
- state->write_location (*this, t->exp.locus);
+ if (state)
+ state->write_location (*this, t->exp.locus);
/* Walk in forward order, as (for instance) REQUIRES_EXPR has a
bunch of unscoped parms on its first operand. It's safer to
@@ -6140,9 +6142,12 @@ trees_out::core_vals (tree t)
/* Miscellaneous common nodes. */
case BLOCK:
- state->write_location (*this, t->block.locus);
- state->write_location (*this, t->block.end_locus);
-
+ if (state)
+ {
+ state->write_location (*this, t->block.locus);
+ state->write_location (*this, t->block.end_locus);
+ }
+
/* DECL_LOCAL_DECL_P decls are first encountered here and
streamed by value. */
chained_decls (t->block.vars);
@@ -6183,7 +6188,8 @@ trees_out::core_vals (tree t)
/* The ompcode is serialized in start. */
if (streaming_p ())
WU (t->omp_clause.subcode.map_kind);
- state->write_location (*this, t->omp_clause.locus);
+ if (state)
+ state->write_location (*this, t->omp_clause.locus);
unsigned len = omp_clause_num_ops[OMP_CLAUSE_CODE (t)];
for (unsigned ix = 0; ix != len; ix++)
@@ -6270,8 +6276,9 @@ trees_out::core_vals (tree t)
WT (((lang_tree_node *)t)->lambda_expression.extra_scope);
/* pending_proxies is a parse-time thing. */
gcc_assert (!((lang_tree_node *)t)->lambda_expression.pending_proxies);
- state->write_location
- (*this, ((lang_tree_node *)t)->lambda_expression.locus);
+ if (state)
+ state->write_location
+ (*this, ((lang_tree_node *)t)->lambda_expression.locus);
if (streaming_p ())
{
WU (((lang_tree_node *)t)->lambda_expression.default_capture_mode);
@@ -6291,8 +6298,9 @@ trees_out::core_vals (tree t)
case STATIC_ASSERT:
WT (((lang_tree_node *)t)->static_assertion.condition);
WT (((lang_tree_node *)t)->static_assertion.message);
- state->write_location
- (*this, ((lang_tree_node *)t)->static_assertion.location);
+ if (state)
+ state->write_location
+ (*this, ((lang_tree_node *)t)->static_assertion.location);
break;
case TEMPLATE_DECL:
@@ -6324,7 +6332,8 @@ trees_out::core_vals (tree t)
WT (m.binfo);
WT (m.decl);
WT (m.diag_decl);
- state->write_location (*this, m.loc);
+ if (state)
+ state->write_location (*this, m.loc);
}
}
}
@@ -13159,9 +13168,9 @@ depset::hash::add_mergeable (depset *mergeable)
entries on the same binding that need walking. */
void
-depset::hash::find_dependencies ()
+depset::hash::find_dependencies (module_state *module)
{
- trees_out walker (NULL, NULL, *this);
+ trees_out walker (NULL, module, *this);
vec<depset *> unreached;
unreached.create (worklist.length ());
@@ -13547,7 +13556,7 @@ sort_cluster (depset::hash *original, depset *scc[], unsigned size)
gcc_checking_assert (use_lwm <= bind_lwm);
dump (dumper::MERGE) && dump ("Ordering %u/%u depsets", use_lwm, size);
- table.find_dependencies ();
+ table.find_dependencies (nullptr);
vec<depset *> order = table.connect ();
gcc_checking_assert (order.length () == use_lwm);
@@ -17571,7 +17580,7 @@ module_state::write (elf_out *to, cpp_reader *reader)
}
/* Now join everything up. */
- table.find_dependencies ();
+ table.find_dependencies (this);
if (!table.finalize_dependencies ())
{
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-21 19:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-19 19:35 c++: Fix null this pointer [PR 98624] Nathan Sidwell
2021-01-21 19:42 Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).