[clang] c66d25d - [APINotes] Do not crash for C++ operators
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 10:40:04 PDT 2024
Author: Egor Zhdan
Date: 2024-07-29T18:40:01+01:00
New Revision: c66d25d1429fbf49c97ee9cd0195246642178cb7
URL: https://github.com/llvm/llvm-project/commit/c66d25d1429fbf49c97ee9cd0195246642178cb7
DIFF: https://github.com/llvm/llvm-project/commit/c66d25d1429fbf49c97ee9cd0195246642178cb7.diff
LOG: [APINotes] Do not crash for C++ operators
This fixes a crash during `CXXMethod->getName()` in
`Sema::ProcessAPINotes`: we were trying to get the name of a C++ method
as a string, which fails with an assertion if the name is not a simple
identifier.
Added:
Modified:
clang/lib/Sema/SemaAPINotes.cpp
clang/test/APINotes/Inputs/Headers/Methods.h
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaAPINotes.cpp b/clang/lib/Sema/SemaAPINotes.cpp
index be5b7b92dfe6f..2c49c1f64b2da 100644
--- a/clang/lib/Sema/SemaAPINotes.cpp
+++ b/clang/lib/Sema/SemaAPINotes.cpp
@@ -1044,11 +1044,16 @@ void Sema::ProcessAPINotes(Decl *D) {
if (auto TagContext = dyn_cast<TagDecl>(D->getDeclContext())) {
if (auto CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
- for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
- if (auto Context = UnwindTagContext(TagContext, APINotes)) {
- auto Info =
- Reader->lookupCXXMethod(Context->id, CXXMethod->getName());
- ProcessVersionedAPINotes(*this, CXXMethod, Info);
+ if (!isa<CXXConstructorDecl>(CXXMethod) &&
+ !isa<CXXDestructorDecl>(CXXMethod) &&
+ !isa<CXXConversionDecl>(CXXMethod) &&
+ !CXXMethod->isOverloadedOperator()) {
+ for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
+ if (auto Context = UnwindTagContext(TagContext, APINotes)) {
+ auto Info =
+ Reader->lookupCXXMethod(Context->id, CXXMethod->getName());
+ ProcessVersionedAPINotes(*this, CXXMethod, Info);
+ }
}
}
}
diff --git a/clang/test/APINotes/Inputs/Headers/Methods.h b/clang/test/APINotes/Inputs/Headers/Methods.h
index 6a96b12762871..cbb57ccd0afbd 100644
--- a/clang/test/APINotes/Inputs/Headers/Methods.h
+++ b/clang/test/APINotes/Inputs/Headers/Methods.h
@@ -2,6 +2,8 @@ struct IntWrapper {
int value;
IntWrapper getIncremented() const { return {value + 1}; }
+
+ IntWrapper operator+(const IntWrapper& RHS) const { return {value + RHS.value}; }
};
struct Outer {
@@ -9,5 +11,9 @@ struct Outer {
int value;
Inner getDecremented() const { return {value - 1}; }
+
+ bool operator==(const Inner& RHS) const {
+ return value == RHS.value;
+ }
};
};
More information about the cfe-commits
mailing list