diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-08-11 16:46:49 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-08-11 16:46:49 +0200 |
commit | 7840b4dc05539cf5575b3e9ff57ff5f6c3da2cae (patch) | |
tree | a9139a627ff165f24adeb611b5ff969b2f36a575 /gcc/c-family/c-common.c | |
parent | 299c98578bda88c020a6d5b2c319c9e191a315d4 (diff) | |
download | gcc-7840b4dc05539cf5575b3e9ff57ff5f6c3da2cae.zip gcc-7840b4dc05539cf5575b3e9ff57ff5f6c3da2cae.tar.gz gcc-7840b4dc05539cf5575b3e9ff57ff5f6c3da2cae.tar.bz2 |
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 <jakub@redhat.com>
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.
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r-- | gcc/c-family/c-common.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 96ed233..873bea9 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -7017,8 +7017,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", |