[clang] [C] Allow __attribute__((nonstring)) on multidimensional arrays (PR #138133)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu May 1 07:27:46 PDT 2025


================
@@ -261,8 +261,21 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
           << Str->getSourceRange();
     else if (StrLength - 1 == ArrayLen) {
       // If the entity being initialized has the nonstring attribute, then
-      // silence the "missing nonstring" diagnostic.
-      if (const ValueDecl *D = Entity.getDecl();
+      // silence the "missing nonstring" diagnostic. If there's no entity,
+      // check whether we're initializing an array of arrays; if so, walk the
+      // parents to find an entity.
+      auto FindCorrectEntity = [](const InitializedEntity &Entity) {
+        const ValueDecl *Ret = nullptr;
----------------
erichkeane wrote:

This feels really difficult to reason about.  Best I can tell the intent here is to search for the first 'decl' in the entity chain, but only going 'up' if we are in an array.  BTW, should this check `InitializedEntity::EntityKind` instead?  

It seems to handle what it should, and I'm not sure I can come up with clearer though.  

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


More information about the cfe-commits mailing list