@@ -68,6 +68,7 @@ class remove_asmt
6868 void gcc_asm_function_call (
6969 const irep_idt &function_base_name,
7070 const code_asm_gcct &code,
71+ std::size_t n_args,
7172 goto_programt &dest);
7273
7374 void msc_asm_function_call (
@@ -83,10 +84,12 @@ class remove_asmt
8384// / \param function_base_name: Name of the function to call
8485// / \param code: gcc-style inline assembly statement to translate to function
8586// / call
87+ // / \param n_args: Number of arguments required by \p function_base_name
8688// / \param dest: Goto program to append the function call to
8789void remove_asmt::gcc_asm_function_call (
8890 const irep_idt &function_base_name,
8991 const code_asm_gcct &code,
92+ std::size_t n_args,
9093 goto_programt &dest)
9194{
9295 irep_idt function_identifier = function_base_name;
@@ -115,6 +118,16 @@ void remove_asmt::gcc_asm_function_call(
115118 }
116119 }
117120
121+ // An inline asm statement may consist of multiple commands, not all of which
122+ // use all of the inputs/outputs of the inline asm statement.
123+ DATA_INVARIANT_WITH_DIAGNOSTICS (
124+ arguments.size () >= n_args,
125+ " insufficient number of arguments for calling " +
126+ id2string (function_identifier),
127+ " required arguments: " + std::to_string (n_args),
128+ code.pretty ());
129+ arguments.resize (n_args);
130+
118131 code_typet fkt_type{
119132 code_typet::parameterst{
120133 arguments.size (), code_typet::parametert{void_pointer}},
@@ -139,9 +152,12 @@ void remove_asmt::gcc_asm_function_call(
139152 }
140153 else
141154 {
142- DATA_INVARIANT (
155+ DATA_INVARIANT_WITH_DIAGNOSTICS (
143156 symbol_table.lookup_ref (function_identifier).type == fkt_type,
144- " function types should match" );
157+ " types of function " + id2string (function_identifier) + " should match" ,
158+ code.pretty (),
159+ symbol_table.lookup_ref (function_identifier).type .pretty (),
160+ fkt_type.pretty ());
145161 }
146162}
147163
@@ -299,12 +315,12 @@ void remove_asmt::process_instruction_gcc(
299315
300316 if (command == " fstcw" || command == " fnstcw" || command == " fldcw" ) // x86
301317 {
302- gcc_asm_function_call (" __asm_" + id2string (command), code, tmp_dest);
318+ gcc_asm_function_call (" __asm_" + id2string (command), code, 1 , tmp_dest);
303319 }
304320 else if (
305321 command == " mfence" || command == " lfence" || command == " sfence" ) // x86
306322 {
307- gcc_asm_function_call (" __asm_" + id2string (command), code, tmp_dest);
323+ gcc_asm_function_call (" __asm_" + id2string (command), code, 0 , tmp_dest);
308324 }
309325 else if (command == ID_sync) // Power
310326 {
0 commit comments