This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization bug?
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Martin Sebor <msebor at gmail dot com>,Sören Brinkmann <soren dot brinkmann at xilinx dot com>,pinskia at gmail dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 20 Sep 2015 08:38:00 +0200
- Subject: Re: Optimization bug?
- Authentication-results: sourceware.org; auth=none
- References: <20150919180019 dot GC2722 at xsjsorenbubuntu> <A4D9A9EC-DD45-4395-BB31-974C4C4536BF at gmail dot com> <20150919213247 dot GA344 at xsjsorenbubuntu> <55FDF25C dot 5060805 at gmail dot com>
On September 20, 2015 1:40:12 AM GMT+02:00, Martin Sebor <msebor@gmail.com> wrote:
>On 09/19/2015 03:32 PM, SÃren Brinkmann wrote:
>> Hi Andrew,
>>
>> On Sat, 2015-09-19 at 11:34AM -0700, pinskia@gmail.com wrote:
>>>
>>>
>>>> On Sep 19, 2015, at 11:00 AM, SÃren Brinkmann
><soren.brinkmann@xilinx.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I recently came across some bug in my program that I could narrow
>down
>>>> to the snipped below (also attached with a Makefile).
>>>>
>>>> extern unsigned int _vector_table;
>>>
>>> You need the attribute weak here if the location of _vector_table
>can be a null pointer.
>>
>> Indeed, that fixes the problem. Would you have any additional
>background
>> why the 'weak' is required in this case? To me it sounded like the
>> '-fno-delete-null-pointer-checks' should be sufficient.
>
>-fno-delete-null-pointer-checks prevents GCC from removing tests
>for null pointers after such pointers have been dereferenced. For
>example, in the following function, GCC normally eliminates the
>second if statement because the first statement lets it assume
>that p is not null (otherwise dereferencing it would be undefined).
>
> int foo (int *p) {
> if (*p == 0) return 0;
> if (p == 0) return 1;
> return 2;
> }
>
>The option doesn't affect other assumptions such as that every
>object and function in a program lives at a valid, non-null
>address.
Actually we abuse this flag for exactly this purpose so I think the testcase shows a bug. Unless the particular target cannot have global vars at address zero.
Would you mind opening a bugreport?
Richard.
>
>Martin