[PATCH] D155641: [-Wunsafe-buffer-usage] Do not assert that function parameters have names.

Ziqing Luo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 19 14:14:47 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ziqingluo-90 marked an inline comment as done.
Closed by commit rG4b5f17e008c6: [-Wunsafe-buffer-usage] Do not assert that function parameters have names (authored by ziqingluo-90).

Changed prior to commit:
  https://reviews.llvm.org/D155641?vs=541723&id=542188#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155641/new/

https://reviews.llvm.org/D155641

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp


Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
===================================================================
--- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
@@ -156,4 +156,9 @@
   if (++MyName){}
 }
 
+// CHECK-NOT: fix-it:{{.*}}:
+void parmHasNoName(int *p, int *) { // cannot fix the function because there is one parameter has no name.
+  p[5] = 5;
+}
+
 #endif
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===================================================================
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1885,9 +1885,12 @@
       const ParmVarDecl *Parm = FD->getParamDecl(i);
 
       if (Parm->isImplicit())
-        continue;
-      assert(Parm->getIdentifier() &&
-             "A parameter of a function definition has no name");
+        continue;      
+      // FIXME: If a parameter has no name, it is unused in the
+      // definition. So we could just leave it as it is.
+      if (!Parm->getIdentifier()) 
+	// If a parameter of a function definition has no name:
+        return std::nullopt;
       if (i == ParmIdx)
         // This is our spanified paramter!
         SS << NewTypeText.str() << "(" << Parm->getIdentifier()->getName().str() << ", "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155641.542188.patch
Type: text/x-patch
Size: 1358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230719/f5e5f018/attachment-0001.bin>


More information about the cfe-commits mailing list