Author: Jinsong Ji
Date: 2026-07-08T09:23:39-04:00
New Revision: 44858419d766322d9c51d85f4ac83501a5181597

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

LOG: Revert "[clang][AST] Inline StmtVisitor fallback methods" for STMT macro 
in debug builds (#208106)

This partially reverts commit 8b50847a31f927d258cf22953035db206d42fc5d.

The LLVM_ATTRIBUTE_ALWAYS_INLINE on STMT macro fallback methods caused
stack overflow in debug builds when processing deeply nested
expressions.
The test many-logical-ops.c with 2000+ logical AND operators would crash
in SequenceChecker due to excessive stack consumption.

Introduce LLVM_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG which expands to
LLVM_ATTRIBUTE_ALWAYS_INLINE in release builds (preserving the binary
size optimization) but to plain `inline` in debug builds (avoiding stack
overflow).

Apply this to the STMT macro while keeping LLVM_ATTRIBUTE_ALWAYS_INLINE
on BINOP_FALLBACK, CAO_FALLBACK, and UNARYOP_FALLBACK.

Fixes regressions in debug builds only:
   Clang :: C/C99/n590.c
   Clang :: Index/index-many-logical-ops.c
   Clang :: Sema/deep_recursion.c
   Clang :: Sema/many-logical-ops.c

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.5 <[email protected]>

Added: 
    

Modified: 
    clang/include/clang/AST/StmtVisitor.h
    llvm/include/llvm/Support/Compiler.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/StmtVisitor.h 
b/clang/include/clang/AST/StmtVisitor.h
index 45e203578c9fd..e4b3d35a9b16e 100644
--- a/clang/include/clang/AST/StmtVisitor.h
+++ b/clang/include/clang/AST/StmtVisitor.h
@@ -115,8 +115,10 @@ class StmtVisitorBase {
 
   // If the implementation chooses not to implement a certain visit method, 
fall
   // back on VisitExpr or whatever else is the superclass.
+  // Note: In debug builds, avoid ALWAYS_INLINE to prevent stack overflow with
+  // deeply nested expressions (e.g., 2000+ logical operators).
 #define STMT(CLASS, PARENT)                                                    
\
-  LLVM_ATTRIBUTE_ALWAYS_INLINE                                                 
\
+  LLVM_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG                                    
\
   RetTy Visit##CLASS(PTR(CLASS) S, ParamTys... P) { DISPATCH(PARENT, PARENT); }
 #include "clang/AST/StmtNodes.inc"
 

diff  --git a/llvm/include/llvm/Support/Compiler.h 
b/llvm/include/llvm/Support/Compiler.h
index 35f92b2b51430..cffab778deeb4 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -358,6 +358,15 @@
 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
 #endif
 
+/// LLVM_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG - Like
+/// LLVM_ATTRIBUTE_ALWAYS_INLINE but disabled in debug builds to avoid stack
+/// overflow with deep recursion.
+#if defined(NDEBUG)
+#define LLVM_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG LLVM_ATTRIBUTE_ALWAYS_INLINE
+#else
+#define LLVM_ATTRIBUTE_ALWAYS_INLINE_UNLESS_DEBUG inline
+#endif
+
 /// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do
 /// so, mark a method "no debug" because debug info makes the debugger
 /// experience worse.


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

Reply via email to