mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:16:43 +00:00
[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:
parent
67652a3d9f
commit
3edbe36c3e
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user