20#include "llvm/ADT/APSInt.h"
42 if (ArgType->getAsPlaceholderType())
59 if (
const auto *RT = ArgType->getAsCanonical<TagType>())
60 if (!RT->getOriginalDecl()->getDeclName().isEmpty())
68 if (ArgType->getAsPlaceholderType())
75 const auto *UO = dyn_cast<UnaryOperator>(Arg->
IgnoreParens());
79 const auto *CE = dyn_cast<CStyleCastExpr>(UO->getSubExpr());
82 if (CE->getCastKind() != CK_IntegralToPointer &&
83 CE->getCastKind() != CK_NullToPointer)
87 const auto *DR = dyn_cast<DeclRefExpr>(CE->getSubExpr());
92 dyn_cast<EnumConstantDecl>(DR->getDecl());
97 const auto *ED = ArgType->getAsEnumDecl();
102 return llvm::is_contained(ED->enumerators(),
Enumerator);
107 assert((BuiltinID == BPF::BI__builtin_preserve_field_info ||
108 BuiltinID == BPF::BI__builtin_btf_type_id ||
109 BuiltinID == BPF::BI__builtin_preserve_type_info ||
110 BuiltinID == BPF::BI__builtin_preserve_enum_value) &&
111 "unexpected BPF builtin");
113 if (
SemaRef.checkArgCount(TheCall, 2))
121 if (BuiltinID == BPF::BI__builtin_preserve_field_info)
122 kind = diag::err_preserve_field_info_not_const;
123 else if (BuiltinID == BPF::BI__builtin_btf_type_id)
124 kind = diag::err_btf_type_id_not_const;
125 else if (BuiltinID == BPF::BI__builtin_preserve_type_info)
126 kind = diag::err_preserve_type_info_not_const;
128 kind = diag::err_preserve_enum_value_not_const;
135 bool InvalidArg =
false;
136 bool ReturnUnsignedInt =
true;
137 if (BuiltinID == BPF::BI__builtin_preserve_field_info) {
140 kind = diag::err_preserve_field_info_not_field;
142 }
else if (BuiltinID == BPF::BI__builtin_preserve_type_info) {
145 kind = diag::err_preserve_type_info_invalid;
147 }
else if (BuiltinID == BPF::BI__builtin_preserve_enum_value) {
150 kind = diag::err_preserve_enum_value_invalid;
152 ReturnUnsignedInt =
false;
153 }
else if (BuiltinID == BPF::BI__builtin_btf_type_id) {
154 ReturnUnsignedInt =
false;
162 if (ReturnUnsignedInt)
163 TheCall->
setType(Context.UnsignedIntTy);
165 TheCall->
setType(Context.UnsignedLongTy);
171 for (
auto *D : RD->
decls()) {
172 if (D->hasAttr<BPFPreserveAccessIndexAttr>())
175 D->addAttr(BPFPreserveAccessIndexAttr::CreateImplicit(
getASTContext()));
176 if (
auto *Rec = dyn_cast<RecordDecl>(D))
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 ...
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
An instance of this object exists for each enum constant that is defined.
This represents one expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
ParsedAttr - Represents a syntactic attribute.
A (possibly-)qualified type.
Represents a struct/union/class.
void handlePreserveAIRecord(RecordDecl *RD)
void handlePreserveAccessIndexAttr(Decl *D, const ParsedAttr &AL)
bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
ASTContext & getASTContext() const
Sema - This implements semantic analysis and AST building for C.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
const BuiltinType * getAsPlaceholderType() const
unsigned kind
All of the diagnostics that can be emitted by the frontend.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
static bool isValidPreserveFieldInfoArg(Expr *Arg)
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
static bool isValidPreserveEnumValueArg(Expr *Arg)
static bool isValidPreserveTypeInfoArg(Expr *Arg)
U cast(CodeGen::Address addr)
@ Enumerator
Enumerator value with fixed underlying type.