https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86092
Bug ID: 86092 Summary: global constant pointer optimization Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: srinivas.sundar at vvdntech dot in Target Milestone: --- Here is my sample kernel code. which works fine in gcc-4, had an issue with gcc-5. I get both the print even if I allocate the dynamic memory to kern_buff_p. Disassemble of code gives the constant variable is optimized in the If statement. Can you provide me any FLAG to disable this optimization with this constant pointers. static char* const kern_buff_p; static int __init hello_start(void) { if(!kern_buff_p) printk(KERN_INFO "buffer is NULL for first time \n"); *((char**)(unsigned long int)((&kern_buff_p)))=kmalloc(KERN_BUF_SIZE,GFP_KERNEL); if(!kern_buff_p) printk(KERN_INFO "buffer is NULL for second time \n"); }