[Openmp-commits] [clang-tools-extra] [mlir] [compiler-rt] [libcxx] [lld] [flang] [libcxxabi] [libc] [lldb] [libunwind] [openmp] [clang] [llvm] [clang] static operators should evaluate object argument (PR #68485)

Tianlan Zhou via Openmp-commits openmp-commits at lists.llvm.org
Tue Jan 30 06:21:35 PST 2024


================
@@ -5865,10 +5867,24 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee
         break;
       }
     }
+
+    if (const auto *MD =
+            dyn_cast_if_present<CXXMethodDecl>(OCE->getCalleeDecl());
+        MD && MD->isStatic())
+      StaticOperator = true;
   }
 
-  EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), E->arguments(),
-               E->getDirectCallee(), /*ParamsToSkip*/ 0, Order);
+  if (StaticOperator) {
+    // If we're calling a static operator, we need to emit the object argument
+    // and ignore it.
+    EmitIgnoredExpr(E->getArg(0));
+
+    EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType),
+                 drop_begin(E->arguments(), 1), E->getDirectCallee(),
+                 /*ParamsToSkip=*/0, Order);
+  } else
+    EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), E->arguments(),
+                 E->getDirectCallee(), /*ParamsToSkip=*/0, Order);
----------------
SuperSodaSea wrote:

I tried to use `ParamsToSkip` before, and got assertion error for type mismatch in test **cxx2b-static-call-operator.cpp** & **cxx2b-static-subscript-operator.cpp**:

```
# | Assertion failed: (isGenericMethod || Ty->isVariablyModifiedType() || Ty.getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType(Ty.getNonReferenceType()) .getTypePtr() == getContext().getCanonicalType((*Arg)->getType()).getTypePtr()) && "type mismatch in call argument!", file .../llvm-project/clang/lib/CodeGen/CGCall.cpp, line 4470
```

https://github.com/llvm/llvm-project/blob/22be6a2c66fceead40cf7561806bdaf424cd3c71/clang/lib/CodeGen/CGCall.cpp#L4463-L4470

So I have to use `drop_begin` instead.

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


More information about the Openmp-commits mailing list