analyzer: fix ICE on putenv of a field [PR124232]

store::mark_as_escaped requires the region passed in to be a base
region, but the analyzer's implementation of putenv wasn't respecting
that.

Fixed thusly.

gcc/analyzer/ChangeLog:
	PR analyzer/124232
	* kf.cc (kf_putenv::impl_call_pre): Use base region when marking
	pointer as having escaped.

gcc/testsuite/ChangeLog:
	PR analyzer/124232
	* gcc.dg/analyzer/putenv-ice-pr124232.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
David Malcolm
2026-02-25 21:50:58 -05:00
parent 6557358b39
commit f8380ded1f
2 changed files with 11 additions and 1 deletions

View File

@@ -858,7 +858,7 @@ public:
const region *reg
= model->deref_rvalue (ptr_sval, cd.get_arg_tree (0), ctxt);
store_manager *store_mgr = model->get_manager ()->get_store_manager ();
model->get_store ()->mark_as_escaped (*store_mgr, reg);
model->get_store ()->mark_as_escaped (*store_mgr, reg->get_base_region ());
enum memory_space mem_space = reg->get_memory_space ();
switch (mem_space)
{

View File

@@ -0,0 +1,10 @@
extern int putenv (char *__string)
__attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1)));
struct {
char s[16];
} e = { "a=b" };
int main(int, char *[]) {
return putenv(e.s);
}