Skip to content

Commit

Permalink
Stop trying to reuse imported Clang types. Required for opaque pointe…
Browse files Browse the repository at this point in the history
…r migration.
  • Loading branch information
elliottslaughter committed Aug 25, 2023
1 parent 8f43bed commit cb3f5ec
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/tcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,25 +586,13 @@ class Types {
return true;
}
StructType *CreateStruct(Obj *typ) {
// check to see if it was initialized externally first
if (typ->boolean("llvm_definingfunction")) {
const char *name = typ->string("llvm_definingfunction");
size_t target_id = typ->number("llvm_definingtarget");
TerraTarget *TT = T->targets[target_id];
assert(TT);
// Important: only use the externally defined type if is was
// defined in the current target
if (TT == CU->TT) {
Function *df = TT->external->getFunction(name);
assert(df);
int argpos = typ->number("llvm_argumentposition");
StructType *st = cast<StructType>(df->getFunctionType()
->getParamType(argpos)
->getPointerElementType());
assert(st);
return st;
}
}
// Note: historically, Terra tried to reuse the types generated by Clang when
// importing C headers. This is why we maintain an `llvm_definingfunction` and
// `llvm_definingtarget`. As of the opaque pointer migration (circa LLVM 15-17),
// this approach no longer works. But it turns out that we don't need it: we can
// just define the structs below, as we've always been doing (and found was
// required for external targets).

std::string name = typ->asstring("name");
bool isreserved = beginsWith(name, "struct.") || beginsWith(name, "union.");
name = (isreserved) ? std::string("$") + name : name;
Expand Down

0 comments on commit cb3f5ec

Please sign in to comment.