This is the mail archive of the gcc@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] |
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; int main(void) { unsigned int *vector_base = &_vector_table; if (vector_base == 0) { return 1; } else { return 2; } } The code generated for this function is (I tested a couple of different compilers and architectures (4.7, 4.9 and 5.2)): 0000000000000000 <main>: 0: b8 02 00 00 00 mov $0x2,%eax 5: c3 retq If my understanding is correct, this is a legal optimization under the assumption that no object may reside at address 0, resulting in the optimized out if branch. Though, my understanding is that the switch '-fno-delete-null-pointer-checks' would remove that assumption allowing such code to be compiled "correctly" (I'm on an embedded system and code at 0 is actually important). Could somebody tell me what the correct way for implementing something like that would be? Or whether this is actually a gcc issue? Thanks, SÃren
extern unsigned int _vector_table; int main(void) { unsigned int *vector_base = &_vector_table; if (vector_base == 0) { return 1; } else { return 2; } }
Attachment:
Makefile
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |