[PATCH] D83906: [CodeGen] Emit a call instruction instead of an invoke if the called llvm function is marked nounwind
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 9 07:09:34 PST 2023
ahatanak added a comment.
clang marks the called function `foo` in p1.cpp as nounwind here: https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CodeGenFunction.cpp#L1284
clang can also mark a function declaration as nounwind based on the information in the source code, for example, when it is annotated with `__attribute__((pure))`.
I haven't read everything discussed in https://reviews.llvm.org/D18634 yet, but it seems like it's safe to do this optimization when the called function is `linkonce_odr`. If clang or llvm's optimization determines one version of the function doesn't throw, then other versions of the same function can't throw either.
But it looks like clang doesn't do the right thing when the `foo` is weak. clang emits a call instead of an invoke when it compiles the following code:
int foo() __attribute__((weak, pure));
int bar() noexcept { return foo();};
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83906/new/
https://reviews.llvm.org/D83906
More information about the cfe-commits
mailing list