[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-04-05 Thread via cfe-commits
@@ -158,6 +158,7 @@ Non-comprehensive list of changes in this release - Support parsing the `cc` operand modifier and alias it to the `c` modifier (#GH127719). - Added `__builtin_elementwise_exp10`. +- Added `__builtin_is_modifiable_lvalue` to identify assignable arguments in

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-25 Thread Kees Cook via cfe-commits
kees wrote: Thanks for all the feedback! I'll continue working on this next week (I'm OoO this week). https://github.com/llvm/llvm-project/pull/132524 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listi

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-24 Thread Andrew Pinski via cfe-commits
@@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify %s pinskia wrote: > This feels like a pretty bare bones set of tests, I think we can do better. > > For example, it has been discussed that there should not be side effects, > let's verify that

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread via cfe-commits
@@ -12985,6 +12985,16 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, assert(Src.isInt()); return Success((Src.getInt() & (Alignment - 1)) == 0 ? 1 : 0, E); } + case Builtin::BI__builtin_is_modifiable_lvalue: { +const Expr *Arg = E->getArg(0);

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread via cfe-commits
@@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify %s + Sirraide wrote: > Edit: Perhaps it's wanted to make this intrinsic accept VLA (and report > `false`) and variably-modified types without evaluating the non-constant > array size. That sho

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread via cfe-commits
@@ -0,0 +1,50 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s| FileCheck %s + +void report(int value); Sirraide wrote: Yeah, all of these should just be sema tests using `static_assert`; maybe 1 or 2 codegen tests just to make sure we can emit

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread Timm Baeder via cfe-commits
tbaederr wrote: > > It looks like this is similar to `__builtin_constant_p` - what is the > > proposed behavior wrt. side effects in the evaluated expression? gcc and > > clang disagree about this a lot currently: https://godbolt.org/z/rbneznT9z > > IIUC this intrinsic shouldn't be similar to

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread A. Jiang via cfe-commits
https://github.com/frederick-vs-ja edited https://github.com/llvm/llvm-project/pull/132524 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread A. Jiang via cfe-commits
https://github.com/frederick-vs-ja edited https://github.com/llvm/llvm-project/pull/132524 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread A. Jiang via cfe-commits
frederick-vs-ja wrote: > It looks like this is similar to `__builtin_constant_p` - what is the > proposed behavior wrt. side effects in the evaluated expression? gcc and > clang disagree about this a lot currently: https://godbolt.org/z/rbneznT9z IIUC this intrinsic shouldn't be similar to `__

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread A. Jiang via cfe-commits
https://github.com/frederick-vs-ja edited https://github.com/llvm/llvm-project/pull/132524 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread Andrew Pinski via cfe-commits
@@ -12985,6 +12985,16 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, assert(Src.isInt()); return Success((Src.getInt() & (Alignment - 1)) == 0 ? 1 : 0, E); } + case Builtin::BI__builtin_is_modifiable_lvalue: { +const Expr *Arg = E->getArg(0);

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread A. Jiang via cfe-commits
@@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify %s + frederick-vs-ja wrote: Would it make more sense to use `_Static_assert(__builtin_is_modifiable_lvalue(...), "")`? Also, I think it would be valuable to cover more types. N1570 6.3.2.1/1,

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread Andrew Pinski via cfe-commits
pinskia wrote: Note the GCC implementtion of __builtin_is_modifiable_lvalue that I have implemented (unlike __builtin_constant_p which in some but not all cases) throws away the full expression that is inside __builtin_is_modifiable_lvalue since it is fully implemented in the parser rather tha

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread Kees Cook via cfe-commits
kees wrote: > It looks like this is similar to `__builtin_constant_p` - what is the > proposed behavior wrt. side effects in the evaluated expression? gcc and > clang disagree about this a lot currently: https://godbolt.org/z/rbneznT9z It is intended to have no side-effects. I followed the sam

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-22 Thread Timm Baeder via cfe-commits
tbaederr wrote: > > It looks like this is similar to `__builtin_constant_p` - what is the > > proposed behavior wrt. side effects in the evaluated expression? gcc and > > clang disagree about this a lot currently: https://godbolt.org/z/rbneznT9z > > It is intended to have no side-effects. I fo

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-21 Thread Timm Baeder via cfe-commits
tbaederr wrote: It looks like this is similar to `__builtin_constant_p` - what is the proposed behavior wrt. side effects in the evaluated expression? gcc and clang disagree about this a lot currently: https://godbolt.org/z/rbneznT9z https://github.com/llvm/llvm-project/pull/132524 ___

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-21 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr deleted https://github.com/llvm/llvm-project/pull/132524 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-21 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kees Cook (kees) Changes Provide a way to introspect expressions to see if they are assignable, which becomes very useful in macros that want to perform additional work on arguments that are lvalues. GCC is adding this builtin as well: h

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-21 Thread Timm Baeder via cfe-commits
@@ -964,6 +964,13 @@ def IsConstantEvaluated : LangBuiltin<"CXX_LANG"> { let Prototype = "bool()"; } +def IsLValue : Builtin { + let Spellings = ["__builtin_is_modifiable_lvalue"]; + let Attributes = [NoThrow, CustomTypeChecking, UnevaluatedArguments, +

[clang] [Clang] Introduce __builtin_is_modifiable_lvalue() (PR #132524)

2025-03-21 Thread Kees Cook via cfe-commits
https://github.com/kees created https://github.com/llvm/llvm-project/pull/132524 Provide a way to introspect expressions to see if they are assignable, which becomes very useful in macros that want to perform additional work on arguments that are lvalues. GCC is adding this builtin as well: ht