================
@@ -6064,13 +6064,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr<MSAllocatorAttr>())
     getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr<ErrorAttr>()) {
-    llvm::ConstantInt *Line =
-        llvm::ConstantInt::get(Int64Ty, Loc.getRawEncoding());
-    llvm::ConstantAsMetadata *MD = llvm::ConstantAsMetadata::get(Line);
-    llvm::MDTuple *MDT = llvm::MDNode::get(getLLVMContext(), {MD});
-    CI->setMetadata("srcloc", MDT);
+  // Add srcloc metadata for [[gnu::error/warning]] diagnostics. Track
+  // inline/static calls for the heuristic fallback when debug info is not
+  // available. This heuristic is conservative and best-effort since static or
+  // inline-annotated functions are still not guaranteed to be inlined.
+  if (TargetDecl) {
+    bool NeedSrcLoc = TargetDecl->hasAttr<ErrorAttr>();
+    if (!NeedSrcLoc) {
+      if (const auto *FD = dyn_cast<FunctionDecl>(TargetDecl))
+        NeedSrcLoc = FD->isInlined() || FD->hasAttr<AlwaysInlineAttr>() ||
+                     FD->getStorageClass() == SC_Static ||
+                     FD->isInAnonymousNamespace();
----------------
JustinStitt wrote:

@efriedma-quic 
> I think I'd like to see peak memory usage numbers for some C++ code.

I ran some benchmarks and saw the following results, note that each block is 10 
runs building some clang Sema code. 

```
peak memory usage building Sema/SemaExpr.cpp                                    
                        
    ┌─────────────┬──────────────┬──────────────┬──────────────┐                
 
    │ Config      │    Blk 1     │    Blk 2     │   Overhead   │                
 
    ├─────────────┼──────────────┼──────────────┼──────────────┤                
 
    │ Vanilla     │  1013.9 MB   │  1013.4 MB   │      -       │                
 
    │ Heuristic   │  1031.2 MB   │  1031.0 MB   │   +1.7%      │                
 
    │ Debug       │  1353.9 MB   │  1355.8 MB   │  +33.7%      │
    └─────────────┴──────────────┴──────────────┴──────────────┘ 
```

I am not exactly sure how representative `SemaExpr.cpp` is of C++ code in the 
wild but we probably shouldn't be pushing 2% memory overhead too frequently, 
especially for simple diagnostic changes. 

I wanted to hide all of this behind a flag but as you can see early on in this 
PR we opted to not do that. What are other options here? Can we drop the 
heuristic mode entirely and just let users build with `-g1` if they are 
debugging a `error/warning`-annotated stack?

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

Reply via email to