[clang] clang_EvalResult_getAsCXString impl (PR #134551)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 22 06:15:51 PST 2026


================
@@ -25,14 +25,19 @@ enum CXStringFlag {
   /// CXString contains a 'const char *' that it doesn't own.
   CXS_Unmanaged,
 
-  /// CXString contains a 'const char *' that it allocated with malloc().
-  CXS_Malloc,
+  /// CXString contains a 'CStringImpl' that it allocated with malloc().
+  CXS_MallocWithSize,
 
   /// CXString contains a CXStringBuf that needs to be returned to the
   /// CXStringPool.
   CXS_StringBuf
 };
 
+struct CStringImpl {
+  size_t length;
+  char buffer[sizeof(length)];
----------------
dingxiangfei2009 wrote:

Hey @xTachyon, thank you so much for working on this!

I gave it a spin, rebased it and it mostly works. I also patched up some issues in `c-index-test` which is very intrusive. For this you can check `duplicateCXString` function.

Here is a patch after the rebasing. Would you like to take a look? 
https://gist.github.com/dingxiangfei2009/cbe9d7debcee6f3c32d507f8b2adf1c0

https://github.com/llvm/llvm-project/pull/134551


More information about the cfe-commits mailing list