[clang] [CIR] Upstream missing support for vtables and virtual bases (PR #192617)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 10:53:38 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang/test/CIR/CodeGen/virtual-base-cast.cpp clang/lib/CIR/CodeGen/CIRGenClass.cpp clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp clang/lib/CIR/CodeGen/CIRGenModule.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
index 4a4196694..1d1db03b9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
@@ -479,7 +479,9 @@ bool CIRGenItaniumCXXABI::needsVTTParameter(GlobalDecl gd) {
   return false;
 }
 
-mlir::StringAttr CIRGenModule::getOrCreateMetadataIdentifierForType(QualType T, llvm::StringRef suffix) {
+mlir::StringAttr
+CIRGenModule::getOrCreateMetadataIdentifierForType(QualType T,
+                                                   llvm::StringRef suffix) {
   if (auto *fnType = T->getAs<FunctionProtoType>())
     T = getASTContext().getFunctionType(
         fnType->getReturnType(), fnType->getParamTypes(),
@@ -571,7 +573,8 @@ void CIRGenItaniumCXXABI::emitVTableTypeMetadata(const CXXRecordDecl *rd,
                        AP.second.AddressPointIndex,
                    {}};
     llvm::raw_string_ostream stream(N.TypeName);
-    CanQualType T = getMangleContext().getASTContext().getCanonicalTagType(N.Base);
+    CanQualType T =
+        getMangleContext().getASTContext().getCanonicalTagType(N.Base);
     getMangleContext().mangleCanonicalTypeName(T, stream);
     AddressPoints.push_back(std::move(N));
   }
@@ -592,8 +595,10 @@ void CIRGenItaniumCXXABI::emitVTableTypeMetadata(const CXXRecordDecl *rd,
     //    for (unsigned I = 0; I != Comps.size(); ++I) {
     //      if (Comps[I].getKind() != VTableComponent::CK_FunctionPointer)
     //        continue;
-    //      //      llvm::Metadata *MD = CreateMetadataIdentifierForVirtualMemPtrType(
-    //      //          getMangleContext().getASTContext().getMemberPointerType(Comps[I].getFunctionDecl()->getType(),
+    //      //      llvm::Metadata *MD =
+    //      CreateMetadataIdentifierForVirtualMemPtrType(
+    //      //
+    //      getMangleContext().getASTContext().getMemberPointerType(Comps[I].getFunctionDecl()->getType(),
     //      //                                       /*Qualifier=*/std::nullopt,
     //      //                                       AP.Base));
     //      llvm::Metadata *md = nullptr;
@@ -603,14 +608,14 @@ void CIRGenItaniumCXXABI::emitVTableTypeMetadata(const CXXRecordDecl *rd,
 
   // TODO:vtable
 
-//  if (cgm.getCodeGenOpts().VirtualFunctionElimination ||
-//      cgm.getCodeGenOpts().WholeProgramVTables) {
-//    llvm::DenseSet<const CXXRecordDecl *> visited;
-//    llvm::GlobalObject::VCallVisibility typeVis =
-//        GetVCallVisibilityLevel(rd, Visited);
-//    if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
-//      vTable->setVCallVisibilityMetadata(TypeVis);
-//  }
+  //  if (cgm.getCodeGenOpts().VirtualFunctionElimination ||
+  //      cgm.getCodeGenOpts().WholeProgramVTables) {
+  //    llvm::DenseSet<const CXXRecordDecl *> visited;
+  //    llvm::GlobalObject::VCallVisibility typeVis =
+  //        GetVCallVisibilityLevel(rd, Visited);
+  //    if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
+  //      vTable->setVCallVisibilityMetadata(TypeVis);
+  //  }
 
   cgm.errorNYI(rd->getSourceRange(), "emitVTableTypeMetadata");
 }
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h
index fc13f2c5a..52d489f5d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -822,7 +822,8 @@ public:
   /// Emits AMDGPU specific Metadata.
   void emitAMDGPUMetadata();
 
-  mlir::StringAttr getOrCreateMetadataIdentifierForType(QualType T, llvm::StringRef suffix);
+  mlir::StringAttr getOrCreateMetadataIdentifierForType(QualType T,
+                                                        llvm::StringRef suffix);
 
 private:
   // An ordered map of canonical GlobalDecls to their mangled names.

``````````

</details>


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


More information about the cfe-commits mailing list