Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CIRGen][Bugfix] Emit valid type for evaluated const #456

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
handle (1 || RHS = 1)
  • Loading branch information
YazZz1k committed Feb 8, 2024
commit 3bdf8a88fe765c4a1c32e081a823c4d81d051e2d
8 changes: 6 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2200,8 2200,12 @@ mlir::Value ScalarExprEmitter::VisitBinLOr(const clang::BinaryOperator *E) {
return Builder.createZExtOrBitCast(RHSCond.getLoc(), RHSCond, ResTy);
}
// 1 || RHS: If it is safe, just elide the RHS, and return 1/true.
if (!CGF.ContainsLabel(E->getRHS()))
return Builder.getBool(true, Loc);
if (!CGF.ContainsLabel(E->getRHS())) {
if (auto intTy = ResTy.dyn_cast<mlir::cir::IntType>())
return Builder.getConstInt(Loc, intTy, 1);
else
return Builder.getBool(true, Loc);
}
}

CIRGenFunction::ConditionalEvaluation eval(CGF);
Expand Down
4 changes: 3 additions & 1 deletion clang/test/CIR/CodeGen/evaluate-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,9 @@

static const int g = 1;
void foo() {
if((g != 1) && (g != 1))
if ((g != 1) && (g != 1))
return;
if ((g == 1) || (g == 1))
return;
}
// CHECK: cir.func no_proto @foo()
Expand Down
Loading