[clang] [clang-repl] Expose RuntimeInterfaceBuilder to allow customization (PR #83126)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 28 02:18:55 PST 2024


Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gränitz?= <stefan.graenitz at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/83126 at github.com>


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 841a4168addba6931114e81d446c35114208eda2 f069bafd8a3c597934f17236b530ffbcfe8d0f92 -- clang/include/clang/Interpreter/Interpreter.h clang/lib/Interpreter/Interpreter.cpp
``````````

</details>

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

``````````diff
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h
index 0aae00ddd2..5c2741a19d 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -77,7 +77,8 @@ class RuntimeInterfaceBuilder {
 public:
   virtual ~RuntimeInterfaceBuilder() = default;
 
-  using AddCallToRuntimeInterfaceFunction = ExprResult(RuntimeInterfaceBuilder *Builder, Expr *, ArrayRef<Expr *>);
+  using AddCallToRuntimeInterfaceFunction =
+      ExprResult(RuntimeInterfaceBuilder *Builder, Expr *, ArrayRef<Expr *>);
   virtual AddCallToRuntimeInterfaceFunction *getCallCallback() = 0;
 };
 
@@ -102,7 +103,8 @@ class Interpreter {
 protected:
   Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err);
 
-  RuntimeInterfaceBuilder::AddCallToRuntimeInterfaceFunction* AddCallToRuntimeInterface = nullptr;
+  RuntimeInterfaceBuilder::AddCallToRuntimeInterfaceFunction
+      *AddCallToRuntimeInterface = nullptr;
 
   void finalizeInitPTUStack();
 
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index a1c577bd28..7bd4691224 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -647,7 +647,8 @@ public:
       : Interp(Interp), Ctx(C), S(S) {}
 
   AddCallToRuntimeInterfaceFunction *getCallCallback() override {
-    return [](RuntimeInterfaceBuilder *Builder, Expr *E, ArrayRef<Expr *> FixedArgs) -> ExprResult {
+    return [](RuntimeInterfaceBuilder *Builder, Expr *E,
+              ArrayRef<Expr *> FixedArgs) -> ExprResult {
       auto *B = static_cast<InProcessRuntimeInterfaceBuilder *>(Builder);
 
       // Get rid of ExprWithCleanups.
@@ -669,8 +670,8 @@ public:
         Ty = B->Ctx.getLValueReferenceType(Ty);
       }
 
-      Expr *TypeArg =
-          CStyleCastPtrExpr(B->S, B->Ctx.VoidPtrTy, (uintptr_t)Ty.getAsOpaquePtr());
+      Expr *TypeArg = CStyleCastPtrExpr(B->S, B->Ctx.VoidPtrTy,
+                                        (uintptr_t)Ty.getAsOpaquePtr());
       // The QualType parameter `OpaqueType`, represented as `void*`.
       Visitor.Args.push_back(TypeArg);
 
@@ -683,11 +684,14 @@ public:
         // __clang_Interpreter_SetValueWithAlloc.
         ExprResult AllocCall = B->S.ActOnCallExpr(
             /*Scope=*/nullptr,
-            B->Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::WithAlloc],
+            B->Interp
+                .getValuePrintingInfo()[Interpreter::InterfaceKind::WithAlloc],
             E->getBeginLoc(), Visitor.Args, E->getEndLoc());
-        assert(!AllocCall.isInvalid() && "Can't create runtime interface call!");
+        assert(!AllocCall.isInvalid() &&
+               "Can't create runtime interface call!");
 
-        TypeSourceInfo *TSI = B->Ctx.getTrivialTypeSourceInfo(Ty, SourceLocation());
+        TypeSourceInfo *TSI =
+            B->Ctx.getTrivialTypeSourceInfo(Ty, SourceLocation());
 
         // Force CodeGen to emit destructor.
         if (auto *RD = Ty->getAsCXXRecordDecl()) {
@@ -706,13 +710,14 @@ public:
           Expr *Args[] = {E, AllocCall.get(), ArrSizeExpr};
           return B->S.ActOnCallExpr(
               /*Scope *=*/nullptr,
-              B->Interp
-                  .getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray],
+              B->Interp.getValuePrintingInfo()
+                  [Interpreter::InterfaceKind::CopyArray],
               SourceLocation(), Args, SourceLocation());
         }
         Expr *Args[] = {
             AllocCall.get(),
-            B->Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]};
+            B->Interp
+                .getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]};
         ExprResult CXXNewCall = B->S.BuildCXXNew(
             E->getSourceRange(),
             /*UseGlobal=*/true, /*PlacementLParen=*/SourceLocation(), Args,
@@ -721,16 +726,17 @@ public:
             E->getSourceRange(), E);
 
         assert(!CXXNewCall.isInvalid() &&
-              "Can't create runtime placement new call!");
+               "Can't create runtime placement new call!");
 
         return B->S.ActOnFinishFullExpr(CXXNewCall.get(),
-                                    /*DiscardedValue=*/false);
+                                        /*DiscardedValue=*/false);
       }
         // __clang_Interpreter_SetValueNoAlloc.
       case Interpreter::InterfaceKind::NoAlloc: {
         return B->S.ActOnCallExpr(
             /*Scope=*/nullptr,
-            B->Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NoAlloc],
+            B->Interp
+                .getValuePrintingInfo()[Interpreter::InterfaceKind::NoAlloc],
             E->getBeginLoc(), Visitor.Args, E->getEndLoc());
       }
       default:
@@ -770,7 +776,8 @@ Expr *Interpreter::SynthesizeExpr(Expr *E) {
     AddCallToRuntimeInterface = RuntimeIB->getCallCallback();
   }
 
-  assert(AddCallToRuntimeInterface && "We don't have a runtime interface for pretty print!");
+  assert(AddCallToRuntimeInterface &&
+         "We don't have a runtime interface for pretty print!");
 
   // Create parameter `ThisInterp`.
   auto *ThisInterp = CStyleCastPtrExpr(S, Ctx.VoidPtrTy, (uintptr_t)this);
@@ -779,7 +786,8 @@ Expr *Interpreter::SynthesizeExpr(Expr *E) {
   auto *OutValue = CStyleCastPtrExpr(S, Ctx.VoidPtrTy, (uintptr_t)&LastValue);
 
   // Build `__clang_Interpreter_SetValue*` call.
-  ExprResult Result = AddCallToRuntimeInterface(RuntimeIB.get(), E, {ThisInterp, OutValue});
+  ExprResult Result =
+      AddCallToRuntimeInterface(RuntimeIB.get(), E, {ThisInterp, OutValue});
 
   // It could fail, like printing an array type in C. (not supported)
   if (Result.isInvalid())

``````````

</details>


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


More information about the cfe-commits mailing list