llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Adamya Verma (Kirito-89) <details> <summary>Changes</summary> Clang's constant evaluator would unconditionally reject the initializer of any [[gnu::weak]] variable. This was intended to prevent unsafe constant folding but also incorrectly blocked valid constant evaluation in C++14 (e.g., static constexpr initialization). This patch refines the logic to only apply the check when the evaluation mode is not EvaluationMode::ConstantExpression. This fixes the bug by allowing required constexpr evaluation to proceed while still preventing unsafe folding in other contexts. --- Full diff: https://github.com/llvm/llvm-project/pull/166852.diff 1 Files Affected: - (modified) clang/lib/AST/ExprConstant.cpp (+1-1) ``````````diff diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 97eeba8b9d6cc..cb3a359a6df95 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -3611,7 +3611,7 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E, // Never use the initializer of a weak variable, not even for constant // folding. We can't be sure that this is the definition that will be used. - if (VD->isWeak()) { + if (VD->isWeak()&& (Info.EvalMode != EvaluationMode::ConstantExpression)) { Info.FFDiag(E, diag::note_constexpr_var_init_weak) << VD; NoteLValueLocation(Info, Base); return false; `````````` </details> https://github.com/llvm/llvm-project/pull/166852 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
