[llvm-bugs] [Bug 25955] New: [C standard violation] incorrect value of a variable pointer to a constant value after a recursive function call
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Dec 28 09:33:11 PST 2015
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: unassignedclangbugs at nondot.org
Reporter: andrey.kuleshov at intel.com
CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151228/75fd2195/attachment-0001.html>
More information about the llvm-bugs
mailing list