[clang] 96ae7c4 - [clang-repl] Implement continuation for preprocessor directives. (#107552)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 20 00:07:49 PDT 2024


Author: Vassil Vassilev
Date: 2024-09-20T10:07:46+03:00
New Revision: 96ae7c4f1aa02cb10455dda22abbb0b3b2ceaa6b

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

LOG: [clang-repl] Implement continuation for preprocessor directives. (#107552)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/test/Interpreter/multiline.cpp b/clang/test/Interpreter/multiline.cpp
index 054e61a7e3d62e..0f5ef48417f133 100644
--- a/clang/test/Interpreter/multiline.cpp
+++ b/clang/test/Interpreter/multiline.cpp
@@ -1,6 +1,8 @@
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+
+// expected-no-diagnostics
 
 extern "C" int printf(const char*,...);
 int i = \
@@ -17,8 +19,7 @@ void f(int x) \
 f(i);
 // CHECK: x=12
 
-// FIXME: Support preprocessor directives.
-// #if 0 \
-//   #error "Can't be!" \
-// #endif
+#if 0                   \
+  #error "Can't be!"    \
+#endif
 

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp b/clang/tools/clang-repl/ClangRepl.cpp
index 9cfc70462893dd..08c54e6cafa901 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -232,8 +232,10 @@ int main(int argc, const char **argv) {
       llvm::StringRef L = *Line;
       L = L.trim();
       if (L.ends_with("\\")) {
-        // FIXME: Support #ifdef X \ ...
         Input += L.drop_back(1);
+        // If it is a preprocessor directive, new lines matter.
+        if (L.starts_with('#'))
+          Input += "\n";
         LE.setPrompt("clang-repl...   ");
         continue;
       }


        


More information about the cfe-commits mailing list