Which situations cause “Use of instruction is not an instruction” in LLVM IR?












0















I keep getting this error many times. Then, when I shift things around it works. My code is too complex to post here. I can't simplify and reproduce the problem.



The source code in LLVM that raises an exception is here: http://llvm.org/doxygen/Verifier_8cpp_source.html:



   // Check that all uses of the instruction, if they are instructions
// themselves, actually have parent basic blocks. If the use is not an
// instruction, it is an error!
for (Use &U : I.uses()) {
if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
Assert(Used->getParent() != nullptr,
"Instruction referencing"
" instruction not embedded in a basic block!",
&I, Used);
else {
CheckFailed("Use of instruction is not an instruction!", U);
return;
}
}


But I still don't understand what it means



So, I wonder if anyone has a small example that cause the "Use of instruction is not an instruction" error and also explain why it happens.



Thank you!










share|improve this question


















  • 1





    Why exactly can't you make a smaller example from your current code? Your code is probably saved in a repository, which means you can delete some uninteresting part, try to compile it and if it still shows the error, even commit it to a local branch. Repeat until you have a small example.

    – Roland Illig
    Jan 1 at 9:55











  • I did that in multiple combinations. The problem disappeared and etc. It's definitely because I'm new to LLVM. So, I want take a different route of understanding this error by understanding a small example that causes it instead.

    – Tanin
    Jan 1 at 14:48


















0















I keep getting this error many times. Then, when I shift things around it works. My code is too complex to post here. I can't simplify and reproduce the problem.



The source code in LLVM that raises an exception is here: http://llvm.org/doxygen/Verifier_8cpp_source.html:



   // Check that all uses of the instruction, if they are instructions
// themselves, actually have parent basic blocks. If the use is not an
// instruction, it is an error!
for (Use &U : I.uses()) {
if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
Assert(Used->getParent() != nullptr,
"Instruction referencing"
" instruction not embedded in a basic block!",
&I, Used);
else {
CheckFailed("Use of instruction is not an instruction!", U);
return;
}
}


But I still don't understand what it means



So, I wonder if anyone has a small example that cause the "Use of instruction is not an instruction" error and also explain why it happens.



Thank you!










share|improve this question


















  • 1





    Why exactly can't you make a smaller example from your current code? Your code is probably saved in a repository, which means you can delete some uninteresting part, try to compile it and if it still shows the error, even commit it to a local branch. Repeat until you have a small example.

    – Roland Illig
    Jan 1 at 9:55











  • I did that in multiple combinations. The problem disappeared and etc. It's definitely because I'm new to LLVM. So, I want take a different route of understanding this error by understanding a small example that causes it instead.

    – Tanin
    Jan 1 at 14:48
















0












0








0








I keep getting this error many times. Then, when I shift things around it works. My code is too complex to post here. I can't simplify and reproduce the problem.



The source code in LLVM that raises an exception is here: http://llvm.org/doxygen/Verifier_8cpp_source.html:



   // Check that all uses of the instruction, if they are instructions
// themselves, actually have parent basic blocks. If the use is not an
// instruction, it is an error!
for (Use &U : I.uses()) {
if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
Assert(Used->getParent() != nullptr,
"Instruction referencing"
" instruction not embedded in a basic block!",
&I, Used);
else {
CheckFailed("Use of instruction is not an instruction!", U);
return;
}
}


But I still don't understand what it means



So, I wonder if anyone has a small example that cause the "Use of instruction is not an instruction" error and also explain why it happens.



Thank you!










share|improve this question














I keep getting this error many times. Then, when I shift things around it works. My code is too complex to post here. I can't simplify and reproduce the problem.



The source code in LLVM that raises an exception is here: http://llvm.org/doxygen/Verifier_8cpp_source.html:



   // Check that all uses of the instruction, if they are instructions
// themselves, actually have parent basic blocks. If the use is not an
// instruction, it is an error!
for (Use &U : I.uses()) {
if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
Assert(Used->getParent() != nullptr,
"Instruction referencing"
" instruction not embedded in a basic block!",
&I, Used);
else {
CheckFailed("Use of instruction is not an instruction!", U);
return;
}
}


But I still don't understand what it means



So, I wonder if anyone has a small example that cause the "Use of instruction is not an instruction" error and also explain why it happens.



Thank you!







llvm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 9:33









TaninTanin

1,0441917




1,0441917








  • 1





    Why exactly can't you make a smaller example from your current code? Your code is probably saved in a repository, which means you can delete some uninteresting part, try to compile it and if it still shows the error, even commit it to a local branch. Repeat until you have a small example.

    – Roland Illig
    Jan 1 at 9:55











  • I did that in multiple combinations. The problem disappeared and etc. It's definitely because I'm new to LLVM. So, I want take a different route of understanding this error by understanding a small example that causes it instead.

    – Tanin
    Jan 1 at 14:48
















  • 1





    Why exactly can't you make a smaller example from your current code? Your code is probably saved in a repository, which means you can delete some uninteresting part, try to compile it and if it still shows the error, even commit it to a local branch. Repeat until you have a small example.

    – Roland Illig
    Jan 1 at 9:55











  • I did that in multiple combinations. The problem disappeared and etc. It's definitely because I'm new to LLVM. So, I want take a different route of understanding this error by understanding a small example that causes it instead.

    – Tanin
    Jan 1 at 14:48










1




1





Why exactly can't you make a smaller example from your current code? Your code is probably saved in a repository, which means you can delete some uninteresting part, try to compile it and if it still shows the error, even commit it to a local branch. Repeat until you have a small example.

– Roland Illig
Jan 1 at 9:55





Why exactly can't you make a smaller example from your current code? Your code is probably saved in a repository, which means you can delete some uninteresting part, try to compile it and if it still shows the error, even commit it to a local branch. Repeat until you have a small example.

– Roland Illig
Jan 1 at 9:55













I did that in multiple combinations. The problem disappeared and etc. It's definitely because I'm new to LLVM. So, I want take a different route of understanding this error by understanding a small example that causes it instead.

– Tanin
Jan 1 at 14:48







I did that in multiple combinations. The problem disappeared and etc. It's definitely because I'm new to LLVM. So, I want take a different route of understanding this error by understanding a small example that causes it instead.

– Tanin
Jan 1 at 14:48














1 Answer
1






active

oldest

votes


















2














You are probably generating bogus IR somewhere in your code. The assertion you mention might be triggered by, for example, constructing a constant expression that uses result of other instruction as operand:



%0 = <some instruction producing result>
store i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0), ...


Here, the getelementptr inbounds ... part is a constant expression, which can't contain anything except other constants. Hence, we can't use %0 as indices here.



Instead, we need to use getelementptr instruction:



%0 = <some instruction producing result>
%1 = i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0)
store i8* %1, ...


As for your case, you can just call I.dump() from your code or inside debugger to figure out what instruction causes failed assertion exactly.






share|improve this answer
























  • Let me get this right. We merely need to store the result in an intermediate variable to make it a non-constant, right? Coming from a normal programming language, this is a huge gotcha. I didn't even realise the above 2 code were not equivalent. Could you point to more explanation around this concept? What is this concept called? I'd like to read more.

    – Tanin
    Jan 1 at 22:44













  • More question: I notice that it only fails when verifying the function. What happens if we just go ahead and run the code anyway? How would it be wrong? Thank you!

    – Tanin
    Jan 1 at 22:51











  • For my specific problem, I'm stuck with this: Use of instruction is not an instruction! %size_with_terminator = add i32 %cstring_size, 1. I'm not sure how to solve it. The line is already on its own.

    – Tanin
    Jan 1 at 23:15











  • I've figured it out. I later used %size_with_terminator in another constant expression. The error was misleading; It was the use of %size_with_terminator, not the declaration of %size_with_terminator. Do you have any trick to figure this out quickly? It failed when verifying a function, so I couldn't even run it. Thank you for the pointer. It really helps me understand LLVM better.

    – Tanin
    Jan 1 at 23:45








  • 1





    I'm using debugger for this. All of Instruction, BasicBlock, Function and Module classes have dump() method that prints corresponding IR. Whenever assertion fails, the debuggers breaks and allows you to inspect IR on which Verifier choked.

    – arrowd
    Jan 2 at 8:59











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994377%2fwhich-situations-cause-use-of-instruction-is-not-an-instruction-in-llvm-ir%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You are probably generating bogus IR somewhere in your code. The assertion you mention might be triggered by, for example, constructing a constant expression that uses result of other instruction as operand:



%0 = <some instruction producing result>
store i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0), ...


Here, the getelementptr inbounds ... part is a constant expression, which can't contain anything except other constants. Hence, we can't use %0 as indices here.



Instead, we need to use getelementptr instruction:



%0 = <some instruction producing result>
%1 = i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0)
store i8* %1, ...


As for your case, you can just call I.dump() from your code or inside debugger to figure out what instruction causes failed assertion exactly.






share|improve this answer
























  • Let me get this right. We merely need to store the result in an intermediate variable to make it a non-constant, right? Coming from a normal programming language, this is a huge gotcha. I didn't even realise the above 2 code were not equivalent. Could you point to more explanation around this concept? What is this concept called? I'd like to read more.

    – Tanin
    Jan 1 at 22:44













  • More question: I notice that it only fails when verifying the function. What happens if we just go ahead and run the code anyway? How would it be wrong? Thank you!

    – Tanin
    Jan 1 at 22:51











  • For my specific problem, I'm stuck with this: Use of instruction is not an instruction! %size_with_terminator = add i32 %cstring_size, 1. I'm not sure how to solve it. The line is already on its own.

    – Tanin
    Jan 1 at 23:15











  • I've figured it out. I later used %size_with_terminator in another constant expression. The error was misleading; It was the use of %size_with_terminator, not the declaration of %size_with_terminator. Do you have any trick to figure this out quickly? It failed when verifying a function, so I couldn't even run it. Thank you for the pointer. It really helps me understand LLVM better.

    – Tanin
    Jan 1 at 23:45








  • 1





    I'm using debugger for this. All of Instruction, BasicBlock, Function and Module classes have dump() method that prints corresponding IR. Whenever assertion fails, the debuggers breaks and allows you to inspect IR on which Verifier choked.

    – arrowd
    Jan 2 at 8:59
















2














You are probably generating bogus IR somewhere in your code. The assertion you mention might be triggered by, for example, constructing a constant expression that uses result of other instruction as operand:



%0 = <some instruction producing result>
store i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0), ...


Here, the getelementptr inbounds ... part is a constant expression, which can't contain anything except other constants. Hence, we can't use %0 as indices here.



Instead, we need to use getelementptr instruction:



%0 = <some instruction producing result>
%1 = i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0)
store i8* %1, ...


As for your case, you can just call I.dump() from your code or inside debugger to figure out what instruction causes failed assertion exactly.






share|improve this answer
























  • Let me get this right. We merely need to store the result in an intermediate variable to make it a non-constant, right? Coming from a normal programming language, this is a huge gotcha. I didn't even realise the above 2 code were not equivalent. Could you point to more explanation around this concept? What is this concept called? I'd like to read more.

    – Tanin
    Jan 1 at 22:44













  • More question: I notice that it only fails when verifying the function. What happens if we just go ahead and run the code anyway? How would it be wrong? Thank you!

    – Tanin
    Jan 1 at 22:51











  • For my specific problem, I'm stuck with this: Use of instruction is not an instruction! %size_with_terminator = add i32 %cstring_size, 1. I'm not sure how to solve it. The line is already on its own.

    – Tanin
    Jan 1 at 23:15











  • I've figured it out. I later used %size_with_terminator in another constant expression. The error was misleading; It was the use of %size_with_terminator, not the declaration of %size_with_terminator. Do you have any trick to figure this out quickly? It failed when verifying a function, so I couldn't even run it. Thank you for the pointer. It really helps me understand LLVM better.

    – Tanin
    Jan 1 at 23:45








  • 1





    I'm using debugger for this. All of Instruction, BasicBlock, Function and Module classes have dump() method that prints corresponding IR. Whenever assertion fails, the debuggers breaks and allows you to inspect IR on which Verifier choked.

    – arrowd
    Jan 2 at 8:59














2












2








2







You are probably generating bogus IR somewhere in your code. The assertion you mention might be triggered by, for example, constructing a constant expression that uses result of other instruction as operand:



%0 = <some instruction producing result>
store i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0), ...


Here, the getelementptr inbounds ... part is a constant expression, which can't contain anything except other constants. Hence, we can't use %0 as indices here.



Instead, we need to use getelementptr instruction:



%0 = <some instruction producing result>
%1 = i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0)
store i8* %1, ...


As for your case, you can just call I.dump() from your code or inside debugger to figure out what instruction causes failed assertion exactly.






share|improve this answer













You are probably generating bogus IR somewhere in your code. The assertion you mention might be triggered by, for example, constructing a constant expression that uses result of other instruction as operand:



%0 = <some instruction producing result>
store i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0), ...


Here, the getelementptr inbounds ... part is a constant expression, which can't contain anything except other constants. Hence, we can't use %0 as indices here.



Instead, we need to use getelementptr instruction:



%0 = <some instruction producing result>
%1 = i8* getelementptr inbounds ([123 x i8], [123 x i8]* @some_string, i32 %0, i32 0)
store i8* %1, ...


As for your case, you can just call I.dump() from your code or inside debugger to figure out what instruction causes failed assertion exactly.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 19:33









arrowdarrowd

22.7k45383




22.7k45383













  • Let me get this right. We merely need to store the result in an intermediate variable to make it a non-constant, right? Coming from a normal programming language, this is a huge gotcha. I didn't even realise the above 2 code were not equivalent. Could you point to more explanation around this concept? What is this concept called? I'd like to read more.

    – Tanin
    Jan 1 at 22:44













  • More question: I notice that it only fails when verifying the function. What happens if we just go ahead and run the code anyway? How would it be wrong? Thank you!

    – Tanin
    Jan 1 at 22:51











  • For my specific problem, I'm stuck with this: Use of instruction is not an instruction! %size_with_terminator = add i32 %cstring_size, 1. I'm not sure how to solve it. The line is already on its own.

    – Tanin
    Jan 1 at 23:15











  • I've figured it out. I later used %size_with_terminator in another constant expression. The error was misleading; It was the use of %size_with_terminator, not the declaration of %size_with_terminator. Do you have any trick to figure this out quickly? It failed when verifying a function, so I couldn't even run it. Thank you for the pointer. It really helps me understand LLVM better.

    – Tanin
    Jan 1 at 23:45








  • 1





    I'm using debugger for this. All of Instruction, BasicBlock, Function and Module classes have dump() method that prints corresponding IR. Whenever assertion fails, the debuggers breaks and allows you to inspect IR on which Verifier choked.

    – arrowd
    Jan 2 at 8:59



















  • Let me get this right. We merely need to store the result in an intermediate variable to make it a non-constant, right? Coming from a normal programming language, this is a huge gotcha. I didn't even realise the above 2 code were not equivalent. Could you point to more explanation around this concept? What is this concept called? I'd like to read more.

    – Tanin
    Jan 1 at 22:44













  • More question: I notice that it only fails when verifying the function. What happens if we just go ahead and run the code anyway? How would it be wrong? Thank you!

    – Tanin
    Jan 1 at 22:51











  • For my specific problem, I'm stuck with this: Use of instruction is not an instruction! %size_with_terminator = add i32 %cstring_size, 1. I'm not sure how to solve it. The line is already on its own.

    – Tanin
    Jan 1 at 23:15











  • I've figured it out. I later used %size_with_terminator in another constant expression. The error was misleading; It was the use of %size_with_terminator, not the declaration of %size_with_terminator. Do you have any trick to figure this out quickly? It failed when verifying a function, so I couldn't even run it. Thank you for the pointer. It really helps me understand LLVM better.

    – Tanin
    Jan 1 at 23:45








  • 1





    I'm using debugger for this. All of Instruction, BasicBlock, Function and Module classes have dump() method that prints corresponding IR. Whenever assertion fails, the debuggers breaks and allows you to inspect IR on which Verifier choked.

    – arrowd
    Jan 2 at 8:59

















Let me get this right. We merely need to store the result in an intermediate variable to make it a non-constant, right? Coming from a normal programming language, this is a huge gotcha. I didn't even realise the above 2 code were not equivalent. Could you point to more explanation around this concept? What is this concept called? I'd like to read more.

– Tanin
Jan 1 at 22:44







Let me get this right. We merely need to store the result in an intermediate variable to make it a non-constant, right? Coming from a normal programming language, this is a huge gotcha. I didn't even realise the above 2 code were not equivalent. Could you point to more explanation around this concept? What is this concept called? I'd like to read more.

– Tanin
Jan 1 at 22:44















More question: I notice that it only fails when verifying the function. What happens if we just go ahead and run the code anyway? How would it be wrong? Thank you!

– Tanin
Jan 1 at 22:51





More question: I notice that it only fails when verifying the function. What happens if we just go ahead and run the code anyway? How would it be wrong? Thank you!

– Tanin
Jan 1 at 22:51













For my specific problem, I'm stuck with this: Use of instruction is not an instruction! %size_with_terminator = add i32 %cstring_size, 1. I'm not sure how to solve it. The line is already on its own.

– Tanin
Jan 1 at 23:15





For my specific problem, I'm stuck with this: Use of instruction is not an instruction! %size_with_terminator = add i32 %cstring_size, 1. I'm not sure how to solve it. The line is already on its own.

– Tanin
Jan 1 at 23:15













I've figured it out. I later used %size_with_terminator in another constant expression. The error was misleading; It was the use of %size_with_terminator, not the declaration of %size_with_terminator. Do you have any trick to figure this out quickly? It failed when verifying a function, so I couldn't even run it. Thank you for the pointer. It really helps me understand LLVM better.

– Tanin
Jan 1 at 23:45







I've figured it out. I later used %size_with_terminator in another constant expression. The error was misleading; It was the use of %size_with_terminator, not the declaration of %size_with_terminator. Do you have any trick to figure this out quickly? It failed when verifying a function, so I couldn't even run it. Thank you for the pointer. It really helps me understand LLVM better.

– Tanin
Jan 1 at 23:45






1




1





I'm using debugger for this. All of Instruction, BasicBlock, Function and Module classes have dump() method that prints corresponding IR. Whenever assertion fails, the debuggers breaks and allows you to inspect IR on which Verifier choked.

– arrowd
Jan 2 at 8:59





I'm using debugger for this. All of Instruction, BasicBlock, Function and Module classes have dump() method that prints corresponding IR. Whenever assertion fails, the debuggers breaks and allows you to inspect IR on which Verifier choked.

– arrowd
Jan 2 at 8:59




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994377%2fwhich-situations-cause-use-of-instruction-is-not-an-instruction-in-llvm-ir%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith