Fix v1.31 regression wrt. unresolved IrAggr (#4312)

And use `IrTypeClass::getVtblType()` to get the vtable LLVM array
type, instead of deriving it from the `IrClass::getVtblSymbol()`
global (invoking that function may define the vtable!).

I've hit some compiler crashes for the Symmetry code base, on
Windows only. I guess the problem surfaced due to
`-link-defaultlib-shared`, which on Windows causes some vtables of
instantiated classes to be defined whenever accessing the vtable
symbol. I don't have a reduced test case unfortunately.
This commit is contained in:
Martin Kinkelin 2023-02-06 17:02:07 +01:00 committed by GitHub
parent 58c4b8bdae
commit 5f46c65ab5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 39 deletions

View file

@ -39,6 +39,7 @@
#include "ir/irfunction.h"
#include "ir/irmodule.h"
#include "ir/irtypeaggr.h"
#include "ir/irtypeclass.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
@ -1895,16 +1896,12 @@ DLValue *DtoIndexAggregate(LLValue *src, AggregateDeclaration *ad,
// Cast the pointer we got to the canonical struct type the indices are
// based on.
LLType *st = nullptr;
LLType *pst = nullptr;
if (ad->isClassDeclaration()) {
st = getIrAggr(ad)->getLLStructType();
pst = DtoType(ad->type);
if (auto irtc = irTypeAggr->isClass()) {
st = irtc->getMemoryLLType();
} else {
st = irTypeAggr->getLLType();
}
else {
st = DtoType(ad->type);
pst = getPtrToType(st);
}
ptr = DtoBitCast(ptr, pst);
ptr = DtoBitCast(ptr, st->getPointerTo());
ptr = DtoGEP(st, ptr, 0, off);
ty = isaStruct(st)->getElementType(off);
}