llvm-project
llvm-project copied to clipboard
Correctly handle default arguments
See default_argument in attr-psets.
int* null(int* p = nullptr);
int* p = null();
__lifetime_pset(p); //should be {{pset(p) = ((null))}}, but currently returns ((static)) because the default parameter is not considered at all
I did a really quick investigation. The source of the problem is that the default argument's expression is owned by the declaration. It is pretty easy to add an option to the CFG to include the default argument's expression, but it will be the same expression for every call site. So if we have:
g();
g();
We will end up visiting the same nullptr twice. As long as we end up having the same result the only problem it implies is that we cannot create an assertion that warns if we visit the same stuff multiple times because it would be triggered by default arguments.
If the default argument for example is a function call, it is performed on every invocation of the function. I'm trying to think of a case where the second evaluation of the default argument could result in a different pset, but I cannot think of any. Anyhow, I would says that evaluating the default argument expressions multiple time should be ok.