[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-15 Thread Aaron Ballman via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: AaronBallman wrote: > @AaronBallman, @c

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-14 Thread via cfe-commits
apple-fcloutier wrote: @AaronBallman, @cor3ntin, what do you think? Split this in two, [like Oliver suggests](https://github.com/llvm/llvm-project/pull/135864#issuecomment-2879466843)? https://github.com/llvm/llvm-project/pull/135864 ___ cfe-commits m

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-14 Thread Oliver Hunt via cfe-commits
ojhunt wrote: @apple-fcloutier I feel like this PR can be made easier to review by separating the improvements to string constant evaluation from the improvements to the format string checking, as the former introduces a number of new interfaces and the operations required to provide those API

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
https://github.com/apple-fcloutier updated https://github.com/llvm/llvm-project/pull/135864 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Aria

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -1920,9 +1920,17 @@ static bool EvaluateComplex(c

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
@@ -1920,9 +1920,17 @@ static bool EvaluateComplex(const Expr *E, ComplexValue &Res, EvalInfo &Info); static bool EvaluateAtomic(const Expr *E, const LValue *This, APValue &Result, EvalInfo &Info); static bool EvaluateAsRValue(EvalInfo &Info, const E

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
@@ -17971,46 +18006,117 @@ static bool EvaluateBuiltinStrLen(const Expr *E, uint64_t &Result, S->getCharByteWidth() == 1 && // FIXME: Add fast-path for wchar_t too. Info.Ctx.hasSameUnqualifiedType(CharTy, Info.Ctx.CharTy)) { - Str = Str.substr(Off)

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -1920,9 +1920,17 @@ static bool EvaluateComplex(c

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
@@ -791,10 +791,26 @@ class Expr : public ValueStmt { const Expr *PtrExpression, ASTContext &Ctx, EvalResult &Status) const; - /// If the current Expr can be evaluated to a pointer to a null-terminated - /// c

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
=?utf-8?q?F=C3=A9lix?= Cloutier , =?utf-8?q?F=C3=A9lix?= Cloutier , =?utf-8?q?F=C3=A9lix?= Cloutier , =?utf-8?q?F=C3=A9lix?= Cloutier , =?utf-8?q?F=C3=A9lix?= Cloutier , =?utf-8?q?F=C3=A9lix?= Cloutier , =?utf-8?q?F=C3=A9lix?= Cloutier Message-ID: In-Reply-To: @@ -791,10 +791,2

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
@@ -1920,9 +1920,17 @@ static bool EvaluateComplex(const Expr *E, ComplexValue &Res, EvalInfo &Info); static bool EvaluateAtomic(const Expr *E, const LValue *This, APValue &Result, EvalInfo &Info); static bool EvaluateAsRValue(EvalInfo &Info, const E

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -1920,9 +1920,17 @@ static bool EvaluateComplex(c

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-12 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -17971,46 +18006,117 @@ static bool EvaluateBuilt

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-07 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your c

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-07 Thread via cfe-commits
https://github.com/apple-fcloutier updated https://github.com/llvm/llvm-project/pull/135864 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Aria

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-07 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -238,3 +246,69 @@ void f(Scoped1 S1, Scoped2 S2) { } #endif + +#if __cplus

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-07 Thread via cfe-commits
apple-fcloutier wrote: Yeah, I'm fixing the merge conflict, unfortunately I got sidetracked _immediately_ after I pushed and found there was a conflict. I'll hopefully get it out by EOD. https://github.com/llvm/llvm-project/pull/135864 ___ cfe-commit

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-07 Thread Hubert Tong via cfe-commits
@@ -238,3 +246,69 @@ void f(Scoped1 S1, Scoped2 S2) { } #endif + +#if __cplusplus >= 202000L +class my_string { + char *data; + unsigned size; + +public: + template + constexpr my_string(const char (&literal)[N]) { +data = new char[N+1]; +for (size = 0; size < N; +

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-07 Thread Aaron Ballman via cfe-commits
@@ -238,3 +246,69 @@ void f(Scoped1 S1, Scoped2 S2) { } #endif + +#if __cplusplus >= 202000L +class my_string { + char *data; + unsigned size; + +public: + template + constexpr my_string(const char (&literal)[N]) { +data = new char[N+1]; +for (size = 0; size < N; +

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-05-03 Thread Oliver Hunt via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: ojhunt wrote: The pointer auth options PR would also benefit from this - it currently has an ad hoc and restricted version of this as it needed to support

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-28 Thread Aaron Ballman via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -1,6 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks %s // RUN: %clang_cc1 -fsyntax-only -verify

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-28 Thread Aaron Ballman via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -9105,7 +9105,7 @@ def err_expected_callable_argument : Error< def note_building_builtin_dump_struct_call : Note< "in call to printing function with arguments '(

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-28 Thread Aaron Ballman via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -238,3 +246,69 @@ void f(Scoped1 S1, Scoped2 S2) { } #endif + +#if __cplusplus >= 202000L +class my_string { + char *data; + unsigned size; + +public: + templ

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread Hubert Tong via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: https://github.com/hubert-reinterpretcast edited https://github.com/llvm/llvm-project/pull/135864 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.l

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread Hubert Tong via cfe-commits
=?utf-8?q?F=C3=A9lix?= Cloutier , =?utf-8?q?F=C3=A9lix?= Cloutier Message-ID: In-Reply-To: @@ -10170,6 +10170,8 @@ def warn_format_bool_as_character : Warning< "using '%0' format specifier, but argument has boolean value">, InGroup; def note_format_string_defined : Note<

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: apple-fcloutier wrote: (The broken tests are because I updated the note wording and then did not update the tests. We have ongoing conversation for that so I'll fix that when we have a resolution) https://githu

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: @@ -10170,6 +10170,8 @@ def warn_format_bool_as_character : Warning< "using '%0' format specifier, but argument has boolean value">, InGroup; def note_format_string_defined : Note<"format st

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: apple-fcloutier wrote: I have addressed current feedback, except that I still haven't checked for perf (will follow Aaron's directions on that soon) and I'm still working out what I need to check for `if constex

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier , =?utf-8?q?Félix?= Cloutier Message-ID: In-Reply-To: https://github.com/apple-fcloutier updated https://github.com/llvm/llvm-project/pull/135864 >From 7e15ec24e6de96b9828f13f21099446e55831591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Cloutier?= Date: T

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread via cfe-commits
@@ -6331,26 +6321,79 @@ static StringLiteralCheckType checkFormatStringExpr( } } -return SLCT_NotALiteral; +// try to constant-evaluate the string +break; } default: +// try to constant-evaluate the string +break; + } + + const StringLit

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread via cfe-commits
@@ -10170,6 +10170,8 @@ def warn_format_bool_as_character : Warning< "using '%0' format specifier, but argument has boolean value">, InGroup; def note_format_string_defined : Note<"format string is defined here">; +def note_format_string_evaluated_to : Note< + "format stri

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread via cfe-commits
@@ -17945,15 +17945,36 @@ bool Expr::tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx, static bool EvaluateBuiltinStrLen(const Expr *E, uint64_t &Result, EvalInfo &Info, std::string *StringResult) { - if (!E->getType()->hasPointerRepr

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread Aaron Ballman via cfe-commits
@@ -265,6 +265,9 @@ related warnings within the method body. ``format_matches`` accepts an example valid format string as its third argument. For more information, see the Clang attributes documentation. +- Format string checking now supports the compile-time evaluation of

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread Aaron Ballman via cfe-commits
@@ -6331,26 +6321,79 @@ static StringLiteralCheckType checkFormatStringExpr( } } -return SLCT_NotALiteral; +// try to constant-evaluate the string +break; } default: +// try to constant-evaluate the string +break; + } + + const StringLit

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread Aaron Ballman via cfe-commits
@@ -6331,26 +6321,79 @@ static StringLiteralCheckType checkFormatStringExpr( } } -return SLCT_NotALiteral; +// try to constant-evaluate the string +break; } default: +// try to constant-evaluate the string +break; + } + + const StringLit

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-22 Thread Aaron Ballman via cfe-commits
@@ -3,6 +3,11 @@ // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-unknown-fuchsia %s // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-linux-android %s +// expected-n

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-21 Thread via cfe-commits
@@ -3,6 +3,11 @@ // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-unknown-fuchsia %s // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-linux-android %s +// expected-n

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-21 Thread via cfe-commits
https://github.com/apple-fcloutier edited https://github.com/llvm/llvm-project/pull/135864 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-21 Thread via cfe-commits
@@ -6331,26 +6321,79 @@ static StringLiteralCheckType checkFormatStringExpr( } } -return SLCT_NotALiteral; +// try to constant-evaluate the string +break; } default: +// try to constant-evaluate the string +break; + } + + const StringLit

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-18 Thread via cfe-commits
@@ -5935,8 +5936,14 @@ static void CheckFormatString( llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg, bool IgnoreStringsWithoutSpecifiers); -static const Expr *maybeConstEvalStringLiteral(ASTContext &Context, -

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-18 Thread via cfe-commits
@@ -3,6 +3,11 @@ // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-unknown-fuchsia %s // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-linux-android %s +// expected-n

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-18 Thread via cfe-commits
@@ -6331,26 +6321,79 @@ static StringLiteralCheckType checkFormatStringExpr( } } -return SLCT_NotALiteral; +// try to constant-evaluate the string +break; } default: +// try to constant-evaluate the string +break; + } + + const StringLit

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-18 Thread via cfe-commits
@@ -6331,26 +6321,79 @@ static StringLiteralCheckType checkFormatStringExpr( } } -return SLCT_NotALiteral; +// try to constant-evaluate the string +break; } default: +// try to constant-evaluate the string +break; + } + + const StringLit

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-18 Thread via cfe-commits
@@ -5935,8 +5936,14 @@ static void CheckFormatString( llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg, bool IgnoreStringsWithoutSpecifiers); -static const Expr *maybeConstEvalStringLiteral(ASTContext &Context, -

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-18 Thread via cfe-commits
@@ -5935,8 +5936,14 @@ static void CheckFormatString( llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg, bool IgnoreStringsWithoutSpecifiers); -static const Expr *maybeConstEvalStringLiteral(ASTContext &Context, -

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-18 Thread via cfe-commits
@@ -17945,15 +17945,36 @@ bool Expr::tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx, static bool EvaluateBuiltinStrLen(const Expr *E, uint64_t &Result, cor3ntin wrote: We probably want to rename that method to `EvaluateCString` or something like tha

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-16 Thread via cfe-commits
@@ -3,6 +3,11 @@ // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-unknown-fuchsia %s // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-linux-android %s +// expected-n

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-16 Thread Hubert Tong via cfe-commits
https://github.com/hubert-reinterpretcast edited https://github.com/llvm/llvm-project/pull/135864 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-15 Thread Hubert Tong via cfe-commits
@@ -238,3 +246,69 @@ void f(Scoped1 S1, Scoped2 S2) { } #endif + +#if __cplusplus >= 202000L +class my_string { + char *data; + unsigned size; + +public: + template + constexpr my_string(const char (&literal)[N]) { +data = new char[N+1]; +for (size = 0; size < N; +

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-15 Thread Hubert Tong via cfe-commits
@@ -10170,6 +10170,8 @@ def warn_format_bool_as_character : Warning< "using '%0' format specifier, but argument has boolean value">, InGroup; def note_format_string_defined : Note<"format string is defined here">; +def note_format_string_evaluated_to : Note< + "format stri

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-15 Thread via cfe-commits
@@ -10170,6 +10170,8 @@ def warn_format_bool_as_character : Warning< "using '%0' format specifier, but argument has boolean value">, InGroup; def note_format_string_defined : Note<"format string is defined here">; +def note_format_string_evaluated_to : Note< + "format stri

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-15 Thread via cfe-commits
https://github.com/apple-fcloutier edited https://github.com/llvm/llvm-project/pull/135864 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-15 Thread Shafik Yaghmour via cfe-commits
@@ -3,6 +3,11 @@ // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-unknown-fuchsia %s // RUN: %clang_cc1 -fblocks -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -triple=x86_64-linux-android %s +// expected-n

[clang] [clang] Constant-evaluate format strings as last resort (PR #135864)

2025-04-15 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (apple-fcloutier) Changes I [asked on the forums](https://discourse.llvm.org/t/should-attribute-format-checking-try-to-const-evaluate-strings/85854/4) and people were generally supportive of the idea, so: Clang's -Wformat checker ca