[PATCH] D141824: [clang-repl] Add a command to load dynamic libraries

Anubhab Ghosh via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 17 09:51:06 PDT 2023


argentite added a comment.

We should probably also address the lack of linker issue as well. Should we go for a precompiled dynamic library file? There seems to be some "precedent" of this in other tests.



================
Comment at: clang/test/Interpreter/dynamic-library.cpp:6
+
+#include <cstdio>
+
----------------
sgraenitz wrote:
> bcain wrote:
> > This test fails for me like below.  
> > 
> > 
> > ```
> > FAIL: Clang :: Interpreter/dynamic-library.cpp (1 of 17751)
> > ******************** TEST 'Clang :: Interpreter/dynamic-library.cpp' FAILED ********************
> > Script:
> > --
> > : 'RUN: at line 4';   /local/mnt/workspace/upstream/obj_ubuntu/bin/clang -xc++ -o /local/mnt/workspace/upstream/obj_ubuntu/tools/clang/test/Interpreter/Output/libdynamic-library-test.so -fPIC -shared -DLIBRARY /local/mnt/workspace/upstream/llvm-project/clang/test/Interpreter/Inputs/dynamic-library-test.cpp
> > : 'RUN: at line 5';   cat /local/mnt/workspace/upstream/llvm-project/clang/test/Interpreter/dynamic-library.cpp | env LD_LIBRARY_PATH=/local/mnt/workspace/upstream/obj_ubuntu/tools/clang/test/Interpreter/Output:$LD_LIBRARY_PATH /local/mnt/workspace/upstream/obj_ubuntu/bin/clang-repl | /local/mnt/workspace/upstream/obj_ubuntu/bin/FileCheck /local/mnt/workspace/upstream/llvm-project/clang/test/Interpreter/dynamic-library.cpp
> > --
> > Exit Code: 1
> > 
> > Command Output (stderr):
> > --
> > In file included from <<< inputs >>>:1:
> > input_line_6:1:10: fatal error: 'cstdio' file not found
> > #include <cstdio>
> >          ^~~~~~~~
> > error: Parsing failed.
> > input_line_12:1:1: error: use of undeclared identifier 'printf'
> > printf("Return value: %d\n", calculate_answer());
> > ^
> > error: Parsing failed.
> > input_line_15:1:1: error: use of undeclared identifier 'printf'
> > printf("Variable: %d\n", ultimate_answer);
> > ^
> > error: Parsing failed.
> > /local/mnt/workspace/upstream/llvm-project/clang/test/Interpreter/dynamic-library.cpp:15:11: error: CHECK: expected string not found in input
> > // CHECK: Return value: 5
> >           ^
> > <stdin>:1:1: note: scanning from here
> > clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
> > ^
> > <stdin>:1:231: note: possible intended match here
> > clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
> >                                                                                                                                                                                                                                       ^
> > 
> > Input file: <stdin>
> > Check file: /local/mnt/workspace/upstream/llvm-project/clang/test/Interpreter/dynamic-library.cpp
> > 
> > -dump-input=help explains the following input dump.
> > 
> > Input was:
> > <<<<<<
> >             1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl>  
> > check:15'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
> > check:15'1                                                                                                                                                                                                                                           ?           possible intended match
> > >>>>>>
> > 
> > --
> > 
> > ********************
> > ********************
> > Failed Tests (1):
> >   Clang :: Interpreter/dynamic-library.cpp
> > 
> > ```
> Thanks for your note, sounds reasonable. @argentite It should be sufficient to forward declare `printf`right? While we are here, can we somehow check whether the symbol is non-null before calling it?
Yes I think I can do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141824/new/

https://reviews.llvm.org/D141824



More information about the cfe-commits mailing list