This is an archive of the discontinued LLVM Phabricator instance.

Add LLVM_ATTRIBUTE_NORETURN to report_bad_alloc_error
ClosedPublic

Authored by aaronpuchert on Jun 5 2020, 4:35 PM.

Details

Summary

The attribute just means that there will be no regular return, it still
leaves room for exceptions to be thrown. It is easily verified: there
are no direct returns and the last statement is either a throw or a call
to abort.

Having the annotation helps static analyzers with this code from
Support/MemAlloc.h (slightly simplified):

LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_malloc(size_t Sz) {

void *Result = std::malloc(Sz);
if (Result == nullptr)
  report_bad_alloc_error("Allocation failed");
return Result;

}

Were report_bad_alloc_error to return regularly, the function would
return nullptr, contradicting the attribute.

Diff Detail

Event Timeline

aaronpuchert created this revision.Jun 5 2020, 4:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2020, 4:35 PM
dblaikie accepted this revision.Jun 8 2020, 6:26 PM
dblaikie added a subscriber: dblaikie.

Sounds good to me!

This revision is now accepted and ready to land.Jun 8 2020, 6:26 PM
aaron.ballman accepted this revision.Jun 9 2020, 4:25 AM
aaron.ballman added a subscriber: aaron.ballman.

LGTM!

This revision was automatically updated to reflect the committed changes.