[clang] Fix crash with -funique-internal-linkage-names
authorEllis Hoag <ellis.sparky.hoag@gmail.com>
Thu, 13 Oct 2022 23:38:02 +0000 (16:38 -0700)
committerEllis Hoag <ellis.sparky.hoag@gmail.com>
Mon, 17 Oct 2022 15:57:23 +0000 (08:57 -0700)
commit970e1ea01aa0dce4f606eee1610c92b8b838f303
treee965033dde654e6abc8f2c0d05f87ffe7edeff9b
parent6102364b0d0e16d63cc38c74a2a315a75253b4e8
[clang] Fix crash with -funique-internal-linkage-names

Calling `getFunctionLinkage(CalleeInfo.getCalleeDecl())` will crash when the declaration does not have a body, e.g., `extern void foo();`. Instead, we can use `isExternallyVisible()` to see if the delcaration has internal linkage.

I believe using `!isExternallyVisible()` is correct because the clang linkage must be `InternalLinkage` or `UniqueExternalLinkage`, both of which are "internal linkage" in llvm.
https://github.com/llvm/llvm-project/blob/9c26f51f5e178ac0fda98419e3a61d205d3b58b1/clang/include/clang/Basic/Linkage.h#L28-L40

Fixes https://github.com/llvm/llvm-project/issues/54139

Reviewed By: tmsriram

Differential Revision: https://reviews.llvm.org/D135926
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/unique-internal-linkage-names.c [new file with mode: 0644]