Skip to content

Commit 283b28b

Browse files
authored
merge main into amd-staging (#755)
2 parents 44a46f2 + dddaefb commit 283b28b

File tree

60 files changed

+19565
-22050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+19565
-22050
lines changed

.github/workflows/issue-write.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,4 @@ jobs:
162162
if: >-
163163
always() &&
164164
steps.download-artifact.outputs.artifact-ids != ''
165-
run: cat comments
165+
run: cat comments*

clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "RedundantCastingCheck.h"
1010
#include "../utils/FixItHintUtils.h"
1111
#include "clang/AST/ASTContext.h"
12+
#include "clang/AST/TypeBase.h"
1213
#include "clang/ASTMatchers/ASTMatchFinder.h"
1314
#include "clang/Lex/Lexer.h"
1415

@@ -29,7 +30,7 @@ static bool areTypesEqual(QualType S, QualType D) {
2930
const QualType PtrD = D->getPointeeType();
3031

3132
if (!PtrS.isNull() && !PtrD.isNull())
32-
return areTypesEqual(PtrS, PtrD);
33+
return areTypesEqual(PtrS.IgnoreParens(), PtrD.IgnoreParens());
3334

3435
const DeducedType *DT = S->getContainedDeducedType();
3536
if (DT && DT->isDeduced())

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ Changes in existing checks
567567
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
568568
`IgnoreAliasing`, that allows not looking at underlying types of type aliases.
569569

570+
- Improved :doc:`readability-redundant-casting
571+
<clang-tidy/checks/readability/redundant-casting>` check by fixing false
572+
negatives when explicitly cast from function pointer.
573+
570574
- Improved :doc:`readability-uppercase-literal-suffix
571575
<clang-tidy/checks/readability/uppercase-literal-suffix>` check to recognize
572576
literal suffixes added in C++23 and C23.

clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,13 @@ void testRedundantDependentNTTPCasting() {
235235
// CHECK-MESSAGES: :[[@LINE-4]]:25: note: source type originates from referencing this non-type template parameter
236236
// CHECK-FIXES: T a = V;
237237
}
238+
239+
namespace gh170476 {
240+
int f(void);
241+
int g1() {
242+
int (*fp)() = (int(*)(void))&f;
243+
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant explicit casting to the same type 'int (*)()' as the sub-expression, remove this casting [readability-redundant-casting]
244+
// CHECK-FIXES: int (*fp)() = (&f);
245+
return fp();
246+
}
247+
} // namespace gh170476

flang-rt/test/Driver/exec.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
! REQUIRES: flang-rt
21
! UNSUPPORTED: offload-cuda
32

43
! Verify that flang can correctly build executables.

flang/include/flang/Parser/openmp-utils.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define FORTRAN_PARSER_OPENMP_UTILS_H
1515

1616
#include "flang/Common/indirection.h"
17+
#include "flang/Common/template.h"
1718
#include "flang/Parser/parse-tree.h"
1819
#include "llvm/Frontend/OpenMP/OMP.h"
1920

@@ -127,7 +128,88 @@ template <typename T> struct IsStatement<Statement<T>> {
127128
std::optional<Label> GetStatementLabel(const ExecutionPartConstruct &x);
128129
std::optional<Label> GetFinalLabel(const OpenMPConstruct &x);
129130

131+
namespace detail {
132+
// Clauses with flangClass = "OmpObjectList".
133+
using MemberObjectListClauses =
134+
std::tuple<OmpClause::Copyin, OmpClause::Copyprivate, OmpClause::Exclusive,
135+
OmpClause::Firstprivate, OmpClause::HasDeviceAddr, OmpClause::Inclusive,
136+
OmpClause::IsDevicePtr, OmpClause::Link, OmpClause::Private,
137+
OmpClause::Shared, OmpClause::UseDeviceAddr, OmpClause::UseDevicePtr>;
138+
139+
// Clauses with flangClass = "OmpSomeClause", and OmpObjectList a
140+
// member of tuple OmpSomeClause::t.
141+
using TupleObjectListClauses = std::tuple<OmpClause::AdjustArgs,
142+
OmpClause::Affinity, OmpClause::Aligned, OmpClause::Allocate,
143+
OmpClause::Enter, OmpClause::From, OmpClause::InReduction,
144+
OmpClause::Lastprivate, OmpClause::Linear, OmpClause::Map,
145+
OmpClause::Reduction, OmpClause::TaskReduction, OmpClause::To>;
146+
147+
// Does U have WrapperTrait (i.e. has a member 'v'), and if so, is T the
148+
// type of v?
149+
template <typename T, typename U, bool IsWrapper> struct WrappedInType {
150+
static constexpr bool value{false};
151+
};
152+
153+
template <typename T, typename U> struct WrappedInType<T, U, true> {
154+
static constexpr bool value{std::is_same_v<T, decltype(U::v)>};
155+
};
156+
157+
// Same as WrappedInType, but with a list of types Us. Satisfied if any
158+
// type U in Us satisfies WrappedInType<T, U>.
159+
template <typename...> struct WrappedInTypes;
160+
161+
template <typename T> struct WrappedInTypes<T> {
162+
static constexpr bool value{false};
163+
};
164+
165+
template <typename T, typename U, typename... Us>
166+
struct WrappedInTypes<T, U, Us...> {
167+
static constexpr bool value{WrappedInType<T, U, WrapperTrait<U>>::value ||
168+
WrappedInTypes<T, Us...>::value};
169+
};
170+
171+
// Same as WrappedInTypes, but takes type list in a form of a tuple or
172+
// a variant.
173+
template <typename...> struct WrappedInTupleOrVariant {
174+
static constexpr bool value{false};
175+
};
176+
template <typename T, typename... Us>
177+
struct WrappedInTupleOrVariant<T, std::tuple<Us...>> {
178+
static constexpr bool value{WrappedInTypes<T, Us...>::value};
179+
};
180+
template <typename T, typename... Us>
181+
struct WrappedInTupleOrVariant<T, std::variant<Us...>> {
182+
static constexpr bool value{WrappedInTypes<T, Us...>::value};
183+
};
184+
template <typename T, typename U>
185+
constexpr bool WrappedInTupleOrVariantV{WrappedInTupleOrVariant<T, U>::value};
186+
} // namespace detail
187+
188+
template <typename T> const OmpObjectList *GetOmpObjectList(const T &clause) {
189+
using namespace detail;
190+
static_assert(std::is_class_v<T>, "Unexpected argument type");
191+
192+
if constexpr (common::HasMember<T, decltype(OmpClause::u)>) {
193+
if constexpr (common::HasMember<T, MemberObjectListClauses>) {
194+
return &clause.v;
195+
} else if constexpr (common::HasMember<T, TupleObjectListClauses>) {
196+
return &std::get<OmpObjectList>(clause.v.t);
197+
} else {
198+
return nullptr;
199+
}
200+
} else if constexpr (WrappedInTupleOrVariantV<T, TupleObjectListClauses>) {
201+
return &std::get<OmpObjectList>(clause.t);
202+
} else if constexpr (WrappedInTupleOrVariantV<T, decltype(OmpClause::u)>) {
203+
return nullptr;
204+
} else {
205+
// The condition should be type-dependent, but it should always be false.
206+
static_assert(sizeof(T) < 0 && "Unexpected argument type");
207+
}
208+
}
209+
130210
const OmpObjectList *GetOmpObjectList(const OmpClause &clause);
211+
const OmpObjectList *GetOmpObjectList(const OmpClause::Depend &clause);
212+
const OmpObjectList *GetOmpObjectList(const OmpDependClause::TaskDep &x);
131213

132214
template <typename T>
133215
const T *GetFirstArgument(const OmpDirectiveSpecification &spec) {

flang/lib/Optimizer/Transforms/FIRToSCF.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct IterWhileConversion : public mlir::OpRewritePattern<fir::IterWhileOp> {
126126

127127
mlir::Value okInit = iterWhileOp.getIterateIn();
128128
mlir::ValueRange iterArgs = iterWhileOp.getInitArgs();
129+
bool hasFinalValue = iterWhileOp.getFinalValue().has_value();
129130

130131
mlir::SmallVector<mlir::Value> initVals;
131132
initVals.push_back(lowerBound);
@@ -164,17 +165,22 @@ struct IterWhileConversion : public mlir::OpRewritePattern<fir::IterWhileOp> {
164165

165166
auto *afterBody = scfWhileOp.getAfterBody();
166167
auto resultOp = mlir::cast<fir::ResultOp>(afterBody->getTerminator());
167-
mlir::SmallVector<mlir::Value> results(resultOp->getOperands());
168-
mlir::Value ivInAfter = scfWhileOp.getAfterArguments()[0];
168+
mlir::SmallVector<mlir::Value> results;
169+
mlir::Value iv = scfWhileOp.getAfterArguments()[0];
169170

170171
rewriter.setInsertionPointToStart(afterBody);
171-
results[0] = mlir::arith::AddIOp::create(rewriter, loc, ivInAfter, step);
172+
results.push_back(mlir::arith::AddIOp::create(rewriter, loc, iv, step));
173+
llvm::append_range(results, hasFinalValue
174+
? resultOp->getOperands().drop_front()
175+
: resultOp->getOperands());
172176

173177
rewriter.setInsertionPointToEnd(afterBody);
174178
rewriter.replaceOpWithNewOp<mlir::scf::YieldOp>(resultOp, results);
175179

176180
scfWhileOp->setAttrs(iterWhileOp->getAttrs());
177-
rewriter.replaceOp(iterWhileOp, scfWhileOp);
181+
rewriter.replaceOp(iterWhileOp,
182+
hasFinalValue ? scfWhileOp->getResults()
183+
: scfWhileOp->getResults().drop_front());
178184
return mlir::success();
179185
}
180186
};

flang/lib/Parser/openmp-utils.cpp

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -117,43 +117,20 @@ std::optional<Label> GetFinalLabel(const OpenMPConstruct &x) {
117117
}
118118

119119
const OmpObjectList *GetOmpObjectList(const OmpClause &clause) {
120-
// Clauses with OmpObjectList as its data member
121-
using MemberObjectListClauses = std::tuple<OmpClause::Copyin,
122-
OmpClause::Copyprivate, OmpClause::Exclusive, OmpClause::Firstprivate,
123-
OmpClause::HasDeviceAddr, OmpClause::Inclusive, OmpClause::IsDevicePtr,
124-
OmpClause::Link, OmpClause::Private, OmpClause::Shared,
125-
OmpClause::UseDeviceAddr, OmpClause::UseDevicePtr>;
126-
127-
// Clauses with OmpObjectList in the tuple
128-
using TupleObjectListClauses = std::tuple<OmpClause::AdjustArgs,
129-
OmpClause::Affinity, OmpClause::Aligned, OmpClause::Allocate,
130-
OmpClause::Enter, OmpClause::From, OmpClause::InReduction,
131-
OmpClause::Lastprivate, OmpClause::Linear, OmpClause::Map,
132-
OmpClause::Reduction, OmpClause::TaskReduction, OmpClause::To>;
133-
134-
// TODO:: Generate the tuples using TableGen.
120+
return common::visit([](auto &&s) { return GetOmpObjectList(s); }, clause.u);
121+
}
122+
123+
const OmpObjectList *GetOmpObjectList(const OmpClause::Depend &clause) {
135124
return common::visit(
136125
common::visitors{
137-
[&](const OmpClause::Depend &x) -> const OmpObjectList * {
138-
if (auto *taskDep{std::get_if<OmpDependClause::TaskDep>(&x.v.u)}) {
139-
return &std::get<OmpObjectList>(taskDep->t);
140-
} else {
141-
return nullptr;
142-
}
143-
},
144-
[&](const auto &x) -> const OmpObjectList * {
145-
using Ty = std::decay_t<decltype(x)>;
146-
if constexpr (common::HasMember<Ty, MemberObjectListClauses>) {
147-
return &x.v;
148-
} else if constexpr (common::HasMember<Ty,
149-
TupleObjectListClauses>) {
150-
return &std::get<OmpObjectList>(x.v.t);
151-
} else {
152-
return nullptr;
153-
}
154-
},
126+
[](const OmpDoacross &) { return nullptr; },
127+
[](const OmpDependClause::TaskDep &x) { return GetOmpObjectList(x); },
155128
},
156-
clause.u);
129+
clause.v.u);
130+
}
131+
132+
const OmpObjectList *GetOmpObjectList(const OmpDependClause::TaskDep &x) {
133+
return &std::get<OmpObjectList>(x.t);
157134
}
158135

159136
const BlockConstruct *GetFortranBlockConstruct(

flang/lib/Semantics/check-omp-loop.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,8 @@ void OmpStructureChecker::CheckDistLinear(
480480

481481
// Collect symbols of all the variables from linear clauses
482482
for (auto &clause : clauses.v) {
483-
if (auto *linearClause{std::get_if<parser::OmpClause::Linear>(&clause.u)}) {
484-
auto &objects{std::get<parser::OmpObjectList>(linearClause->v.t)};
485-
GetSymbolsInObjectList(objects, indexVars);
483+
if (std::get_if<parser::OmpClause::Linear>(&clause.u)) {
484+
GetSymbolsInObjectList(*parser::omp::GetOmpObjectList(clause), indexVars);
486485
}
487486
}
488487

@@ -604,8 +603,6 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
604603
auto *maybeModifier{OmpGetUniqueModifier<ReductionModifier>(modifiers)};
605604
if (maybeModifier &&
606605
maybeModifier->v == ReductionModifier::Value::Inscan) {
607-
const auto &objectList{
608-
std::get<parser::OmpObjectList>(reductionClause->v.t)};
609606
auto checkReductionSymbolInScan = [&](const parser::Name *name) {
610607
if (auto &symbol = name->symbol) {
611608
if (!symbol->test(Symbol::Flag::OmpInclusiveScan) &&
@@ -618,7 +615,7 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
618615
}
619616
}
620617
};
621-
for (const auto &ompObj : objectList.v) {
618+
for (const auto &ompObj : parser::omp::GetOmpObjectList(clause)->v) {
622619
common::visit(
623620
common::visitors{
624621
[&](const parser::Designator &designator) {

0 commit comments

Comments
 (0)