From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 82329385B503; Fri, 19 Jul 2024 16:48:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82329385B503 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1721407723; bh=gza10TJa7ccT+ajypnxEfeiJKz7DUZDX7lPZ/Z3QIRM=; h=From:To:Subject:Date:From; b=hEuMHItu1JjEe5WU3Xjvl8smhnsLVe9ilOVL0Jq4hcC+3iA5gh+A9tTih8LlYg9Sm eS3nxz2RhZAmShfTh6+G/Z2mmERnf0a7ppJDNzwws4GkXdBT019apmquTbE0Y7nLMa sTJcB7rTpxMbYA6wb89D5tCEeK7QKsFOTHFk2ma4= From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/116006] New: RFE: detect usage of pointers to local variables that are out of scope Date: Fri, 19 Jul 2024 16:48:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D116006 Bug ID: 116006 Summary: RFE: detect usage of pointers to local variables that are out of scope Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- Consider e.g.: struct A *extref =3D something; ... for (int i =3D 0; i < n; i++) { struct A intref =3D *extref; intref.memb =3D i; extref =3D &intref; } This is storing a pointer to local variable "intref" into extref. I think we detect the case where someone tries to use *extref once the func= tion frame has been popped (via the poisoned_svalue machinery) but I don't think= we detect the case where the usage happens in the same function but outside the scope of "intref". Trying it out here: https://godbolt.org/z/6s9WMh53K but I can't seem to tri= gger even the popped frame case=