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