diff --git a/lib/ImportModelFromC/HeaderToModel.cpp b/lib/ImportModelFromC/HeaderToModel.cpp index ee619f677..bea18ab59 100644 --- a/lib/ImportModelFromC/HeaderToModel.cpp +++ b/lib/ImportModelFromC/HeaderToModel.cpp @@ -459,7 +459,7 @@ DeclVisitor::getTypeByNameOrID(llvm::StringRef Name, TypeKind::Values Kind) { std::istringstream TheStream(ID); TheStream >> TypeID; - auto KeyType = model::Type::Key{ Kind, TypeID }; + auto KeyType = model::Type::Key{ TypeID, Kind }; auto TheType = Model->getTypePath(KeyType); if (TheType.get()) @@ -941,9 +941,11 @@ bool DeclVisitor::VisitTypedefDecl(const TypedefDecl *D) { llvm::erase_if(Model->Types(), [&](UpcastablePointer &P) { return P.get()->ID() == (*Type)->ID(); }); - } - Model->recordNewType(std::move(TypeTypedef)); + Model->Types().insert(std::move(TypeTypedef)); + } else { + Model->recordNewType(std::move(TypeTypedef)); + } return true; } @@ -1014,9 +1016,11 @@ bool DeclVisitor::VisitFunctionPrototype(const FunctionProtoType *FP, llvm::erase_if(Model->Types(), [&](UpcastablePointer &P) { return P.get()->ID() == (*Type)->ID(); }); - } - Model->recordNewType(std::move(NewType)); + Model->Types().insert(std::move(NewType)); + } else { + Model->recordNewType(std::move(NewType)); + } return true; } @@ -1126,18 +1130,23 @@ bool DeclVisitor::handleStructType(const clang::RecordDecl *RD) { // TODO: Can this be calculated/fetched automatically? Struct->Size() = CurrentOffset; - if (AnalysisOption == ImportModelFromCOption::EditType) { + switch (AnalysisOption) { + case ImportModelFromCOption::EditType: // Remove old and add new type with the same ID. llvm::erase_if(Model->Types(), [&](UpcastablePointer &P) { return P.get()->ID() == (*Type)->ID(); }); - } + Model->Types().insert(std::move(NewType)); + break; - if (AnalysisOption != ImportModelFromCOption::EditFunctionPrototype) - Model->recordNewType(std::move(NewType)); - - if (AnalysisOption == ImportModelFromCOption::EditFunctionPrototype) + case ImportModelFromCOption::EditFunctionPrototype: MultiRegisterReturnValue = ReturnValues; + break; + + case ImportModelFromCOption::AddType: + Model->recordNewType(std::move(NewType)); + break; + } return true; } @@ -1187,9 +1196,11 @@ bool DeclVisitor::handleUnionType(const clang::RecordDecl *RD) { llvm::erase_if(Model->Types(), [&](UpcastablePointer &P) { return P.get()->ID() == (*Type)->ID(); }); + Model->Types().insert(std::move(NewType)); + } else { + Model->recordNewType(std::move(NewType)); } - Model->recordNewType(std::move(NewType)); return true; } @@ -1279,9 +1290,12 @@ bool DeclVisitor::VisitEnumDecl(const EnumDecl *D) { llvm::erase_if(Model->Types(), [&](UpcastablePointer &P) { return P.get()->ID() == (*Type)->ID(); }); + + Model->Types().insert(std::move(NewType)); + } else { + Model->recordNewType(std::move(NewType)); } - Model->recordNewType(std::move(NewType)); return true; } diff --git a/tests/unit/llvm-lit-tests/CheckDLA.ll b/tests/unit/llvm-lit-tests/CheckDLA.ll index 0b8ea12cf..8a0c881d8 100644 --- a/tests/unit/llvm-lit-tests/CheckDLA.ll +++ b/tests/unit/llvm-lit-tests/CheckDLA.ll @@ -2,7 +2,7 @@ ; Copyright rev.ng Labs Srl. See LICENSE.md for details. ; -; RUN: %revngopt %s -S --dla --model-type-id-seed=0xDEADBEEF -o - | revng model dump | revng model compare %s.yml - +; RUN: %revngopt %s -S --dla -o - | revng model dump | revng model compare %s.yml - ; This file is meant to be used to test that the DLA is able to merge the ; recovered type information with an already existing model. ; In particular, in this file all functions and indirect calls share the same