This is an archive of the discontinued LLVM Phabricator instance.

basic code generation for use-after-dtor
ClosedPublic

Authored by nmusgrave on Jul 10 2015, 2:19 PM.

Details

Reviewers
kcc
eugenis

Diff Detail

Event Timeline

nmusgrave updated this revision to Diff 29496.Jul 10 2015, 2:19 PM
nmusgrave retitled this revision from to basic code generation for use-after-dtor.
nmusgrave updated this object.
nmusgrave added reviewers: eugenis, kcc.
nmusgrave added a subscriber: cfe-commits.
nmusgrave updated this revision to Diff 29587.Jul 13 2015, 10:51 AM
  • changed arg types for generated dtor handler
eugenis edited edge metadata.Jul 13 2015, 11:23 AM

Please add a CodeGen test.

lib/CodeGen/CGClass.cpp
1471

I think remove "_exit" from the name - it can be confused with the program exit.

kcc added inline comments.Jul 13 2015, 11:26 AM
lib/CodeGen/CGClass.cpp
1456

why not just array with a {} initializer?

nmusgrave updated this revision to Diff 29595.Jul 13 2015, 12:35 PM
nmusgrave edited edge metadata.
  • passing in array instead of vector, simple codegen tests started

The test should be in CodeGenCXX, and probably called "sanitize-dtor-callback.cpp".

test/CodeGen/sanitize-dtor-usage.cpp
7 ↗(On Diff #29595)

You probably don't need a lot of this code, like main() function, or A() constructor.

11 ↗(On Diff #29595)

remove the comments.

20 ↗(On Diff #29595)

Add a CHECK-LABEL: test for the function name to make sure the call is in the destructor.

You'll probably need -triple=x86_64-pc-linux in the run line so that destructor name mangling is consistent.

22 ↗(On Diff #29595)

This does not do anything because of --check-prefix=DTOR (CHECK is the default prefix that is disabled if you set some other prefix). Add --check-prefix=CHECK.

Test that the function call is not added when building without -fsanitize-memory-use-after-dtor.

rnk added a subscriber: rnk.Jul 13 2015, 2:15 PM
rnk added inline comments.
lib/CodeGen/CGClass.cpp
1456

Would you mind factoring this out to a helper function? Most readers of clang irgen probably aren't interested in this instrumentation.

nmusgrave updated this revision to Diff 29615.Jul 13 2015, 3:05 PM
nmusgrave marked 4 inline comments as done.
  • refactored test for modularity, better flags
eugenis added inline comments.Jul 13 2015, 3:11 PM
lib/CodeGen/CGClass.cpp
1452

memory-poisoning

test/CodeGenCXX/sanitize-dtor-callback.cpp
10

Does it work without main?

15

A nit: it's common to write just CHECK-LABEL: _ZN6SimpleD2Ev

19

Please add a -LABEL check

nmusgrave updated this revision to Diff 29617.Jul 13 2015, 3:27 PM
nmusgrave marked an inline comment as done.
  • refactor label name
samsonov added inline comments.
lib/CodeGen/CGClass.cpp
1459

Remove the size of the array here. For instance, if you reduce the number of elements, the code would still compile, but the array would have trailing nullptrs.

nmusgrave updated this revision to Diff 29618.Jul 13 2015, 3:45 PM
  • helper function for dtor codegen
nmusgrave updated this revision to Diff 29626.Jul 13 2015, 4:49 PM
nmusgrave marked 4 inline comments as done.
  • simplified tests, formatting
eugenis accepted this revision.Jul 13 2015, 4:59 PM
eugenis edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jul 13 2015, 4:59 PM
eugenis closed this revision.Jul 13 2015, 5:35 PM

Committed as r242097.