https://llvm.org/bugs/show_bug.cgi?id=25955
Bug ID: 25955 Summary: [C standard violation] incorrect value of a variable pointer to a constant value after a recursive function call Product: clang Version: trunk Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: Frontend Assignee: unassignedclangb...@nondot.org Reporter: andrey.kules...@intel.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified -! this bug seems to be a violation of C standard (6.2.4 Storage durations of objects paragraph 6): "If the block is entered recursively, a new instance of the object is created each time. The initial value of the object is indeterminate." --! This problem appears because clang FE transforms const int b [] = {constant} to an "internal constant", that means that the value is showed as a local symbol (STB_LOCAL in the case of ELF) in the object file. But this corresponds to a "static" keyword. Because of this no new temporary objects are created and values of pointers are equal. To my mind such array might be declared as "private", not "internal" in IR ==============HOW TO REPRODUCE==================== #include <stdio.h> int f(int x, #ifndef OK const #endif int *a) { #ifndef OK const #endif int b[] = { 1, 2, 3}; // any recursive call might create if (!x) return f(1, b); // f is recursively called with a const int b[] as an argument // a new temporary object might be crated with a pointer to another address (6.2.4p6) printf("const int b[] (variable declared in function): %p\n", b); printf("const int *a (argument of a function): %p\n", a); return b == a; } int main(void) { printf("Result of f(0,0) is: %d (might be 0)\n", f(0,0)); return 0; } ================COMPARED TO OTHER COMPILERS======================= >>>Microsoft cl: const int b[] (variable declared in function): 000000ECFCE4FBF8 const int *a (argument of a function): 000000ECFCE4FC48 Result of f(0,0) is: 0 (might be 0) >>>Intel icc: const int b[] (variable declared in function): 0xffa3f9e0 const int *a (argument of a function): 0xffa3fa80 Result of f(0,0) is: 0 (might be 0) >>>gcc: const int b[] (variable declared in function): 0x7fff8a6dfa00 const int *a (argument of a function): 0x7fff8a6dfa30 Result of f(0,0) is: 0 (might be 0) >>>clang: const int b[] (variable declared in function): 0x400640 const int *a (argument of a function): 0x400640 Result of f(0,0) is: 1 (might be 0) ------------------------- Intel Software Engineer Andrey Kuleshov -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs