Skip to content

Commit c111ed9

Browse files
Adding comments for the new data member and removing usage of magic numbers
1 parent e38fd30 commit c111ed9

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,10 @@ class SemaOpenMP : public SemaBase {
14911491
/// All `omp assumes` we encountered so far.
14921492
SmallVector<OMPAssumeAttr *, 4> OMPAssumeGlobal;
14931493

1494+
/// Device number specified by the context selector.
14941495
int DeviceNum = -1;
14951496

1497+
/// Device number identifier specified by the context selector.
14961498
StringRef DeviceNumID;
14971499
};
14981500

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ void Parser::parseOMPTraitPropertyKind(OMPTraitProperty &TIProperty,
893893
Name = "number";
894894
TIProperty.Kind = getOpenMPContextTraitPropertyKind(Set, Selector, Name);
895895
ExprResult DeviceNumExprResult = ParseExpression();
896-
if (!DeviceNumExprResult.isInvalid()) {
896+
if (DeviceNumExprResult.isUsable()) {
897897
Expr *DeviceNumExpr = DeviceNumExprResult.get();
898898
Actions.OpenMP().ActOnOpenMPDeviceNum(DeviceNumExpr);
899899
}
@@ -2266,7 +2266,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
22662266
TargetOMPContext OMPCtx(
22672267
ASTCtx, std::move(DiagUnknownTrait),
22682268
/* CurrentFunctionDecl */ nullptr,
2269-
/* ConstructTraits */ ArrayRef<llvm::omp::TraitProperty>(), -1);
2269+
/* ConstructTraits */ ArrayRef<llvm::omp::TraitProperty>(),
2270+
Actions.OpenMP().getOpenMPDeviceNum());
22702271

22712272
if (isVariantApplicableInContext(VMI, OMPCtx, /* DeviceSetOnly */ true)) {
22722273
Actions.OpenMP().ActOnOpenMPBeginDeclareVariant(Loc, TI);
@@ -2818,7 +2819,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
28182819
};
28192820
TargetOMPContext OMPCtx(ASTContext, std::move(DiagUnknownTrait),
28202821
/* CurrentFunctionDecl */ nullptr,
2821-
ArrayRef<llvm::omp::TraitProperty>(), -1);
2822+
ArrayRef<llvm::omp::TraitProperty>(),
2823+
Actions.OpenMP().getOpenMPDeviceNum());
28222824

28232825
// A single match is returned for OpenMP 5.0
28242826
int BestIdx = getBestVariantMatchForContext(VMIs, OMPCtx);

llvm/lib/Frontend/OpenMP/OMPContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace omp;
2727
OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple,
2828
Triple TargetOffloadTriple, int DeviceNum) {
2929
// Add the appropriate target device kind trait based on the target triple
30-
if (!TargetOffloadTriple.getTriple().empty() && DeviceNum > 0) {
30+
if (!TargetOffloadTriple.getTriple().empty() && DeviceNum > -1) {
3131
// If target triple is present, then target device is not a host
3232
ActiveTraits.set(unsigned(TraitProperty::target_device_kind_nohost));
3333
switch (TargetOffloadTriple.getArch()) {

0 commit comments

Comments
 (0)