This is an archive of the discontinued LLVM Phabricator instance.

[Support] Remove incorrect noalias return attribute in BumpPtrAllocator
ClosedPublic

Authored by nikic on Jan 19 2022, 5:35 AM.

Details

Summary

The memory returned by the Allocate() function is also otherwise accessible -- and is indeed accessed by the DestroyAll() method of SpecificBumpPtrAlloactor. This is a violation of the noalias return contract.

This should address the issue reported in https://reviews.llvm.org/D116728#3252464.

Diff Detail

Event Timeline

nikic created this revision.Jan 19 2022, 5:35 AM
nikic requested review of this revision.Jan 19 2022, 5:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2022, 5:35 AM

There's a couple more occurrences of noalias in the same file. I think if we remove one, we need to remove all. Please also add a comment explaining that these are *not* noalias and why. (So we don't add the same bug back.)

Removing this is unfortunate just to allow destruction, but it does seem to be required with the current code structure. I think we could add Allocate wrappers on the standard bump pointer typedef (i.e turn it into a subclass) and preserve noalias there, but I'm fine landing the removal and then restructing if we see a regression.

nikic updated this revision to Diff 401249.Jan 19 2022, 8:16 AM

Add comment.

nikic added a comment.Jan 19 2022, 8:19 AM

There's a couple more occurrences of noalias in the same file.

I don't see any other references apart from these two. We have another in MemAlloc.h, but that's unrelated (and legit).

Removing this is unfortunate just to allow destruction, but it does seem to be required with the current code structure. I think we could add Allocate wrappers on the standard bump pointer typedef (i.e turn it into a subclass) and preserve noalias there, but I'm fine landing the removal and then restructing if we see a regression.

Yeah, that might be possible. I think it wouldn't be strictly speaking correct, but likely wouldn't cause issues as long as SpecificBumpPtrAllocator is split out.

reames accepted this revision.Jan 19 2022, 8:28 AM

LGTM

Sorry for the confusing comment on the extra call site. I was thinking of the second one in your original diff, but somehow didn't see it. Not enough coffee yet apparently. :)

This revision is now accepted and ready to land.Jan 19 2022, 8:28 AM

There might more to it. Unfortunately I don't see any difference after the patch, either applied on rG3cef3cf02f09e397c471cf008060c89b34951959 or on ToT. The repro still don't emit the movs into the target buffer. Is anyone able to confirm?

Maybe add a macro LLVM_ATTRIBUTE_RETURNS_ALIAS for documentation.

nikic added a comment.Jan 19 2022, 9:54 AM

There might more to it. Unfortunately I don't see any difference after the patch, either applied on rG3cef3cf02f09e397c471cf008060c89b34951959 or on ToT. The repro still don't emit the movs into the target buffer. Is anyone able to confirm?

When I tested this I dropped the __attribute__((malloc)) from the preprocessed source, and that did it for me. Note that this patch needs to be in the source code for the stage2 lld build, not the stage1 clang build.

This patch is a correctness fix on it's own and should land.

On the original regression, can I ask we file a bug and move discussion there? It's already fragmented across two reviews and getting increasingly hard to follow.

There might more to it. Unfortunately I don't see any difference after the patch, either applied on rG3cef3cf02f09e397c471cf008060c89b34951959 or on ToT. The repro still don't emit the movs into the target buffer. Is anyone able to confirm?

When I tested this I dropped the __attribute__((malloc)) from the preprocessed source, and that did it for me. Note that this patch needs to be in the source code for the stage2 lld build, not the stage1 clang build.

You're right, I don't know what I was thinking :-/ Apologies @nikic, it works now. Many thanks for your time!

This revision was landed with ongoing or failed builds.Jan 20 2022, 12:24 AM
This revision was automatically updated to reflect the committed changes.