Author: Timm Baeder Date: 2025-05-27T08:12:18+02:00 New Revision: 17ef0fe59437f107e8f1cf7edb2fe109de4e332f
URL: https://github.com/llvm/llvm-project/commit/17ef0fe59437f107e8f1cf7edb2fe109de4e332f DIFF: https://github.com/llvm/llvm-project/commit/17ef0fe59437f107e8f1cf7edb2fe109de4e332f.diff LOG: [clang][OpenCL] Only evaluate initializer once to check for zero init (#141474) Both Expr::isIntegerConstantExpr() and Expr::EvaluateKnownConstInt() evaluate the expression. Just do it once and check the integer result. Added: Modified: clang/lib/Sema/SemaInit.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 2f682dbc1f000..776cb022e6925 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6410,9 +6410,9 @@ static bool TryOCLSamplerInitialization(Sema &S, return true; } -static bool IsZeroInitializer(Expr *Initializer, Sema &S) { - return Initializer->isIntegerConstantExpr(S.getASTContext()) && - (Initializer->EvaluateKnownConstInt(S.getASTContext()) == 0); +static bool IsZeroInitializer(const Expr *Init, ASTContext &Ctx) { + std::optional<llvm::APSInt> Value = Init->getIntegerConstantExpr(Ctx); + return Value && Value->isZero(); } static bool TryOCLZeroOpaqueTypeInitialization(Sema &S, @@ -6431,7 +6431,7 @@ static bool TryOCLZeroOpaqueTypeInitialization(Sema &S, // event should be zero. // if (DestType->isEventT() || DestType->isQueueT()) { - if (!IsZeroInitializer(Initializer, S)) + if (!IsZeroInitializer(Initializer, S.getASTContext())) return false; Sequence.AddOCLZeroOpaqueTypeStep(DestType); @@ -6447,7 +6447,7 @@ static bool TryOCLZeroOpaqueTypeInitialization(Sema &S, if (DestType->isOCLIntelSubgroupAVCMcePayloadType() || DestType->isOCLIntelSubgroupAVCMceResultType()) return false; - if (!IsZeroInitializer(Initializer, S)) + if (!IsZeroInitializer(Initializer, S.getASTContext())) return false; Sequence.AddOCLZeroOpaqueTypeStep(DestType); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits