-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Open
Open
Copy link
Labels
Description
Through #169989 we were able to skip CodeGen for top-level decls when diagnostics report errors and as a result of this, we could have these cases fixed.
$ ./clang-repl --Xcc=-x --Xcc=c --Xcc=-std=c23
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> #include <stdio.h>
clang-repl> printf("10\n");
10
$ ./clang-repl --Xcc=-x --Xcc=c --Xcc=-std=c23 --Xcc=-fno-builtin
clang-repl> printf("10\n");
In file included from <<< inputs >>>:1:
input_line_1:1:1: error: use of undeclared identifier 'printf'
1 | printf("10\n");
| ^~~~~~
error: Parsing failed.
clang-repl> #include <stdio.h>
clang-repl> printf("10\n");
10
$ ./clang-repl --Xcc=-x --Xcc=c --Xcc=-std=c17
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> #include <stdio.h>
clang-repl> printf("10\n");
10
The c23 and c17 case would make use of LazilyCreateBuiltin. But I notice the case that involves an implicit function definition and ends up calling ImplicitlyDefineFunction because we disallow builtins would end up like this
anutosh491@vv-nuc:/build/anutosh491/llvm-project/build/bin$ ./clang-repl --Xcc=-x --Xcc=c --Xcc=-std=c17 --Xcc=-fno-builtin
clang-repl> printf("10\n");
In file included from <<< inputs >>>:1:
input_line_1:1:1: error: call to undeclared function 'printf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1 | printf("10\n");
| ^
error: Parsing failed.
clang-repl> #include <stdio.h>
In file included from <<< inputs >>>:1:
In file included from input_line_2:1:
/usr/include/stdio.h:356:12: error: conflicting types for 'printf'
356 | extern int printf (const char *__restrict __format, ...);
| ^
input_line_1:1:1: note: previous implicit declaration is here
1 | printf("10\n");
| ^
error: Parsing failed.
Problem : When a call to an undeclared function occurs in C17 mode, Clang emits an implicit-function-declaration diagnostic and also creates an implicit FunctionDecl; CleanUpPTU fails to remove this implicitly-created FunctionDecl, allowing it to leak into later PTUs and causing redefinition errors when <stdio.h> is included.