Skip to content

Commit 3edbe36

Browse files
authored
[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`.
1 parent 67652a3 commit 3edbe36

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clang/lib/AST/Expr.cpp

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

16251625
// If the return type is a struct, union, or enum that is marked nodiscard,
16261626
// 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)