Hi! Not all INTEGER_CSTs satisfy tree_fits_uhwi_p, and those that don't ICE in tree_to_uhwi. But, what the memmodel_base function actually does is mask only the 16 low bits, the upper bits are reserved for target dependent flags and -Winvalid-memory-model already warns about those during expansion. So it makes no sense to warn about say (-1 << 16) here, thus I'm using TREE_INT_CST_LOW instead of tree_to_*hwi, because we really care just about the low 16 bits thereof.
The i386.c change is an obvious capitalization fix. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-11-20 Jakub Jelinek <ja...@redhat.com> PR c++/83059 * c-common.c (get_atomic_generic_size): Use TREE_INT_CST_LOW instead of tree_to_uhwi, formatting fix. * config/i386/i386.c (ix86_memmodel_check): Start -Winvalid-memory-model diagnostics with lowercase letter. * c-c++-common/pr83059.c: New test. --- gcc/c-family/c-common.c.jj 2017-11-15 09:38:22.000000000 +0100 +++ gcc/c-family/c-common.c 2017-11-20 11:35:08.720607317 +0100 @@ -6671,13 +6671,10 @@ get_atomic_generic_size (location_t loc, tree p = (*params)[x]; if (TREE_CODE (p) == INTEGER_CST) { - int i = tree_to_uhwi (p); - if (i < 0 || (memmodel_base (i) >= MEMMODEL_LAST)) - { - warning_at (loc, OPT_Winvalid_memory_model, - "invalid memory model argument %d of %qE", x + 1, - function); - } + if (memmodel_base (TREE_INT_CST_LOW (p)) >= MEMMODEL_LAST) + warning_at (loc, OPT_Winvalid_memory_model, + "invalid memory model argument %d of %qE", x + 1, + function); } else if (!INTEGRAL_TYPE_P (TREE_TYPE (p))) --- gcc/config/i386/i386.c.jj 2017-11-20 11:02:42.000000000 +0100 +++ gcc/config/i386/i386.c 2017-11-20 11:44:16.286754295 +0100 @@ -49066,7 +49066,7 @@ ix86_memmodel_check (unsigned HOST_WIDE_ || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE))) { warning (OPT_Winvalid_memory_model, - "Unknown architecture specific memory model"); + "unknown architecture specific memory model"); return MEMMODEL_SEQ_CST; } strong = (is_mm_acq_rel (model) || is_mm_seq_cst (model)); --- gcc/testsuite/c-c++-common/pr83059.c.jj 2017-11-20 12:01:52.491531090 +0100 +++ gcc/testsuite/c-c++-common/pr83059.c 2017-11-20 12:02:32.930024696 +0100 @@ -0,0 +1,10 @@ +/* PR c++/83059 */ +/* { dg-do compile } */ + +void +foo (int *p, int *q, int *r) +{ + __atomic_compare_exchange (p, q, r, 0, 0, -1); /* { dg-warning "invalid memory model argument 6" } */ + /* { dg-warning "unknown architecture specifi" "" { target *-*-* } .-1 } */ + /* { dg-warning "failure memory model cannot be stronger than success memory model" "" { target *-*-* } .-2 } */ +} Jakub