> On Sep 14, 2024, at 8:59 PM, Jakub Jelinek <ja...@redhat.com> wrote:
> 
> On Wed, Sep 11, 2024 at 09:13:40PM +0000, Qing Zhao wrote:
>> @@ -11741,6 +11770,55 @@ c_parser_postfix_expression (c_parser *parser)
>>        set_c_expr_source_range (&expr, loc, close_paren_loc);
>>        break;
>>      }
>> +    case RID_BUILTIN_COUNTED_BY_REF:
>> +      {
>> +        vec<c_expr_t, va_gc> *cexpr_list;
>> +        c_expr_t *e_p;
>> +        location_t close_paren_loc;
>> +
>> +        in_builtin_counted_by_ref++;
> 
> I think this in_builtin_counted_by_ref stuff here plus the whole c-typeck.cc
> hunk should be replaced with:
> 
>> +        c_parser_consume_token (parser);
>> +        if (!c_parser_get_builtin_args (parser,
>> +                        "__builtin_counted_by_ref",
>> +                        &cexpr_list, false,
>> +                        &close_paren_loc))
>> +          {
>> +        expr.set_error ();
>> +        in_builtin_counted_by_ref--;
>> +        break;
>> +          }
>> +        if (vec_safe_length (cexpr_list) != 1)
>> +          {
>> +        error_at (loc, "wrong number of arguments to "
>> +                   "%<__builtin_counted_by_ref%>");
>> +        expr.set_error ();
>> +        in_builtin_counted_by_ref--;
>> +        break;
>> +          }
>> +
>> +        e_p = &(*cexpr_list)[0];
>> +
>> +        if (TREE_CODE (TREE_TYPE (e_p->value)) != ARRAY_TYPE)
>> +          {
>> +        error_at (loc, "the argument must be an array"
>> +                   "%<__builtin_counted_by_ref%>");
>> +        expr.set_error ();
>> +        in_builtin_counted_by_ref--;
>> +        break;
>> +          }
>> +
> 
>        if (has_counted_by_object (e_p->value))
>          expr.value = get_counted_by_ref (e_p->value);
>        else if (in_typeof && TREE_CODE (e_p->value) == COMPONENT_REF)
>          {
>        tree counted_by_type = NULL_TREE;
>        tree arg = (*cexpr_
>        if (build_counted_by_ref (TREE_OPERAND (e_p->value, 0),
>                      TREE_OPERAND (e_p->value, 1),
>                      &counted_by_type))
>          expr.value
>            = build_zero_cst (build_pointer_type (counted_by_type));
>        else
>          expr.value = null_pointer_node;
>          }
>        else
>          expr.value = null_pointer_node;
> 
> (plus make build_counted_by_ref non-static and add prototype).
> 
> Completely untested.

Thanks a lot!will update as you suggested 

Qing


> 
>> +        if (has_counted_by_object ((*cexpr_list)[0].value))
>> +          expr.value
>> +        = get_counted_by_ref ((*cexpr_list)[0].value);
>> +        else
>> +          expr.value
>> +        = build_int_cst (build_pointer_type (void_type_node), 0);
> 
>    Jakub
> 

Reply via email to