From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 1CD8C3972029; Wed, 16 Sep 2020 19:22:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CD8C3972029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600284178; bh=4hxDY06943iiHAy8d5UKiChLN7kTcdLrUoyaCW8dBd0=; h=From:To:Subject:Date:From; b=UbHXPfshDHYT84vctTgvN+iw/SHAOicfoA1dCn2/m4FkO1oiuTtSgxghTU+KhIbUa 99P8tmWfH6GKyUiQjc0+t2hJpwxr+wIVyCjXDRyQqmDPGZQTE0LkXwUps29fg/PkAv ZCqlcTKJ2iWT3Yzu8ZaG+7LB44Txtw84UIG6D9uU= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-8908] c-family: Fix ICE in get_atomic_generic_size [PR96545] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: cdc1ed0ceaf7e520164c262358ea6bfe89ff027c X-Git-Newrev: 67627293b4fe2b230c6c32484752adb49f713315 Message-Id: <20200916192258.1CD8C3972029@sourceware.org> Date: Wed, 16 Sep 2020 19:22:58 +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 19:22:58 -0000 https://gcc.gnu.org/g:67627293b4fe2b230c6c32484752adb49f713315 commit r9-8908-g67627293b4fe2b230c6c32484752adb49f713315 Author: Jakub Jelinek Date: Tue Aug 11 16:46:49 2020 +0200 c-family: Fix ICE in get_atomic_generic_size [PR96545] As the testcase shows, we would ICE if the type of the first argument of various atomic builtins was pointer to (non-void) incomplete type, we would assume that TYPE_SIZE_UNIT must be non-NULL. This patch diagnoses it instead. And also changes the TREE_CODE != INTEGER_CST check to !tree_fits_uhwi_p, as we use tree_to_uhwi after this and at least in theory the int could be too large and not fit. 2020-08-11 Jakub Jelinek PR c/96545 * c-common.c (get_atomic_generic_size): Require that first argument's type points to a complete type and use tree_fits_uhwi_p instead of just INTEGER_CST TREE_CODE check for the TYPE_SIZE_UNIT. * c-c++-common/pr96545.c: New test. (cherry picked from commit 7840b4dc05539cf5575b3e9ff57ff5f6c3da2cae) Diff: --- gcc/c-family/c-common.c | 9 ++++++++- gcc/testsuite/c-c++-common/pr96545.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 18d69274b87..485e2076f68 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -6891,8 +6891,15 @@ get_atomic_generic_size (location_t loc, tree function, return 0; } + if (!COMPLETE_TYPE_P (TREE_TYPE (type_0))) + { + error_at (loc, "argument 1 of %qE must be a pointer to a complete type", + function); + return 0; + } + /* Types must be compile time constant sizes. */ - if (TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type_0)))) != INTEGER_CST) + if (!tree_fits_uhwi_p ((TYPE_SIZE_UNIT (TREE_TYPE (type_0))))) { error_at (loc, "argument 1 of %qE must be a pointer to a constant size type", diff --git a/gcc/testsuite/c-c++-common/pr96545.c b/gcc/testsuite/c-c++-common/pr96545.c new file mode 100644 index 00000000000..bc6b0cf345c --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr96545.c @@ -0,0 +1,31 @@ +/* PR c/96545 */ +/* { dg-do compile } */ + +extern char x[], y[], z[]; +struct S; +extern struct S s, t, u; +int v, w; + +void +foo (void) +{ + __atomic_exchange (&x, &y, &z, 0); /* { dg-error "must be a pointer to a complete type" } */ +} + +void +bar (void) +{ + __atomic_exchange (&s, &t, &u, 0); /* { dg-error "must be a pointer to a complete type" } */ +} + +void +baz (void) +{ + __atomic_exchange (&v, &t, &w, 0); /* { dg-error "size mismatch in argument 2 of" } */ +} + +void +qux (void) +{ + __atomic_exchange (&v, &w, &t, 0); /* { dg-error "size mismatch in argument 3 of" } */ +}