Skip to content
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

Fix compilation issue for std::vector in some cases #1402

Merged
merged 1 commit into from
Mar 14, 2024
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
2 changes: 2 additions & 0 deletions lib/Frontend/nvqpp/ConvertExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,8 @@ bool QuakeBridgeVisitor::WalkUpFromCXXOperatorCallExpr(
bool QuakeBridgeVisitor::VisitCXXOperatorCallExpr(
clang::CXXOperatorCallExpr *x) {
auto loc = toLocation(x->getSourceRange());

// Helper to replace the operator[] function name with the value, v.
auto replaceTOSValue = [&](Value v) {
[[maybe_unused]] auto funcVal = popValue();
assert(funcVal.getDefiningOp<func::ConstantOp>());
Expand Down
13 changes: 13 additions & 0 deletions lib/Frontend/nvqpp/ConvertStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,19 @@ bool QuakeBridgeVisitor::TraverseIfStmt(clang::IfStmt *x,
// If there is no initialization expression, skip creating an `if` scope.
if (!TraverseStmt(cond))
return false;

// For something like an `operator[]` the TOS value (likely) is a
// pointer to the indexed element in a vector. Since there may not be a cast
// node in the AST to make that a RHS value, we must explicitly check here
// and add the required a load and cast.
if (auto ptrTy = dyn_cast<cc::PointerType>(peekValue().getType())) {
Value v = popValue();
pushValue(builder.create<cc::LoadOp>(loc, v));
if (ptrTy != builder.getI1Type()) {
reportClangError(x, mangler,
"expression in condition not yet supported");
}
}
if (x->getElse())
builder.create<cc::IfOp>(loc, TypeRange{}, popValue(),
stmtBuilder(x->getThen()),
Expand Down
Loading