-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr #118636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Yihe Li (Mick235711) ChangesFixes #117975, a regression introduced by #112521 due to me forgetting to check for Full diff: https://github.com/llvm/llvm-project/pull/118636.diff 2 Files Affected:
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a4fb4d5a1f2ec4..286f02ded27196 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1619,8 +1619,9 @@ 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 (D != nullptr)
+ 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.
diff --git a/clang/test/SemaCXX/warn-unused-result.cpp b/clang/test/SemaCXX/warn-unused-result.cpp
index 682c500dc1d96d..5105f347db8b53 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was approved, do you need someone to merge this for you?
Yes, I do; I don't really have merge permissions. Thanks a lot for the helping hand. |
Sorry about that, it fell in the cracks. (in the future, feel free to ping every week if no one replies) |
llvm#118636) Fixes llvm#117975, a regression introduced by llvm#112521 due to forgetting to check for `nullptr` before dereferencing in `CallExpr::getUnusedResultAttr`.
Fixes #117975, a regression introduced by #112521 due to me forgetting to check for
nullptr
before dereferencing inCallExpr::getUnusedResultAttr
.A regression test has been added as per the comments on the fixed issue.