This is an archive of the discontinued LLVM Phabricator instance.

[Clang] `nothrow`-implying attributes should actually manifest `nothrow` attribute (PR58798)
AbandonedPublic

Authored by lebedev.ri on Nov 12 2022, 6:05 PM.

Details

Summary

This is part of https://reviews.llvm.org/D137381,
i've stumbled into this in https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52989&q=label%3AProj-librawspeed

Look at the callee_with_clang_attr().
pure attribute implies nounwind, and we successfully manifest that at IRgen,
and calls from nounwind functions treat it as non-unwinding,
except that when generating function definition,
we'd suddenly forget that it is nounwind...

Here, everything that could go wrong, goes wrong.

CodeGenFunction::EmitStartEHSpec() looks at the AST function exception specification,
and not IR attributes, so

You'd think we can inferr the attribute in AST after the fact,
in Sema::ActOnFunctionDeclarator(), and while that is sufficient to get the diagnostics,
the function exception specification has already been computed from parsed attributes.

So we also need to adjust handleFunctionTypeAttr() (called by processTypeAttrs())
so it considers just-parsed pure as if it's nothrow...

It would somewhat less ugly if we could just infer nothrow attribute
during *attribute parsing* from pure/etc. Is that possible?

Also, OpenMP declare variant tests are showing an unexpected error,
looks like i'm missing some attribute propagation?

Diff Detail

Event Timeline

lebedev.ri created this revision.Nov 12 2022, 6:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2022, 6:05 PM
lebedev.ri requested review of this revision.Nov 12 2022, 6:05 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: sstefan1. · View Herald Transcript
MaskRay added a subscriber: MaskRay.EditedNov 13 2022, 6:16 PM
This comment has been deleted.
erichkeane added inline comments.Nov 15 2022, 6:48 AM
clang/lib/Sema/SemaDeclAttr.cpp
8794

First, I'm not a fan of doing this in this list ast all, we shouldn't really have logic here, this is mostly just a jump table.

Second, I guess I'm not getting why IRGen cannot figure out from the AST that Pure/Const/NoAlias all imply nothrow?

lebedev.ri abandoned this revision.Nov 15 2022, 8:53 AM

Actually, apparently those attributes really do introduce UB, so it is correct that they do not cause program termination.
https://reviews.llvm.org/D137381#3927923