This is an archive of the discontinued LLVM Phabricator instance.

[MS] Change the metadata for heapallocsite calls when the function return type is cast.
ClosedPublic

Authored by akhuang on May 1 2019, 3:02 PM.

Details

Reviewers
rnk

Event Timeline

akhuang created this revision.May 1 2019, 3:02 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 1 2019, 3:02 PM
akhuang added a reviewer: rnk.May 1 2019, 3:04 PM
rnk added a comment.May 1 2019, 3:32 PM

Nice, this is way less complicated than we thought originally.

clang/lib/CodeGen/CGExprScalar.cpp
572

Please revert unrelated whitespace changes.

2067

One thought I had here was, should this look through casts? I guess, what does MSVC do in wacky cases like this:

struct Foo; struct Bar;
Foo *p = (Foo*)(Bar*)malloc(42);

I tested locally, and MSVC emits the first cast as the allocated type, so I guess that's consistent with what you have. Let's add the double cast test case to be thorough, though.

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
1093 ↗(On Diff #197651)

This change is unrelated, and also surprising to me, usually any symbol record wants to refer to the complete type index if it can.

akhuang updated this revision to Diff 197830.May 2 2019, 11:03 AM
akhuang marked an inline comment as done.
  • Add test case for multiple casts
  • Remove unrelated changes
akhuang marked 2 inline comments as done.May 2 2019, 11:07 AM

Reverted getCompleteTypeIndex change, to be fixed elsewhere

rnk accepted this revision.May 2 2019, 11:12 AM

lgtm, with a minor tweak

clang/lib/CodeGen/CGExprScalar.cpp
2068

It's more idiomatic to say isa<ExplicitCastExpr>(CE) than to use dyn_cast and test for nullness. The casting API actually has reasonably good documentation on it if you're curious:
http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates

This revision is now accepted and ready to land.May 2 2019, 11:12 AM
akhuang updated this revision to Diff 197851.May 2 2019, 1:04 PM

Change dyn_cast to isa

akhuang marked an inline comment as done.May 2 2019, 1:05 PM
akhuang closed this revision.May 2 2019, 1:41 PM

Committed in r359823