From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2209) id 5FE053851C35; Wed, 16 Sep 2020 22:58:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FE053851C35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600297114; bh=fir139b7YkZO9kzhPP3+EzGQSCsHGZc+D1FPDFhW7P0=; h=From:To:Subject:Date:From; b=LtTQwL6VWMTcfkqNZlx6UfwjUkbIchLzRDVfVh21Htfcsa2pgK0Nz46k55HqRLG2a j+aGE+qz89+S6VgAlhWwQb5pEieAFOZRfmugVKKFprh2BcYmSeUXX9UiBh/SHRZYHs YxX56et5Cgl97z9qdS55vVrpX0XwuZnkvdDiqVTY= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: David Malcolm To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-3242] analyzer: getchar has no side-effects X-Act-Checkin: gcc X-Git-Author: David Malcolm X-Git-Refname: refs/heads/master X-Git-Oldrev: 3f4b15f52f4d5f202a7f27bdbb41a8fff218d323 X-Git-Newrev: e097c9ab83192fc2f738ec6426a275282e9a51ea Message-Id: <20200916225834.5FE053851C35@sourceware.org> Date: Wed, 16 Sep 2020 22:58:34 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Sep 2020 22:58:34 -0000 https://gcc.gnu.org/g:e097c9ab83192fc2f738ec6426a275282e9a51ea commit r11-3242-ge097c9ab83192fc2f738ec6426a275282e9a51ea Author: David Malcolm Date: Wed Sep 16 13:12:39 2020 -0400 analyzer: getchar has no side-effects Seen whilst debugging another issue, where the analyzer was assuming conservatively that a call to getchar could clobber a global. This is handled for most of the other stdio functions by the list in sm-file.cc gcc/analyzer/ChangeLog: * region-model.cc (region_model::on_call_pre): Treat getchar as having no side-effects. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/getchar-1.c: New test. Diff: --- gcc/analyzer/region-model.cc | 5 +++++ gcc/testsuite/gcc.dg/analyzer/getchar-1.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index d53272e4332..1312391557d 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -732,6 +732,11 @@ region_model::on_call_pre (const gcall *call, region_model_context *ctxt) return impl_call_calloc (cd); else if (is_named_call_p (callee_fndecl, "alloca", call, 1)) return impl_call_alloca (cd); + else if (is_named_call_p (callee_fndecl, "getchar", call, 0)) + { + /* No side-effects (tracking stream state is out-of-scope + for the analyzer). */ + } else if (is_named_call_p (callee_fndecl, "memset", call, 3)) { impl_call_memset (cd); diff --git a/gcc/testsuite/gcc.dg/analyzer/getchar-1.c b/gcc/testsuite/gcc.dg/analyzer/getchar-1.c new file mode 100644 index 00000000000..25595e0786e --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/getchar-1.c @@ -0,0 +1,19 @@ +#include +#include "analyzer-decls.h" + +int test_1 (void) +{ + int c = getchar (); + return c; +} + +int glob_2; +int test_2 (void) +{ + int c; + glob_2 = 42; + __analyzer_eval (glob_2 == 42); /* { dg-warning "TRUE" } */ + c = getchar (); + __analyzer_eval (glob_2 == 42); /* { dg-warning "TRUE" } */ + return c; +}