[PATCH] D145123: Call MarkVirtualMembersReferenced on an actual class definition

Stephan Bergmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 1 14:46:43 PST 2023


sberg created this revision.
sberg added reviewers: doug.gregor, aaron.ballman.
sberg added a project: clang.
Herald added a project: All.
sberg requested review of this revision.

...rather than on potentially just a declaration.
Without the fix, the newly added `clang/test/SemaCXX/warn-undefined-internal.cpp` failed with

  error: 'warning' diagnostics expected but not seen:
    File /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp Line 12 (directive at /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:13): function 'test2()::S::f' has internal linkage but is not defined
  error: 'note' diagnostics expected but not seen:
    File /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp Line 14 (directive at /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:15): used here

(I ran into this when two LibreOffice Clang plugins produced false positive warnings, as they relied on `Decl::isReferenced()` returning true for such virtual member functions of local classes.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145123

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/warn-undefined-internal.cpp


Index: clang/test/SemaCXX/warn-undefined-internal.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/warn-undefined-internal.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -Wundefined-internal -verify %s
+
+void test1() {
+  struct S { virtual void f(); };
+  // expected-warning at -1{{function 'test1()::S::f' has internal linkage but is not defined}}
+  S s;
+  // expected-note at -1{{used here}}
+}
+
+void test2() {
+  struct S;
+  struct S { virtual void f(); };
+  // expected-warning at -1{{function 'test2()::S::f' has internal linkage but is not defined}}
+  S s;
+  // expected-note at -1{{used here}}
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -17975,7 +17975,7 @@
   // immediately. For all other classes, we mark their virtual members
   // at the end of the translation unit.
   if (Class->isLocalClass())
-    MarkVirtualMembersReferenced(Loc, Class);
+    MarkVirtualMembersReferenced(Loc, Class->getDefinition());
   else
     VTableUses.push_back(std::make_pair(Class, Loc));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145123.501669.patch
Type: text/x-patch
Size: 1192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230301/6cfe4da6/attachment-0001.bin>


More information about the cfe-commits mailing list