[clang] clang_EvalResult_getAsCXString impl (PR #134551)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 1 13:24:53 PDT 2025


================
@@ -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)];
----------------
AaronBallman wrote:

This not being in C++ is a good point. Given that this is purely internal, maybe we want to just have the size field and then tail-allocate the buffer? We could probably even use `llvm::TrailingObjects` given that this all lives in a C++ file?

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


More information about the cfe-commits mailing list