Skip to content

Commit 4e2c45e

Browse files
vdonaldsonjeanPerier
authored andcommitted
Uninitialized variable warning fix + test update (#693)
1 parent 70fab97 commit 4e2c45e

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,12 +1267,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
12671267
continue;
12681268
}
12691269
mlir::CmpIPredicate pred;
1270-
if (attr.isa<fir::PointIntervalAttr>())
1270+
if (attr.isa<fir::PointIntervalAttr>()) {
12711271
pred = mlir::CmpIPredicate::eq;
1272-
else if (attr.isa<fir::LowerBoundAttr>())
1272+
} else if (attr.isa<fir::LowerBoundAttr>()) {
12731273
pred = mlir::CmpIPredicate::sge;
1274-
else if (attr.isa<fir::UpperBoundAttr>())
1274+
} else {
1275+
assert(attr.isa<fir::UpperBoundAttr>() && "unexpected predicate");
12751276
pred = mlir::CmpIPredicate::sle;
1277+
}
12761278
auto cond = genCond(*caseValue++, pred);
12771279
genFIRConditionalBranch(cond, *caseBlock++, newBlock);
12781280
builder->setInsertionPointToEnd(newBlock);

flang/test/Lower/associate-construct.f90

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1-
! RUN: bbc %s -o - | tco | llc --relocation-model=pic --filetype=obj -o %t.o
2-
! RUN: %CC %t.o -L%L -Wl,-rpath -Wl,%L -lFortran_main -lFortranRuntime -lFortranDecimal -lm -o %t.out
3-
! RUN: %t.out | FileCheck %s
1+
! RUN: bbc -emit-fir -o - %s | FileCheck %s
42

3+
! CHECK-LABEL: func @_QQmain
54
program p
6-
integer :: n, foo
7-
n = 0
8-
associate (i => n, j => n + 10, k => foo(20))
9-
! CHECK: 0 0 10 20
10-
print*, n, i, j, k
5+
! CHECK: [[N:%[0-9]+]] = fir.alloca i32 {name = "_QEn"}
6+
! CHECK: [[T:%[0-9]+]] = fir.address_of(@_QEt) : !fir.ref<!fir.array<3xi32>>
7+
integer :: n, foo, t(3)
8+
! CHECK: [[N]]
9+
! CHECK-COUNT-3: fir.coordinate_of [[T]]
10+
n = 100; t(1) = 111; t(2) = 222; t(3) = 333
11+
! CHECK: fir.load [[N]]
12+
! CHECK: addi {{.*}} %c5
13+
! CHECK: fir.store %{{[0-9]*}} to [[B:%[0-9]+]]
14+
! CHECK: [[C:%[0-9]+]] = fir.coordinate_of [[T]]
15+
! CHECK: fir.call @_QPfoo
16+
! CHECK: fir.store %{{[0-9]*}} to [[D:%[0-9]+]]
17+
associate (a => n, b => n+5, c => t(2), d => foo(7))
18+
! CHECK: fir.load [[N]]
19+
! CHECK: addi %{{[0-9]*}}, %c1
20+
! CHECK: fir.store %{{[0-9]*}} to [[N]]
21+
a = a + 1
22+
! CHECK: fir.load [[C]]
23+
! CHECK: addi %{{[0-9]*}}, %c1
24+
! CHECK: fir.store %{{[0-9]*}} to [[C]]
25+
c = c + 1
26+
! CHECK: fir.load [[N]]
27+
! CHECK: addi %{{[0-9]*}}, %c1
28+
! CHECK: fir.store %{{[0-9]*}} to [[N]]
1129
n = n + 1
12-
! CHECK: 1 1 10 20
13-
print*, n, i, j, k
14-
i = i + 1
15-
! CHECK: 2 2 10 20
16-
print*, n, i, j, k
30+
! CHECK: fir.load [[N]]
31+
! CHECK: fir.embox [[T]]
32+
! CHECK: fir.load [[N]]
33+
! CHECK: fir.load [[B]]
34+
! CHECK: fir.load [[C]]
35+
! CHECK: fir.load [[D]]
36+
print*, n, t, a, b, c, d ! expected output: 102 111 223 333 102 105 223 7
1737
end associate
18-
! CHECK: 2
19-
print*, n
2038
end
2139

40+
! CHECK-LABEL: func @_QPfoo
2241
integer function foo(x)
2342
integer x
2443
integer, save :: i = 0

0 commit comments

Comments
 (0)