This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/67651] New: Optimizer assumes nothing can reside at address 0 despite -fno-delete-null-pointer-checks


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]