[clang] f01d45c - Reland "[clang-repl] Allow passing in code as positional arguments."

Vassil Vassilev via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 10 11:58:24 PDT 2021


Author: Vassil Vassilev
Date: 2021-07-10T17:54:00Z
New Revision: f01d45c378cd0271e279d971c79d6e4900f045e0

URL: https://github.com/llvm/llvm-project/commit/f01d45c378cd0271e279d971c79d6e4900f045e0
DIFF: https://github.com/llvm/llvm-project/commit/f01d45c378cd0271e279d971c79d6e4900f045e0.diff

LOG: Reland "[clang-repl] Allow passing in code as positional arguments."

This reverts commit 3ec88ca60b24 which reverted e386871e1d21 due to a asan build
failure.

This patch removes the new lines in the test case which seem to introduce the
failure.

Differential revision: https://reviews.llvm.org/D104898

Added: 
    

Modified: 
    clang/test/Interpreter/execute.cpp
    clang/tools/clang-repl/ClangRepl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/Interpreter/execute.cpp b/clang/test/Interpreter/execute.cpp
index 108b79b23a59..298046c068c3 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,7 +1,9 @@
-// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:            'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);
@@ -11,5 +13,4 @@ struct S { float f = 1.0; S *m = nullptr;} s;
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long long>(s.m));
 // CHECK-NEXT: S[f=1.000000, m=0x0]
-
 quit

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp b/clang/tools/clang-repl/ClangRepl.cpp
index b5b5bf6e0c6b..ba6bb11abc86 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -28,6 +28,9 @@ static llvm::cl::list<std::string>
               llvm::cl::CommaSeparated);
 static llvm::cl::opt<bool> OptHostSupportsJit("host-supports-jit",
                                               llvm::cl::Hidden);
+static llvm::cl::list<std::string> OptInputs(llvm::cl::Positional,
+                                             llvm::cl::ZeroOrMore,
+                                             llvm::cl::desc("[code to run]"));
 
 static void LLVMErrorHandler(void *UserData, const std::string &Message,
                              bool GenCrashDiag) {
@@ -78,15 +81,22 @@ int main(int argc, const char **argv) {
                                     static_cast<void *>(&CI->getDiagnostics()));
 
   auto Interp = ExitOnErr(clang::Interpreter::create(std::move(CI)));
-  llvm::LineEditor LE("clang-repl");
-  // FIXME: Add LE.setListCompleter
-  while (llvm::Optional<std::string> Line = LE.readLine()) {
-    if (*Line == "quit")
-      break;
-    if (auto Err = Interp->ParseAndExecute(*Line))
+  for (const std::string &input : OptInputs) {
+    if (auto Err = Interp->ParseAndExecute(input))
       llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  if (OptInputs.empty()) {
+    llvm::LineEditor LE("clang-repl");
+    // FIXME: Add LE.setListCompleter
+    while (llvm::Optional<std::string> Line = LE.readLine()) {
+      if (*Line == "quit")
+        break;
+      if (auto Err = Interp->ParseAndExecute(*Line))
+        llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+    }
+  }
+
   // Our error handler depends on the Diagnostics object, which we're
   // potentially about to delete. Uninstall the handler now so that any
   // later errors use the default handling behavior instead.


        


More information about the cfe-commits mailing list