clang 24.0.0git
SemaBPF.cpp
Go to the documentation of this file.
1//===------ SemaBPF.cpp ---------- BPF target-specific routines -----------===//
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 implements semantic analysis functions specific to BPF.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Sema/SemaBPF.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/Expr.h"
17#include "clang/AST/Type.h"
23#include "clang/Sema/Sema.h"
24#include "llvm/ADT/APSInt.h"
25#include <optional>
26
27namespace clang {
28
30
32 if (Arg->getType()->getAsPlaceholderType())
33 return false;
34
35 // The first argument needs to be a record field access.
36 // If it is an array element access, we delay decision
37 // to BPF backend to check whether the access is a
38 // field access or not.
39 return (Arg->IgnoreParens()->getObjectKind() == OK_BitField ||
42}
43
45 QualType ArgType = Arg->getType();
46 if (ArgType->getAsPlaceholderType())
47 return false;
48
49 // for TYPE_EXISTENCE/TYPE_MATCH/TYPE_SIZEOF reloc type
50 // format:
51 // 1. __builtin_preserve_type_info(*(<type> *)0, flag);
52 // 2. <type> var;
53 // __builtin_preserve_type_info(var, flag);
54 if (!isa<DeclRefExpr>(Arg->IgnoreParens()) &&
56 return false;
57
58 // Typedef type.
59 if (ArgType->getAs<TypedefType>())
60 return true;
61
62 // Record type or Enum type.
63 if (const auto *RT = ArgType->getAsCanonical<TagType>())
64 if (!RT->getDecl()->getDeclName().isEmpty())
65 return true;
66
67 return false;
68}
69
71 QualType ArgType = Arg->getType();
72 if (ArgType->getAsPlaceholderType())
73 return false;
74
75 // for ENUM_VALUE_EXISTENCE/ENUM_VALUE reloc type
76 // format:
77 // __builtin_preserve_enum_value(*(<enum_type> *)<enum_value>,
78 // flag);
79 const auto *UO = dyn_cast<UnaryOperator>(Arg->IgnoreParens());
80 if (!UO)
81 return false;
82
83 const auto *CE = dyn_cast<CStyleCastExpr>(UO->getSubExpr());
84 if (!CE)
85 return false;
86 if (CE->getCastKind() != CK_IntegralToPointer &&
87 CE->getCastKind() != CK_NullToPointer)
88 return false;
89
90 // The integer must be from an EnumConstantDecl.
91 const auto *DR = dyn_cast<DeclRefExpr>(CE->getSubExpr());
92 if (!DR)
93 return false;
94
96 dyn_cast<EnumConstantDecl>(DR->getDecl());
97 if (!Enumerator)
98 return false;
99
100 // The type must be EnumType.
101 const auto *ED = ArgType->getAsEnumDecl();
102 if (!ED)
103 return false;
104
105 // The enum value must be supported.
106 return llvm::is_contained(ED->enumerators(), Enumerator);
107}
108
109// The kind of a C-style cast of the enumerator E to a pointer, as computed by
110// Sema::PrepareScalarCast().
112 const Expr *E) {
114 ? CK_NullToPointer
115 : CK_IntegralToPointer;
116}
117
118// In __builtin_preserve_enum_value(*(<enum_type> *)<enumerator>, flag), the
119// enumerator names itself, not its value, so undo
120// BuildPreserveAIEnumeratorRef() there, as if there were no attribute.
121static void unwrapPreserveEnumValueArg(ASTContext &Context, Expr *Arg) {
122 auto *UO = dyn_cast<UnaryOperator>(Arg->IgnoreParens());
123 if (!UO || UO->getOpcode() != UO_Deref)
124 return;
125 auto *CE = dyn_cast<CStyleCastExpr>(UO->getSubExpr());
126 if (!CE || !SemaBPF::isPreserveAIEnumeratorRef(CE->getSubExpr()))
127 return;
128 auto *DRE = cast<DeclRefExpr>(
129 cast<PseudoObjectExpr>(CE->getSubExpr())->getSyntacticForm());
130 CE->setSubExpr(DRE);
131 CE->setCastKind(getEnumeratorToPointerCastKind(Context, DRE));
132}
133
135 CallExpr *TheCall) {
136 assert((BuiltinID == BPF::BI__builtin_preserve_field_info ||
137 BuiltinID == BPF::BI__builtin_btf_type_id ||
138 BuiltinID == BPF::BI__builtin_preserve_type_info ||
139 BuiltinID == BPF::BI__builtin_preserve_enum_value) &&
140 "unexpected BPF builtin");
141 ASTContext &Context = getASTContext();
142 if (SemaRef.checkArgCount(TheCall, 2))
143 return true;
144
145 // The second argument needs to be a constant int
146 Expr *Arg = TheCall->getArg(1);
147 std::optional<llvm::APSInt> Value = Arg->getIntegerConstantExpr(Context);
149 if (!Value) {
150 if (BuiltinID == BPF::BI__builtin_preserve_field_info)
151 kind = diag::err_preserve_field_info_not_const;
152 else if (BuiltinID == BPF::BI__builtin_btf_type_id)
153 kind = diag::err_btf_type_id_not_const;
154 else if (BuiltinID == BPF::BI__builtin_preserve_type_info)
155 kind = diag::err_preserve_type_info_not_const;
156 else
157 kind = diag::err_preserve_enum_value_not_const;
158 Diag(Arg->getBeginLoc(), kind) << 2 << Arg->getSourceRange();
159 return true;
160 }
161
162 // The first argument
163 Arg = TheCall->getArg(0);
164 bool InvalidArg = false;
165 bool ReturnUnsignedInt = true;
166 if (BuiltinID == BPF::BI__builtin_preserve_field_info) {
167 if (!isValidPreserveFieldInfoArg(Arg)) {
168 InvalidArg = true;
169 kind = diag::err_preserve_field_info_not_field;
170 }
171 } else if (BuiltinID == BPF::BI__builtin_preserve_type_info) {
172 if (!isValidPreserveTypeInfoArg(Arg)) {
173 InvalidArg = true;
174 kind = diag::err_preserve_type_info_invalid;
175 }
176 } else if (BuiltinID == BPF::BI__builtin_preserve_enum_value) {
177 unwrapPreserveEnumValueArg(Context, Arg);
178 if (!isValidPreserveEnumValueArg(Arg)) {
179 InvalidArg = true;
180 kind = diag::err_preserve_enum_value_invalid;
181 }
182 ReturnUnsignedInt = false;
183 } else if (BuiltinID == BPF::BI__builtin_btf_type_id) {
184 ReturnUnsignedInt = false;
185 }
186
187 if (InvalidArg) {
188 Diag(Arg->getBeginLoc(), kind) << 1 << Arg->getSourceRange();
189 return true;
190 }
191
192 if (ReturnUnsignedInt)
193 TheCall->setType(Context.UnsignedIntTy);
194 else
195 TheCall->setType(Context.UnsignedLongTy);
196 return false;
197}
198
200 // Add preserve_access_index attribute to all fields and inner records, but
201 // not inner enums, so that their enumerators stay constants.
202 for (auto *D : RD->decls()) {
203 if (isa<EnumDecl>(D) || D->hasAttr<BPFPreserveAccessIndexAttr>())
204 continue;
205
206 D->addAttr(BPFPreserveAccessIndexAttr::CreateImplicit(getASTContext()));
207 if (auto *Rec = dyn_cast<RecordDecl>(D))
209 }
210}
211
213 if (auto *Rec = dyn_cast<RecordDecl>(D))
215 auto *A =
216 ::new (getASTContext()) BPFPreserveAccessIndexAttr(getASTContext(), AL);
217 if (auto *ED = dyn_cast<EnumDecl>(D);
218 ED && !ED->getDeclName() && !AL.isPragmaClangAttribute())
219 AnonPreserveAIEnums.insert({ED, A});
220 D->addAttr(A);
221}
222
224 for (auto [ED, A] : AnonPreserveAIEnums)
225 if (!ED->getTypedefNameForAnonDecl())
226 Diag(A->getLocation(), diag::warn_preserve_access_index_anon_enum) << A;
227 AnonPreserveAIEnums.clear();
228}
229
230// Return the enum type, or its typedef name, that the enumerator E is relocated
231// against, or a null type if E is not relocated.
233 const DeclRefExpr *E) {
234 const auto *Enumerator = dyn_cast<EnumConstantDecl>(E->getDecl());
235 if (!Enumerator)
236 return QualType();
237
238 // In C, an enumerator usually has type int, not the enum type, so find the
239 // enum from its context. Within the enum's definition, e.g., A in B = A + 1,
240 // the enum is incomplete and A stays a constant.
241 const auto *ED = dyn_cast<EnumDecl>(Enumerator->getDeclContext());
242 if (!ED || !ED->isCompleteDefinition() ||
243 !ED->hasAttr<BPFPreserveAccessIndexAttr>())
244 return QualType();
245
246 // libbpf matches relocations by type name, so an anonymous enum needs a
247 // typedef name. An enum named by -fbpf-no-enum-reloc= is not relocated.
248 const TypedefNameDecl *TD = nullptr;
249 if (!ED->getDeclName()) {
250 TD = ED->getTypedefNameForAnonDecl();
251 if (!TD)
252 return QualType();
253 }
254 StringRef Name = TD ? TD->getName() : ED->getName();
255 if (llvm::is_contained(Context.getLangOpts().BPFNoEnumRelocs, Name))
256 return QualType();
257 return TD ? Context.getTypeDeclType(TD) : Context.getCanonicalTagType(ED);
258}
259
260static bool isInSwitchCaseLabel(Sema &S) {
262 return S.currentEvaluationContext().IsCaseExpr && FSI &&
263 !FSI->SwitchStack.empty();
264}
265
266// Return the enumerator reference E, or, if it is relocated, a pseudo-object
267// whose semantic form is a __builtin_preserve_enum_value() call.
269 if (SemaRef.isUnevaluatedContext())
270 return E;
271
272 ASTContext &Context = getASTContext();
273 QualType EnumTy = getPreserveAIEnumType(Context, E);
274 if (EnumTy.isNull())
275 return E;
276
277 // The value cannot be relocated where a constant is required: in a constant
278 // evaluated context, e.g., an array bound, or outside of a function, e.g., a
279 // global initializer. Warn, and use the enumerator's value. A case label is
280 // an exception, see verifyCaseExpr().
281 if ((SemaRef.isConstantEvaluatedContext() && !isInSwitchCaseLabel(SemaRef)) ||
282 SemaRef.CurContext->getRedeclContext()->isFileContext()) {
283 Diag(E->getExprLoc(),
284 diag::warn_preserve_access_index_enumerator_not_relocated)
285 << E->getDecl() << EnumTy << E->getSourceRange();
286 return E;
287 }
288
289 // Keep it a constant anywhere in an unevaluated operand, e.g., in a block
290 // literal in sizeof. TransformToPotentiallyEvaluated() relocates it when it
291 // rebuilds a variably modified operand.
292 if (llvm::any_of(SemaRef.ExprEvalContexts,
294 return Rec.isUnevaluated();
295 }))
296 return E;
297
298 // Build *(enum_type *)E in the form required by
299 // __builtin_preserve_enum_value().
300 SourceLocation Loc = E->getExprLoc();
301 auto *Ref = DeclRefExpr::Create(Context, E->getQualifierLoc(),
302 SourceLocation(), E->getDecl(),
303 /*RefersToEnclosingVariableOrCapture=*/false,
304 E->getNameInfo(), E->getType(), VK_PRValue);
305 QualType PtrTy = Context.getPointerType(EnumTy);
307 Context, PtrTy, VK_PRValue, getEnumeratorToPointerCastKind(Context, Ref),
308 Ref,
309 /*BasePath=*/nullptr, FPOptionsOverride(),
310 Context.getTrivialTypeSourceInfo(PtrTy, Loc), Loc, Loc);
312 Context, Cast, UO_Deref, EnumTy, VK_LValue, OK_Ordinary, Loc,
313 /*CanOverflow=*/false, FPOptionsOverride());
314
315 // Flag 1 is BPF_ENUMVAL_VALUE.
316 Expr *Flag =
317 IntegerLiteral::Create(Context, llvm::APInt(32, 1), Context.IntTy, Loc);
318 Expr *Args[] = {Deref, Flag};
319 Expr *Conv = SemaRef.BuildBuiltinCallExpr(
320 Loc, BPF::BI__builtin_preserve_enum_value, Args);
321
322 // Cast the unsigned long result to the type of the enumerator, normally int,
323 // so that no type changes, e.g., hash % A stays a 32-bit unsigned remainder.
324 QualType ResultTy = E->getType();
325 if (!Context.hasSameType(Conv->getType(), ResultTy))
327 Context, ResultTy, VK_PRValue, CK_IntegralCast, Conv,
328 /*BasePath=*/nullptr, FPOptionsOverride(),
329 Context.getTrivialTypeSourceInfo(ResultTy, Loc), Loc, Loc);
330
331 // E is the syntactic form, so the AST is printed as written.
332 return PseudoObjectExpr::Create(Context, E, {Conv}, /*resultIndex=*/0);
333}
334
335// Return whether E is an enumerator reference built by
336// BuildPreserveAIEnumeratorRef(), i.e., a pseudo-object for an enumerator whose
337// semantic form is a __builtin_preserve_enum_value() call.
339 const auto *POE = dyn_cast<PseudoObjectExpr>(E);
340 if (!POE)
341 return false;
342 const auto *DRE = dyn_cast<DeclRefExpr>(POE->getSyntacticForm());
343 if (!DRE || !isa<EnumConstantDecl>(DRE->getDecl()))
344 return false;
345 const auto *Call = dyn_cast<CallExpr>(POE->getResultExpr()->IgnoreCasts());
346 return Call &&
347 Call->getBuiltinCallee() == BPF::BI__builtin_preserve_enum_value;
348}
349
350// Return whether S has an enumerator reference built by
351// BuildPreserveAIEnumeratorRef(), e.g., a case value kept relocated by
352// verifyCaseExpr().
354 if (!S)
355 return false;
356 if (const auto *E = dyn_cast<Expr>(S); E && isPreserveAIEnumeratorRef(E))
357 return true;
358 return llvm::any_of(S->children(), hasPreserveAIEnumeratorRef);
359}
360
361// If a relocated enumerator makes E non-constant, return the constant
362// evaluator's note saying so.
363static std::optional<PartialDiagnosticAt>
365 if (!Context.getTargetInfo().getTriple().isBPF() || E->isValueDependent())
366 return std::nullopt;
368 Expr::EvalResult EvalResult;
369 EvalResult.Diag = &Notes;
370 if (E->EvaluateAsRValue(EvalResult, Context, /*InConstantContext=*/true))
371 return std::nullopt;
372 for (PartialDiagnosticAt &Note : Notes)
373 if (Note.second.getDiagID() ==
374 diag::note_constexpr_bpf_preserve_ai_enumerator)
375 return std::move(Note);
376 return std::nullopt;
377}
378
379// After an error that E is not a constant, emit the note if a relocated
380// enumerator is the reason.
382 if (std::optional<PartialDiagnosticAt> Note =
384 Diag(Note->first, Note->second);
385}
386
387static void warnEnumeratorNotRelocated(SemaBPF &S, const DeclRefExpr *DRE) {
388 S.Diag(DRE->getExprLoc(),
389 diag::warn_preserve_access_index_enumerator_not_relocated)
390 << DRE->getDecl() << getPreserveAIEnumType(S.getASTContext(), DRE)
391 << DRE->getSourceRange();
392}
393
394// Replace each relocated enumerator in St with its DeclRefExpr, which has the
395// same type and value kind, and warn that it is not relocated.
397 if (!St)
398 return St;
399 if (auto *E = dyn_cast<Expr>(St);
401 auto *DRE =
402 cast<DeclRefExpr>(cast<PseudoObjectExpr>(E)->getSyntacticForm());
404 return DRE;
405 }
406 for (Stmt *&Child : St->children())
407 Child = keepEnumeratorsConstant(S, Child);
408 return St;
409}
410
411// E must be a constant, e.g., an array designator, so keep its enumerators
412// constants and warn.
416
417// An asm operand E such as "i" must be a constant. If a relocated enumerator
418// makes it non-constant, keep its enumerators constants and warn.
424
425// The initializer of a static or constexpr local variable must be a constant,
426// so keep its enumerators constants and warn.
428 if (!VD->isLocalVarDecl() || (!VD->isStaticLocal() && !VD->isConstexpr()))
429 return Init;
431}
432
433// Replace each relocated enumerator in Slot with its DeclRefExpr, and record it
434// in Replaced to be restored.
435static void
437 SmallVectorImpl<std::pair<Stmt **, Stmt *>> &Replaced) {
438 if (!Slot)
439 return;
440 if (auto *E = dyn_cast<Expr>(Slot);
442 Replaced.push_back({&Slot, Slot});
443 Slot = cast<PseudoObjectExpr>(E)->getSyntacticForm();
444 return;
445 }
446 for (Stmt *&Child : Slot->children())
447 replaceEnumeratorRefs(Child, Replaced);
448}
449
450// Return an explicit __builtin_preserve_enum_value() call in S, not in an
451// operand of sizeof or alignof.
452static const CallExpr *findPreserveEnumValueCall(const Stmt *S) {
454 return nullptr;
455 if (const auto *Call = dyn_cast<CallExpr>(S);
456 Call && Call->getBuiltinCallee() == BPF::BI__builtin_preserve_enum_value)
457 return Call;
458 for (const Stmt *Child : S->children())
459 if (const CallExpr *Call = findPreserveEnumValueCall(Child))
460 return Call;
461 return nullptr;
462}
463
464// Verify that the case label value E is an integer constant expression with the
465// local enumerator values. A relocated enumerator in E is kept, so that
466// "case A:" behaves like "if (cond == A)". Return E in a ConstantExpr with the
467// local value, which is used to check the case values, e.g., for -Wswitch.
470 Stmt *Root = E;
471 replaceEnumeratorRefs(Root, Replaced);
472
473 // Check E with the local enumerator values.
474 auto *ConstE = cast<Expr>(Root);
475 ExprResult ER =
476 SemaRef.VerifyIntegerConstantExpression(ConstE, AllowFoldKind::Allow);
477 if (ER.isInvalid()) {
478 // An explicit __builtin_preserve_enum_value() call is not a constant, but
479 // an enumerator of an enum with the attribute would be relocated here.
480 if (const CallExpr *Call = findPreserveEnumValueCall(ConstE)) {
481 Diag(Call->getBeginLoc(), diag::note_preserve_enum_value_not_const)
482 << Call->getSourceRange();
483 Diag(Call->getBeginLoc(), diag::note_preserve_enum_value_case_attr);
484 }
485 return ER;
486 }
487 if (Replaced.empty())
488 return ER;
489
490 // Evaluate E with the local enumerator values.
492 if (ConstE->isGLValue() ||
493 !ConstE->EvaluateAsRValue(Result, getASTContext(),
494 /*InConstantContext=*/true) ||
495 !Result.Val.isInt()) {
496 // The value is not an integer rvalue, e.g., a compound literal folded as
497 // an extension. Keep the enumerators constants and warn.
498 for (const auto &R : Replaced)
500 return ER;
501 }
502
503 // Restore the relocated enumerators. ActOnFinishSwitchStmt() looks through a
504 // ConstantExpr at the top of a case value to find its unpromoted type, so put
505 // the ConstantExpr in a no-op cast to keep its value, e.g.,
506 // NoOp(ConstantExpr(A)) for "case A:".
507 for (auto [Slot, Ref] : Replaced)
508 *Slot = Ref;
509 ASTContext &Context = getASTContext();
510 Expr *CE = ConstantExpr::Create(Context, E, Result.Val);
511 return ImplicitCastExpr::Create(Context, E->getType(), CK_NoOp, CE,
512 /*BasePath=*/nullptr, VK_PRValue,
514}
515
516} // namespace clang
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
This file declares semantic analysis functions specific to BPF.
Enumerates target-specific builtins in their own namespaces within namespace clang.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
bool isInvalid() const
Definition Ownership.h:167
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition Expr.cpp:2141
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:3012
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3216
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:356
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition DeclBase.h:2403
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1315
DeclarationNameInfo getNameInfo() const
Definition Expr.h:1387
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition Expr.cpp:498
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1408
ValueDecl * getDecl()
Definition Expr.h:1383
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
void addAttr(Attr *A)
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3604
This represents one expression.
Definition Expr.h:114
void setType(QualType t)
Definition Expr.h:147
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:179
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3125
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
Definition Expr.h:876
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:456
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, bool AllowRelaxedEval=false) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
Definition Expr.cpp:4110
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
QualType getType() const
Definition Expr.h:146
Represents difference between two FPOptions values.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2109
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:985
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:303
ParsedAttr - Represents a syntactic attribute.
Definition ParsedAttr.h:119
bool isPragmaClangAttribute() const
True if the attribute is specified using 'pragma clang attribute'.
Definition ParsedAttr.h:363
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5238
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
Represents a struct/union/class.
Definition Decl.h:4506
Expr * checkLocalConstantInitializer(const VarDecl *VD, Expr *Init)
Definition SemaBPF.cpp:427
void notePreserveAIEnumerator(const Expr *E)
Definition SemaBPF.cpp:381
void handlePreserveAIRecord(RecordDecl *RD)
Definition SemaBPF.cpp:199
void DiagnoseAnonymousPreserveAIEnums()
Definition SemaBPF.cpp:223
SemaBPF(Sema &S)
Definition SemaBPF.cpp:29
Expr * keepPreserveAIEnumeratorsConstant(Expr *E)
Definition SemaBPF.cpp:413
static bool isPreserveAIEnumeratorRef(const Expr *E)
Definition SemaBPF.cpp:338
Expr * checkAsmImmediateOperand(Expr *E)
Definition SemaBPF.cpp:419
ExprResult verifyCaseExpr(Expr *E)
Definition SemaBPF.cpp:468
Expr * BuildPreserveAIEnumeratorRef(DeclRefExpr *E)
Definition SemaBPF.cpp:268
void handlePreserveAccessIndexAttr(Decl *D, const ParsedAttr &AL)
Definition SemaBPF.cpp:212
static bool hasPreserveAIEnumeratorRef(const Stmt *S)
Definition SemaBPF.cpp:353
bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall)
Definition SemaBPF.cpp:134
SemaBase(Sema &S)
Definition SemaBase.cpp:7
ASTContext & getASTContext() const
Definition SemaBase.cpp:9
Sema & SemaRef
Definition SemaBase.h:49
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:863
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
Definition Sema.h:7117
sema::FunctionScopeInfo * getCurFunction() const
Definition Sema.h:1367
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:85
child_range children()
Definition Stmt.cpp:304
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
const BuiltinType * getAsPlaceholderType() const
Definition TypeBase.h:9182
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3743
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5201
Represents a variable declaration or definition.
Definition Decl.h:934
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1606
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition Decl.h:1216
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
Definition Decl.h:1276
Retains information about a function, method, or block that is currently being parsed.
Definition ScopeInfo.h:104
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
Definition ScopeInfo.h:214
Defines the clang::TargetInfo interface.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
static bool isValidPreserveFieldInfoArg(Expr *Arg)
Definition SemaBPF.cpp:31
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition Specifiers.h:155
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
Definition Specifiers.h:158
static CastKind getEnumeratorToPointerCastKind(ASTContext &Context, const Expr *E)
Definition SemaBPF.cpp:111
static Stmt * keepEnumeratorsConstant(SemaBPF &S, Stmt *St)
Definition SemaBPF.cpp:396
static void unwrapPreserveEnumValueArg(ASTContext &Context, Expr *Arg)
Definition SemaBPF.cpp:121
@ Result
The result type of a method or function.
Definition TypeBase.h:906
static bool isValidPreserveEnumValueArg(Expr *Arg)
Definition SemaBPF.cpp:70
static const CallExpr * findPreserveEnumValueCall(const Stmt *S)
Definition SemaBPF.cpp:452
static void warnEnumeratorNotRelocated(SemaBPF &S, const DeclRefExpr *DRE)
Definition SemaBPF.cpp:387
static QualType getPreserveAIEnumType(ASTContext &Context, const DeclRefExpr *E)
Definition SemaBPF.cpp:232
static bool isInSwitchCaseLabel(Sema &S)
Definition SemaBPF.cpp:260
CastKind
CastKind - The kind of operation required for a conversion.
static std::optional< PartialDiagnosticAt > getPreserveAIEnumeratorNote(ASTContext &Context, const Expr *E)
Definition SemaBPF.cpp:364
static void replaceEnumeratorRefs(Stmt *&Slot, SmallVectorImpl< std::pair< Stmt **, Stmt * > > &Replaced)
Definition SemaBPF.cpp:436
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:139
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:143
static bool isValidPreserveTypeInfoArg(Expr *Arg)
Definition SemaBPF.cpp:44
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Enumerator
Enumerator value with fixed underlying type.
Definition Sema.h:834
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
EvalResult is a struct with detailed info about an evaluated expression.
Definition Expr.h:667
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
Definition Expr.h:651
Data structure used to record current or nested expression evaluation contexts.
Definition Sema.h:6953
bool IsCaseExpr
Whether evaluating an expression for a switch case label.
Definition Sema.h:7042