Skip to content

[clang][Sema] Create ConstantExprs in AnalyzeComparison #151464

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
18 changes: 17 additions & 1 deletion clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11374,11 +11374,27 @@ static void AnalyzeComparison(Sema &S, BinaryOperator *E) {
LHS->getIntegerConstantExpr(S.Context);

// We don't care about expressions whose result is a constant.
if (RHSValue && LHSValue)
if (RHSValue && LHSValue) {
auto *LHSCE = ConstantExpr::Create(S.Context, LHS, APValue(*LHSValue));
auto *RHSCE = ConstantExpr::Create(S.Context, RHS, APValue(*RHSValue));
E->setLHS(LHSCE);
E->setRHS(RHSCE);
return AnalyzeImpConvsInComparison(S, E);
}

// We only care about expressions where just one side is literal
if ((bool)RHSValue ^ (bool)LHSValue) {

if (LHSValue) {
auto *LHSCE = ConstantExpr::Create(S.Context, LHS, APValue(*LHSValue));
E->setLHS(LHSCE);
LHS = LHSCE;
} else if (RHSValue) {
auto *RHSCE = ConstantExpr::Create(S.Context, RHS, APValue(*RHSValue));
E->setRHS(RHSCE);
RHS = RHSCE;
}

// Is the constant on the RHS or LHS?
const bool RhsConstant = (bool)RHSValue;
Expr *Const = RhsConstant ? RHS : LHS;
Expand Down
Loading