[clang][Interp][NFC] Unify Call() implementations
authorTimm Bäder <tbaeder@redhat.com>
Thu, 13 Oct 2022 15:17:44 +0000 (17:17 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Sat, 22 Oct 2022 08:32:05 +0000 (10:32 +0200)
The type parameter we used to pass to call() was unused. Use the same
implementation for void and value-returning function calls.

clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td

index c785d3c..a5969bb 100644 (file)
@@ -786,7 +786,7 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) {
         return false;
     }
 
-    return this->emitCallVoid(Func, Initializer);
+    return this->emitCall(Func, Initializer);
   } else if (const auto *InitList = dyn_cast<InitListExpr>(Initializer)) {
     const Record *R = getRecord(InitList->getType());
 
@@ -982,18 +982,10 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
         return false;
     }
 
-    // Primitive return value, just call it.
-    if (T)
-      return this->emitCall(*T, Func, E);
-
-    // Void Return value, easy.
-    if (ReturnType->isVoidType())
-      return this->emitCallVoid(Func, E);
-
-    // Non-primitive return value with Return Value Optimization,
-    // we already have a pointer on the stack to write the result into.
-    if (Func->hasRVO())
-      return this->emitCallVoid(Func, E);
+    // In any case call the function. The return value will end up on the stack and
+    // if the function has RVO, we already have the pointer on the stack to write
+    // the result into.
+    return this->emitCall(Func, E);
   } else {
     assert(false && "We don't support non-FunctionDecl callees right now.");
   }
index dc0e15c..22e8695 100644 (file)
@@ -102,17 +102,6 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
   return ReturnValue<T>(S.Stk.pop<T>(), Result);
 }
 
-bool EvalEmitter::emitCallVoid(const Function *Func, const SourceInfo &Info) {
-  APValue VoidResult;
-  InterpFrame *before = S.Current;
-  (void)before;
-  S.Current = new InterpFrame(S, Func, {});
-  bool Success = Interpret(S, VoidResult);
-  assert(VoidResult.isAbsent());
-  assert(S.Current == before);
-  return Success;
-}
-
 bool EvalEmitter::emitRetVoid(const SourceInfo &Info) { return true; }
 
 bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
index ad94f2a..e9bda12 100644 (file)
@@ -53,15 +53,6 @@ static bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   return true;
 }
 
-static bool CallVoid(InterpState &S, CodePtr &PC, const Function *Func) {
-  APValue VoidResult;
-  S.Current = new InterpFrame(S, const_cast<Function *>(Func), PC);
-  bool Success = Interpret(S, VoidResult);
-  assert(VoidResult.isAbsent());
-
-  return Success;
-}
-
 static bool RetVoid(InterpState &S, CodePtr &PC, APValue &Result) {
   S.CallStackDepth--;
 
index 42dff23..73b1bc9 100644 (file)
@@ -1106,8 +1106,7 @@ inline bool ExpandPtr(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
-template <PrimType Name, class T = typename PrimConv<Name>::T>
-static bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
+inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
   auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC);
   if (Func->hasThisPointer()) {
     if (!CheckInvoke(S, PC, NewFrame->getThis())) {
index 52591da..f9d2a59 100644 (file)
@@ -160,16 +160,8 @@ def NoRet : Opcode {}
 
 def Call : Opcode {
   let Args = [ArgFunction];
-  let Types = [AllTypeClass];
-  let ChangesPC = 1;
-  let HasGroup = 1;
-}
-
-def CallVoid : Opcode {
-  let Args = [ArgFunction];
   let Types = [];
   let ChangesPC = 1;
-  let HasCustomEval = 1;
 }
 
 //===----------------------------------------------------------------------===//