Skip to content

Commit 9e53e77

Browse files
authored
[flang] Fix warnings from more recent GCCs (#106567)
While experimenting with some more recent C++ features, I ran into trouble with warnings from GCC 12.3.0 and 14.2.0. These warnings looked legitimate, so I've tweaked the code to avoid them.
1 parent 6facf69 commit 9e53e77

File tree

9 files changed

+26
-23
lines changed

9 files changed

+26
-23
lines changed

flang/include/flang/Evaluate/integer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,9 @@ class Integer {
828828
if (Part ypart{y.LEPart(k)}) {
829829
BigPart xy{xpart};
830830
xy *= ypart;
831-
#if defined __GNUC__ && __GNUC__ < 8
832-
// && to < (2 * parts) was added to avoid GCC < 8 build failure on
833-
// -Werror=array-bounds. This can be removed if -Werror is disable.
831+
#if defined __GNUC__ && __GNUC__ < 8 || __GNUC__ >= 12
832+
// && to < (2 * parts) was added to avoid GCC build failure on
833+
// -Werror=array-bounds. This can be removed if -Werror is disabled.
834834
for (int to{j + k}; xy != 0 && to < (2 * parts); ++to) {
835835
#else
836836
for (int to{j + k}; xy != 0; ++to) {

flang/include/flang/Runtime/descriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ class Descriptor {
438438
}
439439
RT_API_ATTRS inline void SetAllocIdx(int pos) {
440440
raw_.extra &= ~_CFI_ALLOCATOR_IDX_MASK; // Clear the allocator index bits.
441-
raw_.extra |= (pos << _CFI_ALLOCATOR_IDX_SHIFT);
441+
raw_.extra |= pos << _CFI_ALLOCATOR_IDX_SHIFT;
442442
}
443443

444444
private:

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5590,7 +5590,8 @@ class ArrayExprLowering {
55905590
ty = unwrapBoxEleTy(ty);
55915591
mlir::Location loc = getLoc();
55925592
mlir::IndexType idxTy = builder.getIndexType();
5593-
for (auto extent : mlir::cast<fir::SequenceType>(ty).getShape()) {
5593+
auto seqType = mlir::cast<fir::SequenceType>(ty);
5594+
for (auto extent : seqType.getShape()) {
55945595
auto v = extent == fir::SequenceType::getUnknownExtent()
55955596
? builder.create<fir::UndefOp>(loc, idxTy).getResult()
55965597
: builder.createIntegerConstant(loc, idxTy, extent);

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ struct EmboxCommonConversion : public fir::FIROpConversion<OP> {
12731273
} else {
12741274
// Compute the value of the extra field based on allocator_idx and
12751275
// addendum present using a Descriptor object.
1276-
Fortran::runtime::StaticDescriptor<0> staticDescriptor;
1276+
Fortran::runtime::StaticDescriptor staticDescriptor;
12771277
Fortran::runtime::Descriptor &desc{staticDescriptor.descriptor()};
12781278
desc.raw().extra = 0;
12791279
desc.SetAllocIdx(allocatorIdx);

flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ class DesignateOpConversion
411411
llvm::SmallVector<mlir::Value> firstElementIndices;
412412
auto indices = designate.getIndices();
413413
int i = 0;
414-
for (auto isTriplet : designate.getIsTripletAttr().asArrayRef()) {
414+
auto attrs = designate.getIsTripletAttr();
415+
for (auto isTriplet : attrs.asArrayRef()) {
415416
// Coordinate of the first element are the index and triplets lower
416417
// bounds
417418
firstElementIndices.push_back(indices[i]);

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,13 +1796,12 @@ inline void OmpStructureChecker::ErrIfLHSAndRHSSymbolsMatch(
17961796
const auto *e{GetExpr(context_, expr)};
17971797
const auto *v{GetExpr(context_, var)};
17981798
if (e && v) {
1799-
const Symbol &varSymbol = evaluate::GetSymbolVector(*v).front();
1799+
auto vSyms{evaluate::GetSymbolVector(*v)};
1800+
const Symbol &varSymbol = vSyms.front();
18001801
for (const Symbol &symbol : evaluate::GetSymbolVector(*e)) {
18011802
if (varSymbol == symbol) {
18021803
context_.Say(expr.source,
1803-
"RHS expression "
1804-
"on atomic assignment statement"
1805-
" cannot access '%s'"_err_en_US,
1804+
"RHS expression on atomic assignment statement cannot access '%s'"_err_en_US,
18061805
var.GetSource().ToString());
18071806
}
18081807
}
@@ -1942,12 +1941,14 @@ void OmpStructureChecker::CheckAtomicUpdateStmt(
19421941
"Expected scalar variable "
19431942
"on the LHS of atomic update assignment "
19441943
"statement"_err_en_US);
1945-
const Symbol &varSymbol = evaluate::GetSymbolVector(*v).front();
1944+
auto vSyms{evaluate::GetSymbolVector(*v)};
1945+
const Symbol &varSymbol = vSyms.front();
19461946
int numOfSymbolMatches{0};
1947-
SymbolVector exprSymbols = evaluate::GetSymbolVector(*e);
1947+
SymbolVector exprSymbols{evaluate::GetSymbolVector(*e)};
19481948
for (const Symbol &symbol : exprSymbols) {
1949-
if (varSymbol == symbol)
1949+
if (varSymbol == symbol) {
19501950
numOfSymbolMatches++;
1951+
}
19511952
}
19521953
if (isIntrinsicProcedure) {
19531954
std::string varName = var.GetSource().ToString();

flang/lib/Semantics/tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ ComponentIterator<componentKind>::const_iterator::BuildResultDesignatorName()
13541354
const {
13551355
std::string designator;
13561356
for (const auto &node : componentPath_) {
1357-
designator += "%" + DEREF(node.component()).name().ToString();
1357+
designator += "%"s + DEREF(node.component()).name().ToString();
13581358
}
13591359
return designator;
13601360
}

flang/unittests/Runtime/Reduction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ TEST(Reductions, DimMaskProductInt4) {
4242
shape, std::vector<std::int32_t>{1, 2, 3, 4, 5, 6})};
4343
auto mask{MakeArray<TypeCategory::Logical, 1>(
4444
shape, std::vector<bool>{true, false, false, true, true, true})};
45-
StaticDescriptor<1, true> statDesc;
45+
StaticDescriptor<maxRank, true> statDesc;
4646
Descriptor &prod{statDesc.descriptor()};
4747
RTNAME(ProductDim)(prod, *array, 1, __FILE__, __LINE__, &*mask);
4848
EXPECT_EQ(prod.rank(), 1);
@@ -152,7 +152,7 @@ TEST(Reductions, DoubleMaxMinNorm2) {
152152
// A scalar result occurs when you have a rank 1 array and dim == 1.
153153
std::vector<int> shape1{24};
154154
auto array1{MakeArray<TypeCategory::Real, 8>(shape1, rawData)};
155-
StaticDescriptor<1, true> statDesc0[1];
155+
StaticDescriptor<2, true> statDesc0[1];
156156
Descriptor &scalarResult{statDesc0[0].descriptor()};
157157
RTNAME(MaxlocDim)
158158
(scalarResult, *array1, /*KIND=*/2, /*DIM=*/1, __FILE__, __LINE__,
@@ -655,7 +655,7 @@ TEST(Reductions, ReduceInt4) {
655655
TEST(Reductions, ReduceInt4Dim) {
656656
auto intMatrix{MakeArray<TypeCategory::Integer, 4>(
657657
std::vector<int>{2, 2}, std::vector<std::int32_t>{1, 2, 3, 4})};
658-
StaticDescriptor<1, true> statDesc;
658+
StaticDescriptor<2, true> statDesc;
659659
Descriptor &sums{statDesc.descriptor()};
660660
RTNAME(ReduceInteger4DimRef)(sums, *intMatrix, IAdd, __FILE__, __LINE__, 1);
661661
EXPECT_EQ(sums.rank(), 1);

flang/unittests/Runtime/Transformational.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template <int KIND>
3333
static void testBesselJn(BesselFuncType<KIND> rtFunc, int32_t n1, int32_t n2,
3434
CppTypeFor<TypeCategory::Real, KIND> x,
3535
const std::vector<CppTypeFor<TypeCategory::Real, KIND>> &expected) {
36-
StaticDescriptor<1> desc;
36+
StaticDescriptor desc;
3737
Descriptor &result{desc.descriptor()};
3838
unsigned len = expected.size();
3939

@@ -60,7 +60,7 @@ static void testBesselJn(BesselFuncType<KIND> rtFunc, int32_t n1, int32_t n2,
6060
template <int KIND>
6161
static void testBesselJnX0(
6262
BesselX0FuncType<KIND> rtFunc, int32_t n1, int32_t n2) {
63-
StaticDescriptor<1> desc;
63+
StaticDescriptor desc;
6464
Descriptor &result{desc.descriptor()};
6565

6666
rtFunc(result, n1, n2, __FILE__, __LINE__);
@@ -131,7 +131,7 @@ template <int KIND>
131131
static void testBesselYn(BesselFuncType<KIND> rtFunc, int32_t n1, int32_t n2,
132132
CppTypeFor<TypeCategory::Real, KIND> x,
133133
const std::vector<CppTypeFor<TypeCategory::Real, KIND>> &expected) {
134-
StaticDescriptor<1> desc;
134+
StaticDescriptor desc;
135135
Descriptor &result{desc.descriptor()};
136136
unsigned len = expected.size();
137137

@@ -158,7 +158,7 @@ static void testBesselYn(BesselFuncType<KIND> rtFunc, int32_t n1, int32_t n2,
158158
template <int KIND>
159159
static void testBesselYnX0(
160160
BesselX0FuncType<KIND> rtFunc, int32_t n1, int32_t n2) {
161-
StaticDescriptor<1> desc;
161+
StaticDescriptor<2> desc;
162162
Descriptor &result{desc.descriptor()};
163163

164164
rtFunc(result, n1, n2, __FILE__, __LINE__);
@@ -383,7 +383,7 @@ TEST(Transformational, Pack) {
383383
std::vector<std::uint8_t>{false, true, true, false, false, true})};
384384
mask->GetDimension(0).SetLowerBound(0); // shouldn't matter
385385
mask->GetDimension(1).SetLowerBound(2);
386-
StaticDescriptor<1, true> statDesc;
386+
StaticDescriptor<maxRank, true> statDesc;
387387
Descriptor &result{statDesc.descriptor()};
388388

389389
RTNAME(Pack)(result, *array, *mask, nullptr, __FILE__, __LINE__);

0 commit comments

Comments
 (0)