Skip to content

Commit e81792a

Browse files
committed
[clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr
1 parent 026fbe5 commit e81792a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,9 @@ std::pair<const NamedDecl *, const Attr *>
16191619
CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
16201620
// If the callee is marked nodiscard, return that attribute
16211621
const Decl *D = getCalleeDecl();
1622-
if (const auto *A = D->getAttr<WarnUnusedResultAttr>())
1623-
return {nullptr, A};
1622+
if (D != nullptr)
1623+
if (const auto *A = D->getAttr<WarnUnusedResultAttr>())
1624+
return {nullptr, A};
16241625

16251626
// If the return type is a struct, union, or enum that is marked nodiscard,
16261627
// then return the return type attribute.

clang/test/SemaCXX/warn-unused-result.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,12 @@ void use2() {
355355
(void)G{"Hello"};
356356
}
357357
} // namespace nodiscard_specialization
358+
359+
namespace GH117975 {
360+
// Test for a regression for ICE in CallExpr::getUnusedResultAttr
361+
int f() { return 0; }
362+
void id_print_name() {
363+
(int) // expected-warning {{expression result unused}}
364+
((int(*)())f)();
365+
}
366+
} // namespace GH117975

0 commit comments

Comments
 (0)