Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop reusing imported Clang types #640

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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