This is an archive of the discontinued LLVM Phabricator instance.

Variable auto-init: also auto-init alloca
ClosedPublic

Authored by jfb on Apr 10 2019, 3:56 PM.

Details

Summary

alloca isn’t auto-init’d right now because it’s a different path in clang that all the other stuff we support (it’s a builtin, not an expression). Interestingly, alloca doesn’t have a type (as opposed to even VLA) so we can really only initialize it with memset.

rdar://problem/49794007

Diff Detail

Repository
rC Clang

Event Timeline

jfb created this revision.Apr 10 2019, 3:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2019, 3:57 PM
jfb added a comment.Apr 10 2019, 3:58 PM

One downside to alloca is that we can's use __attribute__((uninitialized)) because it's a builtin. Maybe we need a separate uninitialized alloca? What do you all think?

pcc added a comment.Apr 11 2019, 10:27 AM

I probably wouldn't do anything about suppressing init on alloca for now, but if we did do something I think I'd be in favour of the separate builtin for uninitialized alloca. I also considered the alternative of allowing __attribute__((uninitialized)) to appear on a function or block statement, but it seemed clearer for the uninitialized-ness to be as close to the alloca as possible.

jfb added a comment.Apr 11 2019, 12:43 PM
In D60548#1462124, @jfb wrote:

One downside to alloca is that we can's use __attribute__((uninitialized)) because it's a builtin. Maybe we need a separate uninitialized alloca? What do you all think?

Actually I'm wondering if we should just implement:

#pragma clang attribute push (__attribute__((uninitialized)), apply_to = variable(unless(is_global)))

And lean on that for alloca, instead of having a new uninitialized alloca builtin. The pragma is useful for debugging regardless, so I think overall it's better.

jfb added a comment.Apr 11 2019, 12:45 PM
In D60548#1463181, @jfb wrote:
In D60548#1462124, @jfb wrote:

One downside to alloca is that we can's use __attribute__((uninitialized)) because it's a builtin. Maybe we need a separate uninitialized alloca? What do you all think?

Actually I'm wondering if we should just implement:

#pragma clang attribute push (__attribute__((uninitialized)), apply_to = variable(unless(is_global)))

And lean on that for alloca, instead of having a new uninitialized alloca builtin. The pragma is useful for debugging regardless, so I think overall it's better.

Although the pragma syntax doesn't seem to support builtins, only variables, so it's still; weird for alloca... I'd really want the pragma to apply to everything in its scope including alloca.

rjmccall added inline comments.Apr 11 2019, 12:56 PM
lib/CodeGen/CGBuiltin.cpp
58

Can this value be taken from some common source with the existing code? I mean, even if it's just a constant in some header, that'd be a start.

jfb updated this revision to Diff 194736.Apr 11 2019, 1:20 PM
  • Move patternFor to a shared file as requested by @rjmccall
jfb marked 2 inline comments as done.Apr 11 2019, 1:20 PM
jfb added inline comments.
lib/CodeGen/CGBuiltin.cpp
58

Done.

rjmccall added inline comments.Apr 11 2019, 1:54 PM
lib/CodeGen/PatternInit.cpp
18

Please use a qualified declaration here instead of defining it in the namespace.

lib/CodeGen/PatternInit.h
23

Please choose names that mean something outside of the mental context you were in when you wrote the patch. :)

jfb updated this revision to Diff 194762.Apr 11 2019, 2:31 PM
jfb marked 2 inline comments as done.
  • Change name, qualify declaration.
jfb marked 2 inline comments as done.Apr 11 2019, 2:31 PM
jfb added inline comments.
lib/CodeGen/PatternInit.h
23

I was just copy / pasting!

rjmccall accepted this revision.Apr 11 2019, 3:15 PM

LGTM.

lib/CodeGen/PatternInit.h
23

Your own code. :)

This revision is now accepted and ready to land.Apr 11 2019, 3:15 PM
jfb marked an inline comment as done.Apr 11 2019, 3:28 PM
jfb added inline comments.
lib/CodeGen/PatternInit.h
23

Hey you can't pull that one on me! Pulling it on you is *my* hobby!
And like... it's communal code now! ;-)

jfb added a comment.Apr 11 2019, 5:06 PM

I got an lgtm from @pcc on IRC, so I'll commit this.

This revision was automatically updated to reflect the committed changes.