On 06/28/2018 05:00 PM, Tom de Vries wrote:
> [ was: Re: [testsuite] Fix guality/pr45882.c for flto ]
>
> On Thu, Jun 21, 2018 at 02:52:31PM +0200, Richard Biener wrote:
>> On Thu, 21 Jun 2018, Tom de Vries wrote:
>>
>>> Hi,
>>>
>>> Atm this test in pr45882.c:
>>> ...
>>> int d = a[i]; /* { dg-final { gdb-test 16 "d" "112" } } */
>>> ...
>>> fails as follows with -flto:
>>> ...
>>> FAIL: gcc.dg/guality/pr45882.c -O2 -flto -fuse-linker-plugin \
>>> -fno-fat-lto-objects line 16 d == 112
>>> ...
>>>
>>> In more detail, gdb fails to print the value of d:
>>> ...
>>> Breakpoint 1, foo (i=i@entry=7, j=j@entry=7) at pr45882.c:16
>>> 16 ++v;
>>> $1 = <optimized out>
>>> $2 = 112
>>> <optimized out> != 112
>>> ...
>>>
>>> Variable d is a local variable in function foo, initialized from global
>>> array a.
>>> When compiling, first cddce1 removes the initialization of d in foo, given
>>> that d is not used afterwards. Then ipa marks array a as write-only, and
>>> removes the stores to array a in main. This invalidates the location
>>> expression for d, which points to a[i], so it is removed, which is why gdb
>>> ends up printing <optimized out> for d.
>>>
>>> This patches fixes the fail by adding attribute used to array a, preventing
>>> array a from being marked as write-only.
>>>
>>> Tested on x86_64.
>>>
>>> OK for trunk?
>>
>> OK.
>>
>
> I committed this patch, but thought about it some more, and realized that this
> is the right solution for optimized code, but not for non-optimized code.
>
> For optimized code, we generate debug info, but as best effort, and we might
> need to inhibit the optimizers here and there by adding attribute used and
> volatile etc in testcases, in order to allow sufficient debug information to
> be generated.
>
> But for non-optimized code (-O0), we shouldn't need such additions in the
> testcases, since we're not supposed to optimize in the first place.
>
> So, this patch conditionalizes attribute used in pr45882.c, depending on
> whether we're optimizing or not.
>
> This patch as is makes the test-case fail due to adding lines in front of
> gdb-test, and gdb-test using absolute line numbers. So, we either need
> "[testsuite/guality] Use line number vars in gdb-test" (
> https://gcc.gnu.org/ml/gcc-patches/2018-06/msg01825.html ), or the absolute
> line numbers need to be updated.
>
> OK for trunk if bootstrap and reg-test succeeds?
>
> Thanks,
> - Tom
>
> [testsuite/guality] Don't use attribute used in pr45882.c for -O0
>
> 2018-06-28 Tom de Vries <tdevr...@suse.de>
>
> * gcc.dg/guality/guality.exp (guality_transform_options): New proc.
> (toplevel): Apply guality_transform_options on DG_TORTURE_OPTIONS and
> LTO_TORTURE_OPTIONS.
> * gcc.dg/guality/prevent-optimization.h: New file.
> * gcc.dg/guality/pr45882.c: Include prevent-optimization.h.
> (a): Replace __attribute__((used)) with ATTRIBUTE_USED.
OK.
Jeff