Author: Shilei Tian Date: 2022-06-02T17:45:02-04:00 New Revision: 3a96256b7e292de15ad57438202aeea4818956ba
URL: https://github.com/llvm/llvm-project/commit/3a96256b7e292de15ad57438202aeea4818956ba DIFF: https://github.com/llvm/llvm-project/commit/3a96256b7e292de15ad57438202aeea4818956ba.diff LOG: [Clang][OpenMP] Avoid using `IgnoreImpCasts` if possible This patch removes all `IgnoreImpCasts` in Sema, and only uses it if necessary. If the expression is not of the same type as the pointer value, a cast is inserted. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D126602 Added: Modified: clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index b22b278202dc..f509d6fa935f 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -6183,8 +6183,19 @@ static void emitOMPAtomicCompareExpr(CodeGenFunction &CGF, LValue XLVal = CGF.EmitLValue(X); Address XAddr = XLVal.getAddress(CGF); - llvm::Value *EVal = CGF.EmitScalarExpr(E); - llvm::Value *DVal = D ? CGF.EmitScalarExpr(D) : nullptr; + + auto EmitRValueWithCastIfNeeded = [&CGF, Loc](const Expr *X, const Expr *E) { + if (X->getType() == E->getType()) + return CGF.EmitScalarExpr(E); + const Expr *NewE = E->IgnoreImplicitAsWritten(); + llvm::Value *V = CGF.EmitScalarExpr(NewE); + if (NewE->getType() == X->getType()) + return V; + return CGF.EmitScalarConversion(V, NewE->getType(), X->getType(), Loc); + }; + + llvm::Value *EVal = EmitRValueWithCastIfNeeded(X, E); + llvm::Value *DVal = D ? EmitRValueWithCastIfNeeded(X, D) : nullptr; llvm::OpenMPIRBuilder::AtomicOpValue XOpVal{ XAddr.getPointer(), XAddr.getElementType(), diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 753decfb167c..04770975005d 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -11429,11 +11429,11 @@ bool OpenMPAtomicCompareChecker::checkCondUpdateStmt(IfStmt *S, switch (Cond->getOpcode()) { case BO_EQ: { C = Cond; - D = BO->getRHS()->IgnoreImpCasts(); + D = BO->getRHS(); if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) { - E = Cond->getRHS()->IgnoreImpCasts(); + E = Cond->getRHS(); } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) { - E = Cond->getLHS()->IgnoreImpCasts(); + E = Cond->getLHS(); } else { ErrorInfo.Error = ErrorTy::InvalidComparison; ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc(); @@ -11444,7 +11444,7 @@ bool OpenMPAtomicCompareChecker::checkCondUpdateStmt(IfStmt *S, } case BO_LT: case BO_GT: { - E = BO->getRHS()->IgnoreImpCasts(); + E = BO->getRHS(); if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) && checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) { C = Cond; @@ -11524,11 +11524,11 @@ bool OpenMPAtomicCompareChecker::checkCondExprStmt(Stmt *S, switch (Cond->getOpcode()) { case BO_EQ: { C = Cond; - D = CO->getTrueExpr()->IgnoreImpCasts(); + D = CO->getTrueExpr(); if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) { - E = Cond->getRHS()->IgnoreImpCasts(); + E = Cond->getRHS(); } else if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getRHS())) { - E = Cond->getLHS()->IgnoreImpCasts(); + E = Cond->getLHS(); } else { ErrorInfo.Error = ErrorTy::InvalidComparison; ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = Cond->getExprLoc(); @@ -11539,7 +11539,7 @@ bool OpenMPAtomicCompareChecker::checkCondExprStmt(Stmt *S, } case BO_LT: case BO_GT: { - E = CO->getTrueExpr()->IgnoreImpCasts(); + E = CO->getTrueExpr(); if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS()) && checkIfTwoExprsAreSame(ContextRef, E, Cond->getRHS())) { C = Cond; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits