Skip to content

[clang] Improve diagnostics for vector builtins #125673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12519,16 +12519,13 @@ def err_builtin_is_within_lifetime_invalid_arg : Error<
"%select{non-|function }0pointer argument to '__builtin_is_within_lifetime' "
"is not allowed">;

def err_builtin_invalid_arg_type: Error <
"%ordinal0 argument must be "
"%select{a vector, integer or floating point type|a matrix|"
"a pointer to a valid matrix element type|"
"a signed integer or floating point type|a vector type|"
"a floating point type|"
"a vector of integers|"
"an unsigned integer|"
"an 'int'|"
"a vector of floating points}1 (was %2)">;
def err_builtin_invalid_arg_type: Error<
"%ordinal0 argument must be a"
"%select{| scalar| vector| matrix| vector,| vector of| scalar or vector of}1"
"%select{| integer| signed integer| unsigned integer| 'int'|"
" pointer to a valid matrix element}2"
"%plural{0:|:%plural{0:|: or}2}3"
"%select{| floating-point}3 %plural{[0,4]:type|:types}1 (was %4)">;

def err_builtin_matrix_disabled: Error<
"matrix types extension is disabled. Pass -fenable-matrix to enable it">;
Expand Down
27 changes: 21 additions & 6 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2353,9 +2353,18 @@ class Sema final : public SemaBase {
bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
const FunctionProtoType *Proto);

enum class EltwiseBuiltinArgTyRestriction {
None,
FloatTy,
IntegerTy,
SignedIntOrFloatTy,
};

/// \param FPOnly restricts the arguments to floating-point types.
std::optional<QualType> BuiltinVectorMath(CallExpr *TheCall,
bool FPOnly = false);
std::optional<QualType>
BuiltinVectorMath(CallExpr *TheCall,
EltwiseBuiltinArgTyRestriction ArgTyRestr =
EltwiseBuiltinArgTyRestriction::None);
bool BuiltinVectorToScalarMath(CallExpr *TheCall);

void checkLifetimeCaptureBy(FunctionDecl *FDecl, bool IsMemberFunction,
Expand Down Expand Up @@ -2459,9 +2468,13 @@ class Sema final : public SemaBase {
bool *ICContext = nullptr,
bool IsListInit = false);

bool BuiltinElementwiseTernaryMath(CallExpr *TheCall,
bool CheckForFloatArgs = true);
bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
bool
BuiltinElementwiseTernaryMath(CallExpr *TheCall,
EltwiseBuiltinArgTyRestriction ArgTyRestr =
EltwiseBuiltinArgTyRestriction::FloatTy);
bool PrepareBuiltinElementwiseMathOneArgCall(
CallExpr *TheCall, EltwiseBuiltinArgTyRestriction ArgTyRestr =
EltwiseBuiltinArgTyRestriction::None);

private:
void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
Expand Down Expand Up @@ -2570,7 +2583,9 @@ class Sema final : public SemaBase {
AtomicExpr::AtomicOp Op);

/// \param FPOnly restricts the arguments to floating-point types.
bool BuiltinElementwiseMath(CallExpr *TheCall, bool FPOnly = false);
bool BuiltinElementwiseMath(CallExpr *TheCall,
EltwiseBuiltinArgTyRestriction ArgTyRestr =
EltwiseBuiltinArgTyRestriction::None);
bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);

bool BuiltinNonDeterministicValue(CallExpr *TheCall);
Expand Down
Loading
Loading