Skip to content

Commit

Permalink
Fix PostDec operator (#361)
Browse files Browse the repository at this point in the history
* Fix PostDec operator

* Add test: decrement operator
  • Loading branch information
WAAutoMaton authored Sep 20, 2023
1 parent fd4194b commit 423dd17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/cgeist/Lib/clang-mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) {
}
sub.store(loc, builder, next);
return ValueCategory(
(U->getOpcode() == clang::UnaryOperator::Opcode::UO_PostInc) ? prev
(U->getOpcode() == clang::UnaryOperator::Opcode::UO_PostDec) ? prev
: next,
/*isReference*/ false);
}
Expand Down
21 changes: 21 additions & 0 deletions tools/cgeist/Test/Verification/decrement.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: cgeist %s --function=* -S | FileCheck %s

int prefix_decrement(int x)
{
return --x;
}

int postfix_decrement(int x)
{
return x--;
}

// CHECK: func.func @prefix_decrement(%[[arg0:.+]]: i32) -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
// CHECK-NEXT: %[[c1_i32:.+]] = arith.constant -1 : i32
// CHECK-NEXT: %[[V0:.+]] = arith.addi %[[arg0]], %[[c1_i32]] : i32
// CHECK-NEXT: return %[[V0]] : i32
// CHECK-NEXT: }

// CHECK: func.func @postfix_decrement(%[[arg0:.+]]: i32) -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
// CHECK-NEXT: return %[[arg0]] : i32
// CHECK-NEXT: }

0 comments on commit 423dd17

Please sign in to comment.