-
Notifications
You must be signed in to change notification settings - Fork 431
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
Alias analysis bug with compilation flags -O1 -Xclang -disable-O0-optnone #1482
Comments
We will review the issue and take care of the bug. |
Hi, has there been any progress on fixing this bug? |
Could you also provide the two bc files, before and after optimization? |
Could you also try to make the example as small as possible so that my debugging would be easier? |
Unfortunately, I can't reproduce your error. After optimisation under |
Thanks for taking a look over this. Below is the exact step I followed to produce the bug. I trimmed the test a little bit to make it cleaner.
#include "aliascheck.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct Dot{
int val;
} Dot;
typedef struct IndirectDot {
Dot *dot;
} IndirectDot;
int main (int argc, char *argv[]) {
Dot *dot = (Dot *)malloc(sizeof(Dot));
IndirectDot *indirectDot = (IndirectDot *)malloc(sizeof(IndirectDot));
indirectDot->dot = dot;
// Main computation
int result = 0;
Dot *dot2 = indirectDot->dot;
MAYALIAS(&(dot->val), &(dot2->val));
result += sqrt(dot2->val);
printf("%d\n", result);
return 0;
}
Below is what prints out on my terminal:
However, if you replace the verify function
but this result is incorrect, the two memory addresses I attach the test source along with the bitcode files here: test.zip |
@yiansu the bc file you gave me the two arguments are llvm's Could you redo the correct optimization and send back the bc? Thanks, |
@yuleisui Sorry for not getting back to you sooner. Unfortunately, the test case needs to remain a certain level of complexity, so I borrowed it from my original repost. Also, our group uses LLVM-14.0.6, so I checked out SVF-2.9. I'm not sure if this bug still exists in the master branch because LLVM 16 optimizes the bitcode differently than 14, making the bug hard to reproduce. Below is the exact step I followed to generate the bug:
#include "aliascheck.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct Dot{
int dummy_field;
int val;
} Dot;
typedef struct IndirectDot {
Dot *dot;
} IndirectDot;
int main (int argc, char *argv[]) {
Dot *dot = (Dot *)malloc(sizeof(Dot));
IndirectDot *indirectDot = (IndirectDot *)malloc(sizeof(IndirectDot));
indirectDot->dot = dot;
// Dot array allocation and initialization
Dot **dotArray = (Dot **)malloc(sizeof(Dot *) * argc);
for (int i = 0; i < argc; i++) {
Dot *tmp = (Dot *)malloc(sizeof(Dot));
tmp->val = argc++;
dotArray[argc - 1] = tmp;
}
// Main computation
Dot *dot2 = indirectDot->dot;
MAYALIAS(&(dot->val), &(dot2->val));
int result = 0;
for (int i = 0; i < argc; i++) {
dot->val = dotArray[argc - 1]->val;
result += sqrt(dot2->val);
}
printf("%d\n", result);
return 0;
}
Below is what prints out on my terminal:
However, if you replace the verify function
but this result is incorrect, the two memory addresses I attach the test source along with the bitcode files here: test.zip |
I have just read your LLVM-14 bitcode. It appears to me that this version of LLVM has an 'incorrect' optimisation (from my point of view) that uses an unbalanced method of storing a value in the first field of
In the above bitcode, |
Thanks for the explanation; that makes sense to me. I've added the |
Hello, we found that the following program (test.cpp) exposes a bug in SVF's alias analysis when compiling with flags
-O1 -Xclang -disable-O0-optnone
using clang.How to reproduce the bug
__attribute__((noinline))
in theMAYALIAS
function inaliascheck.h
such that this call doesn't get dead code eliminated by clang.clang++ -O1 -Xclang -disable-O0-optnone -c -emit-llvm -g test.cpp -o test.bc
wpa -ander -stat=false test.bc
, this will fail the MAYALIAS testNote
The bug is not exposed using different compilation flags, such as
clang++ -O0 -Xclang -disable-O0-optnone -c -emit-llvm -g test.cpp -o test.bc
clang++ -c -emit-llvm -g test.cpp -o test.bc
The text was updated successfully, but these errors were encountered: