20#include "llvm/ADT/APSInt.h"
61 if (!RT->getDecl()->getDeclName().isEmpty())
64 if (!ET->getDecl()->getDeclName().isEmpty())
80 const auto *UO = dyn_cast<UnaryOperator>(Arg->
IgnoreParens());
84 const auto *CE = dyn_cast<CStyleCastExpr>(UO->getSubExpr());
87 if (CE->getCastKind() != CK_IntegralToPointer &&
88 CE->getCastKind() != CK_NullToPointer)
92 const auto *DR = dyn_cast<DeclRefExpr>(CE->getSubExpr());
97 dyn_cast<EnumConstantDecl>(DR->getDecl());
108 return llvm::is_contained(ET->getDecl()->enumerators(), Enumerator);
113 assert((BuiltinID == BPF::BI__builtin_preserve_field_info ||
114 BuiltinID == BPF::BI__builtin_btf_type_id ||
115 BuiltinID == BPF::BI__builtin_preserve_type_info ||
116 BuiltinID == BPF::BI__builtin_preserve_enum_value) &&
117 "unexpected BPF builtin");
127 if (BuiltinID == BPF::BI__builtin_preserve_field_info)
128 kind = diag::err_preserve_field_info_not_const;
129 else if (BuiltinID == BPF::BI__builtin_btf_type_id)
130 kind = diag::err_btf_type_id_not_const;
131 else if (BuiltinID == BPF::BI__builtin_preserve_type_info)
132 kind = diag::err_preserve_type_info_not_const;
134 kind = diag::err_preserve_enum_value_not_const;
141 bool InvalidArg =
false;
142 bool ReturnUnsignedInt =
true;
143 if (BuiltinID == BPF::BI__builtin_preserve_field_info) {
146 kind = diag::err_preserve_field_info_not_field;
148 }
else if (BuiltinID == BPF::BI__builtin_preserve_type_info) {
151 kind = diag::err_preserve_type_info_invalid;
153 }
else if (BuiltinID == BPF::BI__builtin_preserve_enum_value) {
156 kind = diag::err_preserve_enum_value_invalid;
158 ReturnUnsignedInt =
false;
159 }
else if (BuiltinID == BPF::BI__builtin_btf_type_id) {
160 ReturnUnsignedInt =
false;
168 if (ReturnUnsignedInt)
169 TheCall->
setType(Context.UnsignedIntTy);
171 TheCall->
setType(Context.UnsignedLongTy);
177 for (
auto *
D : RD->
decls()) {
178 if (
D->hasAttr<BPFPreserveAccessIndexAttr>())
181 D->addAttr(BPFPreserveAccessIndexAttr::CreateImplicit(
getASTContext()));
182 if (
auto *Rec = dyn_cast<RecordDecl>(
D))
188 auto *Rec = 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.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
This represents one expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
ParsedAttr - Represents a syntactic attribute.
A (possibly-)qualified type.
Represents a struct/union/class.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
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.
bool checkArgCount(CallExpr *Call, unsigned DesiredArgCount)
Checks that a call expression's argument count is the desired number.
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
The base class of the type hierarchy.
const BuiltinType * getAsPlaceholderType() const
const T * getAs() const
Member-template getAs<specific type>'.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
The JSON file list parser is used to communicate input to InstallAPI.
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)