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

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 09:30:10 PST 2020


rjmccall added inline comments.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:4367
+This is useful for variables that are always written to before use where the
+default zero initialization provided by the toolchain loader is expensive.
+  }];
----------------
How about:

> The ``loader_uninitialized`` attribute can be placed on global variables to
> indicate that the variable does not need to be zero initialized by the loader.
> On most targets, zero-initialization does not incur any additional cost.
> For example, most general purpose operating systems deliberately ensure
> that all memory is properly initialized in order to avoid leaking privileged
> information from the kernel or other programs.  However, some targets
> do not make this guarantee, and on these targets, avoiding an unnecessary
> zero-initialization can have a significant impact on load times and/or code
> size.
>
> A declaration with this attribute is a non-tentative definition just as if it
> provided an initializer.   Variables with this attribute are considered to be
> uninitialized in the same sense as a local variable, and the programs must
> write to them before reading from them.  If the variable's type is a C++ class
> type with a non-trivial default constructor, or an array thereof, this attribute
> only suppresses the static zero-initialization of the variable, not the dynamic
> initialization provided by executing the default constructor.


================
Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7436
+  case ParsedAttr::AT_LoaderUninitialized:
+    handleLoaderUninitializedAttr(S, D, AL);
+    break;
----------------
JonChesterfield wrote:
> aaron.ballman wrote:
> > If you don't need any custom semantic checking, you can remove that function and instead call `handleSimpleAttribute<LoaderUninitializedAttr>(S, D, AL);`
> I think this patch does need some custom semantic checking, I just haven't been able to work out how to implement it. Specifically, the attribute is an initializer, so
> 
> `int foo __attribute__((loader_uninitialised)) = some_value;`
> 
> should be a warning, as the = some_value is going to be ignored.
This should be an error, not a warning, unless there's a specific need to be lenient.


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