Skip to content
This repository was archived by the owner on Jul 3, 2021. It is now read-only.

Commit 8a4bba8

Browse files
Add basic sanity checks for IR code
1 parent 3b47ce8 commit 8a4bba8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ Expected<std::string> codegenIR(Module &module, unsigned items) {
3535
B.SetInsertPoint(BasicBlock::Create(ctx, "entry", fn));
3636
B.CreateRet(ConstantInt::get(returnTy, 0));
3737

38+
std::string buffer;
39+
raw_string_ostream es(buffer);
40+
41+
if (verifyFunction(*fn, &es))
42+
return createStringError(inconvertibleErrorCode(),
43+
"Function verification failed: %s",
44+
es.str().c_str());
45+
46+
if (verifyModule(module, &es))
47+
return createStringError(inconvertibleErrorCode(),
48+
"Module verification failed: %s",
49+
es.str().c_str());
50+
3851
return name;
3952
}
4053

0 commit comments

Comments
 (0)