[clang] [clang-repl] Skip CodeGen for top-level decls when diagnostics report errors (PR #169989)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 8 04:53:26 PST 2025
================
@@ -20,6 +20,9 @@ const char* c_null_str = 0; c_null_str
"Hello, world"
// CHECK-NEXT: ({{(const )?}}char[13]) "Hello, world"
+printf("Hello World\n");
+// expected-error {{call to undeclared library function 'printf' with type 'int (const char *, ...)' }}
+
int x = 42; x
// CHECK-NEXT: (int) 42
----------------
anutosh491 wrote:
Added a test here (can possibly open a new file if needed) but seems like an appropriate place.
On master
```
anutosh491 at vv-nuc:/build/anutosh491/llvm-project/build/bin$ ./clang-repl --Xcc=-x --Xcc=c
clang-repl> printf("Hello World\n");
In file included from <<< inputs >>>:1:
input_line_1:1:1: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1 | printf("Hello World\n");
| ^
input_line_1:1:1: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
error: Parsing failed.
clang-repl> int x = 42; x
Hello World
(int) 42
```
On branch
```
anutosh491 at vv-nuc:/build/anutosh491/llvm-project/build/bin$ ./clang-repl --Xcc=-x --Xcc=c
clang-repl> printf("10\n");
In file included from <<< inputs >>>:1:
input_line_1:1:1: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1 | printf("10\n");
| ^
input_line_1:1:1: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
error: Parsing failed.
clang-repl> int x = 42; x
(int) 42
```
https://github.com/llvm/llvm-project/pull/169989
More information about the cfe-commits
mailing list