Issue 180694
Summary [clang] Indirect virtual inheritance causes assertion failure with MSVC ABI
Labels clang:codegen, platform:windows
Assignees
Reporter DavidTruby
    The following C++ code hits an assertion failure when building for either `x86_64-pc-windows-msvc` or `aarch64-pc-windows-msvc`:
```cpp
struct Base {};
struct A : virtual Base {};
struct B : virtual Base {};
struct C : A, B {};
struct Derived : C {
  Derived() : C() {}
};

Derived make() {
 return {};
}
```
It appears to fail when trying to generate the constructor for Derived. Oddly, if that line is commented out the assertion failure goes away, even though Derived still needs to generate a constructor that calls C's constructor anyway.
I only need `clang -cc1 -emit-llvm -x c++ -triple {x86_64,aarch64}-pc-windows-msvc test.cpp` to reproduce this. The same code works fine with clang on Linux and cl.exe on Windows. I've tried this on a build from main this morning, as well as 21.1.8 and 20.1.4. 

I also tried with a non-assertion build of the compiler to see if this causes a codegen issue. Derived's constructor gets inlined into `make` even on -O0, so here's the code for make:
```llvm
define dso_local void @make(ptr dead_on_unwind noalias writable writeonly sret(%struct.Derived) align 8 captures(none) initializes((0, 16)) %0) local_unnamed_addr #0 {
  store ptr @"??_8Derived@@7BA@@@", ptr %0, align 8
  %2 = getelementptr inbounds nuw i8, ptr %0, i64 8
  store ptr @"??_8Derived@@7BB@@@", ptr %2, align 8
 %3 = getelementptr inbounds nuw i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(18446744073709551608) %3, i8 0, i64 -8, i1 false)
  ret void
}
```
It appears that something is going wrong when generating that memset, as we're getting wrap around; the large number is 2^64 - 8. I assume this will actually fail quite badly at runtime so it isn't just an overly cautious assertion.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to