Hello, On Tue, 27 Jun 2023, Pierrick Philippe wrote:
> My main problem is regarding uninitialized definition, but still not being > considered undefined behavior. > For example, the following code: > > int x; > int *y = &x; > *y = 6; > > What I'm doing is basically looking at each gimple statement if the lhs has a > given attribute for the purpose of the analysis I'm trying to perform. > To precise, I'm plugged into the analyzer, so an out-of-tree plugin. > > But in the example above, the definition of x is not really within the > gimple_seq of the function as it is never directly assigned. Then you need to be a bit more precise in what exactly you want. There are multiple ways to interpret "definition of a variable". a) assigning a value to it: that's what Richard alluded to, you need to iterate all gimple statements to see if any assign to variables you're interested in (in SSA form there will only be one, outside SSA there may be many). As you notice there also may be none at all that directly assign a value. You need to solve the associated data-flow problem in order to (conservatively) know the answer to this question. In particular you need points-to sets (above for instance, that 'y' points to 'x' so that when you modify '*y' that you can note down that "whatever y points to (i.e. at least x) is modified"). There is no ready-made list of statements that potentially modify a local variable in question. You need to do that yourself, but GCC contains many helper routines for parts of this problem (as it needs to answer these questions itself as well, for optimization purposes). b) allocating storage for the variable in question (and possibly giving it an initial value): there are _no_ gimple instruction that express this idea. The very fact that variables are mentioned in local_decls (and are used in a meaningful way in the instruction stream) leads to them being allocated on the stack during function expansion (see expand_used_vars). non-local variables are similarly handled, they are placed in various lists that lead to appropriate assembler statements allocating static storage for them (in the data or bss, or whatever other appropriate, segment). They aren't defined (in the allocate-it sense) by gimple statement either. Ciao, Michael.