Skip to content

Commit 96ae7c4

Browse files
authored
[clang-repl] Implement continuation for preprocessor directives. (#107552)
1 parent 400b725 commit 96ae7c4

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

clang/test/Interpreter/multiline.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// REQUIRES: host-supports-jit
22
// UNSUPPORTED: system-aix
3-
// RUN: cat %s | clang-repl | FileCheck %s
3+
// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
4+
5+
// expected-no-diagnostics
46

57
extern "C" int printf(const char*,...);
68
int i = \
@@ -17,8 +19,7 @@ void f(int x) \
1719
f(i);
1820
// CHECK: x=12
1921

20-
// FIXME: Support preprocessor directives.
21-
// #if 0 \
22-
// #error "Can't be!" \
23-
// #endif
22+
#if 0 \
23+
#error "Can't be!" \
24+
#endif
2425

clang/tools/clang-repl/ClangRepl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,10 @@ int main(int argc, const char **argv) {
232232
llvm::StringRef L = *Line;
233233
L = L.trim();
234234
if (L.ends_with("\\")) {
235-
// FIXME: Support #ifdef X \ ...
236235
Input += L.drop_back(1);
236+
// If it is a preprocessor directive, new lines matter.
237+
if (L.starts_with('#'))
238+
Input += "\n";
237239
LE.setPrompt("clang-repl... ");
238240
continue;
239241
}

0 commit comments

Comments
 (0)