rjmccall wrote: > It seems once codegen meets an odr use of the variable, it doesn't emit the > initializer, only the global variable itself. Then while emitting some > function's body it meets the variable declaration, and if it was a static > variable it adds the initializer via AddInitializerToStaticVarDecl. consteval > function bodies are never handled by CodeGen, hence missing initializers. > This patch makes sure they won't be missing.
That makes sense. I think the cleaner way of handling it is probably to just fit it into the existing lazy-emission system, `DeferredDeclsToEmit`. In fact, we should be able to do that for every static local variable with a constant-expression initializer: don't emit them eagerly when we walk the function body, call `addDeferredDeclToEmit` whenever we ODR-use them for the first time, and then make sure `EmitDeferredDecl` does the right thing for them. > Even if a variable is usable in constant expressions? I believe so, yes. Taking the address of an object of static storage duration is generally allowed in constant expressions, and there's no restriction against that being the current declaration or otherwise forming cycles. https://github.com/llvm/llvm-project/pull/156933 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits