[clang] [C] Add diagnostic + attr for unterminated strings (PR #137829)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 29 09:03:56 PDT 2025


================
@@ -9294,3 +9294,18 @@ Declares that a function potentially allocates heap memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def NonStringDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The ``nonstring`` attribute can be applied to the declaration of a variable or
+a field whose type is a character array to specify that the character array is
+not intended to behave like a null-terminated string. This will silence
+diagnostics with code like:
+
+.. code-block:: c
+
+  char BadStr[3] = "foo"; // No space for the null terminator, diagnosed
+  __attribute__((nonstring)) char NotAStr[3] = "foo"; // Not diagnosed
+  }];
+}
----------------
AaronBallman wrote:

Fixed

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


More information about the cfe-commits mailing list