This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cxx-mem-model merge [4 of 9] c-family
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Andrew MacLeod <amacleod at redhat dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 4 Nov 2011 00:20:13 +0000 (UTC)
- Subject: Re: cxx-mem-model merge [4 of 9] c-family
- References: <4EB328C4.5030502@redhat.com>
On Thu, 3 Nov 2011, Andrew MacLeod wrote:
> + if (VEC_length (tree, params) != n_param)
> + {
> + error ("Incorrect number of arguments to function %qE", function);
Diagnostics start with lowercase letters. The functions such as "error"
that implicitly use input_location are deprecated - all the new functions
producing diagnostics should take location_t parameters that they pass to
error_at. (If a location isn't readily available in the caller then you
might make the caller pass input_location - but you still shouldn't
introduce a new function like this with several calls to plain "error".)
> + /* Get type of first parameter, and determine it's size. */
"its"
> + type_0 = TREE_TYPE (VEC_index (tree, params, 0));
> + if (TREE_CODE (type_0) != POINTER_TYPE)
> + {
> + error ("argument 0 of %qE must be a pointer type", function);
Arguments are numbered from 1 in existing diagnostics, not 0. The
diagnostics here need to be fixed to match that.
> + /* Check memory model parameters for validity. */
> + for (x = n_param - n_model ; x < n_param; x++)
> + {
> + tree p = VEC_index (tree, params, x);
> + if (TREE_CODE (p) == INTEGER_CST)
> + {
> + int i = tree_low_cst (p, 1);
> + if (i < 0 || i >= MEMMODEL_LAST)
> + {
> + error ("invalid memory model argument %d of %qE", x, function);
Given that C and C++ allow variable arguments to the standard type-generic
macros/functions, it is also presumably OK - only undefined at runtime -
for a constant memory model argument of the correct type to have a value
representable in that type that isn't actually a valid memory model. And
so this should generate a warning, not an error (ideally generating a trap
and an informative note that such a trap has been generated - remember
that the side-effects of the function arguments must be evaluated before
the trap, in case an argument exits the program, as in
gcc.c-torture/execute/{call-trap-1.c,va-arg-trap-1.c}).
--
Joseph S. Myers
joseph@codesourcery.com