[clang] [CIR] Emit the object of an inherited static call operator (PR #248242)

Adam Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 4 12:55:32 PST 2026


================
@@ -2695,13 +2695,21 @@ RValue CIRGenFunction::emitCall(clang::QualType calleeTy,
   // `static operator[]`) produce a CXXOperatorCallExpr whose first argument
   // is the object expression even though the operator is static.  Emit the
   // object for its side effects and drop it before walking the parameter
-  // arguments.
+  // arguments.  When the object's type is not the operator's unqualified
+  // class and the address spaces match, Sema converts it with a CK_NoOp
+  // cast, which for an inherited operator changes the record type without
+  // a derived-to-base conversion.  The object is discarded, so emit it
+  // without that cast rather than retype its address.
   auto arguments = e->arguments();
   if (const auto *oce = dyn_cast<CXXOperatorCallExpr>(e)) {
     if (const auto *md =
             dyn_cast_if_present<CXXMethodDecl>(oce->getCalleeDecl());
         md && md->isStatic()) {
-      emitIgnoredExpr(e->getArg(0));
+      const Expr *object = e->getArg(0);
+      if (const auto *ice = dyn_cast<ImplicitCastExpr>(object);
+          ice && ice->getCastKind() == CK_NoOp)
+        object = ice->getSubExpr();
----------------
adams381 wrote:

Done.

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


More information about the cfe-commits mailing list