Skip to content

Commit 423dd17

Browse files
authored
Fix PostDec operator (#361)
* Fix PostDec operator * Add test: decrement operator
1 parent fd4194b commit 423dd17

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tools/cgeist/Lib/clang-mlir.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) {
23352335
}
23362336
sub.store(loc, builder, next);
23372337
return ValueCategory(
2338-
(U->getOpcode() == clang::UnaryOperator::Opcode::UO_PostInc) ? prev
2338+
(U->getOpcode() == clang::UnaryOperator::Opcode::UO_PostDec) ? prev
23392339
: next,
23402340
/*isReference*/ false);
23412341
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: cgeist %s --function=* -S | FileCheck %s
2+
3+
int prefix_decrement(int x)
4+
{
5+
return --x;
6+
}
7+
8+
int postfix_decrement(int x)
9+
{
10+
return x--;
11+
}
12+
13+
// CHECK: func.func @prefix_decrement(%[[arg0:.+]]: i32) -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
14+
// CHECK-NEXT: %[[c1_i32:.+]] = arith.constant -1 : i32
15+
// CHECK-NEXT: %[[V0:.+]] = arith.addi %[[arg0]], %[[c1_i32]] : i32
16+
// CHECK-NEXT: return %[[V0]] : i32
17+
// CHECK-NEXT: }
18+
19+
// CHECK: func.func @postfix_decrement(%[[arg0:.+]]: i32) -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
20+
// CHECK-NEXT: return %[[arg0]] : i32
21+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)