[llvm-bugs] [Bug 39069] New: Non-const extern successfully compiles with const value

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 25 01:58:34 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39069

            Bug ID: 39069
           Summary: Non-const extern successfully compiles with const
                    value
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dorooleg at yandex.ru
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Hello guys!

For the code below, I get a link error for compiler msvc on Windows, but clang
on Linux successfully compiles, but when I run the executable I get segfault.
Is this behavior correct?

// a.cpp
extern int const A = 20;
---
// main.cpp
extern int A;
int main() {
  A = 30;
  return A; // 30
}

My research:
  1. I created two cpp files in one of them extern int A, and in another extern
int const A; Object files created from cpp were completely identical in byte.
  2. The NM utility for these files shows the same information as the following

Name     Value            Class  Type     Size             Line Section

A       ||GLOBAL|NOTYPE  ||    |UNDEF
main    |0000000000000000|GLOBAL|FUNC    |0000000000000014|    |.text
main.cpp|0000000000000000|LOCAL |FILE    |0000000000000000|    |ABS

  3. I opened the ELF format document and found no information about how to
differentiate between const and non-const.
http://www.skyfree.org/linux/references/ELF_Format.pdf

  4. At the same time msvc compiler is able to specify additional information
for extern const

Can anyone explain in more detail why this is so done, not the other way
around?

-- 
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/20180925/18e3de1e/attachment-0001.html>


More information about the llvm-bugs mailing list