On Fri, Jun 11, 2021 at 12:07 PM Erick Ochoa via Gcc <gcc@gcc.gnu.org> wrote: > > Hi, > > I am looking for a small clarification. I understand that during late > SIMPLE_IPA_PASSes some statically initialized global variables might > have error_mark_node trees in their DECL_INITIAL field. > > I believe that I read something similar in the past about how to get > the tree expressions in these situations, and I believe it said one > had to stream in those symbols from the .gnu.lto_.decl section. > > However, on the GCC Internals there is also the following mention: "If > the DECL_INITIAL is the error_mark_node, there is an initializer, but > it is given by an explicit statement later in the code; no bitwise > copy is required. " [0] > > What (if any) is the correct way to get these expressions?
Use ctor_for_folding (decl) to access a known initializer. error_mark_node is returned when there is no known constant initializer, NULL for zero-init and an actual value otherwise. > As a note, when running this pass as an IPA_PASS I am able to see the > DECL_INITIAL node of the variable of interest during LGEN. > > Thanks! > > [0] https://gcc.gnu.org/onlinedocs/gccint/Working-with-declarations.html