[LLVMbugs] [Bug 20256] New: Redundant zero-initialisation of automatic variables of user-defined type in member methods of a class template

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 9 02:04:13 PDT 2014


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

            Bug ID: 20256
           Summary: Redundant zero-initialisation of automatic variables
                    of user-defined type in member methods of a class
                    template
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jhart.public at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12756
  --> http://llvm.org/bugs/attachment.cgi?id=12756&action=edit
output of 'clang -flto -S -o - test.cpp'

In the following code snippet, a call to A::method() produces different
compiler output compared to a call to B<int>::method().

struct data { int i; };

struct A {
  void method() {
    data d;
    d.i = 1;
  }
};

template <typename T>
struct B {
  void method() {
    data d;
    d.i = 1;
  }
};

void test() {
  A a;
  B<int> b;
  a.method();
  b.method();
}

Expected: identical output from both methods.

The generated code differs as follows:

In A::method(), the non-template case, d.i is assigned the value of 1 as
expected.  In B<int>::method(), the template case, d is first zero-initialised
before assigning d.i = 1.

Note the redundant zero-initialisation occurs only in the template case, and
only for user-defined types.  Built-in types do not exhibit the same problem.

-- 
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/20140709/313cec40/attachment.html>


More information about the llvm-bugs mailing list