1//=- UnsafeBufferUsageGadgets.def - List of ways to use a buffer --*- 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/// A gadget is an individual operation in the code that may be of interest to
10/// the UnsafeBufferUsage analysis.
11#ifndef GADGET
12#define GADGET(name)
13#endif
14
15/// Unsafe gadgets correspond to unsafe code patterns that warrant
16/// an immediate warning.
17#ifndef WARNING_GADGET
18#define WARNING_GADGET(name) GADGET(name)
19#endif
20
21/// A `WARNING_GADGET` subset, where the code pattern of each gadget
22/// corresponds uses of a (possibly hardened) contatiner (e.g., `std::span`).
23#ifndef WARNING_CONTAINER_GADGET
24#define WARNING_CONTAINER_GADGET(name) WARNING_GADGET(name)
25#endif
26
27/// Safe gadgets correspond to code patterns that aren't unsafe but need to be
28/// properly recognized in order to emit correct warnings and fixes over unsafe
29/// gadgets.
30#ifndef FIXABLE_GADGET
31#define FIXABLE_GADGET(name) GADGET(name)
32#endif
33
34WARNING_GADGET(Increment)
35WARNING_GADGET(Decrement)
36WARNING_GADGET(ArraySubscript)
37WARNING_GADGET(PointerArithmetic)
38WARNING_GADGET(UnsafeBufferUsageAttr)
39WARNING_GADGET(DataInvocation)
40WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, arg1)`
41FIXABLE_GADGET(ULCArraySubscript) // `DRE[any]` in an Unspecified Lvalue Context
42FIXABLE_GADGET(DerefSimplePtrArithFixable)
43FIXABLE_GADGET(PointerDereference)
44FIXABLE_GADGET(UPCAddressofArraySubscript) // '&DRE[any]' in an Unspecified Pointer Context
45FIXABLE_GADGET(UPCStandalonePointer)
46FIXABLE_GADGET(UPCPreIncrement) // '++Ptr' in an Unspecified Pointer Context
47FIXABLE_GADGET(UUCAddAssign) // 'Ptr += n' in an Unspecified Untyped Context
48FIXABLE_GADGET(PtrToPtrAssignment)
49FIXABLE_GADGET(CArrayToPtrAssignment)
50FIXABLE_GADGET(PointerInit)
51
52#undef FIXABLE_GADGET
53#undef WARNING_GADGET
54#undef WARNING_CONTAINER_GADGET
55#undef GADGET
56

source code of clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def