https://github.com/gburgessiv created 
https://github.com/llvm/llvm-project/pull/224424

Android's code coverage runtime started using these functions recently, and I 
noticed they were undocumented. Since
`clang/docs/SourceBasedCodeCoverage.md` tries to briefly mention similar 
functions, add these there for increased discoverability.

An LLM was used to take a first pass at this; I reviewed and refined.

>From 6e1777c1f9b1f3c51c5f76f657c22ccd0ac5f7d5 Mon Sep 17 00:00:00 2001
From: George Burgess IV <[email protected]>
Date: Thu, 17 Sep 2026 10:48:40 -0600
Subject: [PATCH] [docs][clang] Document additional public profile runtime APIs

Android's code coverage runtime started using these functions recently,
and I noticed they were undocumented. Since
`clang/docs/SourceBasedCodeCoverage.md` tries to briefly mention similar
functions, add these there for increased discoverability.

An LLM was used to take a first pass at this; I reviewed and refined.
---
 clang/docs/SourceBasedCodeCoverage.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/clang/docs/SourceBasedCodeCoverage.md 
b/clang/docs/SourceBasedCodeCoverage.md
index 8d43c5cfa360c..9f94e81a58288 100644
--- a/clang/docs/SourceBasedCodeCoverage.md
+++ b/clang/docs/SourceBasedCodeCoverage.md
@@ -351,6 +351,10 @@ without using static initializers, do this manually:
   pass a filename pattern string to `void __llvm_profile_set_filename(char
   *)`. These calls can be placed anywhere so long as they precede all calls
   to `__llvm_profile_write_file`.
+  - Note: You can forward-declare and call `const char
+    *__llvm_profile_get_filename(void)` to get the currently configured
+    filename. This returns a `malloc`-allocated string that must be passed to
+    `free()` (or `""` on allocation failure).
 - Forward-declare `int __llvm_profile_write_file(void)` and call it to write
   out a profile. This function returns 0 on success, and a non-zero value
   otherwise. Calling this function multiple times appends profile data to an
@@ -381,6 +385,20 @@ under your control:
   profiled. This is only useful if there is some setup that should be excluded
   from the profile.
 
+You can also merge raw profile data from an existing buffer into the current
+process's in-memory counters:
+
+- Forward-declare `int __llvm_profile_check_compatibility(const char
+  *ProfileData, uint64_t ProfileSize)` and call it to verify that the raw
+  profile in `ProfileData` (of size `ProfileSize` bytes) was generated by the
+  same binary and structurally matches the in-process counters and bitmaps. 
This
+  function returns 0 on success, and a non-zero value otherwise.
+- Forward-declare `int __llvm_profile_merge_from_buffer(const char 
*ProfileData,
+  uint64_t ProfileSize)` and call it to merge the raw profile in `ProfileData`
+  into the in-process counters and bitmaps. **The caller is expected to have
+  verified compatibility beforehand.** This function returns 0 on success, and 
a
+  non-zero value if the profile data is invalid or corrupted.
+
 In C++ files, declare these as `extern "C"`.
 
 ## Collecting coverage reports for the llvm project

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to