From 6ce32595abdf5c6edcc598a623634d7c8cd09d5a Mon Sep 17 00:00:00 2001 From: Krisztian Rugasi Date: Fri, 16 May 2025 13:06:11 +0200 Subject: [PATCH] Don't take union field addresses when option is specified --- src/VariableSelector.cpp | 11 ++++++++--- src/VariableSelector.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/VariableSelector.cpp b/src/VariableSelector.cpp index 173444072..86815ee8a 100644 --- a/src/VariableSelector.cpp +++ b/src/VariableSelector.cpp @@ -419,7 +419,8 @@ VariableSelector::choose_var(vector vars, eMatchType mt, const vector& invalid_vars, bool no_bitfield, - bool no_expand_struct_union) + bool no_expand_struct_union, + bool no_union) { vector ok_vars; vector::iterator i; @@ -438,6 +439,8 @@ VariableSelector::choose_var(vector vars, // skip any type mismatched var if (no_bitfield && (*i)->isBitfield_) continue; + if (no_union && (*i)->is_inside_union_field()) + continue; if (type && !type->match((*i)->type, mt)) { continue; } @@ -844,16 +847,18 @@ VariableSelector::make_init_value(Effect::Access access, const CGContext &cg_con vector vars = find_all_visible_vars(b); vector dummy; + const bool no_union = !CGOptions::take_union_field_addr(); + Variable *var = NULL; // b == NULL means we are generating init for globals if (!b && CGOptions::ccomp()) { get_all_array_vars(dummy); - var = choose_var(vars, access, cg_context, type, &qfer, eExact, dummy, true, true); + var = choose_var(vars, access, cg_context, type, &qfer, eExact, dummy, true, true, no_union); } else { if (!CGOptions::addr_taken_of_locals()) get_all_local_vars(b, dummy); - var = choose_var(vars, access, cg_context, type, &qfer, eExact, dummy, true); + var = choose_var(vars, access, cg_context, type, &qfer, eExact, dummy, true, false, no_union); } ERROR_GUARD(NULL); diff --git a/src/VariableSelector.h b/src/VariableSelector.h index 338e32546..d1ba57c26 100644 --- a/src/VariableSelector.h +++ b/src/VariableSelector.h @@ -74,7 +74,7 @@ class VariableSelector static const Variable* choose_visible_read_var(const Block* b, vector written_vars, const Type* type, const vector& facts); static Variable* choose_var(vector vars, Effect::Access access, const CGContext &cg_context, const Type* type, const CVQualifiers* qfer, - eMatchType mt, const vector& invalid_vars, bool no_bitfield = false, bool no_expand_struct = false); + eMatchType mt, const vector& invalid_vars, bool no_bitfield = false, bool no_expand_struct = false, bool no_union = false); static Variable *select_deref_pointer(Effect::Access access, const CGContext &cg_context, const Type* type, const CVQualifiers* qfer, const vector& invalid_vars); static Variable *SelectLoopCtrlVar(const CGContext &cg_context, const vector& invalid_vars);