[clang] [clang-repl] Implement continuation for preprocessor directives. (PR #107552)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 02:43:58 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Vassil Vassilev (vgvassilev)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/107552.diff
2 Files Affected:
- (modified) clang/test/Interpreter/multiline.cpp (+6-5)
- (modified) clang/tools/clang-repl/ClangRepl.cpp (+3-1)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/107552
More information about the cfe-commits
mailing list