[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / unittests / TextAPI / RecordTests.cpp
blobdbe58ca0eea59d7810c2d1e0e107aef8624d0c06
1 //===-- RecordTests.cpp - TextAPI Record Type Test-------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===-----------------------------------------------------------------------===//
9 #include "llvm/TargetParser/Triple.h"
10 #include "llvm/TextAPI/RecordsSlice.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
14 using namespace llvm::MachO;
16 namespace TAPIRecord {
18 TEST(TAPIRecord, Simple) {
19 GlobalRecord API{"_sym", RecordLinkage::Rexported,
20 SymbolFlags::Rexported | SymbolFlags::Text |
21 SymbolFlags::ThreadLocalValue,
22 GlobalRecord::Kind::Function};
23 EXPECT_TRUE(API.isExported());
24 EXPECT_TRUE(API.isText());
25 EXPECT_TRUE(API.isRexported());
26 EXPECT_TRUE(API.isFunction());
27 EXPECT_TRUE(API.isThreadLocalValue());
28 EXPECT_FALSE(API.isInternal());
29 EXPECT_FALSE(API.isUndefined());
30 EXPECT_FALSE(API.isWeakDefined());
31 EXPECT_FALSE(API.isWeakReferenced());
32 EXPECT_FALSE(API.isVariable());
35 TEST(TAPIRecord, SimpleObjC) {
36 ObjCInterfaceRecord Class{"NSObject", RecordLinkage::Exported};
37 ObjCInterfaceRecord ClassEH{"NSObject", RecordLinkage::Exported,
38 /*HasEHType=*/true};
40 EXPECT_TRUE(Class.isExported());
41 EXPECT_EQ(Class.isExported(), ClassEH.isExported());
42 EXPECT_FALSE(Class.hasExceptionAttribute());
43 EXPECT_TRUE(ClassEH.hasExceptionAttribute());
44 EXPECT_EQ(ObjCIVarRecord::createScopedName("NSObject", "var"),
45 "NSObject.var");
48 TEST(TAPIRecord, SimpleSlice) {
49 Triple T("arm64-apple-macosx13.3");
50 RecordsSlice Slice(T);
51 EXPECT_TRUE(Slice.empty());
52 Slice.addRecord("_OBJC_CLASS_$_NSObject", SymbolFlags::None,
53 GlobalRecord::Kind::Unknown, RecordLinkage::Rexported);
54 Slice.addRecord("_OBJC_METACLASS_$_NSObject", SymbolFlags::None,
55 GlobalRecord::Kind::Unknown, RecordLinkage::Rexported);
56 Slice.addRecord("_OBJC_IVAR_$_NSConcreteValue.typeInfo", SymbolFlags::None,
57 GlobalRecord::Kind::Unknown, RecordLinkage::Exported);
58 Slice.addRecord("_OBJC_IVAR_$_NSObject.objInfo", SymbolFlags::None,
59 GlobalRecord::Kind::Unknown, RecordLinkage::Exported);
60 Slice.addRecord("_foo", SymbolFlags::WeakDefined | SymbolFlags::Rexported,
61 GlobalRecord::Kind::Variable, RecordLinkage::Rexported);
62 EXPECT_FALSE(Slice.empty());
64 // Check global.
65 EXPECT_FALSE(Slice.findGlobal("_foo", GlobalRecord::Kind::Function));
66 auto *Global = Slice.findGlobal("_foo");
67 ASSERT_TRUE(Global);
68 EXPECT_TRUE(Global->isVariable());
69 EXPECT_TRUE(Global->isWeakDefined());
70 EXPECT_TRUE(Global->isRexported());
71 EXPECT_TRUE(Global->isData());
73 // Check class.
74 auto *Class = Slice.findObjCInterface("NSObject");
75 ASSERT_TRUE(Class);
76 EXPECT_TRUE(Class->isRexported());
77 EXPECT_TRUE(Class->isData());
78 EXPECT_FALSE(Class->hasExceptionAttribute());
79 auto ClassIVar = Class->findObjCIVar("objInfo");
80 ASSERT_TRUE(ClassIVar);
81 EXPECT_TRUE(ClassIVar->isExported());
82 EXPECT_FALSE(ClassIVar->isRexported());
84 // Check fall-back extension.
85 auto *Cat = Slice.findObjCCategory("NSConcreteValue", "");
86 ASSERT_TRUE(Cat);
87 // There is not linkage information for categories.
88 EXPECT_FALSE(Cat->isExported());
89 EXPECT_FALSE(Cat->isInternal());
90 auto CatIVar = Cat->findObjCIVar("typeInfo");
91 EXPECT_TRUE(CatIVar);
92 EXPECT_TRUE(CatIVar->isExported());
93 EXPECT_FALSE(CatIVar->isRexported());
95 // Find IVars directly.
96 auto TIIVar =
97 Slice.findObjCIVar(/*IsScopedName=*/true, "NSConcreteValue.typeInfo");
98 ASSERT_TRUE(TIIVar);
99 EXPECT_EQ(CatIVar->getName(), TIIVar->getName());
101 auto OIIVar = Slice.findObjCIVar(/*IsScopedName=*/false, "objInfo");
102 ASSERT_TRUE(OIIVar);
103 EXPECT_EQ(ClassIVar->getName(), OIIVar->getName());
105 EXPECT_FALSE(Slice.findObjCIVar(/*IsScopedName=*/true, "typeInfo"));
108 TEST(TAPIRecord, LibraryAttrs) {
109 Triple T("arm64-apple-ios15.1");
110 RecordsSlice Slice(T);
111 EXPECT_TRUE(Slice.empty());
113 auto BA = Slice.getBinaryAttrs();
114 EXPECT_TRUE(Slice.hasBinaryAttrs());
117 } // namespace TAPIRecord