diff options
author | Cyndy Ishida <cyndy_ishida@apple.com> | 2023-12-02 13:19:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-02 13:19:01 -0800 |
commit | b04b89753daf9751a81ffbcfbfbe6c610fb88af8 (patch) | |
tree | 9b6b4e5c152572eabcfea782eccfc71d1e490da0 /llvm/unittests/TextAPI | |
parent | bb6497ffa6a88d1b3a32101d9b6519094d75ef2a (diff) | |
download | llvm-b04b89753daf9751a81ffbcfbfbe6c610fb88af8.zip llvm-b04b89753daf9751a81ffbcfbfbe6c610fb88af8.tar.gz llvm-b04b89753daf9751a81ffbcfbfbe6c610fb88af8.tar.bz2 |
[TextAPI] Introduce Records & RecordSlice Types (#74115)
`Record`'s hold target triple specific information about APIs and
symbols. This holds information about the relationship between ObjC
symbols and their linkage properties. It will be used to compare and run
significant operations between the frontend representation of symbols in
AST and symbol information extracted from Mach-O binaries. This differs
from the lighter weight Symbol and SymbolSet class where they are
deduplicated across targets and only represent exported symbols, that
class is mostly used for serializing.
Diffstat (limited to 'llvm/unittests/TextAPI')
-rw-r--r-- | llvm/unittests/TextAPI/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/TextAPI/RecordTests.cpp | 117 |
2 files changed, 118 insertions, 0 deletions
diff --git a/llvm/unittests/TextAPI/CMakeLists.txt b/llvm/unittests/TextAPI/CMakeLists.txt index aeda32d..f34eaa2 100644 --- a/llvm/unittests/TextAPI/CMakeLists.txt +++ b/llvm/unittests/TextAPI/CMakeLists.txt @@ -8,6 +8,7 @@ add_llvm_unittest(TextAPITests TextStubV3Tests.cpp TextStubV4Tests.cpp TextStubV5Tests.cpp + RecordTests.cpp ) target_link_libraries(TextAPITests PRIVATE LLVMTestingSupport) diff --git a/llvm/unittests/TextAPI/RecordTests.cpp b/llvm/unittests/TextAPI/RecordTests.cpp new file mode 100644 index 0000000..076137d --- /dev/null +++ b/llvm/unittests/TextAPI/RecordTests.cpp @@ -0,0 +1,117 @@ +//===-- RecordTests.cpp - TextAPI Record Type Test-------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===-----------------------------------------------------------------------===// + +#include "llvm/TargetParser/Triple.h" +#include "llvm/TextAPI/RecordsSlice.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::MachO; + +namespace TAPIRecord { + +TEST(TAPIRecord, Simple) { + GlobalRecord API{"_sym", RecordLinkage::Rexported, + SymbolFlags::Rexported | SymbolFlags::Text | + SymbolFlags::ThreadLocalValue, + GlobalRecord::Kind::Function}; + EXPECT_TRUE(API.isExported()); + EXPECT_TRUE(API.isText()); + EXPECT_TRUE(API.isRexported()); + EXPECT_TRUE(API.isFunction()); + EXPECT_TRUE(API.isThreadLocalValue()); + EXPECT_FALSE(API.isInternal()); + EXPECT_FALSE(API.isUndefined()); + EXPECT_FALSE(API.isWeakDefined()); + EXPECT_FALSE(API.isWeakReferenced()); + EXPECT_FALSE(API.isVariable()); +} + +TEST(TAPIRecord, SimpleObjC) { + ObjCInterfaceRecord Class{"NSObject", RecordLinkage::Exported}; + ObjCInterfaceRecord ClassEH{"NSObject", RecordLinkage::Exported, + /*HasEHType=*/true}; + + EXPECT_TRUE(Class.isExported()); + EXPECT_EQ(Class.isExported(), ClassEH.isExported()); + EXPECT_FALSE(Class.hasExceptionAttribute()); + EXPECT_TRUE(ClassEH.hasExceptionAttribute()); + EXPECT_EQ(ObjCIVarRecord::createScopedName("NSObject", "var"), + "NSObject.var"); +} + +TEST(TAPIRecord, SimpleSlice) { + Triple T("arm64-apple-macosx13.3"); + RecordsSlice Slice(T); + EXPECT_TRUE(Slice.isEmpty()); + Slice.addRecord("_OBJC_CLASS_$_NSObject", SymbolFlags::None, + GlobalRecord::Kind::Unknown, RecordLinkage::Rexported); + Slice.addRecord("_OBJC_METACLASS_$_NSObject", SymbolFlags::None, + GlobalRecord::Kind::Unknown, RecordLinkage::Rexported); + Slice.addRecord("_OBJC_IVAR_$_NSConcreteValue.typeInfo", SymbolFlags::None, + GlobalRecord::Kind::Unknown, RecordLinkage::Exported); + Slice.addRecord("_OBJC_IVAR_$_NSObject.objInfo", SymbolFlags::None, + GlobalRecord::Kind::Unknown, RecordLinkage::Exported); + Slice.addRecord("_foo", SymbolFlags::WeakDefined | SymbolFlags::Rexported, + GlobalRecord::Kind::Variable, RecordLinkage::Rexported); + EXPECT_FALSE(Slice.isEmpty()); + + // Check global. + EXPECT_FALSE(Slice.findGlobal("_foo", GlobalRecord::Kind::Function)); + auto *Global = Slice.findGlobal("_foo"); + ASSERT_TRUE(Global); + EXPECT_TRUE(Global->isVariable()); + EXPECT_TRUE(Global->isWeakDefined()); + EXPECT_TRUE(Global->isRexported()); + EXPECT_TRUE(Global->isData()); + + // Check class. + auto *Class = Slice.findObjCInterface("NSObject"); + ASSERT_TRUE(Class); + EXPECT_TRUE(Class->isRexported()); + EXPECT_TRUE(Class->isData()); + EXPECT_FALSE(Class->hasExceptionAttribute()); + auto ClassIVar = Class->findObjCIVar("objInfo"); + ASSERT_TRUE(ClassIVar); + EXPECT_TRUE(ClassIVar->isExported()); + EXPECT_FALSE(ClassIVar->isRexported()); + + // Check fall-back extension. + auto *Cat = Slice.findObjCCategory("NSConcreteValue", ""); + ASSERT_TRUE(Cat); + // There is not linkage information for categories. + EXPECT_FALSE(Cat->isExported()); + EXPECT_FALSE(Cat->isInternal()); + auto CatIVar = Cat->findObjCIVar("typeInfo"); + EXPECT_TRUE(CatIVar); + EXPECT_TRUE(CatIVar->isExported()); + EXPECT_FALSE(CatIVar->isRexported()); + + // Find IVars directly. + auto TIIVar = + Slice.findObjCIVar(/*IsScopedName=*/true, "NSConcreteValue.typeInfo"); + ASSERT_TRUE(TIIVar); + EXPECT_EQ(CatIVar->getName(), TIIVar->getName()); + + auto OIIVar = Slice.findObjCIVar(/*IsScopedName=*/false, "objInfo"); + ASSERT_TRUE(OIIVar); + EXPECT_EQ(ClassIVar->getName(), OIIVar->getName()); + + EXPECT_FALSE(Slice.findObjCIVar(/*IsScopedName=*/true, "typeInfo")); +} + +TEST(TAPIRecord, LibraryAttrs) { + Triple T("arm64-apple-ios15.1"); + RecordsSlice Slice(T); + EXPECT_TRUE(Slice.isEmpty()); + + auto BA = Slice.getBinaryAttrs(); + EXPECT_TRUE(Slice.hasBinaryAttrs()); +} + +} // namespace TAPIRecord |