[PATCH] D74361: [Clang] Undef attribute for global variables

Jon Chesterfield via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 27 16:38:25 PST 2020


JonChesterfield added a comment.

In D74361#1879559 <https://reviews.llvm.org/D74361#1879559>, @rjmccall wrote:

> This will need to impact static analysis and the AST, I think.  Local variables can't be redeclared, but global variables can, so disallowing initializers syntactically when the attribute is present doesn't necessarily stop other declarations from defining the variable.  Also, you need to make the attribute mark something as a definition, the same way that e.g. the alias attribute does.  Also, this probably ought to disable the default-initialization of non-trivial types in C++, in case that's not already done.


I would like this to be the case but am having a tough time understanding how sema works. VarDecl::hasInit() looked promising but doesn't appear to indicate whether there is a syntactic initialiser (e.g. = 10) present. I will continue to investigate. Codegen appears to be working fine.

In D74361#1880904 <https://reviews.llvm.org/D74361#1880904>, @jfb wrote:

> The current uninitialized attribute fits the model C and C++ follow for attributes: they have no semantic meaning for a valid program, in that a compiler can just ignore them and (barring undefined behavior) there's no observable effect to the program. This updated semantic changes the behavior of a valid C and C++ program, because the standards specify the value of uninitialized globals and TLS. I'd much rather have a separate attribute, say `no_zero_init`, to explicitly say what this does.


This proposed attribute can similarly be ignored without observable semantic effect. Instead of an IR undef variable, we would have an IR zeroinitialized variable, which is a legitimate implementation choice for undef. Adding the attribute to an existing program will, in general, change its meaning - but that's also true of other attributes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74361/new/

https://reviews.llvm.org/D74361





More information about the cfe-commits mailing list