This is an archive of the discontinued LLVM Phabricator instance.

Make "#pragma clang attribute" support uninitialized attribute.
ClosedPublic

Authored by jcai19 on Apr 22 2020, 9:34 PM.

Details

Summary

When using -ftrivial-auto-var-init=* options to initiate automatic
variables in a file, to disable initialization on some variables,
currently we have to manually annotate the variables with uninitialized
attribute, such as

int dont_initialize_me __attribute((uninitialized));

Making pragma clang attribute to support this attribute would make
annotating variables much easier, and could be particular useful for
bisection efforts, e.g.

void use(void*);

void buggy() {

int arr[256];
int boom;
float bam;
struct { int oops; } oops;
union { int oof; float aaaaa; } oof;

use(&arr);
use(&boom);
use(&bam);
use(&oops);
use(&oof);

}

Diff Detail

Event Timeline

jcai19 created this revision.Apr 22 2020, 9:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2020, 9:34 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jcai19 added subscribers: srhines, llozano, manojgupta and 4 others.
jfb added a comment.Apr 22 2020, 10:41 PM

Looks pretty good to me. Not my areas of expertise so I’d like to have others look too. Thanks for doing this!

clang/test/Parser/pragma-attribute.cpp
190

Should variable work? Since it’s a superset of local it seems like maybe? But then again only local works, so ok not sure.

aaron.ballman accepted this revision.Apr 23 2020, 4:57 AM
aaron.ballman added a subscriber: aaron.ballman.

LGTM!

clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
38–50

I think you can remove this test case as it's basically identical to the previous one.

clang/test/Parser/pragma-attribute.cpp
190

I think this is correct. Requiring an explicit is_local here is a conservative approach. It means we can start supporting [[clang::uninitialized]] in other contexts without breaking code that uses #pragma clang attribute to apply it to more entities unexpectedly.

This revision is now accepted and ready to land.Apr 23 2020, 4:57 AM
jfb accepted this revision.Apr 23 2020, 9:45 AM
jfb added inline comments.
clang/test/Parser/pragma-attribute.cpp
190

That makes sense, thanks for confirming!

jcai19 updated this revision to Diff 259652.Apr 23 2020, 11:36 AM

Update test cases and documentation.

Thank you all for the comments. I just realized I forgot to update clang documentation. Added that too. Thanks.

This revision was automatically updated to reflect the committed changes.