Skip to content

Commit

Permalink
Fix parsing errors in nomp_init()
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb committed Sep 20, 2023
1 parent 96af364 commit 07c4368
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions clang/lib/Parse/ParseNomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,43 @@ void Parser::ParseNompExprListUntilRParen(llvm::SmallVector<Expr *, 16> &EL,
NompHandleError(diag::err_nomp_rparen_expected, Tok, *this, Pragma);
}

static Expr *ExprToICE(Expr *E, const ASTContext &AST, QualType QT,
CastKind CK) {
static Expr *ExprToArgc(Expr *E, ASTContext &AST, QualType QT, CastKind CK) {
if (IntegerLiteral *IL = dyn_cast_or_null<IntegerLiteral>(E)) {
// FIXME: If it is a Literal, use as is. Need to add checks for
// StringLiteral, FloatLiteral, etc.
return IL;
} else {
// If it is a Expr, do an ICE.
return ImplicitCastExpr::Create(AST, QT, CK, E, nullptr, VK_PRValue,
} else if (DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(E)) {
// If it is a DRE, check if it points to an integer type.
const Type *T = DRE->getType().getTypePtrOrNull();
if (T && T->isIntegerType()) {
return ImplicitCastExpr::Create(AST, QT, CK, DRE, nullptr, VK_PRValue,
FPOptionsOverride());
}
}

NompHandleError(diag::err_nomp_function_arg_invalid, E->getExprLoc(), AST,
"argc");
return nullptr;
}

static Expr *ExprToArgv(Expr *E, ASTContext &AST, QualType QT, CastKind CK) {
if (DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(E)) {
// If it is a DRE, check if it points to an integer type.
const Type *T = DRE->getType().getTypePtrOrNull();
if (T && T->isArrayType()) {
ImplicitCastExpr *ICE = ImplicitCastExpr::Create(
AST, QT, CastKind::CK_ArrayToPointerDecay, DRE, nullptr,
ExprValueKind::VK_PRValue, FPOptionsOverride());
return ImplicitCastExpr::Create(AST, QT, CK, ICE, nullptr,
ExprValueKind::VK_PRValue,
FPOptionsOverride());
}
return ImplicitCastExpr::Create(AST, QT, CK, DRE, nullptr,
ExprValueKind::VK_PRValue,
FPOptionsOverride());
}

NompHandleError(diag::err_nomp_function_arg_invalid, E->getExprLoc(), AST,
"argv");
return nullptr;
}

//==============================================================================
Expand Down Expand Up @@ -280,9 +306,9 @@ StmtResult Parser::ParseNompInit(const SourceLocation &SL) {
llvm::SmallVector<Expr *, 2> FuncArgs;
Expr *Argv = InitArgs.pop_back_val(), *Argc = InitArgs.pop_back_val();
FuncArgs.push_back(
ExprToICE(Argc, AST, getIntType(AST), CastKind::CK_LValueToRValue));
ExprToArgc(Argc, AST, getIntType(AST), CastKind::CK_LValueToRValue));
FuncArgs.push_back(
ExprToICE(Argv, AST, getIntType(AST), CastKind::CK_LValueToRValue));
ExprToArgv(Argv, AST, getIntType(AST), CastKind::CK_LValueToRValue));

ConsumeAnnotationToken(); // tok::annot_pragma_nomp_end

Expand Down

0 comments on commit 07c4368

Please sign in to comment.