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

            Bug ID: 30478
           Summary: UBSan vptr: false positive if virtual method if
                    privately overriden
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedb...@nondot.org
          Reporter: kra...@google.com
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

Created attachment 17329
  --> https://llvm.org/bugs/attachment.cgi?id=17329&action=edit
many_bases.cc

Based on the analysis of a Chromium test failure that feels like a false
positive from UBSan's vptr check, I have come up with the following minimal
reproducer:

many_bases.cc (also attached):
#include <stdio.h>

class Base1 {
 public:
  virtual void Do() { printf("Base1::Do\n"); }
};

class Base2 {
 public:
  virtual void Do2() { printf("Base2::Do2\n"); }
};

class Derived final : public Base1, public Base2 {
private:
  void Do2() override { printf("Derived::Do2\n"); }
};

int main(void) {
  Derived obj;
  static_cast<Base2*>(&obj)->Do2();
}

Compiling and running:
$ clang++ -o many_bases many_bases.cc -fsanitize=vptr
-fno-sanitize-recover=undefined -fvisibility=hidden -std=gnu++11 &&
./many_bases
many_bases.cc:20:30: runtime error: member call on address 0x7ffe64429bb8 which
does not point to an object of type 'Base2'
0x7ffe64429bb8: note: object is of type 'Derived'
 ea 46 63 ba  c0 ee 42 00 00 00 00 00  e0 ee 42 00 00 00 00 00  00 00 00 00 00
00 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'Derived'

The error message does not make sense to me.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to