xref: /freebsd/contrib/llvm-project/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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(UnsafeBufferUsageCtorAttr)
40WARNING_GADGET(DataInvocation)
41WARNING_CONTAINER_GADGET(SpanTwoParamConstructor) // Uses of `std::span(arg0, arg1)`
42FIXABLE_GADGET(ULCArraySubscript)          // `DRE[any]` in an Unspecified Lvalue Context
43FIXABLE_GADGET(DerefSimplePtrArithFixable)
44FIXABLE_GADGET(PointerDereference)
45FIXABLE_GADGET(UPCAddressofArraySubscript) // '&DRE[any]' in an Unspecified Pointer Context
46FIXABLE_GADGET(UPCStandalonePointer)
47FIXABLE_GADGET(UPCPreIncrement)            // '++Ptr' in an Unspecified Pointer Context
48FIXABLE_GADGET(UUCAddAssign)            // 'Ptr += n' in an Unspecified Untyped Context
49FIXABLE_GADGET(PtrToPtrAssignment)
50FIXABLE_GADGET(CArrayToPtrAssignment)
51FIXABLE_GADGET(PointerInit)
52
53#undef FIXABLE_GADGET
54#undef WARNING_GADGET
55#undef WARNING_CONTAINER_GADGET
56#undef GADGET
57