Skip to content

Commit bc89380

Browse files
authored
[flang][preprocessor] fix use of bitwise-and for logical-and (#146758)
The preprocessor used bitwise and to implement logical, this is a bug. towards #146362
1 parent 67d6679 commit bc89380

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

flang/lib/Parser/preprocessor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,16 +1276,20 @@ static std::int64_t ExpressionValue(const TokenSequence &token,
12761276
left = right >= 64 ? 0 : left >> right;
12771277
break;
12781278
case BITAND:
1279-
case AND:
12801279
left = left & right;
12811280
break;
12821281
case BITXOR:
12831282
left = left ^ right;
12841283
break;
12851284
case BITOR:
1286-
case OR:
12871285
left = left | right;
12881286
break;
1287+
case AND:
1288+
left = left && right;
1289+
break;
1290+
case OR:
1291+
left = left || right;
1292+
break;
12891293
case LT:
12901294
left = -(left < right);
12911295
break;

flang/test/Parser/issue-146362.2.f90

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
!RUN: %flang_fc1 -cpp -fdebug-unparse %s | FileCheck %s
2+
PROGRAM P
3+
#if (1 && 2)
4+
!CHECK: TRUE
5+
WRITE(*,*) 'TRUE'
6+
#else
7+
!CHECK-NOT: FALSE
8+
WRITE(*,*) 'FALSE'
9+
#endif
10+
#if ((1 || 2) != 3)
11+
!CHECK: TRUE
12+
WRITE(*,*) 'TRUE'
13+
#else
14+
!CHECK-NOT: FALSE
15+
WRITE(*,*) 'FALSE'
16+
#endif
17+
END PROGRAM
18+

0 commit comments

Comments
 (0)