Author: Nikita Popov
Date: 2026-11-01T12:27:19+01:00
New Revision: bd4d3dd10e53f4978134c889c5dc917802e015ff

URL: 
https://github.com/llvm/llvm-project/commit/bd4d3dd10e53f4978134c889c5dc917802e015ff
DIFF: 
https://github.com/llvm/llvm-project/commit/bd4d3dd10e53f4978134c889c5dc917802e015ff.diff

LOG: [AST] Optimize isWeakImported() for decl without attributes (NFC) (#237619)

This method can only return true if there is a WeakImportAttr or
AvailabilityAttr, so we can skip cases that don't have any attributes.

This avoids the call to canBeWeakImported(), which is fairly expensive
due to the use of isThisDeclarationADefinition().

This improves compile-time for C++ code, by -0.25% for the clang build.

Suggested by LLM. Original motivation was to reduce ASLR noise on
beman-execution.

Added: 
    

Modified: 
    clang/lib/AST/DeclBase.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index bf2a8a01f7b9c..a3ddcb3df01b6 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -874,11 +874,15 @@ bool Decl::canBeWeakImported(bool &IsDefinition) const {
 }
 
 bool Decl::isWeakImported() const {
+  const Decl *MostRecentDecl = getMostRecentDecl();
+  if (!MostRecentDecl->hasAttrs())
+    return false;
+
   bool IsDefinition;
   if (!canBeWeakImported(IsDefinition))
     return false;
 
-  for (const auto *A : getMostRecentDecl()->attrs()) {
+  for (const auto *A : MostRecentDecl->attrs()) {
     if (isa<WeakImportAttr>(A))
       return true;
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to