[clang] acc80ea - [AST] Cleanup on getting the underlying decl of using-shdow decl.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon May 16 04:58:16 PDT 2022
Author: Haojian Wu
Date: 2022-05-16T13:58:08+02:00
New Revision: acc80ea71bac51458df9d75552651e7c161db64b
URL: https://github.com/llvm/llvm-project/commit/acc80ea71bac51458df9d75552651e7c161db64b
DIFF: https://github.com/llvm/llvm-project/commit/acc80ea71bac51458df9d75552651e7c161db64b.diff
LOG: [AST] Cleanup on getting the underlying decl of using-shdow decl.
This should be a NFC cleanup. It removes a unnecessary loop to get the underlying
decl, and add an assertion.
The underlying decl of a using-shadow decl is always the original declaration
has been brought into the scope, clang never builds a nested using-shadow
decl (see Sema::BuildUsingShadowDecl).
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D123422
Added:
Modified:
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 911479bee5ff9..1c5c64d1b3650 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1851,7 +1851,7 @@ bool NamedDecl::hasLinkage() const {
NamedDecl *NamedDecl::getUnderlyingDeclImpl() {
NamedDecl *ND = this;
- while (auto *UD = dyn_cast<UsingShadowDecl>(ND))
+ if (auto *UD = dyn_cast<UsingShadowDecl>(ND))
ND = UD->getTargetDecl();
if (auto *AD = dyn_cast<ObjCCompatibleAliasDecl>(ND))
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index cb6a355f7294a..020c7da52041d 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2968,8 +2968,10 @@ UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC,
BaseUsingDecl *Introducer, NamedDecl *Target)
: NamedDecl(K, DC, Loc, Name), redeclarable_base(C),
UsingOrNextShadow(Introducer) {
- if (Target)
+ if (Target) {
+ assert(!isa<UsingShadowDecl>(Target));
setTargetDecl(Target);
+ }
setImplicit();
}
More information about the cfe-commits
mailing list