This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Disable tail call if the callee function contain __builtin_frame_address or __builtin_return_address
AbandonedPublic

Authored by shiva0217 on May 6 2019, 11:09 PM.

Details

Reviewers
asb
apazos
Summary

Disable tail call if the callee function contain builtin_frame_address or builtin_return_address.
Otherwise, tail call optimization will remove the frame pointer and return address restoration which will make the above two builtin functions get incorrect value.

E.g.

void *callee (char *p) { return __builtin_return_address (1); }
void *caller (void) { char *save = (char*) alloca (4); return callee (save); }

Diff Detail

Repository
rL LLVM

Event Timeline

shiva0217 created this revision.May 6 2019, 11:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 6 2019, 11:09 PM
hfinkel added a subscriber: hfinkel.May 7 2019, 9:30 AM

Is this really a target-independent problem?

mgrang added a subscriber: mgrang.May 7 2019, 12:31 PM
mgrang added inline comments.
lib/Target/RISCV/RISCVISelLowering.cpp
1312

Period at the end of comment.

1415

This check can be combined with the assignment:
if (const Function *CalleeFn = dyn_cast<Function>(G->getGlobal()))

1419

getFrameDepthArg asserts on isFrameAddressOrReturnAddressCall. So we end up calling isFrameAddressOrReturnAddressCall twice here. We could put them into one function but it is cleaner the way it is now.
@asb Do you think this should be cleaned up?

shiva0217 marked 3 inline comments as done.May 7 2019, 8:12 PM

Is this really a target-independent problem?

Hi @hfinkel,
I think you're right, it should be a target-independent problem. I have created D61665, Thanks.

lib/Target/RISCV/RISCVISelLowering.cpp
1312

Got it, thanks.

1415

Got it, thanks.

1419

Hi @mgrang and @asb,
I created D61665 to replace this one and avoid calling isFrameAddressOrReturnAddressCall twice in the new patch.
Do you happy with the new implementation?

shiva0217 abandoned this revision.May 8 2019, 6:53 PM