Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f855795

Browse files
author
Nicolas Geoffray
committed
Always check if a method or a type exist before trying to create it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141490 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 48f248a commit f855795

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lib/Target/CppBackend/CPPBackend.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,19 @@ void CppWriter::printType(Type* Ty) {
534534
case Type::StructTyID: {
535535
StructType* ST = cast<StructType>(Ty);
536536
if (!ST->isLiteral()) {
537-
Out << "StructType *" << typeName << " = ";
537+
Out << "StructType *" << typeName << " = mod->getTypeByName(\"";
538+
printEscapedString(ST->getName());
539+
Out << "\");";
540+
nl(Out);
541+
Out << "if (!" << typeName << ") {";
542+
nl(Out);
543+
Out << typeName << " = ";
538544
Out << "StructType::create(mod->getContext(), \"";
539545
printEscapedString(ST->getName());
540546
Out << "\");";
541547
nl(Out);
548+
Out << "}";
549+
nl(Out);
542550
// Indicate that this type is now defined.
543551
DefinedTypes.insert(Ty);
544552
}
@@ -560,12 +568,18 @@ void CppWriter::printType(Type* Ty) {
560568
Out << "StructType *" << typeName << " = ";
561569
Out << "StructType::get(" << "mod->getContext(), ";
562570
} else {
571+
Out << "if (" << typeName << "->isOpaque()) {";
572+
nl(Out);
563573
Out << typeName << "->setBody(";
564574
}
565575

566576
Out << typeName << "_fields, /*isPacked=*/"
567577
<< (ST->isPacked() ? "true" : "false") << ");";
568578
nl(Out);
579+
if (!ST->isLiteral()) {
580+
Out << "}";
581+
nl(Out);
582+
}
569583
break;
570584
}
571585
case Type::ArrayTyID: {
@@ -1538,13 +1552,12 @@ void CppWriter::printFunctionUses(const Function* F) {
15381552

15391553
void CppWriter::printFunctionHead(const Function* F) {
15401554
nl(Out) << "Function* " << getCppName(F);
1541-
if (is_inline) {
1542-
Out << " = mod->getFunction(\"";
1543-
printEscapedString(F->getName());
1544-
Out << "\", " << getCppName(F->getFunctionType()) << ");";
1545-
nl(Out) << "if (!" << getCppName(F) << ") {";
1546-
nl(Out) << getCppName(F);
1547-
}
1555+
Out << " = mod->getFunction(\"";
1556+
printEscapedString(F->getName());
1557+
Out << "\");";
1558+
nl(Out) << "if (!" << getCppName(F) << ") {";
1559+
nl(Out) << getCppName(F);
1560+
15481561
Out<< " = Function::Create(";
15491562
nl(Out,1) << "/*Type=*/" << getCppName(F->getFunctionType()) << ",";
15501563
nl(Out) << "/*Linkage=*/";
@@ -1581,10 +1594,8 @@ void CppWriter::printFunctionHead(const Function* F) {
15811594
Out << "->setGC(\"" << F->getGC() << "\");";
15821595
nl(Out);
15831596
}
1584-
if (is_inline) {
1585-
Out << "}";
1586-
nl(Out);
1587-
}
1597+
Out << "}";
1598+
nl(Out);
15881599
printAttributes(F->getAttributes(), getCppName(F));
15891600
printCppName(F);
15901601
Out << "->setAttributes(" << getCppName(F) << "_PAL);";

0 commit comments

Comments
 (0)