Quiz time
Now that you have finished reading this chapter, try answering the following questions to test your knowledge:
- Given the following input IR, why is
opt
returning the following error?
The input is as follows:
define i32 @add(i32 %0, i32 %1) {
%2 = add i32 %0, %1
ret i32 %2
}
The error is as follows:
input.ll:2:3: error: instruction expected to be numbered '%3' or greater
%2 = add i32 %0, %1
^
This is because %2
is already used as the implicit name of the entry basic block.
Check the Basic blocks section for more details, or follow the example in the Walking through an example section.
- How could you fix the previous error with minimal changes?
There are two things you could do in this case: rename %2
(for example, to %3
) or change the name of the basic block. For this solution, we decided to go with the latter as it does not imply changing any other reference since the basic block is not explicitly...