[clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (#118636)

Fixes #117975, a regression introduced by #112521 due to forgetting
to check for `nullptr` before dereferencing in
`CallExpr::getUnusedResultAttr`.
This commit is contained in:
Yihe Li 2025-01-06 20:25:40 +08:00 committed by GitHub
parent 67652a3d9f
commit 3edbe36c3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -1618,9 +1618,9 @@ QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const {
std::pair<const NamedDecl *, const Attr *>
CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
// If the callee is marked nodiscard, return that attribute
const Decl *D = getCalleeDecl();
if (const auto *A = D->getAttr<WarnUnusedResultAttr>())
return {nullptr, A};
if (const Decl *D = getCalleeDecl())
if (const auto *A = D->getAttr<WarnUnusedResultAttr>())
return {nullptr, A};
// If the return type is a struct, union, or enum that is marked nodiscard,
// then return the return type attribute.

View File

@ -355,3 +355,12 @@ void use2() {
(void)G{"Hello"};
}
} // namespace nodiscard_specialization
namespace GH117975 {
// Test for a regression for ICE in CallExpr::getUnusedResultAttr
int f() { return 0; }
void id_print_name() {
(int) // expected-warning {{expression result unused}}
((int(*)())f)();
}
} // namespace GH117975