Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM assertion: "Initializer type must match GlobalVariable type" #1406

Closed
251 opened this issue Mar 14, 2024 · 6 comments
Closed

LLVM assertion: "Initializer type must match GlobalVariable type" #1406

251 opened this issue Mar 14, 2024 · 6 comments

Comments

@251
Copy link
Contributor

251 commented Mar 14, 2024

Hi,

I updated to LLVM 15 (with assertions enabled) and whatever I run ends up in an assertion, e.g.:

int main(void) {}
$ wpa -ander -svfg -dump-icfg test.bc
wpa: /llvm/lib/IR/Globals.cpp:471: void llvm::GlobalVariable::setInitializer(llvm::Constant*): Assertion `InitVal->getType() == getValueType() && "Initializer type must match GlobalVariable type"' failed.

I attached gdb and the issue seems to be that:
https://github.com/SVF-tools/SVF/blob/fa0d081299fd2ace031469a630f00904ba1ee42f/svf-llvm/lib/LLVMUtil.cpp#L511C1-L511C33
causes a type mismatch: newCA (InitVal in LLVM) has type [0 x { ptr, ptr, ptr, i32, ptr }] zeroinitializer whereas glob has the type [217 x { ptr, ptr, ptr, i32, ptr }] (the annotation array).

@yuleisui
Copy link
Collaborator

@shuangxiangkan could you take a look at this case?

@shuangxiangkan
Copy link
Contributor

@251 Could you upload the bc file?

@251
Copy link
Contributor Author

251 commented Mar 15, 2024

Sure: test.zip. But keep in mind that assertions in LLVM have to be enabled, for distribution packages this is typically not the case.

@JanWichelmann
Copy link

I ran into the same problem today. I managed to fix it by reverting this change, i.e., I replaced

glob->setInitializer(newCA);

by

auto globName = glob->getName();
glob->setName("llvm.global.annotations_old");

GlobalVariable *newGlob = new GlobalVariable(*module, annotationsType, glob->isConstant(), glob->getLinkage(), newCA, globName, glob, glob->getThreadLocalMode());
newGlob->setSection(glob->getSection());
newGlob->setAlignment(glob->getAlign());

glob->replaceAllUsesWith(newGlob);
glob->eraseFromParent();

in svf-llvm/lib/LLVMUtil.cpp.

@shuangxiangkan
Copy link
Contributor

@251 @JanWichelmann This issue should have been fixed in #1420.

@JanWichelmann
Copy link

Works for me, thank you!

@251 251 closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants