https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83117

Daniel Santos <daniel.santos at pobox dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.santos at pobox dot com

--- Comment #8 from Daniel Santos <daniel.santos at pobox dot com> ---
(In reply to Jakub Jelinek from comment #6)
> The warning is nothing new, GCC has been warning for that for years.  What
> my patch did is just better optimization, so the compiler can see the UB.
> 
> Try:
> extern long do_test_aligned ();
> 
> static long (*const do_test_v1) (long a, ...) = (void *) do_test_aligned;
> 
> extern void check_results (long);
> 
> int test (long a)
> {
>   long ret;
> 
>   ret = do_test_v1 (a);
>   ret += (long (*) (long a, ...)) do_test_aligned;
>   check_results (ret);
> }
> 
> We've warned about the latter, but not the former, since we weren't able to
> fold a const var to its initializer.
> 
> So, either the tests shouldn't use const on these, something like:
> -          out << "static __attribute__ ((ms_abi)) long (*const do_test_"
> +          out << "static __attribute__ ((ms_abi)) long (*do_test_"
> or they should use const volatile, or -w, or should use proper prototypes.
> 
> Daniel needs to decide what to do, it isn't obviously clear what the intent
> is.

Sorry for my slow response.  do_test and do_test_aligned are assembly hacks
that verify that the actual test functions do not alter registers that are
volatile for sysv_abi, but non-volatile for ms_abi (the ms to sysv clobbers). 
So the intention was to lie to the compiler about how to call the function, but
now your patch got smart and figured out that I was lying. :(

So in this example, the function msabi_00_v1 is the real function that is being
tested:

  init_test (msabi_00_v1, "msabi_00_v1", ALIGNMENT_NOT_TESTED,
SHRINK_WRAP_NONE, a);
  ret = do_test_v1 (a);
  check_results (ret);

More specifically, the assembly proxy stubs:
1. store rdi, rsi, xmm6-15,
2. populates them with random data
3. pops the return address and stores it
4. calls the function specified in the init_test call prior
upon return it:
5. stores the new values of rdi, rsi xmm6-15 (for later comparison)
6. restores them to what they were originally
7. jumps to the original return address

The test program is a single-threaded and there is no recursion of of these
hacked calls, so I'm just using globals.

Is there a way to disable this warning with -Wno-xxx?  Otherwise, what is the
proper way to lie to a compiler?  I want the compiler to construct the function
call since that is part of what is being tested.

Reply via email to