Author: Timm Baeder Date: 2026-08-21T08:59:02+02:00 New Revision: 2f24757acd57e6c8a4c58553d18c1ff040fc30b7
URL: https://github.com/llvm/llvm-project/commit/2f24757acd57e6c8a4c58553d18c1ff040fc30b7 DIFF: https://github.com/llvm/llvm-project/commit/2f24757acd57e6c8a4c58553d18c1ff040fc30b7.diff LOG: [clang][ExprConst] Post-merge review for relaxed evaluation (#217675) Rename a function to be more descriptive and add documentation. Added: Modified: clang/include/clang/AST/Expr.h clang/lib/AST/ByteCode/Interp.cpp clang/lib/AST/ByteCode/State.cpp clang/lib/AST/ByteCode/State.h Removed: ################################################################################ diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 112af378258fc..7d4cc10245c0d 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -561,6 +561,10 @@ class Expr : public ValueStmt { /// /// Note: This does not perform the implicit conversions required by C++11 /// [expr.const]p5. + /// + /// If \p AllowRelaxedEval is \c true, this will allow certain constructs that + /// are not valid per the specification. + // FIXME: Add proper documentation about the constructs we allow. std::optional<llvm::APSInt> getIntegerConstantExpr(const ASTContext &Ctx, bool AllowRelaxedEval = false) const; @@ -575,6 +579,10 @@ class Expr : public ValueStmt { /// /// Note: This does not perform the implicit conversions required by C++11 /// [expr.const]p5. + /// + /// If \p AllowRelaxedEval is \c true, this will allow certain constructs that + /// are not valid per the specification. + // FIXME: Add proper documentation about the constructs we allow. bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr, bool AllowRelaxedEval = false) const; diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 37378f41f0a56..bf7bce1a2da13 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1592,7 +1592,7 @@ static bool diagnoseTypeIdField(InterpState &S, CodePtr OpPC, } static bool allowNullSubObj(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { - return Ptr.isZero() && S.shouldRelaxDiag(S.Current->getSource(OpPC).getLoc(), + return Ptr.isZero() && S.emitRelaxedDiag(S.Current->getSource(OpPC).getLoc(), diag::note_constexpr_null_subobject); } diff --git a/clang/lib/AST/ByteCode/State.cpp b/clang/lib/AST/ByteCode/State.cpp index 925e2eddf0ef4..d8e9504e1a8e5 100644 --- a/clang/lib/AST/ByteCode/State.cpp +++ b/clang/lib/AST/ByteCode/State.cpp @@ -18,10 +18,11 @@ using namespace clang::interp; State::~State() {} -bool State::shouldRelaxDiag(const SourceLocation &Loc, diag::kind DiagId) { +bool State::emitRelaxedDiag(SourceLocation Loc, diag::kind DiagId) { if (!Ctx.getLangOpts().MSVCCompat || (!EvalStatus.ExtendedDiag && !InConstantContext)) return false; + switch (DiagId) { case diag::note_constexpr_invalid_cast_ptrtoint: addExtendedDiag(Loc, diag::warn_relaxed_constant_fold_cast); @@ -59,7 +60,7 @@ OptionalDiagnostic State::FFDiag(SourceInfo SI, diag::kind DiagId, OptionalDiagnostic State::CCEDiag(SourceLocation Loc, diag::kind DiagId, unsigned ExtraNotes) { - if (shouldRelaxDiag(Loc, DiagId)) { + if (emitRelaxedDiag(Loc, DiagId)) { setActiveDiagnostic(false); return OptionalDiagnostic(); } diff --git a/clang/lib/AST/ByteCode/State.h b/clang/lib/AST/ByteCode/State.h index 97af0bf2b6866..0fed26e14007b 100644 --- a/clang/lib/AST/ByteCode/State.h +++ b/clang/lib/AST/ByteCode/State.h @@ -92,7 +92,10 @@ class State { ASTContext &getASTContext() const { return Ctx; } const LangOptions &getLangOpts() const { return Ctx.getLangOpts(); } - bool shouldRelaxDiag(const SourceLocation &Loc, diag::kind DiagId); + /// If \c DiagId should be relaxed as per the current evaluation settings, + /// emit it as a warning instead of an error. Returns \c true if a relaxed + /// diagnostic was emitted, \c false otherwise. + bool emitRelaxedDiag(SourceLocation Loc, diag::kind DiagId); /// Note that we have had a side-effect, and determine whether we should /// keep evaluating. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
