[clang] [analyzer] Confidently inline final methods (PR #224070)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 16 12:00:16 PDT 2026


================
@@ -798,10 +798,18 @@ RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {
   if (!MD->isVirtual())
     return AnyFunctionCall::getRuntimeDefinition();
 
+  // If the method is final or declared in a final class, we can inline it.
+  if (MD->hasAttr<FinalAttr>() || MD->getParent()->hasAttr<FinalAttr>())
+    return AnyFunctionCall::getRuntimeDefinition();
+
   auto [RD, CanBeSubClass] = getDeclForDynamicType();
   if (!RD || !RD->hasDefinition())
     return {};
 
+  // We can confidently inline a method called on an object with final type.
+  if (RD->hasAttr<FinalAttr>())
+    CanBeSubClass = false;
----------------
NagyDonat wrote:

In the interesting case when the dynamic type of the object is not the static type, but a subclass of it, then that subclass must already be defined (to be able to specify that it is the subclass of another class), and I'm pretty sure that in this case the record declaration `RD` is the definition.  

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


More information about the cfe-commits mailing list