Skip to content

[NFC][Clang][Interp] Add more test for __builtin_os_log_format_buffer_size #100566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

yronglin
Copy link
Contributor

No description provided.

@yronglin yronglin requested a review from tbaederr as a code owner July 25, 2024 13:38
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

@llvm/pr-subscribers-clang

Author: None (yronglin)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/100566.diff

1 Files Affected:

  • (modified) clang/test/AST/Interp/builtins.cpp (+5)
diff --git a/clang/test/AST/Interp/builtins.cpp b/clang/test/AST/Interp/builtins.cpp
index a74b68bb9d89b..9b2b20773be58 100644
--- a/clang/test/AST/Interp/builtins.cpp
+++ b/clang/test/AST/Interp/builtins.cpp
@@ -31,3 +31,8 @@ constexpr bool assume() {
   return true;
 }
 static_assert(assume(), "");
+
+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);
+  static_assert(len > 0, "Expect len > 0");
+}

@tbaederr
Copy link
Contributor

Did you check locally that this works with sanitizers enabled?

@yronglin
Copy link
Contributor Author

Did you check locally that this works with sanitizers enabled?

Yeah, the memory leak issue in #99895 seems to be caused by other floating point builtins in clang/test/CodeGen/builtins.c. The new examples added in this PR do not have any floating point operations. And I've verifyed in my local with address sanitizer enabled.
Clang build with:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;compiler-rt;libunwind" -DLLVM_TARGETS_TO_BUILD="X86;AArch64" -DCMAKE_C_FLAGS="-fsanitize=address" -DCMAKE_CXX_FLAGS="-fsanitize=address" -DLLVM_USE_SANITIZER=Address ../llvm-project/llvm
➜  test cat os_format.cpp 
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);
  static_assert(len > 0, "Expect len > 0");
}
➜  test ../rel/bin/clang++ -c  -fexperimental-new-constant-interpreter ./os_format.cpp
➜  test 

@yronglin yronglin merged commit 8d4cb92 into llvm:main Jul 26, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants