anutosh491 wrote:

So this fix discards the current CodeGen module whenever 
`Diags.hasErrorOccurred()`, **so IR from a failing input is dropped and cannot 
leak into the next cell**. After the patch in debug mode we can see the 
following !

```
anutosh491@vv-nuc:/build/anutosh491/llvm-project/build/bin$ ./clang-repl 
--debug-only=clang-repl
compile-ptu 0: [TU=0x55556cf78168, M=0x55556cf72c60 (incr_module_0)]
execute-ptu 0: [TU=0x55556cf78168, M=0x55556cf72c60 (incr_module_0)]
clang-repl> printf("hi\n");
In file included from <<< inputs >>>:1:
input_line_1:1:1: error: use of undeclared identifier 'printf'
    1 | printf("hi\n");
      | ^~~~~~
error: Parsing failed.
clang-repl> #include <stdio.h>
compile-ptu 1: [TU=0x55556cfc7c08, M=0x55556cfbeee0 (incr_module_1)]
execute-ptu 1: [TU=0x55556cfc7c08, M=0x55556cfbeee0 (incr_module_1)]
clang-repl> printf("hi\n");
compile-ptu 2: [TU=0x55556d02cd68, M=0x55556cfca4e0 (incr_module_2)]
execute-ptu 2: [TU=0x55556d02cd68, M=0x55556cfca4e0 (incr_module_2)]
hi
clang-repl> 

anutosh491@vv-nuc:/build/anutosh491/llvm-project/build/bin$ ./clang-repl 
--Xcc=-x --Xcc=c --Xcc=-std=c23 --debug-only=clang-repl
compile-ptu 0: [TU=0x55556cfb2b18, M=0x55556cf95a90 (incr_module_0)]
execute-ptu 0: [TU=0x55556cfb2b18, M=0x55556cf95a90 (incr_module_0)]
clang-repl> printf("hi\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("hi\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> 
compile-ptu 1: [TU=0x55556cfbfb20, M=0x55556cf979a0 (incr_module_1)]
execute-ptu 1: [TU=0x55556cfbfb20, M=0x55556cf979a0 (incr_module_1)]
clang-repl> printf("hi\n");
compile-ptu 2: [TU=0x55556d00b5f8, M=0x55556cfc1790 (incr_module_2)]
execute-ptu 2: [TU=0x55556d00b5f8, M=0x55556cfc1790 (incr_module_2)]
hi
```

https://github.com/llvm/llvm-project/pull/169989
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to