[LLVMbugs] [Bug 13329] New: Incorrect code generated for automatic assignment operator

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 11 07:21:09 PDT 2012


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

             Bug #: 13329
           Summary: Incorrect code generated for automatic assignment
                    operator
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: pierre.barbierdereuille at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


I found a bug related to the automatic assignment operator.

To trigger the bug you need to create a class that is "padded", such that the
last member finishes before the "end" of the class (i.e. a long followed by a
boolean for example for a 64 bits machine). Then, you inherit the class, and
the first member of the class must be something like half a word big (i.e. it
must not increase the size of the class). In these conditions, assigning the
base class to the derived will overwrite the extra member with whatever padding
the base class has.

I have confirmed the bug with clang++ 3.0, 3.1 and 3.2 (trunk).

Here is the bug, the program will exit with an error code of 1 if the bug is
there:

$ clang++ test_assign_minim.cpp -o test_assign_minim
barbier at ipskbioinform+~/prog/c++/clang$ ./test_assign_minim; echo $?
1
$ cat test_assign_minim.cpp
struct A
{
  A() : a(0) , b(true) { }
  long a;
  bool b;
};

struct B : public A
{
  B() : A() , c(0xDEADBEEF) { }
  unsigned int c;
};

int main()
{
  A a;
  B b;
  (A&)b = a;
  return (b.c != 0xDEADBEEF);
}

$ clang++ -v
clang version 3.2 (trunk 160045) (llvm/trunk 160043)
Target: x86_64-unknown-linux-gnu
Thread model: posix

-- 
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