This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Avoid creating null pointer lvalue (NFC)
ClosedPublic

Authored by nikic on Dec 23 2021, 2:01 AM.

Details

Summary

The reduction initialization code creates a "naturally aligned null pointer to void lvalue", which I found somewhat odd, even though it works out in the end because it is not actually used. It doesn't look like this code actually needs an LValue for anything though, and we can use an invalid Address to represent this case instead.

Diff Detail

Unit TestsFailed

Event Timeline

nikic created this revision.Dec 23 2021, 2:01 AM
nikic requested review of this revision.Dec 23 2021, 2:01 AM
ABataev added inline comments.Dec 23 2021, 5:42 AM
clang/lib/CodeGen/CGOpenMPRuntime.cpp
897–899

Maybe move this code to the places where it actually used with some asserts instead of if?

assert(SharedAddr.isValid() && ..);
SharedAddr = CGF.Builder.CreateElementBitCast(
        SharedAddr, CGF.ConvertTypeForMem(SharedType));

And insert this code before lines 903 and 906.

nikic updated this revision to Diff 396018.Dec 23 2021, 6:25 AM

Omit cast

nikic added inline comments.Dec 23 2021, 6:27 AM
clang/lib/CodeGen/CGOpenMPRuntime.cpp
897–899

Can we maybe drop this cast entirely? At least I don't get any test failures. emitAggregateInitialization() does its own cast so it's definitely not necessary for that case, but maybe emitInitWithReductionInitializer() does need it and it's not covered by tests.

This revision is now accepted and ready to land.Dec 23 2021, 6:27 AM
This revision was landed with ongoing or failed builds.Dec 24 2021, 12:06 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptDec 24 2021, 12:06 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript