Skip to content

Commit

Permalink
[clang][NFC] Move more things out of SemaChecking.cpp (#96641)
Browse files Browse the repository at this point in the history
This patch moves some functions out of `SemaChecking.cpp`. ObjC-, HLSL-,
OpenCL-related functions are affected.

This patch continues the effort of splitting `Sema` into parts.
Additional context can be found in
#84184 and
#92682.
  • Loading branch information
Endilll authored Jun 27, 2024
1 parent 34e34a0 commit f1c54d7
Show file tree
Hide file tree
Showing 9 changed files with 1,118 additions and 1,101 deletions.
15 changes: 8 additions & 7 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2114,8 +2114,6 @@ class Sema final : public SemaBase {

bool FormatStringHasSArg(const StringLiteral *FExpr);

static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx);

void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
BinaryOperatorKind Opcode);

Expand Down Expand Up @@ -2228,8 +2226,6 @@ class Sema final : public SemaBase {
bool BuiltinVectorMath(CallExpr *TheCall, QualType &Res);
bool BuiltinVectorToScalarMath(CallExpr *TheCall);

bool CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);

void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
const Expr *ThisArg, ArrayRef<const Expr *> Args,
bool IsMemberFunction, SourceLocation Loc, SourceRange Range,
Expand Down Expand Up @@ -2259,6 +2255,14 @@ class Sema final : public SemaBase {

bool ValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum);

void CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
bool *ICContext = nullptr,
bool IsListInit = false);

bool BuiltinElementwiseTernaryMath(CallExpr *TheCall,
bool CheckForFloatArgs = true);
bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);

private:
void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
const ArraySubscriptExpr *ASE = nullptr,
Expand Down Expand Up @@ -2306,9 +2310,6 @@ class Sema final : public SemaBase {
AtomicExpr::AtomicOp Op);

bool BuiltinElementwiseMath(CallExpr *TheCall);
bool BuiltinElementwiseTernaryMath(CallExpr *TheCall,
bool CheckForFloatArgs = true);
bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);

bool BuiltinNonDeterministicValue(CallExpr *TheCall);
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Sema/SemaHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class SemaHLSL : public SemaBase {
void handleShaderAttr(Decl *D, const ParsedAttr &AL);
void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL);
void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);

bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
};

} // namespace clang
Expand Down
21 changes: 21 additions & 0 deletions clang/include/clang/Sema/SemaObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,27 @@ class SemaObjC : public SemaBase {

IdentifierInfo *getNSErrorIdent();

bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx);

/// Diagnose use of %s directive in an NSString which is being passed
/// as formatting string to formatting method.
void DiagnoseCStringFormatDirectiveInCFAPI(const NamedDecl *FDecl,
Expr **Args, unsigned NumArgs);

bool isSignedCharBool(QualType Ty);

void adornBoolConversionDiagWithTernaryFixit(
Expr *SourceExpr, const Sema::SemaDiagnosticBuilder &Builder);

/// Check an Objective-C dictionary literal being converted to the given
/// target type.
void checkDictionaryLiteral(QualType TargetType,
ObjCDictionaryLiteral *DictionaryLiteral);

/// Check an Objective-C array literal being converted to the given
/// target type.
void checkArrayLiteral(QualType TargetType, ObjCArrayLiteral *ArrayLiteral);

private:
IdentifierInfo *Ident_NSError = nullptr;

Expand Down
72 changes: 72 additions & 0 deletions clang/include/clang/Sema/SemaOpenCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,78 @@ class SemaOpenCL : public SemaBase {

// Handles intel_reqd_sub_group_size.
void handleSubGroupSize(Decl *D, const ParsedAttr &AL);

// Performs semantic analysis for the read/write_pipe call.
// \param S Reference to the semantic analyzer.
// \param Call A pointer to the builtin call.
// \return True if a semantic error has been found, false otherwise.
bool checkBuiltinRWPipe(CallExpr *Call);

// Performs a semantic analysis on the {work_group_/sub_group_
// /_}reserve_{read/write}_pipe
// \param S Reference to the semantic analyzer.
// \param Call The call to the builtin function to be analyzed.
// \return True if a semantic error was found, false otherwise.
bool checkBuiltinReserveRWPipe(CallExpr *Call);

bool checkSubgroupExt(CallExpr *Call);

// Performs a semantic analysis on {work_group_/sub_group_
// /_}commit_{read/write}_pipe
// \param S Reference to the semantic analyzer.
// \param Call The call to the builtin function to be analyzed.
// \return True if a semantic error was found, false otherwise.
bool checkBuiltinCommitRWPipe(CallExpr *Call);

// Performs a semantic analysis on the call to built-in Pipe
// Query Functions.
// \param S Reference to the semantic analyzer.
// \param Call The call to the builtin function to be analyzed.
// \return True if a semantic error was found, false otherwise.
bool checkBuiltinPipePackets(CallExpr *Call);

// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
// Performs semantic analysis for the to_global/local/private call.
// \param S Reference to the semantic analyzer.
// \param BuiltinID ID of the builtin function.
// \param Call A pointer to the builtin call.
// \return True if a semantic error has been found, false otherwise.
bool checkBuiltinToAddr(unsigned BuiltinID, CallExpr *Call);

/// OpenCL C v2.0, s6.13.17 - Enqueue kernel function contains four different
/// overload formats specified in Table 6.13.17.1.
/// int enqueue_kernel(queue_t queue,
/// kernel_enqueue_flags_t flags,
/// const ndrange_t ndrange,
/// void (^block)(void))
/// int enqueue_kernel(queue_t queue,
/// kernel_enqueue_flags_t flags,
/// const ndrange_t ndrange,
/// uint num_events_in_wait_list,
/// clk_event_t *event_wait_list,
/// clk_event_t *event_ret,
/// void (^block)(void))
/// int enqueue_kernel(queue_t queue,
/// kernel_enqueue_flags_t flags,
/// const ndrange_t ndrange,
/// void (^block)(local void*, ...),
/// uint size0, ...)
/// int enqueue_kernel(queue_t queue,
/// kernel_enqueue_flags_t flags,
/// const ndrange_t ndrange,
/// uint num_events_in_wait_list,
/// clk_event_t *event_wait_list,
/// clk_event_t *event_ret,
/// void (^block)(local void*, ...),
/// uint size0, ...)
bool checkBuiltinEnqueueKernel(CallExpr *TheCall);

/// OpenCL C v2.0, s6.13.17.6 - Check the argument to the
/// get_kernel_work_group_size
/// and get_kernel_preferred_work_group_size_multiple builtin functions.
bool checkBuiltinKernelWorkGroupSize(CallExpr *TheCall);

bool checkBuiltinNDRangeAndBlock(CallExpr *TheCall);
};

} // namespace clang
Expand Down
Loading

0 comments on commit f1c54d7

Please sign in to comment.