Hi,
I manually add the call_expr statement
sqlite3_prepare_v2 (sqldb0, sql, tlen, stmt, 0);
into the parse tree using the following code:
fn = lookup_name (get_identifier ("sqlite3_prepare_v2"));
argarr[0] = lookup_name (get_identifier ("db"));
argarr[1] = lookup_name (get_identifier ("sql"));
argarr[2] = lookup_name (get_identifier ("len"));
argarr[3] = lookup_name (get_identifier ("stmt"));
argarr[4] = null_pointer_node;
check_function_arguments (TREE_TYPE (fn), 5, argarr);
stmt = build_call_expr_loc_array (input_location, fn, 5, argarr);
add_stmt (stmt);
where the variables were declared as:
struct sqlite3 *db;
char *sql = "SELECT name FROM plist";
int len = strlen(sql)+1;
struct sqlite3_stmt **stmt;
My program compiled successfully but generated segmentation fault
at sqlite3_prepare_v2 because the parameters received there are not
correctly aligned as shown by GDB below
Starting program: /home/dinh/SRC/SAMPLES/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b66bde in sqlite3LockAndPrepare (db=0x601078,
zSql=0x1e <error: Cannot access memory at address 0x1e>,
nBytes=-8848,
saveSqlFlag=1, pOld=0x0, ppStmt=0x0, pzTail=0x601078) at
sqlite3.c:105117
105117 *ppStmt = 0;
(gdb) bt
#0 0x00007ffff7b66bde in sqlite3LockAndPrepare (db=0x601078,
zSql=0x1e <error: Cannot access memory at address 0x1e>,
nBytes=-8848,
saveSqlFlag=1, pOld=0x0, ppStmt=0x0, pzTail=0x601078) at
sqlite3.c:105117
#1 0x00007ffff7b66e1a in sqlite3_prepare_v2 (db=0x601078,
zSql=0x1e <error: Cannot access memory at address 0x1e>,
nBytes=-8848,
ppStmt=0x0, pzTail=0x601078) at sqlite3.c:105199
#2 0x0000000000400953 in main () at t22.c:16
The code generated by "-fdump-tree-gimple" looks fine, In fact, I am able
to compile the (slightly modified) gimple code and run its executable
without any problem. There are mislignment problems with the ways I
built the parse tree above. Can some GCC expert please show me the
correct way of building a general call_expr.
Thank you much.
Dinh