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 all 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
35 changes: 25 additions & 10 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12519,16 +12519,31 @@ 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)">;
// A multi-component builtin type diagnostic. The first component broadly
// selects a scalar or container type (scalar, vector or matrix). The second
// component selects integer types and the third component selects
// floating-point types. Any component can be left empty.
def err_builtin_invalid_arg_type: Error<
"%ordinal0 argument must be a "
// First component: scalar or container types
"%select{|scalar|vector|matrix|vector of|scalar or vector of}1"
// A comma after generic vector/matrix types if there are non-empty second
// and third components, to initiate a list.
"%plural{[2,3]:%plural{0:|:%plural{0:|:,}2}3|:}1"
// A space after a non-empty first component
"%plural{0:|: }1"
// Second component: integer-like types
"%select{|integer|signed integer|unsigned integer|'int'|"
"pointer to a valid matrix element}2"
// A space after a non-empty second component
"%plural{0:|: }2"
// An 'or' if non-empty second and third components are combined
"%plural{0:|:%plural{0:|:or }2}3"
// Third component: floating-point types
"%select{|floating-point}3"
// A space after a non-empty third component
"%plural{0:|: }3"
"%plural{[0,3]: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