[LLVMbugs] [Bug 13732] New: Clang segfaults when __attribute__((constructor)) function refers to local static variable

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 30 10:50:33 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13732

             Bug #: 13732
           Summary: Clang segfaults when __attribute__((constructor))
                    function refers to local static variable
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: arthur.j.odwyer at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 9137
  --> http://llvm.org/bugs/attachment.cgi?id=9137
output of "clang -c test.cc -v"

cat >test.cc <<EOF
int main() {
    static int foo = 0;
    struct S { __attribute__((constructor)) void bar() { foo = 1; } };
}
EOF
clang -c test.cc


If you trick Clang/LLVM into generating a "constructor" function that refers to
a local-scoped variable, the compiler segfaults. Personally, I don't think
member functions should be allowed to have __attribute__((constructor)), but
maybe there is a plausible use case for allowing this kind of thing.

Resolved bug 7101 and resolved bug 11883 are superficially similar, but I doubt
they're directly related.


Stack dump:
0.    Program arguments: /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.8.0
-emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name
test.cc -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables
-target-cpu core2 -target-linker-version 134.3 -coverage-file test.o
-resource-dir /usr/lib/clang/3.2 -fmodule-cache-path
/var/folders/1z/jvnkrdws621c6wmrcf7q_9180000gn/T/clang-module-cache
-fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 147 -stack-protector 1 -mstackrealign -fblocks
-fobjc-runtime=macosx-10.8.0 -fobjc-dispatch-method=mixed
-fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c++ test.cc 
1.    test.cc:3:70: current parser token ';'
2.    test.cc:1:12: parsing function body 'main'
3.    test.cc:1:12: in compound statement ('{}')
4.    test.cc:3:5: parsing struct/union/class body 'S'
5.    test.cc:3:12: LLVM IR generation of declaration 'S'
6.    test.cc:3:50: Generating code for declaration 'main()::S::bar'
7.    test.cc:3:56: LLVM IR generation of compound statement ('{}')
clang: error: unable to execute command: Segmentation fault: 11

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list