This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix label address calculation for ppc32
ClosedPublic

Authored by spetrovic on May 8 2018, 7:38 AM.

Details

Summary

This patch fixes calculating address of label on ppc32 (for -fPIC), I was using gcc as reference. You can try to run this example with and without the patch and see the difference:

unsigned int foo(void) {

return 0;

}

int main() {
L: attribute ((unused));

static const unsigned int arr[] =
{
  (unsigned int) &&x  - (unsigned int)&&L ,
  (unsigned int) &&y  - (unsigned int)&&L
};

unsigned int ret = foo();
void* g = (void *) ((unsigned int)&&L + arr[ret]);
goto *g;

x:

return 15;

y:

return 25;

}

Diff Detail

Repository
rL LLVM

Event Timeline

spetrovic created this revision.May 8 2018, 7:38 AM
hfinkel added inline comments.
lib/Target/PowerPC/PPCISelLowering.cpp
2570 ↗(On Diff #145689)

I don't think that we should be calling setUsesTOCBasePtr outside of 64-bit code.

spetrovic updated this revision to Diff 148808.May 28 2018, 6:24 AM
spetrovic marked an inline comment as done.
hfinkel accepted this revision.Jun 5 2018, 4:57 AM

LGTM

This revision is now accepted and ready to land.Jun 5 2018, 4:57 AM
This revision was automatically updated to reflect the committed changes.