[LLVMbugs] [Bug 22986] New: distinct subclass types aliasing false-positive

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Mar 22 14:56:19 PDT 2015


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

            Bug ID: 22986
           Summary: distinct subclass types aliasing false-positive
           Product: clang
           Version: 3.6
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: drfuchs at yahoo.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Pointers to distinct subclass types can't alias, even if they share a base
class.

But the code generated here indicates clang thinks they can, as it doesn't
collapse the return expression into a constant 4 (and even re-fetches
t1->common):

struct base {int common;};
struct sub1 : base {} *t1;
struct sub2 : base {} *t2;

int fn(void)
{
  t1->common = 1;
  t2->common = 2;
  return t1->common + 3;
}

Compiled -O3, this generates:

fn():                                 # @fn()
    movq    t1(%rip), %rax
    movl    $1, (%rax)
    movq    t2(%rip), %rcx
    movl    $2, (%rcx)
    movl    (%rax), %eax
    addl    $3, %eax
    retq

vs. GCC's:

fn():
    movq    t1(%rip), %rax
    movl    $1, (%rax)
    movq    t2(%rip), %rax
    movl    $2, (%rax)
    movl    $4, %eax
    ret

Note that it doesn't matter that the two subclasses had the same layout; the
exact same code is generated even if they're different:

struct base {int common;};
struct sub1 : base {int foo;} *t1;
struct sub2 : base {char bar;} *t2;

-- 
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/20150322/fed4e6d6/attachment.html>


More information about the llvm-bugs mailing list