Skip to content

Commit 0d92781

Browse files
committed
Address review comments
1 parent 291dc48 commit 0d92781

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

llvm/lib/Frontend/OpenMP/OMP.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ using namespace llvm::omp;
2727

2828
namespace llvm::omp {
2929
ArrayRef<Directive> getLeafConstructs(Directive D) {
30-
auto Idx = static_cast<int>(D);
31-
if (Idx < 0 || Idx >= static_cast<int>(Directive_enumSize))
30+
auto Idx = static_cast<std::size_t>(D);
31+
if (Idx >= Directive_enumSize)
3232
return {};
3333
const auto *Row = LeafConstructTable[LeafConstructTableOrdering[Idx]];
3434
return ArrayRef(&Row[2], &Row[2] + static_cast<int>(Row[1]));
@@ -50,6 +50,12 @@ Directive getCompoundConstruct(ArrayRef<Directive> Parts) {
5050
RawLeafs.push_back(P);
5151
}
5252

53+
// RawLeafs will be used as key in the binary search. The search doesn't
54+
// guarantee that the exact same entry will be found (since RawLeafs may
55+
// not correspond to any compound directive). Because of that, we will
56+
// need to compare the search result with the given set of leafs.
57+
// Also, if there is only one leaf in the list, it corresponds to itself,
58+
// no search is necessary.
5359
auto GivenLeafs{ArrayRef<Directive>(RawLeafs).drop_front(2)};
5460
if (GivenLeafs.size() == 1)
5561
return GivenLeafs.front();

llvm/unittests/Frontend/OpenMPComposeTest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ TEST(Composition, GetCompoundConstruct) {
3232
ASSERT_EQ(C3, OMPD_unknown);
3333
Directive C4 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute});
3434
ASSERT_EQ(C4, OMPD_target_teams_distribute);
35-
Directive C5 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute});
36-
ASSERT_EQ(C5, OMPD_target_teams_distribute);
37-
Directive C6 = getCompoundConstruct({});
38-
ASSERT_EQ(C6, OMPD_unknown);
39-
Directive C7 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd});
40-
ASSERT_EQ(C7, OMPD_parallel_for_simd);
35+
Directive C5 = getCompoundConstruct({});
36+
ASSERT_EQ(C5, OMPD_unknown);
37+
Directive C6 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd});
38+
ASSERT_EQ(C6, OMPD_parallel_for_simd);
4139
}

0 commit comments

Comments
 (0)