This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Don't add `undef` for `operator new` under -fno-exceptions.
AbandonedPublic

Authored by DianQK on Aug 6 2023, 4:59 AM.

Details

Summary

Background: Committing patch D144319 resulted in a runtime error in the UB for libcxx.

The current implementation of operator new under -fno-exceptions returns nullptr. This is undefined behavior. D150610 may take longer to complete.
Removing the undef attribute may be a solution without changing libcxx.

I also tried other things like making -fno-exceptions implicit -fcheck-new. Removing nonnull can have a lot of unintended impacts, such as impacting Clang's static analysis. I gave up on a similar approach.

Diff Detail

Event Timeline

DianQK created this revision.Aug 6 2023, 4:59 AM
Herald added a project: Restricted Project. · View Herald Transcript
DianQK requested review of this revision.Aug 6 2023, 4:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2023, 4:59 AM
DianQK edited the summary of this revision. (Show Details)Aug 6 2023, 5:10 AM
nikic requested changes to this revision.Aug 7 2023, 1:28 AM

Removing noundef makes no sense to me, because the return value is noundef even under fno-exceptions. If we remove something, it should be the nonnull attribute, because that's what's actually being violated.

@ldionne Can you give us an ETA on D150610 please? Do we need to introduce a workaround for this libcxx bug in clang, or do you plan to fix this in the near future?

This revision now requires changes to proceed.Aug 7 2023, 1:28 AM
DianQK added a comment.Aug 7 2023, 1:58 AM

Removing noundef makes no sense to me, because the return value is noundef even under fno-exceptions. If we remove something, it should be the nonnull attribute, because that's what's actually being violated.

Return null on nonnull is poison. So I can also think that the noundef attribute is violated. I think the reason for keeping nonnull is to match the semantics of operator new. But that probably doesn't make sense either.

Removing noundef makes no sense to me, because the return value is noundef even under fno-exceptions. If we remove something, it should be the nonnull attribute, because that's what's actually being violated.

@ldionne Can you give us an ETA on D150610 please? Do we need to introduce a workaround for this libcxx bug in clang, or do you plan to fix this in the near future?

I'll try to do this for LLVM 18, sorry that's just a complicated change. I would recommend not working around this in Clang.