[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/3] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/3] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

>From 5806a5a17631587995d75f0ea5ffe016fac809b8 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 12 Apr 2024 14:25:38 -0700
Subject: [PATCH 3/3] Update clang/docs/LanguageExtensions.rst

Co-authored-by: Aaron Ballman 
---
 clang/docs/LanguageExtensions.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 9078f1c76761bd..a4483ef4f76d00 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3507,7 +3507,7 @@ precedence.
 ``true``, allowing all checks.
 
 Parameter ``kind`` is a string literal representing a user selected kind for
-guarded check. It's unused now. It will enable kind specific lowering in 
future.
+guarded check. It's unused now. It will enable kind-specific lowering in 
future.
 E.g. a higher hotness cutoff can be used for more expensive kind of check.
 
 Query for this feature with ``__has_builtin(__builtin_allow_runtime_check)``.

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

AaronBallman wrote:

> It needs to be compiler time lowered, so I think it should literals.

In that case, I think we want *constant expression* not just literal, right? 
e.g.,
```
constexpr const char *name = "name of check";
if (__builtin_allow_runtime_check(name)) {
}
```
is still able to be lowered at compile time. The reason I ask is because I'm 
thinking about template metaprogramming cases where you might want to do 
something along the lines of:
```
template 
struct S {
  void mem_fun() {
if (__builtin_allow_runtime_check(Ty::check_name) && stuff) {
}
  }
};
```
but maybe this is not a compelling use case? I don't insist on constant 
expression support, more just trying to verify that we support the expected 
usage patterns.

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3464,6 +3464,54 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``
+-
+
+``__builtin_allow_runtime_check`` return true if the check at the current
+program location should be executed. It is expected to be used to implement
+``assert`` like checks which can be safely removed by optimizer.
+
+**Syntax**:
+
+.. code-block:: c++
+
+bool __builtin_allow_runtime_check(const char* kind)
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_allow_runtime_check("mycheck") && !ExpensiveCheck()) {
+ abort();
+  }
+
+**Description**
+
+``__builtin_allow_runtime_check`` is lowered to ` ``llvm.allow.runtime.check``
+`_
+builtin.
+
+The ``__builtin_allow_runtime_check()`` is expected to be used with control
+flow conditions such as in ``if`` to guard expensive runtime checks. The
+specific rules for selecting permitted checks can differ and are controlled by
+the compiler options.
+
+Flags to control checks:
+* ``-mllvm -lower-allow-check-percentile-cutoff-hot=N`` where N is PGO hotness
+cutoff in range ``[0, 99]`` to disallow checks in hot code.
+* ``-mllvm -lower-allow-check-random-rate=P`` where P is number in range
+``[0.0, 1.0]`` representation probability of keeping a check.
+* If both flags are specified, ``-lower-allow-check-random-rate`` takes
+precedence.
+* If none is specified, ``__builtin_allow_runtime_check`` is lowered as
+``true``, allowing all checks.
+
+Parameter ``kind`` is a string literal representing a user selected kind for
+guarded check. It's unused now. It will enable kind specific lowering in 
future.

AaronBallman wrote:

```suggestion
guarded check. It's unused now. It will enable kind-specific lowering in future.
```

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

vitalybuka wrote:

I've started RFC, as @efriedma-quic suggested
https://discourse.llvm.org/t/rfc-introduce-new-clang-builtin-builtin-allow-runtime-check/78281

It needs to be compiler time lowered, so I think it should literals. 



https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits


@@ -3233,6 +3233,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if (BuiltinCountZeroBitsGeneric(*this, TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_allow_runtime_check: {
+Expr *Arg = TheCall->getArg(0);
+// Check if the argument is a string literal.
+if (!isa(Arg->IgnoreParenImpCasts())) {

vitalybuka wrote:

My interest is in using this feature to implement `assert` like macros which 
will be enabled in cold code, and optimized out in hot.  E.g. MY_ASSERT1, 
MY_ASSERT2... 
Each macro can provide own kind as literal. Number of different kinds is 
supposed to be limited. So literal looks enough for me.
We can relax in the future, restricting could be harder.

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

AaronBallman wrote:

The docs aren't particularly clear to me -- why would the check at the current 
program location ever NOT be executed? What strings can be passed in? What 
compiler options impact it? Will it only accept string literals or are runtime 
values fine?

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3233,6 +3233,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if (BuiltinCountZeroBitsGeneric(*this, TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_allow_runtime_check: {
+Expr *Arg = TheCall->getArg(0);
+// Check if the argument is a string literal.
+if (!isa(Arg->IgnoreParenImpCasts())) {

AaronBallman wrote:

This might be a reasonable restriction, but consider other cases like: 
`constexpr` variable of string type, `constexpr` function call that returns a 
`const char *`, `_Generic` that results in a string constant, etc. Would those 
be reasonable to support?

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

vitalybuka wrote:

I assume clang/docs/LanguageExtensions.rst counts as 
https://github.com/llvm/llvm-project/blob/main/clang/CodeOwners.rst#all-parts-of-clang-not-covered-by-someone-else

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Eli Friedman via llvm-branch-commits

efriedma-quic wrote:

I think it's worth re-posting the builtin as a separate RFC on Discourse, since 
the original RFC hadn't settled on the exact design for the clang builtin 
you're using here.

Code changes look fine.

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

vitalybuka wrote:

@MaskRay @nikic  @efriedma-quic  Any comments?

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic commented:

This looks very reasonable to me, but I'm not a clang reviewer...

https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Thurston Dang via llvm-branch-commits

https://github.com/thurstond approved this pull request.


https://github.com/llvm/llvm-project/pull/87568
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits