Opened 7 months ago

#302 new defect

Built-in functions may have wrong types on 32-bit

Reported by: mlbrooks Owned by:
Priority: trivial Component: cfa-cc
Version: 1.0 Keywords: lowering cast size_t builtin x86
Cc:

Description

I stumbled across this phenomenon while doing other work. It may represent a broader issue whose impact is not yet understood. If further impacts are found, please increase the ticket priority accordingly.

A builtin is something that can be called like a function but that GCC may implement in a way that is not a function call. GCC does not provide prototypes for them. CFA provides the resolver with prototypes declared in build/libcfa/(host)/prelude/gcc-builtins.cfa.

One such prototype should be

void * __builtin_memcpy(void *, const void *, size_t);

I consider this signature correct because

  • it matches memcpy
  • gcc is built from a table whose signature-implying symbol for it is BT_FN_PTR_PTR_CONST_PTR_SIZE; reading the name suggests my "correct" types (this table is in cfa-cc/libcfa/prelude/builtins.def, excerpting from the row marked BUILT_IN_MEMCPY)

However, the signature we actually send to the resolver is:

void * __builtin_memcpy(void *, const void *, unsigned long);

which is incorrect on x86, where size_t != unsigned long.

The only impact seen so far is in seeing superfluous casts when inspecting generated code. Given a prior fix to the return type of sizeof (#269, in which its type becomes size_t), builtin calls on x86 change as in

git show d3d54b3f6 -- tests/.expect/extension.x86.txt

having differences like

- ((void)__builtin_memcpy(((void *)_X4_dstU1U_1), ((const void *)(&_X1ai_1)), sizeof(signed int )));
+ ((void)__builtin_memcpy(((void *)_X4_dstU1U_1), ((const void *)(&_X1ai_1)), ((unsigned long int )sizeof(signed int ))));

Change History (0)

Note: See TracTickets for help on using tickets.