-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[clang:frontend] Move helper functions to common location for SemaSPIRV #125045
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
Closed
bassiounix
wants to merge
5
commits into
llvm:main
from
bassiounix:user/bassiounix/move-sema-helper-functions-to-common-location
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d938f75
[clang:frontend] Move helper functions in SemaHLSL to common location…
bassiounix 494ddbe
chore(style): update code style according to LLVM coding standard
bassiounix e366271
chore(license): add license to recently created files
bassiounix 951065b
fix(SemaCommon): Separate the concern of `CheckAllArgTypesAreCorrect`…
bassiounix f42034f
fix(Sema): move helper function definitions to Sema class header.
bassiounix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef LLVM_CLANG_SEMA_COMMON_H | ||
#define LLVM_CLANG_SEMA_COMMON_H | ||
|
||
#include "clang/Sema/Sema.h" | ||
|
||
namespace clang { | ||
|
||
using LLVMFnRef = llvm::function_ref<bool(clang::QualType PassedType)>; | ||
using PairParam = std::pair<unsigned int, unsigned int>; | ||
using CheckParam = std::variant<PairParam, LLVMFnRef>; | ||
|
||
bool CheckArgTypeIsCorrect( | ||
Sema *S, Expr *Arg, QualType ExpectedType, | ||
llvm::function_ref<bool(clang::QualType PassedType)> Check); | ||
|
||
bool CheckAllArgTypesAreCorrect( | ||
Sema *SemaPtr, CallExpr *TheCall, | ||
std::variant<QualType, std::nullopt_t> ExpectedType, CheckParam Check); | ||
|
||
} // namespace clang | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "clang/Sema/Common.h" | ||
|
||
namespace clang { | ||
|
||
bool CheckArgTypeIsCorrect( | ||
Sema *S, Expr *Arg, QualType ExpectedType, | ||
llvm::function_ref<bool(clang::QualType PassedType)> Check) { | ||
QualType PassedType = Arg->getType(); | ||
if (Check(PassedType)) { | ||
if (auto *VecTyA = PassedType->getAs<VectorType>()) | ||
ExpectedType = S->Context.getVectorType( | ||
ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind()); | ||
S->Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible) | ||
<< PassedType << ExpectedType << 1 << 0 << 0; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool CheckAllArgTypesAreCorrect( | ||
Sema *SemaPtr, CallExpr *TheCall, | ||
std::variant<QualType, std::nullopt_t> ExpectedType, CheckParam Check) { | ||
unsigned int NumElts; | ||
unsigned int expected; | ||
if (auto *n = std::get_if<PairParam>(&Check)) { | ||
if (SemaPtr->checkArgCount(TheCall, n->first)) { | ||
return true; | ||
} | ||
NumElts = n->first; | ||
expected = n->second; | ||
} else { | ||
NumElts = TheCall->getNumArgs(); | ||
} | ||
|
||
for (unsigned i = 0; i < NumElts; i++) { | ||
Expr *localArg = TheCall->getArg(i); | ||
if (auto *val = std::get_if<QualType>(&ExpectedType)) { | ||
if (auto *fn = std::get_if<LLVMFnRef>(&Check)) { | ||
return CheckArgTypeIsCorrect(SemaPtr, localArg, *val, *fn); | ||
} | ||
} | ||
|
||
QualType PassedType = localArg->getType(); | ||
if (PassedType->getAs<VectorType>() == nullptr) { | ||
SemaPtr->Diag(localArg->getBeginLoc(), | ||
diag::err_typecheck_convert_incompatible) | ||
<< PassedType | ||
<< SemaPtr->Context.getVectorType(PassedType, expected, | ||
VectorKind::Generic) | ||
<< 1 << 0 << 0; | ||
return true; | ||
} | ||
} | ||
|
||
if (std::get_if<PairParam>(&Check)) { | ||
if (auto *localArgVecTy = | ||
TheCall->getArg(0)->getType()->getAs<VectorType>()) { | ||
TheCall->setType(localArgVecTy->getElementType()); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace clang |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
For example clang::CheckArgTypeIsCorrect instead of opening the clang namespace and just having CheckArgTypeIsCorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed