[clang] [Clang][Interp] `__builtin_os_log_format_buffer_size` should be an unevaluated builtin (PR #99895)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 22 09:48:47 PDT 2024


https://github.com/yronglin created https://github.com/llvm/llvm-project/pull/99895

Follow the current behavior of constant evaluator, `__builtin_os_log_format_buffer_size` should be an unevaluated builtin.

The following code is well-formed:
```
void test_builtin_os_log(void *buf, int i, const char *data) {
  constexpr int len = __builtin_os_log_format_buffer_size("%d %{public}s %{private}.16P", i, data, data);
}
```

>From fa035f21088de9b21f9c335b4f4699a98fcbfc65 Mon Sep 17 00:00:00 2001
From: yronglin <yronglin777 at gmail.com>
Date: Tue, 23 Jul 2024 00:44:56 +0800
Subject: [PATCH] [Clang][Interp] __builtin_os_log_format_buffer_size should be
 an unevaluated builtin

Signed-off-by: yronglin <yronglin777 at gmail.com>
---
 clang/lib/AST/Interp/ByteCodeEmitter.cpp | 3 ++-
 clang/test/CodeGen/builtins.c            | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index a3d4c7d7392da..fee4432a8f661 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -27,7 +27,8 @@ using namespace clang::interp;
 /// Similar information is available via ASTContext::BuiltinInfo,
 /// but that is not correct for our use cases.
 static bool isUnevaluatedBuiltin(unsigned BuiltinID) {
-  return BuiltinID == Builtin::BI__builtin_classify_type;
+  return BuiltinID == Builtin::BI__builtin_classify_type ||
+         BuiltinID == Builtin::BI__builtin_os_log_format_buffer_size;
 }
 
 Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
diff --git a/clang/test/CodeGen/builtins.c b/clang/test/CodeGen/builtins.c
index b41efb59e61db..1f998236501d2 100644
--- a/clang/test/CodeGen/builtins.c
+++ b/clang/test/CodeGen/builtins.c
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -emit-llvm -o %t %s
 // RUN: not grep __builtin %t
 // RUN: %clang_cc1 -emit-llvm -triple x86_64-darwin-apple -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-darwin-apple -fexperimental-new-constant-interpreter -o - %s | FileCheck %s
 
 int printf(const char *, ...);
 



More information about the cfe-commits mailing list