-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL][Sema] Fixed Diagnostics that assumed only two arguments #122772
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
Conversation
@llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Farzon Lotfi (farzonl) ChangesIn the below code B varies over the arg list via a loop. However, the diagnostics do not vary with the loop. Full diff: https://github.com/llvm/llvm-project/pull/122772.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 65ddee05a21512..169a6a6903891c 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1688,8 +1688,9 @@ static bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
auto *VecTyA = ArgTyA->getAs<VectorType>();
SourceLocation BuiltinLoc = TheCall->getBeginLoc();
+ ExprResult B;
for (unsigned i = 1; i < TheCall->getNumArgs(); ++i) {
- ExprResult B = TheCall->getArg(i);
+ B = TheCall->getArg(i);
QualType ArgTyB = B.get()->getType();
auto *VecTyB = ArgTyB->getAs<VectorType>();
if (VecTyA == nullptr && VecTyB == nullptr)
@@ -1712,8 +1713,7 @@ static bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
// HLSLVectorTruncation.
S->Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector)
<< TheCall->getDirectCallee() << /*useAllTerminology*/ true
- << SourceRange(TheCall->getArg(0)->getBeginLoc(),
- TheCall->getArg(1)->getEndLoc());
+ << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc());
retValue = true;
}
return retValue;
@@ -1724,8 +1724,7 @@ static bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
// requires a VectorSplat on Arg0 or Arg1
S->Diag(BuiltinLoc, diag::err_vec_builtin_non_vector)
<< TheCall->getDirectCallee() << /*useAllTerminology*/ true
- << SourceRange(TheCall->getArg(0)->getBeginLoc(),
- TheCall->getArg(1)->getEndLoc());
+ << SourceRange(A.get()->getBeginLoc(), B.get()->getEndLoc());
return true;
}
|
This is clearly a bug, and the fix looks right, but the absence of a test case seems wrong because this isn't an NFC change... it actually fixes a bug. |
We have two builtins that have greater than 2 args clamp and lerp. so should be able to write a test case for this. |
9df164c
to
5ca3dc1
Compare
In the below code B varies over the arg list via a loop. However, the diagnostics do not vary with the loop.
Fix so that diagnostics can vary with B.