1 | //===- unittests/AST/SizelessTypesTest.cpp --- Sizeless type tests --------===// |
---|---|
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 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file contains tests for clang::Type queries related to sizeless types. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "clang/AST/ASTContext.h" |
14 | #include "clang/AST/Type.h" |
15 | #include "clang/Tooling/Tooling.h" |
16 | #include "gtest/gtest.h" |
17 | |
18 | using namespace clang; |
19 | |
20 | struct SizelessTypeTester : public ::testing::Test { |
21 | // Declare an incomplete structure type. |
22 | std::unique_ptr<ASTUnit> AST = tooling::buildASTFromCodeWithArgs( |
23 | Code: "struct foo;", Args: { "-target", "aarch64-linux-gnu"}); |
24 | ASTContext &Ctx = AST->getASTContext(); |
25 | TranslationUnitDecl &TU = *Ctx.getTranslationUnitDecl(); |
26 | TypeDecl *Foo = cast<TypeDecl>(TU.lookup(&Ctx.Idents.get(Name: "foo")).front()); |
27 | const Type *FooTy = Foo->getTypeForDecl(); |
28 | }; |
29 | |
30 | TEST_F(SizelessTypeTester, TestSizelessBuiltin) { |
31 | ASSERT_TRUE(Ctx.SveInt8Ty->isSizelessBuiltinType()); |
32 | ASSERT_TRUE(Ctx.SveInt16Ty->isSizelessBuiltinType()); |
33 | ASSERT_TRUE(Ctx.SveInt32Ty->isSizelessBuiltinType()); |
34 | ASSERT_TRUE(Ctx.SveInt64Ty->isSizelessBuiltinType()); |
35 | |
36 | ASSERT_TRUE(Ctx.SveUint8Ty->isSizelessBuiltinType()); |
37 | ASSERT_TRUE(Ctx.SveUint16Ty->isSizelessBuiltinType()); |
38 | ASSERT_TRUE(Ctx.SveUint32Ty->isSizelessBuiltinType()); |
39 | ASSERT_TRUE(Ctx.SveUint64Ty->isSizelessBuiltinType()); |
40 | |
41 | ASSERT_TRUE(Ctx.SveFloat16Ty->isSizelessBuiltinType()); |
42 | ASSERT_TRUE(Ctx.SveFloat32Ty->isSizelessBuiltinType()); |
43 | ASSERT_TRUE(Ctx.SveFloat64Ty->isSizelessBuiltinType()); |
44 | |
45 | ASSERT_TRUE(Ctx.SveBFloat16Ty->isSizelessBuiltinType()); |
46 | |
47 | ASSERT_TRUE(Ctx.SveBoolTy->isSizelessBuiltinType()); |
48 | ASSERT_TRUE(Ctx.SveCountTy->isSizelessBuiltinType()); |
49 | |
50 | ASSERT_FALSE(Ctx.VoidTy->isSizelessBuiltinType()); |
51 | ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessBuiltinType()); |
52 | ASSERT_FALSE(FooTy->isSizelessBuiltinType()); |
53 | |
54 | ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isSizelessBuiltinType()); |
55 | ASSERT_FALSE( |
56 | Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isSizelessBuiltinType()); |
57 | ASSERT_FALSE( |
58 | Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isSizelessBuiltinType()); |
59 | |
60 | ASSERT_FALSE(Ctx.getPointerType(Ctx.SveCountTy)->isSizelessBuiltinType()); |
61 | ASSERT_FALSE( |
62 | Ctx.getLValueReferenceType(Ctx.SveCountTy)->isSizelessBuiltinType()); |
63 | ASSERT_FALSE( |
64 | Ctx.getRValueReferenceType(Ctx.SveCountTy)->isSizelessBuiltinType()); |
65 | } |
66 | |
67 | TEST_F(SizelessTypeTester, TestSizeless) { |
68 | ASSERT_TRUE(Ctx.SveInt8Ty->isSizelessType()); |
69 | ASSERT_TRUE(Ctx.SveInt16Ty->isSizelessType()); |
70 | ASSERT_TRUE(Ctx.SveInt32Ty->isSizelessType()); |
71 | ASSERT_TRUE(Ctx.SveInt64Ty->isSizelessType()); |
72 | |
73 | ASSERT_TRUE(Ctx.SveUint8Ty->isSizelessType()); |
74 | ASSERT_TRUE(Ctx.SveUint16Ty->isSizelessType()); |
75 | ASSERT_TRUE(Ctx.SveUint32Ty->isSizelessType()); |
76 | ASSERT_TRUE(Ctx.SveUint64Ty->isSizelessType()); |
77 | |
78 | ASSERT_TRUE(Ctx.SveFloat16Ty->isSizelessType()); |
79 | ASSERT_TRUE(Ctx.SveFloat32Ty->isSizelessType()); |
80 | ASSERT_TRUE(Ctx.SveFloat64Ty->isSizelessType()); |
81 | |
82 | ASSERT_TRUE(Ctx.SveBFloat16Ty->isSizelessType()); |
83 | |
84 | ASSERT_TRUE(Ctx.SveBoolTy->isSizelessType()); |
85 | ASSERT_TRUE(Ctx.SveCountTy->isSizelessType()); |
86 | |
87 | ASSERT_FALSE(Ctx.VoidTy->isSizelessType()); |
88 | ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessType()); |
89 | ASSERT_FALSE(FooTy->isSizelessType()); |
90 | |
91 | ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isSizelessType()); |
92 | ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->isSizelessType()); |
93 | ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->isSizelessType()); |
94 | |
95 | ASSERT_FALSE(Ctx.getPointerType(Ctx.SveCountTy)->isSizelessType()); |
96 | ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveCountTy)->isSizelessType()); |
97 | ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveCountTy)->isSizelessType()); |
98 | } |
99 |