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

SVF-example project reports error when compiled with LLVM under Debug mode. #1402

Open
yuffon opened this issue Mar 8, 2024 · 8 comments
Open

Comments

@yuffon
Copy link

yuffon commented Mar 8, 2024

I compile SVF-example project with LLVM 14 under Debug mode.
The program meets an error:

svf-example: /home/yuffon/data/programs/svf2.9-debug-install/include/svf/SVF-LLVM/LLVMModule.h:219: SVF::SVFInstruction *SVF::LLVMModuleSet::getSVFInstruction(const SVF::Instruction *) const: Assertion `it!=LLVMInst2SVFInst.end() && "SVF Instruction not found!"' failed.

The input good.ll file is as follows.

; ModuleID = 'good.c'
source_filename = "good.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: noinline nounwind optnone uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, i32* %1, align 4
  ret i32 1
}

attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 1}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{!"clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)"}

LLVM14 + release mode, gcc + debug/release mode do not report this error.

Is there something wrong?

@yuleisui
Copy link
Collaborator

yuleisui commented Mar 8, 2024

Not sure why. Looks odd. You could do a printing to debug a bit.

how about llvm-16?

@yuffon
Copy link
Author

yuffon commented Mar 8, 2024

Not sure why. Looks odd. You could do a printing to debug a bit.

how about llvm-16?

I have not tested llvm 16 because the other parts of my project need llvm 14.

The stack is

SVF::LLVMModuleSet::getSVFInstruction(const llvm::Instruction *) const LLVMModule.h:219
__GI_abort 0x000014d2b4ef0859
__assert_fail_base 0x000014d2b4ef0729
__GI___assert_fail 0x000014d2b4f01fd6
SVF::LLVMModuleSet::getSVFInstruction(const llvm::Instruction *) const LLVMModule.h:219
SVF::LLVMModuleSet::initSVFBasicBlock(const llvm::Function *) LLVMModule.cpp:376
SVF::LLVMModuleSet::initSVFFunction() LLVMModule.cpp:309
SVF::LLVMModuleSet::build() LLVMModule.cpp:162
SVF::LLVMModuleSet::buildSVFModule(const std::vector<…> &) LLVMModule.cpp:124
main svf-ex.cpp:162
__libc_start_main 0x000014d2b4ef2083
_start 0x000000000042658e

@yuleisui
Copy link
Collaborator

yuleisui commented Mar 8, 2024

Your bc code is small enough. Can you debug to see why the map retrieval failed? I am not able to debug it for you at the moment

@yuffon
Copy link
Author

yuffon commented Mar 15, 2024

VFBasicBlock(const llvm::Function *) LLVMModule

Hi @yuleisui , I follow SVF::LLVMModuleSet::build() line by line.

I see in createSVFDataStructure(); -> createSVFFunction(func) -> addInstructionMap(&inst, svfInst); -> LLVMInst2SVFInst[inst] = svfInst;,
the first instruction of function main in good.ll, i.e., alloca, is added into LLVMInst2SVFInst.
But in
initSVFFunction(); ->initSVFBasicBlock(&f); -> LLVMUtil::getNextInsts(inst, getSVFInstruction(inst)->getSuccInstructions()); ->LLVMInst2SVFInstMap::const_iterator it = LLVMInst2SVFInst.find(inst);,
LLVMInst2SVFInst.find() returns nothing.

It is odd. If I use GCC to compile SVF-example, everything is OK.
But llvm 14 as compiler would report this error.

@yuffon
Copy link
Author

yuffon commented Mar 16, 2024

Your bc code is small enough. Can you debug to see why the map retrieval failed? I am not able to debug it for you at the moment

It seems like a bug when SVF 2.9 works with LLVM 14.
I add some print statements, the error disappears but a new error occurs.

Then I add
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
to SVF top CMakeLists. Everything is OK.

@yuffon yuffon closed this as completed Mar 16, 2024
@yuffon
Copy link
Author

yuffon commented Mar 16, 2024

add
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
to SVF top CMakeLists

@yuleisui
Copy link
Collaborator

How about llvm-16?

@yuleisui yuleisui reopened this Mar 16, 2024
@yuffon
Copy link
Author

yuffon commented Mar 17, 2024

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")

I didn't try LLVM 16 because other parts of my projects need llvm 14.

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

2 participants