diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index c8bde52dc071..53554a620d91 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -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); } diff --git a/tools/cgeist/Test/Verification/decrement.c b/tools/cgeist/Test/Verification/decrement.c new file mode 100644 index 000000000000..e83f06ecb463 --- /dev/null +++ b/tools/cgeist/Test/Verification/decrement.c @@ -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} { +// 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} { +// CHECK-NEXT: return %[[arg0]] : i32 +// CHECK-NEXT: }