| 1 |
// RUN: clang-tblgen -gen-clang-attr-parser-string-switches -I%p/../../include %s -o - 2>&1 | FileCheck %s |
| 2 |
|
| 3 |
// Tests that the tablegen can support attributes with the same spellings but |
| 4 |
// different argument types. |
| 5 |
|
| 6 |
include "clang/Basic/Attr.td" |
| 7 |
|
| 8 |
// Test attributeParsedArgsUnevaluated : different ParseArgumentsAsUnevaluated |
| 9 |
def TestUnEvalOne : InheritableAttr { |
| 10 |
let Spellings = [Clang<"test_uneval">]; |
| 11 |
let Args = [ExprArgument<"Count">]; |
| 12 |
let Subjects = SubjectList<[Function]>; |
| 13 |
let ParseArgumentsAsUnevaluated = 1; |
| 14 |
let Documentation = [Undocumented]; |
| 15 |
} |
| 16 |
|
| 17 |
def TestUnEvalTwo : InheritableAttr { |
| 18 |
let Spellings = [Pragma<"", "test_uneval">]; |
| 19 |
let Args = [ExprArgument<"Count">]; |
| 20 |
let Subjects = SubjectList<[Function]>; |
| 21 |
let Documentation = [Undocumented]; |
| 22 |
} |
| 23 |
|
| 24 |
// CHECK: #if defined(CLANG_ATTR_ARG_CONTEXT_LIST) |
| 25 |
// CHECK: .Case("test_uneval", (Syntax==AttributeCommonInfo::AS_GNU && !ScopeName) ? 1 : |
| 26 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_CXX11 && ScopeName && ScopeName->getName()=="clang") ? 1 : |
| 27 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_C23 && ScopeName && ScopeName->getName()=="clang") ? 1 : 0) |
| 28 |
// CHECK: #endif // CLANG_ATTR_ARG_CONTEXT_LIST |
| 29 |
|
| 30 |
// Test attributeHasIdentifierArg: Same spelling, one with and one without |
| 31 |
// an IdentifierArg. |
| 32 |
def TestIdentOne : Attr { |
| 33 |
let Spellings = [GNU<"test_ident">]; |
| 34 |
let Args = [EnumArgument<"Option", "OptionType", /*is_string=*/false, |
| 35 |
["optA", "optB"], ["OPTA", "OPTB"]>]; |
| 36 |
let Subjects = SubjectList<[Function]>; |
| 37 |
let Documentation = [Undocumented]; |
| 38 |
} |
| 39 |
|
| 40 |
def TestIdentTwo : StmtAttr { |
| 41 |
let Spellings = [Pragma<"", "test_ident">]; |
| 42 |
let Args = [UnsignedArgument<"val", /*opt*/1>]; |
| 43 |
let Subjects = SubjectList<[Function]>; |
| 44 |
let Documentation = [Undocumented]; |
| 45 |
} |
| 46 |
|
| 47 |
// Checks that the simple value is produced if only one attribute with a |
| 48 |
// spelling. |
| 49 |
def TestOnlyIdent : Attr { |
| 50 |
let Spellings = [GNU<"test_only_ident">]; |
| 51 |
let Args = [EnumArgument<"Option", "OptionType", /*is_string=*/false, |
| 52 |
["optA", "optB"], ["OPTA", "OPTB"]>]; |
| 53 |
let Subjects = SubjectList<[Function]>; |
| 54 |
let Documentation = [Undocumented]; |
| 55 |
} |
| 56 |
|
| 57 |
// CHECK: #if defined(CLANG_ATTR_IDENTIFIER_ARG_LIST) |
| 58 |
// CHECK: .Case("test_ident", (Syntax==AttributeCommonInfo::AS_GNU && !ScopeName) |
| 59 |
// CHECK: .Case("test_only_ident", true) |
| 60 |
// CHECK: .Case("test_targspec", |
| 61 |
// CHECK-SAME: (T.getArch() == llvm::Triple::arm)) ? 1 : 0 |
| 62 |
// CHECK: #endif // CLANG_ATTR_IDENTIFIER_ARG_LIST |
| 63 |
|
| 64 |
// Test attributeStringLiteralListArg : Same spelling, some with a |
| 65 |
// StringArgument, some without, some in different locations. |
| 66 |
def TestStringOne : DeclOrTypeAttr { |
| 67 |
let Spellings = [Clang<"test_string">]; |
| 68 |
let Args = [UnsignedArgument<"unsarg">]; |
| 69 |
let Subjects = SubjectList<[Function, TypedefName, ParmVar]>; |
| 70 |
let Documentation = [AcquireHandleDocs]; |
| 71 |
} |
| 72 |
|
| 73 |
def TestStringTwo : InheritableAttr { |
| 74 |
let Spellings = [Pragma<"", "test_string">]; |
| 75 |
let Args = [StringArgument<"strarg">]; |
| 76 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 77 |
let Documentation = [Undocumented]; |
| 78 |
} |
| 79 |
|
| 80 |
// In a different position |
| 81 |
def TestStringThree : Attr { |
| 82 |
let Spellings = [Declspec<"test_string">]; |
| 83 |
let Args = [UnsignedArgument<"uarg">, StringArgument<"strarg">]; |
| 84 |
let Subjects = SubjectList<[Function, TypedefName, ParmVar]>; |
| 85 |
let Documentation = [AcquireHandleDocs]; |
| 86 |
} |
| 87 |
|
| 88 |
// CHECK: #if defined(CLANG_ATTR_STRING_LITERAL_ARG_LIST) |
| 89 |
// CHECK: .Case("test_string", (Syntax==AttributeCommonInfo::AS_Declspec && !ScopeName) ? 2 : |
| 90 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_Pragma && !ScopeName) ? 1 : 0) |
| 91 |
// CHECK: .Case("test_targspec", |
| 92 |
// CHECK-SAME: (T.getArch() == llvm::Triple::arm)) ? 4294967294 : |
| 93 |
// CHECK-SAME: (T.getArch() == llvm::Triple::ppc)) ? 1 : |
| 94 |
// CHECK: #endif // CLANG_ATTR_STRING_LITERAL_ARG_LIST |
| 95 |
|
| 96 |
// Test attributeHasVariadicIdentifierArg : One with VariadicIdentifierArgument |
| 97 |
// and one without. |
| 98 |
def TestVariadicIdentOne : InheritableAttr { |
| 99 |
let Spellings = [Clang<"test_var_ident">]; |
| 100 |
let Args = [UnsignedArgument<"Hint">]; |
| 101 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 102 |
let Documentation = [Undocumented]; |
| 103 |
} |
| 104 |
|
| 105 |
def TestVariadicIdentTwo : InheritableAttr { |
| 106 |
let Spellings = [Pragma<"", "test_var_ident">]; |
| 107 |
let Args = [VariadicIdentifierArgument<"iargs">]; |
| 108 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 109 |
let Documentation = [Undocumented]; |
| 110 |
} |
| 111 |
|
| 112 |
// CHECK: #if defined(CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST) |
| 113 |
// CHECK: .Case("test_var_ident", (Syntax==AttributeCommonInfo::AS_Pragma && !ScopeName)) |
| 114 |
// CHECK: #endif // CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST |
| 115 |
|
| 116 |
// Test attributeTreatsKeywordThisAsIdentifier : Same spelling, one with and |
| 117 |
// one without VariadicParamOrParamIdxArgument. |
| 118 |
def TestVarOrIdxOne : InheritableAttr { |
| 119 |
let Spellings = [Clang<"test_var_idx">]; |
| 120 |
let Args = [VariadicParamOrParamIdxArgument<"arg">]; |
| 121 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 122 |
let Documentation = [Undocumented]; |
| 123 |
} |
| 124 |
|
| 125 |
def TestVarOrIdxTwo : InheritableAttr { |
| 126 |
let Spellings = [Pragma<"", "test_var_idx">]; |
| 127 |
let Args = [UnsignedArgument<"Hint">]; |
| 128 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 129 |
let Documentation = [Undocumented]; |
| 130 |
} |
| 131 |
|
| 132 |
// CHECK: #if defined(CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST) |
| 133 |
// CHECK: .Case("test_var_idx", (Syntax==AttributeCommonInfo::AS_GNU && !ScopeName) ? 1 : |
| 134 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_CXX11 && ScopeName && ScopeName->getName()=="clang") ? 1 : |
| 135 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_C23 && ScopeName && ScopeName->getName()=="clang") ? 1 : 0) |
| 136 |
// CHECK: #endif // CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST |
| 137 |
|
| 138 |
// Test attributeAcceptsExprPack : One with, one without. |
| 139 |
def TestExprPackOne : InheritableAttr { |
| 140 |
let Spellings = [Clang<"test_expr_pack">]; |
| 141 |
let Args = [StringArgument<"str">, VariadicExprArgument<"args">]; |
| 142 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 143 |
let AcceptsExprPack = 1; |
| 144 |
let Documentation = [Undocumented]; |
| 145 |
} |
| 146 |
|
| 147 |
def TestExprPackTwo : InheritableAttr { |
| 148 |
let Spellings = [Pragma<"", "test_expr_pack">]; |
| 149 |
let Args = [StringArgument<"str">, VariadicExprArgument<"args">]; |
| 150 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 151 |
let Documentation = [Undocumented]; |
| 152 |
} |
| 153 |
|
| 154 |
// CHECK: #if defined(CLANG_ATTR_ACCEPTS_EXPR_PACK) |
| 155 |
// CHECK: .Case("test_expr_pack", (Syntax==AttributeCommonInfo::AS_GNU && !ScopeName) ? 1 : |
| 156 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_CXX11 && ScopeName && ScopeName->getName()=="clang") ? 1 : |
| 157 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_C23 && ScopeName && ScopeName->getName()=="clang") ? 1 : 0) |
| 158 |
// CHECK: #endif // CLANG_ATTR_ACCEPTS_EXPR_PACK |
| 159 |
|
| 160 |
|
| 161 |
// Test attributeIsTypeArgAttr : Same spelling, one with TypeArgument and one |
| 162 |
// without. |
| 163 |
def TestTypeOne : InheritableAttr { |
| 164 |
let Spellings = [Clang<"test_type">]; |
| 165 |
let Args = [TypeArgument<"Hint">]; |
| 166 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 167 |
let Documentation = [Undocumented]; |
| 168 |
} |
| 169 |
|
| 170 |
def TestTypeTwo : InheritableAttr { |
| 171 |
let Spellings = [Pragma<"", "test_type">]; |
| 172 |
let Args = [UnsignedArgument<"Hint">]; |
| 173 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 174 |
let Documentation = [Undocumented]; |
| 175 |
} |
| 176 |
|
| 177 |
// CHECK: #if defined(CLANG_ATTR_TYPE_ARG_LIST) |
| 178 |
// CHECK: .Case("test_type", (Syntax==AttributeCommonInfo::AS_GNU && !ScopeName) ? 1 : |
| 179 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_CXX11 && ScopeName && ScopeName->getName()=="clang") ? 1 : |
| 180 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_C23 && ScopeName && ScopeName->getName()=="clang") ? 1 : 0) |
| 181 |
// CHECK: #endif // CLANG_ATTR_TYPE_ARG_LIST |
| 182 |
|
| 183 |
// Test attributeHasStrictIdentifierArgs, one used StrictEnumParameters, the |
| 184 |
// other does not. |
| 185 |
def TestStrictEnumOne : InheritableAttr { |
| 186 |
let Spellings = [Clang<"strict_enum">]; |
| 187 |
let StrictEnumParameters = 1; |
| 188 |
let Args = [EnumArgument<"One", "OneType", /*is_string=*/true, |
| 189 |
["a", "b", "c", "d"], |
| 190 |
["A", "B", "C", "D"]>, |
| 191 |
IntArgument<"Other", 1>, |
| 192 |
EnumArgument<"Two", "TwoType", /*is_string=*/true, |
| 193 |
["e", "f", "g", "h"], |
| 194 |
["E", "F", "G", "H"]>]; |
| 195 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 196 |
let Documentation = [Undocumented]; |
| 197 |
} |
| 198 |
|
| 199 |
def TestStrictEnumTwo : InheritableAttr { |
| 200 |
let Spellings = [Pragma<"", "strict_enum">]; |
| 201 |
let Args = [VariadicExprArgument<"Args">]; |
| 202 |
let Subjects = SubjectList<[Function], ErrorDiag>; |
| 203 |
let Documentation = [Undocumented]; |
| 204 |
} |
| 205 |
|
| 206 |
// CHECK: #if defined(CLANG_ATTR_STRICT_IDENTIFIER_ARG_LIST) |
| 207 |
// CHECK: .Case("strict_enum", (Syntax==AttributeCommonInfo::AS_GNU && !ScopeName) ? 1 : |
| 208 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_CXX11 && ScopeName && ScopeName->getName()=="clang") ? 1 : |
| 209 |
// CHECK-SAME: (Syntax==AttributeCommonInfo::AS_C23 && ScopeName && ScopeName->getName()=="clang") ? 1 : 0) |
| 210 |
// CHECK: #endif // CLANG_ATTR_STRICT_IDENTIFIER_ARG_LIST |
| 211 |
|
| 212 |
// Test that TargetSpecific attributes work as expected. |
| 213 |
|
| 214 |
def TargSpecX86 : InheritableAttr, TargetSpecificAttr<TargetArch<["x86"]>> { |
| 215 |
let Spellings = [GCC<"test_targspec">]; |
| 216 |
let Subjects = SubjectList<[Function]>; |
| 217 |
let Args = [UnsignedArgument<"ua">, DefaultIntArgument<"o", 0>]; |
| 218 |
let ParseKind = "TargSpec"; |
| 219 |
let Documentation = [Undocumented]; |
| 220 |
} |
| 221 |
def TargSpecPPC : InheritableAttr, TargetSpecificAttr<TargetArch<["ppc"]>> { |
| 222 |
let Spellings = [GCC<"test_targspec">]; |
| 223 |
let Subjects = SubjectList<[Function]>; |
| 224 |
let Args = [StringArgument<"str">, VariadicExprArgument<"args">]; |
| 225 |
let ParseKind = "TargSpec"; |
| 226 |
let Documentation = [Undocumented]; |
| 227 |
} |
| 228 |
def TargSpecARM : InheritableAttr, TargetSpecificAttr<TargetArch<["arm"]>> { |
| 229 |
let Spellings = [GCC<"test_targspec">]; |
| 230 |
let Subjects = SubjectList<[Function]>; |
| 231 |
let Args = [IdentifierArgument<"id">, VariadicStringArgument<"sargs">]; |
| 232 |
let ParseKind = "TargSpec"; |
| 233 |
let Documentation = [Undocumented]; |
| 234 |
} |