public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/67651] New: Optimizer assumes nothing can reside at address 0 despite -fno-delete-null-pointer-checks
@ 2015-09-20 16:14 soren.brinkmann at xilinx dot com
  2015-09-20 16:19 ` [Bug c/67651] " soren.brinkmann at xilinx dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: soren.brinkmann at xilinx dot com @ 2015-09-20 16:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67651
           Summary: Optimizer assumes nothing can reside at address 0
                    despite -fno-delete-null-pointer-checks
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: soren.brinkmann at xilinx dot com
  Target Milestone: ---

Created attachment 36351
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36351&action=edit
Test case source

For the c source:
extern unsigned int _vector_table;

int main(void)
{
        unsigned int *vector_base = &_vector_table;

        if (vector_base == 0) {
                return 1;
        } else {
                return 2;
        }
}


the generated code is, when compiled with '-O2
-fno-delete-null-pointer-checks':
0000000000000000 <main>:
   0:   b8 02 00 00 00          mov    $0x2,%eax
   5:   c3                      retq


I.e. the if branch is completely removed from the final object.
The behavior is consistent across the gcc versions I could test (4.7, 4.9 for
ARMv7 and 4.9, 5.2 for x86_64)

The behavior has been discussed on the list
(http://thread.gmane.org/gmane.comp.gcc.devel/141346). One workaround/fix
mentioned there is to add the 'weak' attribute to '_vector_table'. But it seems
that '-fno-delete-null-pointer-checks' is supposed to remove the assumption
regarding objects at address 0 and should be sufficient to generate "correct"
code.

For completeness, this is a Makefile to compile the test case:
CC ?= gcc
OBJDUMP = objdump
CFLAGS = -Wall -Wextra -fno-delete-null-pointer-checks -O2
-fno-delete-null-pointer-checks

SRC = main.c

all: $(SRC:.c=.dump) $(SRC:.c=.s) $(SRC:.c=.o)

%.dump: %.o
        $(OBJDUMP) -DS $< > $@

%.s: %.c
        $(CC) $(CFLAGS) -S $< -o $@

%.o: %.c
        $(CC) $(CFLAGS) -c $< -o $@

.PHONY: clean
clean:
        rm -rf *.o *.s *.dump


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-21 12:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-20 16:14 [Bug c/67651] New: Optimizer assumes nothing can reside at address 0 despite -fno-delete-null-pointer-checks soren.brinkmann at xilinx dot com
2015-09-20 16:19 ` [Bug c/67651] " soren.brinkmann at xilinx dot com
2015-09-21  8:06 ` [Bug middle-end/67651] " rguenth at gcc dot gnu.org
2015-09-21 12:33 ` rguenth at gcc dot gnu.org
2015-09-21 12:33 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).