[LLVMbugs] [Bug 19121] New: ARC/member variable initialization incorrect code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Mar 12 19:16:55 PDT 2014


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

            Bug ID: 19121
           Summary: ARC/member variable initialization incorrect code
           Product: clang
           Version: 3.3
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: peter at stairways.com.au
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I am not sure whether this is properly filed under C++11 or LLVM Codegen, as it
is a C++11 feature, but a codegen failure.

clang as included in Xcode 5.1 generates incorrect code for member variable
initialisation of Objective C objects using ARC.  This is a regression from
Xcode 5.0.2 which generates correct code.

This simple program demonstrates the incorrect code:

#import <Foundation/Foundation.h>

class XClipboardDataSet
{
    NSMutableDictionary* mClipData = [NSMutableDictionary new];
};

int main()
{
    XClipboardDataSet clip;
    return 0;
}

The generated code is:

    .private_extern    __ZN17XClipboardDataSetC2Ev
    .globl    __ZN17XClipboardDataSetC2Ev
    .weak_def_can_be_hidden    __ZN17XClipboardDataSetC2Ev
    .align    4, 0x90
__ZN17XClipboardDataSetC2Ev:            ## @_ZN17XClipboardDataSetC2Ev
    .cfi_startproc
Lfunc_begin4:
    .loc    1 3 0                   ## TestClangARC.mm:3:0
## BB#0:
    pushq    %rbp
Ltmp32:
    .cfi_def_cfa_offset 16
Ltmp33:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp34:
    .cfi_def_cfa_register %rbp
    subq    $32, %rsp
    movq    %rdi, -8(%rbp)
    movq    -8(%rbp), %rdi
    .loc    1 3 0 prologue_end      ## TestClangARC.mm:3:0
Ltmp35:
    movq    L_OBJC_CLASSLIST_REFERENCES_$_(%rip), %rax
    movq    L_OBJC_SELECTOR_REFERENCES_(%rip), %rsi
    movq    %rdi, -16(%rbp)         ## 8-byte Spill
    movq    %rax, %rdi
    callq    _objc_msgSend
    movq    %rax, %rsi
    movq    %rsi, %rdi
    movq    %rax, -24(%rbp)         ## 8-byte Spill
    callq    _objc_release
    movq    -24(%rbp), %rax         ## 8-byte Reload
    movq    %rax, %rdi
    callq    _objc_retain
    movq    -16(%rbp), %rsi         ## 8-byte Reload
    movq    %rax, (%rsi)
    addq    $32, %rsp
    popq    %rbp
    ret
Ltmp36:
Lfunc_end4:
    .cfi_endproc

The _objc_msgSend is the call to [NSMutableDictionary new].  The seven lines
following it are new in the clang included in Xcode 5.1:

    movq    %rax, %rsi
    movq    %rsi, %rdi
    movq    %rax, -24(%rbp)         ## 8-byte Spill
    callq    _objc_release
    movq    -24(%rbp), %rax         ## 8-byte Reload
    movq    %rax, %rdi
    callq    _objc_retain

At first I thought it was releasing the previous (uninitialised) value of the
member variable, but it actually appears to be immediately releasing the
returned object and then retaining it.  The object is deallocated after the
release, and then the retain may or may not crash depending on the whim of the
system, but the object has been deallocated so the program will almost
certainly crash in the near future if not immediately here.

Failing clang details are:

Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

Previous, working clang was:

Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

Compilation commands, assembly:

/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-isysroot
/Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
-fobjc-arc -S -o TestClangARC.s TestClangARC.mm

code:

/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-isysroot
/Applications/Xcode.app//Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
-framework Foundation -fobjc-arc -lstdc++ -o TestClangARC TestClangARC.mm
setenv NSZombieEnabled YES
./TestClangARC

-- 
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/20140313/5d940f33/attachment.html>


More information about the llvm-bugs mailing list