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

Vitaly Buka via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 10 15:09:41 PDT 2024


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 <vitalybuka at google.com>
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<Value *> OBD("separate_storage", Values);
+    Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+    return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
     StringRef Kind =
         cast<StringLiteral>(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
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<StringLiteral>(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..b6568610000755 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}}



More information about the llvm-branch-commits mailing list