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

Conditionally Specializing Global Integer Failing Type Assertion #10

Open
tshiUCSB opened this issue Jun 1, 2023 · 1 comment
Open

Comments

@tshiUCSB
Copy link

tshiUCSB commented Jun 1, 2023

Hi there, I've been trying to conditionally specialize a global integer variable but was getting an assertion error Assertion failed: (ConstType->isIntegerTy() || (ConstType->isPointerTy() && !assumeInt)) && "Instructions with an integer assumption must be integer typed" every time LLPE tries to specialize the program. Note that I have tried conditionally specializing an integer argument to a function as well which results in the same assertion failure. I am wondering if I'm using LLPE correctly?

Below is the C code that is being specialized, where global_int is the global variable that serves as the condition:

#include "string.h"
#include "stdio.h"

int global_int = 3;

int exponent (int e) { // assume e >= 1
    int result = 1;
    for (int i = 0; i < e; i++) {
        result *= global_int;
    }
    
    return result;
}

int main(int argc, char** argv) {
    int ret = 0;

    for (int i = 0; i < 10; i++) {
        ret += exponent(5);
    }

    printf("%i\n", ret);
    return ret;
}

Here are the commands that I am running in terminal to conditionally specialize the program:

$ clang -c -emit-llvm int_spec.c -o int_spec.bc
$ clang int_spec.bc -o int_spec.out
$ opt -load /home/tina/Codes/llpe/build/utils/libLLVMLLPEUtils.so -nameblocks int_spec.bc -o int_spec_named.bc
$ $LLPE_OPT -llpe-root exponent \
	-llpe-force-noalias-arg 0 \
	-llpe-path-condition-int exponent,__globals__,global_int,3,exponent,1 \
	int_spec_named.bc -o int_spec_spec.bc

And below is the resulting output:

Assertion failed: (ConstType->isIntegerTy() || (ConstType->isPointerTy() && !assumeInt)) && "Instructions with an integer assumption must be integer typed"
Stack dump:
0.	Program arguments: opt -load /home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so -load /home/tina/Codes/llpe/build/driver/libLLVMLLPEDriver.so -loop-simplify -lcssa -llpe -llpe-root exponent -llpe-force-noalias-arg 0 -llpe-path-condition-int exponent,__globals__,global_int,3,exponent,1 int_spec_named.bc -o int_spec_spec.bc 
1.	Running pass 'LLPE Analysis' on module 'int_spec_named.bc'.
 #0 0x0000000001f72364 PrintStackTraceSignalHandler(void*) (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1f72364)
 #1 0x0000000001f7021e llvm::sys::RunSignalHandlers() (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1f7021e)
 #2 0x0000000001f72758 SignalHandler(int) (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1f72758)
 #3 0x00007fcf02842520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007fcf02896a7c pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)
 #5 0x00007fcf02842476 raise (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007fcf028287f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007fcf02fa0fc1 llvm::LLPEAnalysisPass::parsePathConditions(llvm::cl::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, llvm::cl::parser<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, llvm::PathConditionTypes, llvm::InlineAttempt*) (/home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so+0xe0fc1)
 #8 0x00007fcf02fa78ac llvm::LLPEAnalysisPass::parseArgsPostCreation(llvm::InlineAttempt*) (/home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so+0xe78ac)
 #9 0x00007fcf02fb29b2 llvm::LLPEAnalysisPass::runOnModule(llvm::Module&) (/home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so+0xf29b2)
#10 0x0000000001a46b48 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1a46b48)
#11 0x0000000000831338 main (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x831338)
#12 0x00007fcf02829d90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#13 0x00007fcf02829e40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#14 0x000000000081a7ba _start (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x81a7ba)

Thank you for your time and greatly appreciate any help here!

@smowton
Copy link
Owner

smowton commented Jun 7, 2023

Works for me! What version of LLVM are you using / building against?

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