[llvm-bugs] [Bug 50726] New: static initialization order not respected across translation units for constructors with priority

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 15 14:19:24 PDT 2021


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

            Bug ID: 50726
           Summary: static initialization order not respected across
                    translation units for constructors with priority
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hiraditya at msn.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

It seems this has been reported before in
https://bugs.llvm.org/show_bug.cgi?id=12556 and
https://bugs.llvm.org/show_bug.cgi?id=26331 which were marked as wontfix.

Here is an example to repro the bug:
$ cat a.cpp

#include <cstdio>

struct test {
    test() {
        printf("i am constructed!\n");
    }
};

test test1;

__attribute__((constructor(0))) void cons_highestpri() {
    printf("i am also constructed highest pri!\n");
}


__attribute__((constructor(1010))) void cons_lopri() {
    printf("i am also constructed lopri!\n");
}

test test2;

int main() {

}


$ cat b.cpp
#include<cstdio>
__attribute__((constructor(101))) void cons_hipri() {
    printf("i am also constructed hipri!\n");
}


$ clang++ -flto=thin a.cpp b.cpp -O2 && ./a.out 

i am also constructed highest pri!
i am also constructed lopri!
i am constructed!
i am constructed!
i am also constructed hipri!

-- 
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/20210615/48fbd794/attachment-0001.html>


More information about the llvm-bugs mailing list