OperationKinds.def revision 360784
1//===--- OperationKinds.def - Operations Database ---------------*- C++ -*-===// 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 enumerates the different kinds of operations that can be 10// performed by various expressions. 11// 12//===----------------------------------------------------------------------===// 13// 14/// @file OperationKinds.def 15/// 16/// In this file, each of the C/C++ operations is enumerated CAST_OPERATION, 17/// BINARY_OPERATION or UNARY_OPERATION macro, each of which can be specified by 18/// the code including this file. 19/// 20/// Macros had one or two arguments: 21/// 22/// Name: The name of the operation. Name (prefixed with CK_, UO_ or BO_) will 23/// be the name of the corresponding enumerator (see OperationsKinds.h). 24/// 25/// Spelling: A string that provides a canonical spelling for the operation. 26 27#ifndef CAST_OPERATION 28# define CAST_OPERATION(Name) 29#endif 30 31#ifndef BINARY_OPERATION 32# define BINARY_OPERATION(Name, Spelling) 33#endif 34 35#ifndef UNARY_OPERATION 36# define UNARY_OPERATION(Name, Spelling) 37#endif 38 39//===- Cast Operations ---------------------------------------------------===// 40 41/// CK_Dependent - A conversion which cannot yet be analyzed because 42/// either the expression or target type is dependent. These are 43/// created only for explicit casts; dependent ASTs aren't required 44/// to even approximately type-check. 45/// (T*) malloc(sizeof(T)) 46/// reinterpret_cast<intptr_t>(A<T>::alloc()); 47CAST_OPERATION(Dependent) 48 49/// CK_BitCast - A conversion which causes a bit pattern of one type 50/// to be reinterpreted as a bit pattern of another type. Generally 51/// the operands must have equivalent size and unrelated types. 52/// 53/// The pointer conversion char* -> int* is a bitcast. A conversion 54/// from any pointer type to a C pointer type is a bitcast unless 55/// it's actually BaseToDerived or DerivedToBase. A conversion to a 56/// block pointer or ObjC pointer type is a bitcast only if the 57/// operand has the same type kind; otherwise, it's one of the 58/// specialized casts below. 59/// 60/// Vector coercions are bitcasts. 61CAST_OPERATION(BitCast) 62 63/// CK_LValueBitCast - A conversion which reinterprets the address of 64/// an l-value as an l-value of a different kind. Used for 65/// reinterpret_casts of l-value expressions to reference types. 66/// bool b; reinterpret_cast<char&>(b) = 'a'; 67CAST_OPERATION(LValueBitCast) 68 69/// CK_LValueToRValueBitCast - A conversion that causes us to reinterpret the 70/// object representation of an lvalue as an rvalue. Created by 71/// __builtin_bit_cast. 72CAST_OPERATION(LValueToRValueBitCast) 73 74/// CK_LValueToRValue - A conversion which causes the extraction of 75/// an r-value from the operand gl-value. The result of an r-value 76/// conversion is always unqualified. 77CAST_OPERATION(LValueToRValue) 78 79/// CK_NoOp - A conversion which does not affect the type other than 80/// (possibly) adding qualifiers. 81/// int -> int 82/// char** -> const char * const * 83CAST_OPERATION(NoOp) 84 85/// CK_BaseToDerived - A conversion from a C++ class pointer/reference 86/// to a derived class pointer/reference. 87/// B *b = static_cast<B*>(a); 88CAST_OPERATION(BaseToDerived) 89 90/// CK_DerivedToBase - A conversion from a C++ class pointer 91/// to a base class pointer. 92/// A *a = new B(); 93CAST_OPERATION(DerivedToBase) 94 95/// CK_UncheckedDerivedToBase - A conversion from a C++ class 96/// pointer/reference to a base class that can assume that the 97/// derived pointer is not null. 98/// const A &a = B(); 99/// b->method_from_a(); 100CAST_OPERATION(UncheckedDerivedToBase) 101 102/// CK_Dynamic - A C++ dynamic_cast. 103CAST_OPERATION(Dynamic) 104 105/// CK_ToUnion - The GCC cast-to-union extension. 106/// int -> union { int x; float y; } 107/// float -> union { int x; float y; } 108CAST_OPERATION(ToUnion) 109 110/// CK_ArrayToPointerDecay - Array to pointer decay. 111/// int[10] -> int* 112/// char[5][6] -> char(*)[6] 113CAST_OPERATION(ArrayToPointerDecay) 114 115/// CK_FunctionToPointerDecay - Function to pointer decay. 116/// void(int) -> void(*)(int) 117CAST_OPERATION(FunctionToPointerDecay) 118 119/// CK_NullToPointer - Null pointer constant to pointer, ObjC 120/// pointer, or block pointer. 121/// (void*) 0 122/// void (^block)() = 0; 123CAST_OPERATION(NullToPointer) 124 125/// CK_NullToMemberPointer - Null pointer constant to member pointer. 126/// int A::*mptr = 0; 127/// int (A::*fptr)(int) = nullptr; 128CAST_OPERATION(NullToMemberPointer) 129 130/// CK_BaseToDerivedMemberPointer - Member pointer in base class to 131/// member pointer in derived class. 132/// int B::*mptr = &A::member; 133CAST_OPERATION(BaseToDerivedMemberPointer) 134 135/// CK_DerivedToBaseMemberPointer - Member pointer in derived class to 136/// member pointer in base class. 137/// int A::*mptr = static_cast<int A::*>(&B::member); 138CAST_OPERATION(DerivedToBaseMemberPointer) 139 140/// CK_MemberPointerToBoolean - Member pointer to boolean. A check 141/// against the null member pointer. 142CAST_OPERATION(MemberPointerToBoolean) 143 144/// CK_ReinterpretMemberPointer - Reinterpret a member pointer as a 145/// different kind of member pointer. C++ forbids this from 146/// crossing between function and object types, but otherwise does 147/// not restrict it. However, the only operation that is permitted 148/// on a "punned" member pointer is casting it back to the original 149/// type, which is required to be a lossless operation (although 150/// many ABIs do not guarantee this on all possible intermediate types). 151CAST_OPERATION(ReinterpretMemberPointer) 152 153/// CK_UserDefinedConversion - Conversion using a user defined type 154/// conversion function. 155/// struct A { operator int(); }; int i = int(A()); 156CAST_OPERATION(UserDefinedConversion) 157 158/// CK_ConstructorConversion - Conversion by constructor. 159/// struct A { A(int); }; A a = A(10); 160CAST_OPERATION(ConstructorConversion) 161 162/// CK_IntegralToPointer - Integral to pointer. A special kind of 163/// reinterpreting conversion. Applies to normal, ObjC, and block 164/// pointers. 165/// (char*) 0x1001aab0 166/// reinterpret_cast<int*>(0) 167CAST_OPERATION(IntegralToPointer) 168 169/// CK_PointerToIntegral - Pointer to integral. A special kind of 170/// reinterpreting conversion. Applies to normal, ObjC, and block 171/// pointers. 172/// (intptr_t) "help!" 173CAST_OPERATION(PointerToIntegral) 174 175/// CK_PointerToBoolean - Pointer to boolean conversion. A check 176/// against null. Applies to normal, ObjC, and block pointers. 177CAST_OPERATION(PointerToBoolean) 178 179/// CK_ToVoid - Cast to void, discarding the computed value. 180/// (void) malloc(2048) 181CAST_OPERATION(ToVoid) 182 183/// CK_VectorSplat - A conversion from an arithmetic type to a 184/// vector of that element type. Fills all elements ("splats") with 185/// the source value. 186/// __attribute__((ext_vector_type(4))) int v = 5; 187CAST_OPERATION(VectorSplat) 188 189/// CK_IntegralCast - A cast between integral types (other than to 190/// boolean). Variously a bitcast, a truncation, a sign-extension, 191/// or a zero-extension. 192/// long l = 5; 193/// (unsigned) i 194CAST_OPERATION(IntegralCast) 195 196/// CK_IntegralToBoolean - Integral to boolean. A check against zero. 197/// (bool) i 198CAST_OPERATION(IntegralToBoolean) 199 200/// CK_IntegralToFloating - Integral to floating point. 201/// float f = i; 202CAST_OPERATION(IntegralToFloating) 203 204/// CK_FixedPointCast - Fixed point to fixed point. 205/// (_Accum) 0.5r 206CAST_OPERATION(FixedPointCast) 207 208/// CK_FixedPointToIntegral - Fixed point to integral. 209/// (int) 2.0k 210CAST_OPERATION(FixedPointToIntegral) 211 212/// CK_IntegralToFixedPoint - Integral to a fixed point. 213/// (_Accum) 2 214CAST_OPERATION(IntegralToFixedPoint) 215 216/// CK_FixedPointToBoolean - Fixed point to boolean. 217/// (bool) 0.5r 218CAST_OPERATION(FixedPointToBoolean) 219 220/// CK_FloatingToIntegral - Floating point to integral. Rounds 221/// towards zero, discarding any fractional component. 222/// (int) f 223CAST_OPERATION(FloatingToIntegral) 224 225/// CK_FloatingToBoolean - Floating point to boolean. 226/// (bool) f 227CAST_OPERATION(FloatingToBoolean) 228 229// CK_BooleanToSignedIntegral - Convert a boolean to -1 or 0 for true and 230// false, respectively. 231CAST_OPERATION(BooleanToSignedIntegral) 232 233/// CK_FloatingCast - Casting between floating types of different size. 234/// (double) f 235/// (float) ld 236CAST_OPERATION(FloatingCast) 237 238/// CK_CPointerToObjCPointerCast - Casting a C pointer kind to an 239/// Objective-C pointer. 240CAST_OPERATION(CPointerToObjCPointerCast) 241 242/// CK_BlockPointerToObjCPointerCast - Casting a block pointer to an 243/// ObjC pointer. 244CAST_OPERATION(BlockPointerToObjCPointerCast) 245 246/// CK_AnyPointerToBlockPointerCast - Casting any non-block pointer 247/// to a block pointer. Block-to-block casts are bitcasts. 248CAST_OPERATION(AnyPointerToBlockPointerCast) 249 250/// Converting between two Objective-C object types, which 251/// can occur when performing reference binding to an Objective-C 252/// object. 253CAST_OPERATION(ObjCObjectLValueCast) 254 255/// A conversion of a floating point real to a floating point 256/// complex of the original type. Injects the value as the real 257/// component with a zero imaginary component. 258/// float -> _Complex float 259CAST_OPERATION(FloatingRealToComplex) 260 261/// Converts a floating point complex to floating point real 262/// of the source's element type. Just discards the imaginary 263/// component. 264/// _Complex long double -> long double 265CAST_OPERATION(FloatingComplexToReal) 266 267/// Converts a floating point complex to bool by comparing 268/// against 0+0i. 269CAST_OPERATION(FloatingComplexToBoolean) 270 271/// Converts between different floating point complex types. 272/// _Complex float -> _Complex double 273CAST_OPERATION(FloatingComplexCast) 274 275/// Converts from a floating complex to an integral complex. 276/// _Complex float -> _Complex int 277CAST_OPERATION(FloatingComplexToIntegralComplex) 278 279/// Converts from an integral real to an integral complex 280/// whose element type matches the source. Injects the value as 281/// the real component with a zero imaginary component. 282/// long -> _Complex long 283CAST_OPERATION(IntegralRealToComplex) 284 285/// Converts an integral complex to an integral real of the 286/// source's element type by discarding the imaginary component. 287/// _Complex short -> short 288CAST_OPERATION(IntegralComplexToReal) 289 290/// Converts an integral complex to bool by comparing against 291/// 0+0i. 292CAST_OPERATION(IntegralComplexToBoolean) 293 294/// Converts between different integral complex types. 295/// _Complex char -> _Complex long long 296/// _Complex unsigned int -> _Complex signed int 297CAST_OPERATION(IntegralComplexCast) 298 299/// Converts from an integral complex to a floating complex. 300/// _Complex unsigned -> _Complex float 301CAST_OPERATION(IntegralComplexToFloatingComplex) 302 303/// [ARC] Produces a retainable object pointer so that it may 304/// be consumed, e.g. by being passed to a consuming parameter. 305/// Calls objc_retain. 306CAST_OPERATION(ARCProduceObject) 307 308/// [ARC] Consumes a retainable object pointer that has just 309/// been produced, e.g. as the return value of a retaining call. 310/// Enters a cleanup to call objc_release at some indefinite time. 311CAST_OPERATION(ARCConsumeObject) 312 313/// [ARC] Reclaim a retainable object pointer object that may 314/// have been produced and autoreleased as part of a function return 315/// sequence. 316CAST_OPERATION(ARCReclaimReturnedObject) 317 318/// [ARC] Causes a value of block type to be copied to the 319/// heap, if it is not already there. A number of other operations 320/// in ARC cause blocks to be copied; this is for cases where that 321/// would not otherwise be guaranteed, such as when casting to a 322/// non-block pointer type. 323CAST_OPERATION(ARCExtendBlockObject) 324 325/// Converts from _Atomic(T) to T. 326CAST_OPERATION(AtomicToNonAtomic) 327/// Converts from T to _Atomic(T). 328CAST_OPERATION(NonAtomicToAtomic) 329 330/// Causes a block literal to by copied to the heap and then 331/// autoreleased. 332/// 333/// This particular cast kind is used for the conversion from a C++11 334/// lambda expression to a block pointer. 335CAST_OPERATION(CopyAndAutoreleaseBlockObject) 336 337// Convert a builtin function to a function pointer; only allowed in the 338// callee of a call expression. 339CAST_OPERATION(BuiltinFnToFnPtr) 340 341// Convert a zero value for OpenCL opaque types initialization (event_t, 342// queue_t, etc.) 343CAST_OPERATION(ZeroToOCLOpaqueType) 344 345// Convert a pointer to a different address space. 346CAST_OPERATION(AddressSpaceConversion) 347 348// Convert an integer initializer to an OpenCL sampler. 349CAST_OPERATION(IntToOCLSampler) 350 351//===- Binary Operations -------------------------------------------------===// 352// Operators listed in order of precedence. 353// Note that additions to this should also update the StmtVisitor class and 354// BinaryOperator::getOverloadedOperator. 355 356// [C++ 5.5] Pointer-to-member operators. 357BINARY_OPERATION(PtrMemD, ".*") 358BINARY_OPERATION(PtrMemI, "->*") 359// [C99 6.5.5] Multiplicative operators. 360BINARY_OPERATION(Mul, "*") 361BINARY_OPERATION(Div, "/") 362BINARY_OPERATION(Rem, "%") 363// [C99 6.5.6] Additive operators. 364BINARY_OPERATION(Add, "+") 365BINARY_OPERATION(Sub, "-") 366// [C99 6.5.7] Bitwise shift operators. 367BINARY_OPERATION(Shl, "<<") 368BINARY_OPERATION(Shr, ">>") 369// C++20 [expr.spaceship] Three-way comparison operator. 370BINARY_OPERATION(Cmp, "<=>") 371// [C99 6.5.8] Relational operators. 372BINARY_OPERATION(LT, "<") 373BINARY_OPERATION(GT, ">") 374BINARY_OPERATION(LE, "<=") 375BINARY_OPERATION(GE, ">=") 376// [C99 6.5.9] Equality operators. 377BINARY_OPERATION(EQ, "==") 378BINARY_OPERATION(NE, "!=") 379// [C99 6.5.10] Bitwise AND operator. 380BINARY_OPERATION(And, "&") 381// [C99 6.5.11] Bitwise XOR operator. 382BINARY_OPERATION(Xor, "^") 383// [C99 6.5.12] Bitwise OR operator. 384BINARY_OPERATION(Or, "|") 385// [C99 6.5.13] Logical AND operator. 386BINARY_OPERATION(LAnd, "&&") 387// [C99 6.5.14] Logical OR operator. 388BINARY_OPERATION(LOr, "||") 389// [C99 6.5.16] Assignment operators. 390BINARY_OPERATION(Assign, "=") 391BINARY_OPERATION(MulAssign, "*=") 392BINARY_OPERATION(DivAssign, "/=") 393BINARY_OPERATION(RemAssign, "%=") 394BINARY_OPERATION(AddAssign, "+=") 395BINARY_OPERATION(SubAssign, "-=") 396BINARY_OPERATION(ShlAssign, "<<=") 397BINARY_OPERATION(ShrAssign, ">>=") 398BINARY_OPERATION(AndAssign, "&=") 399BINARY_OPERATION(XorAssign, "^=") 400BINARY_OPERATION(OrAssign, "|=") 401// [C99 6.5.17] Comma operator. 402BINARY_OPERATION(Comma, ",") 403 404 405//===- Unary Operations ---------------------------------------------------===// 406// Note that additions to this should also update the StmtVisitor class and 407// UnaryOperator::getOverloadedOperator. 408 409// [C99 6.5.2.4] Postfix increment and decrement 410UNARY_OPERATION(PostInc, "++") 411UNARY_OPERATION(PostDec, "--") 412// [C99 6.5.3.1] Prefix increment and decrement 413UNARY_OPERATION(PreInc, "++") 414UNARY_OPERATION(PreDec, "--") 415// [C99 6.5.3.2] Address and indirection 416UNARY_OPERATION(AddrOf, "&") 417UNARY_OPERATION(Deref, "*") 418// [C99 6.5.3.3] Unary arithmetic 419UNARY_OPERATION(Plus, "+") 420UNARY_OPERATION(Minus, "-") 421UNARY_OPERATION(Not, "~") 422UNARY_OPERATION(LNot, "!") 423// "__real expr"/"__imag expr" Extension. 424UNARY_OPERATION(Real, "__real") 425UNARY_OPERATION(Imag, "__imag") 426// __extension__ marker. 427UNARY_OPERATION(Extension, "__extension__") 428// [C++ Coroutines] co_await operator 429UNARY_OPERATION(Coawait, "co_await") 430 431#undef CAST_OPERATION 432#undef BINARY_OPERATION 433#undef UNARY_OPERATION 434