Skip to content

[analyzer] Remove some false negatives in StackAddrEscapeChecker #125638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Flandini
Copy link
Contributor

@Flandini Flandini commented Feb 4, 2025

Fixes #123459.

Previously, when the StackAddrEscapeChecker checked return values, it did not scan into the structure of the return SVal. Now it does, and we can catch some more false negatives that were already mocked out in the tests in addition to those mentioned in #123459.

The warning message at the moment for these newly caught leaks is not great. I think they would be better if they had a better trace of why and how the region leaks. If y'all are happy with these changes, I would try to improve these warnings and work on normalizing this SVal checking on the checkEndFunction side of the checker also.

Two of the stack address leak test cases now have two warnings, one warning from return expression checking and another from checkEndFunction iterBindings checking. For these two cases, I prefer the warnings from the return expression checking, but I couldn't figure out a way to drop the checkEndFunction without breaking other checkEndFunction warnings that we do want. Thoughts here? They're fine, some test cases will warn twice depending on if checkEndFunction and checkPreStmt both emit warnings, like if leaking through an arg object and also returning the arg object.

@Flandini Flandini changed the title Remove some false negatives in StackAddrEscapeChecker [analyzer] Remove some false negatives in StackAddrEscapeChecker Feb 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 4, 2025

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Michael Flanders (Flandini)

Changes

Fixes #123459.

Previously, when the StackAddrEscapeChecker checked return values, it did not scan into the structure of the return SVal. Now it does, and we can catch some more false negatives that were already mocked out in the tests in addition to those mentioned in #123459.

The warning message at the moment for these newly caught leaks is not great. I think they would be better if they had a better trace of why and how the region leaks. If y'all are happy with these changes, I would try to improve these warnings and work on normalizing this SVal checking on the checkEndFunction side of the checker also.

Two of the stack address leak test cases now have two warnings, one warning from return expression checking and another from checkEndFunction iterBindings checking. For these two cases, I prefer the warnings from the return expression checking, but I couldn't figure out a way to drop the checkEndFunction without breaking other checkEndFunction warnings that we do want. Thoughts here?


Full diff: https://github.com/llvm/llvm-project/pull/125638.diff

3 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp (+135-53)
  • (modified) clang/test/Analysis/stack-addr-ps.cpp (+55-20)
  • (modified) clang/test/Analysis/stackaddrleak.cpp (+2-2)
diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
index f4de3b500499c48..86f0949994cf6b9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -54,8 +54,8 @@ class StackAddrEscapeChecker
                                   CheckerContext &C) const;
   void checkAsyncExecutedBlockCaptures(const BlockDataRegion &B,
                                        CheckerContext &C) const;
-  void EmitStackError(CheckerContext &C, const MemRegion *R,
-                      const Expr *RetE) const;
+  void EmitReturnLeakError(CheckerContext &C, const MemRegion *LeakedRegion,
+                           const Expr *RetE) const;
   bool isSemaphoreCaptured(const BlockDecl &B) const;
   static SourceRange genName(raw_ostream &os, const MemRegion *R,
                              ASTContext &Ctx);
@@ -147,9 +147,22 @@ StackAddrEscapeChecker::getCapturedStackRegions(const BlockDataRegion &B,
   return Regions;
 }
 
-void StackAddrEscapeChecker::EmitStackError(CheckerContext &C,
-                                            const MemRegion *R,
-                                            const Expr *RetE) const {
+static void EmitReturnedAsPartOfError(llvm::raw_ostream &OS, SVal ReturnedVal,
+                                      const MemRegion *LeakedRegion) {
+  if (const MemRegion *ReturnedRegion = ReturnedVal.getAsRegion()) {
+    if (isa<BlockDataRegion>(ReturnedRegion)) {
+      OS << " is captured by a returned block";
+      return;
+    }
+  }
+
+  // Generic message
+  OS << " returned to caller";
+}
+
+void StackAddrEscapeChecker::EmitReturnLeakError(CheckerContext &C,
+                                                 const MemRegion *R,
+                                                 const Expr *RetE) const {
   ExplodedNode *N = C.generateNonFatalErrorNode();
   if (!N)
     return;
@@ -157,11 +170,15 @@ void StackAddrEscapeChecker::EmitStackError(CheckerContext &C,
     BT_returnstack = std::make_unique<BugType>(
         CheckNames[CK_StackAddrEscapeChecker],
         "Return of address to stack-allocated memory");
+
   // Generate a report for this bug.
   SmallString<128> buf;
   llvm::raw_svector_ostream os(buf);
+
+  // Error message formatting
   SourceRange range = genName(os, R, C.getASTContext());
-  os << " returned to caller";
+  EmitReturnedAsPartOfError(os, C.getSVal(RetE), R);
+
   auto report =
       std::make_unique<PathSensitiveBugReport>(*BT_returnstack, os.str(), N);
   report->addRange(RetE->getSourceRange());
@@ -209,30 +226,6 @@ void StackAddrEscapeChecker::checkAsyncExecutedBlockCaptures(
   }
 }
 
-void StackAddrEscapeChecker::checkReturnedBlockCaptures(
-    const BlockDataRegion &B, CheckerContext &C) const {
-  for (const MemRegion *Region : getCapturedStackRegions(B, C)) {
-    if (isNotInCurrentFrame(Region, C))
-      continue;
-    ExplodedNode *N = C.generateNonFatalErrorNode();
-    if (!N)
-      continue;
-    if (!BT_capturedstackret)
-      BT_capturedstackret = std::make_unique<BugType>(
-          CheckNames[CK_StackAddrEscapeChecker],
-          "Address of stack-allocated memory is captured");
-    SmallString<128> Buf;
-    llvm::raw_svector_ostream Out(Buf);
-    SourceRange Range = genName(Out, Region, C.getASTContext());
-    Out << " is captured by a returned block";
-    auto Report = std::make_unique<PathSensitiveBugReport>(*BT_capturedstackret,
-                                                           Out.str(), N);
-    if (Range.isValid())
-      Report->addRange(Range);
-    C.emitReport(std::move(Report));
-  }
-}
-
 void StackAddrEscapeChecker::checkPreCall(const CallEvent &Call,
                                           CheckerContext &C) const {
   if (!ChecksEnabled[CK_StackAddrAsyncEscapeChecker])
@@ -247,45 +240,134 @@ void StackAddrEscapeChecker::checkPreCall(const CallEvent &Call,
   }
 }
 
-void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS,
-                                          CheckerContext &C) const {
-  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
-    return;
+/// A visitor made for use with a ScanReachableSymbols scanner, used
+/// for finding stack regions within an SVal that live on the current
+/// stack frame of the given checker context. This visitor excludes
+/// NonParamVarRegion that data is bound to in a BlockDataRegion's
+/// bindings, since these are likely uninteresting, e.g., in case a
+/// temporary is constructed on the stack, but it captures values
+/// that would leak.
+class FindStackRegionsSymbolVisitor final : public SymbolVisitor {
+  CheckerContext &Ctxt;
+  const StackFrameContext *StackFrameContext;
+  SmallVector<const MemRegion *> &EscapingStackRegions;
 
-  const Expr *RetE = RS->getRetValue();
-  if (!RetE)
-    return;
-  RetE = RetE->IgnoreParens();
+public:
+  explicit FindStackRegionsSymbolVisitor(
+      CheckerContext &Ctxt,
+      SmallVector<const MemRegion *> &StorageForStackRegions)
+      : Ctxt(Ctxt), StackFrameContext(Ctxt.getStackFrame()),
+        EscapingStackRegions(StorageForStackRegions) {}
 
-  SVal V = C.getSVal(RetE);
-  const MemRegion *R = V.getAsRegion();
-  if (!R)
-    return;
+  bool VisitSymbol(SymbolRef sym) override { return true; }
 
-  if (const BlockDataRegion *B = dyn_cast<BlockDataRegion>(R))
-    checkReturnedBlockCaptures(*B, C);
+  bool VisitMemRegion(const MemRegion *MR) override {
+    SaveIfEscapes(MR);
 
-  if (!isa<StackSpaceRegion>(R->getMemorySpace()) || isNotInCurrentFrame(R, C))
-    return;
+    if (const BlockDataRegion *BDR = MR->getAs<BlockDataRegion>())
+      return VisitBlockDataRegionCaptures(BDR);
+
+    return true;
+  }
+
+private:
+  void SaveIfEscapes(const MemRegion *MR) {
+    const StackSpaceRegion *SSR =
+        MR->getMemorySpace()->getAs<StackSpaceRegion>();
+    if (SSR && SSR->getStackFrame() == StackFrameContext)
+      EscapingStackRegions.push_back(MR);
+  }
+
+  bool VisitBlockDataRegionCaptures(const BlockDataRegion *BDR) {
+    for (auto Var : BDR->referenced_vars()) {
+      SVal Val = Ctxt.getState()->getSVal(Var.getCapturedRegion());
+      const MemRegion *Region = Val.getAsRegion();
+      if (Region) {
+        SaveIfEscapes(Region);
+        VisitMemRegion(Region);
+      }
+    }
+
+    return false;
+  }
+};
+
+/// Given some memory regions that are flagged by FindStackRegionsSymbolVisitor,
+/// this function filters out memory regions that are being returned that are
+/// likely not true leaks:
+/// 1. If returning a block data region that has stack memory space
+/// 2. If returning a constructed object that has stack memory space
+static SmallVector<const MemRegion *>
+FilterReturnExpressionLeaks(const SmallVector<const MemRegion *> &MaybeEscaped,
+                            CheckerContext &C, const Expr *RetE, SVal &RetVal) {
+
+  SmallVector<const MemRegion *> WillEscape;
+
+  const MemRegion *RetRegion = RetVal.getAsRegion();
 
   // Returning a record by value is fine. (In this case, the returned
   // expression will be a copy-constructor, possibly wrapped in an
   // ExprWithCleanups node.)
   if (const ExprWithCleanups *Cleanup = dyn_cast<ExprWithCleanups>(RetE))
     RetE = Cleanup->getSubExpr();
-  if (isa<CXXConstructExpr>(RetE) && RetE->getType()->isRecordType())
-    return;
+  bool IsConstructExpr =
+      isa<CXXConstructExpr>(RetE) && RetE->getType()->isRecordType();
 
   // The CK_CopyAndAutoreleaseBlockObject cast causes the block to be copied
   // so the stack address is not escaping here.
+  bool IsCopyAndAutoreleaseBlockObj = false;
   if (const auto *ICE = dyn_cast<ImplicitCastExpr>(RetE)) {
-    if (isa<BlockDataRegion>(R) &&
-        ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject) {
-      return;
-    }
+    IsCopyAndAutoreleaseBlockObj =
+        isa_and_nonnull<BlockDataRegion>(RetRegion) &&
+        ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject;
+  }
+
+  for (const MemRegion *MR : MaybeEscaped) {
+    if (RetRegion == MR && (IsCopyAndAutoreleaseBlockObj || IsConstructExpr))
+      continue;
+
+    // If this is a construct expr of an unelided return value copy, then don't
+    // warn about returning a region that currently lives on the stack.
+    if (IsConstructExpr && RetVal.getAs<nonloc::LazyCompoundVal>() &&
+        isa<CXXTempObjectRegion>(MR))
+      continue;
+
+    WillEscape.push_back(MR);
   }
 
-  EmitStackError(C, R, RetE);
+  return WillEscape;
+}
+
+/// For use in finding regions that live on the checker context's current
+/// stack frame, deep in the SVal representing the return value.
+static SmallVector<const MemRegion *>
+FindEscapingStackRegions(CheckerContext &C, const Expr *RetE, SVal RetVal) {
+  SmallVector<const MemRegion *> FoundStackRegions;
+
+  FindStackRegionsSymbolVisitor Finder(C, FoundStackRegions);
+  ScanReachableSymbols Scanner(C.getState(), Finder);
+  Scanner.scan(RetVal);
+
+  return FilterReturnExpressionLeaks(FoundStackRegions, C, RetE, RetVal);
+}
+
+void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS,
+                                          CheckerContext &C) const {
+  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
+    return;
+
+  const Expr *RetE = RS->getRetValue();
+  if (!RetE)
+    return;
+  RetE = RetE->IgnoreParens();
+
+  SVal V = C.getSVal(RetE);
+
+  SmallVector<const MemRegion *> EscapedStackRegions =
+      FindEscapingStackRegions(C, RetE, V);
+
+  for (const MemRegion *ER : EscapedStackRegions)
+    EmitReturnLeakError(C, ER, RetE);
 }
 
 static const MemSpaceRegion *getStackOrGlobalSpaceRegion(const MemRegion *R) {
diff --git a/clang/test/Analysis/stack-addr-ps.cpp b/clang/test/Analysis/stack-addr-ps.cpp
index 73e9dbeca460f60..392982d92a3f14c 100644
--- a/clang/test/Analysis/stack-addr-ps.cpp
+++ b/clang/test/Analysis/stack-addr-ps.cpp
@@ -251,7 +251,7 @@ void* lambda_to_context_direct_pointer_uncalled() {
     int local = 42;
     p = &local; // no-warning: analyzed only as top-level, ignored explicitly by the checker
   };
-  return new MyFunction(&lambda);
+  return new MyFunction(&lambda); // expected-warning{{Address of stack memory associated with local variable 'lambda' returned to caller}}
 }
 
 void lambda_to_context_direct_pointer_lifetime_extended() {
@@ -410,16 +410,16 @@ void** returned_arr_of_ptr_top() {
   int* p = &local;
   void** arr = new void*[2];
   arr[1] = p;
-  return arr;
-} // no-warning False Negative
+  return arr; // expected-warning{{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 void** returned_arr_of_ptr_callee() {
   int local = 42;
   int* p = &local;
   void** arr = new void*[2];
   arr[1] = p;
-  return arr;
-} // no-warning False Negative
+  return arr; // expected-warning{{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 void returned_arr_of_ptr_caller() {
   void** arr = returned_arr_of_ptr_callee();
@@ -466,16 +466,16 @@ void** returned_arr_of_ptr_top(int idx) {
   int* p = &local;
   void** arr = new void*[2];
   arr[idx] = p;
-  return arr;
-} // no-warning False Negative
+  return arr; // expected-warning{{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 void** returned_arr_of_ptr_callee(int idx) {
   int local = 42;
   int* p = &local;
   void** arr = new void*[2];
   arr[idx] = p;
-  return arr;
-} // no-warning False Negative
+  return arr; // expected-warning{{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 void returned_arr_of_ptr_caller(int idx) {
   void** arr = returned_arr_of_ptr_callee(idx);
@@ -525,14 +525,25 @@ S returned_struct_with_ptr_top() {
   int local = 42;
   S s;
   s.p = &local;
-  return s;
-} // no-warning False Negative, requires traversing returned LazyCompoundVals
+  return s; // expected-warning{{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 S returned_struct_with_ptr_callee() {
   int local = 42;
   S s;
   s.p = &local;
-  return s; // expected-warning{{'local' is still referred to by the caller variable 's'}}
+  return s; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}} expected-warning{{Address of stack memory associated with local variable 'local' is still referred to by the caller variable 's' upon returning to the caller.  This will be a dangling reference}}
+}
+
+S leak_through_field_of_returned_object() {
+  int local = 14;
+  S s{&local};
+  return s; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
+}
+
+S leak_through_compound_literal() {
+  int local = 0;
+  return (S) { &local }; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
 }
 
 void returned_struct_with_ptr_caller() {
@@ -555,6 +566,30 @@ void static_struct_with_ptr() {
 }
 } // namespace leaking_via_struct_with_ptr
 
+namespace leaking_via_nested_structs_with_ptr {
+struct Inner {
+  int *ptr;
+};
+
+struct Outer {
+  Inner I;
+};
+
+struct Deriving : public Outer {};
+
+Outer leaks_through_nested_objects() {
+  int local = 0;
+  Outer O{&local};
+  return O; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
+}
+
+Deriving leaks_through_base_objects() {
+  int local = 0;
+  Deriving D{&local};
+  return D; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
+}
+} // namespace leaking_via_nested_structs_with_ptr
+
 namespace leaking_via_ref_to_struct_with_ptr {
 struct S {
   int* p;
@@ -613,15 +648,15 @@ S* returned_ptr_to_struct_with_ptr_top() {
   int local = 42;
   S* s = new S;
   s->p = &local;
-  return s;
-} // no-warning False Negative
+  return s; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 S* returned_ptr_to_struct_with_ptr_callee() {
   int local = 42;
   S* s = new S;
   s->p = &local;
-  return s;
-} // no-warning False Negative
+  return s; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 void returned_ptr_to_struct_with_ptr_caller() {
   S* s = returned_ptr_to_struct_with_ptr_callee();
@@ -676,15 +711,15 @@ S* returned_ptr_to_struct_with_ptr_top() {
   int local = 42;
   S* s = new S[2];
   s[1].p = &local;
-  return s;
-} // no-warning False Negative
+  return s; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 S* returned_ptr_to_struct_with_ptr_callee() {
   int local = 42;
   S* s = new S[2];
   s[1].p = &local;
-  return s;
-} // no-warning  False Negative
+  return s; // expected-warning {{Address of stack memory associated with local variable 'local' returned to caller}}
+}
 
 void returned_ptr_to_struct_with_ptr_caller() {
   S* s = returned_ptr_to_struct_with_ptr_callee();
diff --git a/clang/test/Analysis/stackaddrleak.cpp b/clang/test/Analysis/stackaddrleak.cpp
index 3daffb35a6cd9a6..a44fb1f7d2dd121 100644
--- a/clang/test/Analysis/stackaddrleak.cpp
+++ b/clang/test/Analysis/stackaddrleak.cpp
@@ -18,8 +18,8 @@ struct myfunction {
 myfunction create_func() {
   int n;
   auto c = [&n] {};
-  return c; // expected-warning {{Address of stack memory associated with local variable 'n' is still referred to by a temporary object on the stack upon returning to the caller.  This will be a dangling reference}}
+  return c; // expected-warning {{Address of stack memory associated with local variable 'n' returned to caller}} expected-warning{{Address of stack memory associated with local variable 'n' is still referred to by a temporary object on the stack upon returning to the caller.  This will be a dangling reference}}
 }
 void gh_66221() {
   create_func()();
-}
+}
\ No newline at end of file

Copy link
Collaborator

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going in the right direction but I'd love to see more tests and some more thought about some scenarios.


// If this is a construct expr of an unelided return value copy, then don't
// warn about returning a region that currently lives on the stack.
if (IsConstructExpr && RetVal.getAs<nonloc::LazyCompoundVal>() &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this is the right solution here. I am a bit concerned that there are some other cases that we missed here. I think we are only interested in stack memory regions that are behind a pointer.

But this is also not entirely true. Imagine the following case:

DoesDeepCopy myFunc() {
   int local;
   DoesDeepCopy l(&local);
   return l;
};

Here, if DoesDeepCopy's ctor would copy the value behind the pointer, the code above is fine. On the second though, I wonder if NRVO can actually kick in making this code unsafe.

That being said, if the copy ctor is actually invoked, hopefully we would observe the effects of that, the fields would get invalidated, and we would not see the memory region from the stack.

Overall, I think some scenarios here might need more tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is only for removing warnings. It is a little loose and maybe could cause some false negatives. Is there a way here to relate the lazy compound val that would be returned and the temp object region in an example like this from copy-elision.cpp test:

template <typename T> struct AddressVector {
  T *buf[20];
  int len;

  AddressVector() : len(0) {}

  void push(T *t) {
    buf[len] = t;
    ++len;
  }
};

class ClassWithoutDestructor {
  AddressVector<ClassWithoutDestructor> &v;

public:
  ClassWithoutDestructor(AddressVector<ClassWithoutDestructor> &v) : v(v) {
    push();
  }

  ClassWithoutDestructor(ClassWithoutDestructor &&c) : v(c.v) { push(); }
  ClassWithoutDestructor(const ClassWithoutDestructor &c) : v(c.v) { push(); }

  void push() { v.push(this); }
};

ClassWithoutDestructor make1(AddressVector<ClassWithoutDestructor> &v) {
  return ClassWithoutDestructor(v); 
  // no-elide-warning@-1 {{Address of stack memory associated with temporary \
object of type 'ClassWithoutDestructor' is still \
referred to by the caller variable 'v' upon returning to the caller}}
}

Without some check like this, then the line with return ClassWithoutDestructor(v); will warn, and I think it should not under -analyzer-config elide-constructors=false -DNO_ELIDE_FLAG -std=c++11. Is there a better way to relate the lazy compound val of the return expr and the temp object region that is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are only interested in stack memory regions that are behind a pointer.

I think there are still some cases where warning on the returned pointer is also wanted, like this one, or maybe more complicated versions of this that normal compilation warnings wouldn't catch

int *test() {
  int x = 14;
  return &x;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local memory region in the function test is behind a pointer so that is matches my description.

But we would not want to warn for:

int test2() {
  int x = 14;
  return x;
}

Because here x is not behind a pointer.

Could you elaborate why the analyzer thinks the temporary is referred to by v here?

Is there a better way to relate the lazy compound val of the return expr and the temp object region that is created?

Dealing with LazyCompoundVals can be a bit fiddly. You could take a look at FindUninitializedField in CallAndMessageChecker.cpp .

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I wonder if what we have here is similar to what the analyzer is doing when creating the checkPointerEscape callback. We basically want to collect all the pointers from the returned value a similar way and want to check if any of those point to stack memory. I think collecting the pointers might be an API that we need/want to expose to the checkers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We basically want to collect all the pointers from the returned value a similar way and want to check if any of those point to stack memory.

That is what I was hoping this PR was: add a ScanReachableSymbols & SymbolVisitor that takes all stack regions behind the return SVal and warns on those. Previously, this checker only did this for BlockDataRegion captures and it only checked if the return SVal is a stack space region.

IIUC, you would like this instead to be reworked into checkPointerEscape?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does a v.push(this)

Ah, thanks for the explanation, I missed this detail somehow. So this actually is a true positive warning when copy elision is not happening. I think in that case we should only filter these temporaries out when the temporary is actually elided (we should see this in the AST).

And now I better understand what you mean by relating the returned memory region and the lazy compound val. You already have a RetRegion, would comparing that to LazyCompoundVal::getRegion() work?

Copy link
Collaborator

@Xazax-hun Xazax-hun Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, you would like this instead to be reworked into checkPointerEscape?

Nope, my bad. Sorry, I misunderstood something. Using ScanReachableSymbols sounds like the right approach to me. I am wondering why is it sufficient to check if a memory region belongs to the current stack. I.e., why we would not warn on:

int test2() {
  int x = someFunc();
  return x;
}

Copy link
Contributor Author

@Flandini Flandini Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering why is it sufficient to check if a memory region belongs to the current stack. I.e., why we would not warn on:

int test2() {
int x = someFunc();
 return x;
}

Is it because we do this:

void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS,
                                          CheckerContext &C) const {
  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
    return;

  const Expr *RetE = RS->getRetValue();
  if (!RetE)
    return;
  RetE = RetE->IgnoreParens();

  SVal V = C.getSVal(RetE);

  ... scan V for escaping stack regions ...

we get the result of the LValueToRValue conversion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we get the result of the LValueToRValue conversion?

Ah, I see. Thanks!

@Flandini
Copy link
Contributor Author

Flandini commented Feb 4, 2025

I think this is going in the right direction but I'd love to see more tests and some more thought about some scenarios.

I'll do some structural induction approach to what could be returned and what could hold which things, and make sure these all have some test case coverage.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder amdgpu-offload-rhel-9-cmake-build-only running on rocm-docker-rhel-9 while building clang at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/424

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: '../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py --jobs=32' (failure)
...
[6643/7633] Linking CXX executable bin/llvm-exegesis
[6644/7633] Linking CXX shared library lib/libFortranSupport.so.21.0git
[6645/7633] Creating library symlink lib/libFortranSupport.so
[6646/7633] Building AMDGPUGenRegisterBank.inc...
[6647/7633] Linking CXX shared library lib/libFortranParser.so.21.0git
[6648/7633] Creating library symlink lib/libFortranParser.so
[6649/7633] Linking CXX executable bin/f18-parse-demo
[6650/7633] Linking CXX shared library lib/libFortranEvaluate.so.21.0git
[6651/7633] Creating library symlink lib/libFortranEvaluate.so
[6652/7633] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/tools/clang/lib/StaticAnalyzer/Checkers -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/tools/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/include -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: ‘StackFrameContext’ declared here as ‘class clang::StackFrameContext’
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
[6653/7633] Linking CXX shared library lib/libFortranSemantics.so.21.0git
[6654/7633] Building InstCombineTables.inc...
ninja: build stopped: subcommand failed.
['ninja'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py", line 45, in step
    yield
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py", line 36, in main
    run_command(["ninja"])
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py", line 58, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib64/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja']' returned non-zero exit status 1.
@@@STEP_FAILURE@@@
Step 7 (build cmake config) failure: build cmake config (failure)
...
[6643/7633] Linking CXX executable bin/llvm-exegesis
[6644/7633] Linking CXX shared library lib/libFortranSupport.so.21.0git
[6645/7633] Creating library symlink lib/libFortranSupport.so
[6646/7633] Building AMDGPUGenRegisterBank.inc...
[6647/7633] Linking CXX shared library lib/libFortranParser.so.21.0git
[6648/7633] Creating library symlink lib/libFortranParser.so
[6649/7633] Linking CXX executable bin/f18-parse-demo
[6650/7633] Linking CXX shared library lib/libFortranEvaluate.so.21.0git
[6651/7633] Creating library symlink lib/libFortranEvaluate.so
[6652/7633] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/tools/clang/lib/StaticAnalyzer/Checkers -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/tools/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/include -I/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-project/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: ‘StackFrameContext’ declared here as ‘class clang::StackFrameContext’
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
[6653/7633] Linking CXX shared library lib/libFortranSemantics.so.21.0git
[6654/7633] Building InstCombineTables.inc...
ninja: build stopped: subcommand failed.
['ninja'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py", line 45, in step
    yield
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py", line 36, in main
    run_command(["ninja"])
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py", line 58, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib64/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja']' returned non-zero exit status 1.
program finished with exit code 0
elapsedTime=50.615068

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder flang-aarch64-latest-gcc running on linaro-flang-aarch64-latest-gcc while building clang at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/130/builds/9793

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
91.044 [957/19/6370] Building CXX object tools/clang/tools/clang-installapi/CMakeFiles/clang-installapi.dir/Options.cpp.o
91.160 [952/23/6371] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXCompilationDatabase.cpp.o
91.184 [952/22/6372] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXLoadedDiagnostic.cpp.o
91.280 [945/28/6373] Building CXX object tools/clang/tools/amdgpu-arch/CMakeFiles/amdgpu-arch.dir/AMDGPUArch.cpp.o
91.288 [945/27/6374] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/FatalErrorHandler.cpp.o
91.318 [945/26/6375] Building CXX object tools/clang/tools/amdgpu-arch/CMakeFiles/amdgpu-arch.dir/AMDGPUArchByHIP.cpp.o
91.332 [945/25/6376] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexer.cpp.o
91.374 [945/24/6377] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexDiagnostic.cpp.o
91.384 [945/23/6378] Building CXX object tools/clang/tools/amdgpu-arch/CMakeFiles/amdgpu-arch.dir/AMDGPUArchByKFD.cpp.o
91.428 [945/22/6379] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
/usr/local/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/clang/lib/StaticAnalyzer/Checkers -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/clang/lib/StaticAnalyzer/Checkers -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/clang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/clang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
../llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-Wchanges-meaning]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
../llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:9: note: used here to mean ‘class clang::StackFrameContext’
  252 |   const StackFrameContext *StackFrameContext;
      |         ^~~~~~~~~~~~~~~~~
In file included from ../llvm-project/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from ../llvm-project/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from ../llvm-project/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from ../llvm-project/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
../llvm-project/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: declared here
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
91.450 [945/21/6380] Building CXX object tools/clang/tools/clang-refactor/CMakeFiles/clang-refactor.dir/ClangRefactor.cpp.o
91.480 [945/20/6381] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXComment.cpp.o
91.485 [945/19/6382] Building CXX object tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/core_main.cpp.o
91.593 [945/18/6383] Building CXX object tools/clang/tools/clang-extdef-mapping/CMakeFiles/clang-extdef-mapping.dir/ClangExtDefMapGen.cpp.o
91.604 [945/17/6384] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexUSRs.cpp.o
91.617 [945/16/6385] Building CXX object tools/clang/tools/clang-scan-deps/CMakeFiles/clang-scan-deps.dir/ClangScanDeps.cpp.o
91.643 [945/15/6386] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexInclusionStack.cpp.o
91.644 [945/14/6387] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexHigh.cpp.o
91.692 [945/13/6388] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXCursor.cpp.o
91.740 [945/12/6389] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndex.cpp.o
91.846 [945/11/6390] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXStoredDiagnostic.cpp.o
../llvm-project/clang/tools/libclang/CXStoredDiagnostic.cpp: In member function ‘virtual CXString clang::CXStoredDiagnostic::getFixIt(unsigned int, CXSourceRange*) const’:
../llvm-project/clang/tools/libclang/CXStoredDiagnostic.cpp:103:20: warning: possibly dangling reference to a temporary [-Wdangling-reference]
  103 |   const FixItHint &Hint = Diag.fixit_begin()[FixIt];
      |                    ^~~~
../llvm-project/clang/tools/libclang/CXStoredDiagnostic.cpp:103:51: note: the temporary was destroyed at the end of the full expression ‘(&((const clang::CXStoredDiagnostic*)this)->clang::CXStoredDiagnostic::Diag)->clang::StoredDiagnostic::fixit_begin().__gnu_cxx::__normal_iterator<const clang::FixItHint*, std::vector<clang::FixItHint, std::allocator<clang::FixItHint> > >::operator[](((__gnu_cxx::__normal_iterator<const clang::FixItHint*, std::vector<clang::FixItHint, std::allocator<clang::FixItHint> > >::difference_type)FixIt))’
  103 |   const FixItHint &Hint = Diag.fixit_begin()[FixIt];
      |                                                   ^
91.861 [945/10/6391] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXString.cpp.o
91.892 [945/9/6392] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXSourceLocation.cpp.o
91.893 [945/8/6393] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXType.cpp.o
91.936 [945/7/6394] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexCodeCompletion.cpp.o
91.971 [945/6/6395] Building CXX object tools/clang/tools/clang-installapi/CMakeFiles/clang-installapi.dir/ClangInstallAPI.cpp.o
91.977 [945/5/6396] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/Rewrite.cpp.o

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder polly-x86_64-linux-noassert running on polly-x86_64-gce1 while building clang at step 5 "build".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/28/builds/6734

Here is the relevant piece of the build log for the reference
Step 5 (build) failure: 'ninja' (failure)
...
[61/110] Linking CXX executable bin/llvm-symbolizer
[62/110] Generating ../../bin/llvm-addr2line
[63/110] Linking CXX executable bin/obj2yaml
[64/110] Linking CXX executable bin/llvm-xray
[65/110] Linking CXX executable bin/sancov
[66/110] Linking CXX executable bin/sanstats
[67/110] Linking CXX executable bin/yaml2obj
[68/110] Copying llvm-locstats into /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/./bin
[69/110] Linking CXX executable bin/verify-uselistorder
[70/110] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/tools/clang/lib/StaticAnalyzer/Checkers -I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers -I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/include -I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/tools/clang/include -I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/include -I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: ‘StackFrameContext’ declared here as ‘class clang::StackFrameContext’
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
[71/110] Building CXX object lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/AsmPrinter.cpp.o
[72/110] Building CXX object lib/LTO/CMakeFiles/LLVMLTO.dir/LTO.cpp.o
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder polly-x86_64-linux-shlib running on polly-x86_64-gce2 while building clang at step 5 "build".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/99/builds/4643

Here is the relevant piece of the build log for the reference
Step 5 (build) failure: 'ninja' (failure)
[1/141] Generating VCSRevision.h
[2/141] Generating VCSVersion.inc
[3/141] Building CXX object tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o
[4/141] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/IRSymtab.cpp.o
[5/141] Linking CXX static library lib/libLLVMObject.a
[6/141] Linking CXX executable bin/llvm-config
[7/141] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Version.cpp.o
[8/141] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.obj/tools/clang/lib/StaticAnalyzer/Checkers -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.obj/tools/clang/include -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.obj/include -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: ‘StackFrameContext’ declared here as ‘class clang::StackFrameContext’
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
[9/141] Building CXX object lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/AsmPrinter.cpp.o
[10/141] Building CXX object lib/LTO/CMakeFiles/LLVMLTO.dir/LTO.cpp.o
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder clang-x86_64-linux-abi-test running on sie-linux-worker2 while building clang at step 6 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/8/builds/11001

Here is the relevant piece of the build log for the reference
Step 6 (build-unified-tree) failure: build (failure)
...
155.242 [2059/10/5001] Linking CXX executable bin/clang-extdef-mapping
155.247 [2058/10/5002] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/FasterStrsplitDelimiterCheck.cpp.o
155.252 [2057/10/5003] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/NoInternalDependenciesCheck.cpp.o
155.263 [2056/10/5004] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/NoNamespaceCheck.cpp.o
155.283 [2055/10/5005] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/RedundantStrcatCallsCheck.cpp.o
155.287 [2054/10/5006] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/StrCatAppendCheck.cpp.o
155.289 [2053/10/5007] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/StringFindStrContainsCheck.cpp.o
155.316 [2052/10/5008] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/TimeComparisonCheck.cpp.o
155.323 [2051/10/5009] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/UpgradeDurationConversionsCheck.cpp.o
155.327 [2050/10/5010] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
/opt/ccache/bin/g++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbot/buildbot-root/abi-test/build/tools/clang/lib/StaticAnalyzer/Checkers -I/home/buildbot/buildbot-root/abi-test/llvm/clang/lib/StaticAnalyzer/Checkers -I/home/buildbot/buildbot-root/abi-test/llvm/clang/include -I/home/buildbot/buildbot-root/abi-test/build/tools/clang/include -I/home/buildbot/buildbot-root/abi-test/build/include -I/home/buildbot/buildbot-root/abi-test/llvm/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/buildbot/buildbot-root/abi-test/llvm/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/buildbot/buildbot-root/abi-test/llvm/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/buildbot/buildbot-root/abi-test/llvm/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/buildbot/buildbot-root/abi-test/llvm/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/buildbot/buildbot-root/abi-test/llvm/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/buildbot/buildbot-root/abi-test/llvm/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/buildbot/buildbot-root/abi-test/llvm/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: ‘StackFrameContext’ declared here as ‘class clang::StackFrameContext’
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
155.331 [2050/9/5011] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/TimeSubtractionCheck.cpp.o
155.339 [2050/8/5012] Building CXX object tools/clang/tools/extra/clang-tidy/altera/CMakeFiles/obj.clangTidyAlteraModule.dir/AlteraTidyModule.cpp.o
155.354 [2050/7/5013] Building CXX object tools/clang/tools/extra/clang-tidy/altera/CMakeFiles/obj.clangTidyAlteraModule.dir/SingleWorkItemBarrierCheck.cpp.o
155.428 [2050/6/5014] Building CXX object tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/CoverageChecker.cpp.o
155.489 [2050/5/5015] Building CXX object tools/clang/tools/extra/clang-tidy/CMakeFiles/obj.clangTidy.dir/ExpandModularHeadersPPCallbacks.cpp.o
155.850 [2050/4/5016] Building CXX object tools/clang/tools/extra/clang-tidy/altera/CMakeFiles/obj.clangTidyAlteraModule.dir/KernelNameRestrictionCheck.cpp.o
155.896 [2050/3/5017] Building CXX object tools/clang/tools/extra/clang-tidy/abseil/CMakeFiles/obj.clangTidyAbseilModule.dir/StringFindStartswithCheck.cpp.o
155.956 [2050/2/5018] Linking CXX executable bin/clang-reorder-fields
156.719 [2050/1/5019] Linking CXX executable bin/clang-scan-deps
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder polly-x86_64-linux-shlib-plugin running on polly-x86_64-gce2 while building clang at step 5 "build".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/75/builds/4974

Here is the relevant piece of the build log for the reference
Step 5 (build) failure: 'ninja' (failure)
...
[116/141] Creating library symlink lib/libRemarks.so
[117/141] Linking CXX executable bin/sanstats
[118/141] Linking CXX shared module lib/ExampleIRTransforms.so
[119/141] Linking CXX shared module lib/Bye.so
[120/141] Linking CXX shared module unittests/Analysis/InlineAdvisorPlugin.so
[121/141] Linking CXX shared module unittests/Analysis/InlineOrderPlugin.so
[122/141] Linking CXX shared module unittests/Passes/Plugins/TestPlugin.so
[123/141] Copying llvm-locstats into /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.obj/./bin
[124/141] Linking CXX shared module unittests/Passes/Plugins/DoublerPlugin.so
[125/141] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.obj/tools/clang/lib/StaticAnalyzer/Checkers -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.obj/tools/clang/include -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.obj/include -I/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/worker/buildbot-workers/polly-x86_64-gce2/rundir/llvm.src/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: ‘StackFrameContext’ declared here as ‘class clang::StackFrameContext’
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building clang at step 5 "compile-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/7858

Here is the relevant piece of the build log for the reference
Step 5 (compile-openmp) failure: build (failure)
...
286.650 [619/4/4662] Linking CXX static library lib/libclangDependencyScanning.a
286.679 [618/4/4663] Linking CXX static library lib/libclangIndex.a
286.688 [617/4/4664] Building CXX object tools/clang/lib/StaticAnalyzer/Frontend/CMakeFiles/obj.clangStaticAnalyzerFrontend.dir/ModelInjector.cpp.o
286.692 [616/4/4665] Linking CXX static library lib/libclangCrossTU.a
286.730 [615/4/4666] Linking CXX static library lib/libclangExtractAPI.a
286.751 [614/4/4667] Linking CXX static library lib/libclangToolingRefactoring.a
286.845 [613/4/4668] Linking CXX static library lib/libclangTransformer.a
286.878 [612/4/4669] Building CXX object tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/IncrementalExecutor.cpp.o
286.892 [611/4/4670] Linking CXX static library lib/libclangStaticAnalyzerCore.a
286.930 [610/4/4671] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/tools/clang/lib/StaticAnalyzer/Checkers -I/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/lib/StaticAnalyzer/Checkers -I/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/include -I/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/tools/clang/include -I/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/include -I/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of 'const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext' changes meaning of 'StackFrameContext' [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: 'StackFrameContext' declared here as 'class clang::StackFrameContext'
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
287.238 [610/3/4672] Building CXX object tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/CodeCompletion.cpp.o
287.523 [610/2/4673] Building CXX object tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/IncrementalParser.cpp.o
287.746 [610/1/4674] Building CXX object tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/Interpreter.cpp.o
ninja: build stopped: subcommand failed.

@Xazax-hun
Copy link
Collaborator

I reverted the change due to the build failure. Could you open a new PR with the error fixed?

@Flandini
Copy link
Contributor Author

I reverted the change due to the build failure. Could you open a new PR with the error fixed?

Yes, sorry.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 10, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building clang at step 5 "compile-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/13004

Here is the relevant piece of the build log for the reference
Step 5 (compile-openmp) failure: build (failure)
...
42.162 [563/12/3799] Linking CXX executable bin/llvm-exegesis
43.065 [563/11/3800] Linking CXX executable bin/clang-diff
43.105 [563/10/3801] Building AMDGPUGenGlobalISel.inc...
43.329 [563/9/3802] Linking CXX executable bin/clang-refactor
43.646 [563/8/3803] Linking CXX executable bin/clang-installapi
44.627 [563/7/3804] Building AMDGPUGenAsmMatcher.inc...
45.172 [563/6/3805] Building AMDGPUGenDAGISel.inc...
45.405 [563/5/3806] Linking CXX executable bin/clang-import-test
45.824 [563/4/3807] Building AMDGPUGenInstrInfo.inc...
45.943 [563/3/3808] Building CXX object tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o
FAILED: tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/tools/clang/lib/StaticAnalyzer/Checkers -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/lib/StaticAnalyzer/Checkers -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/include -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/tools/clang/include -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/include -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -MF tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o.d -o tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/StackAddrEscapeChecker.cpp.o -c /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:252:28: error: declaration of ‘const clang::StackFrameContext* FindStackRegionsSymbolVisitor::StackFrameContext’ changes meaning of ‘StackFrameContext’ [-fpermissive]
  252 |   const StackFrameContext *StackFrameContext;
      |                            ^~~~~~~~~~~~~~~~~
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/include/clang/Analysis/ProgramPoint.h:17,
                 from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/include/clang/StaticAnalyzer/Core/Checker.h:16,
                 from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h:18,
                 from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:17:
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/clang/include/clang/Analysis/AnalysisDeclContext.h:299:7: note: ‘StackFrameContext’ declared here as ‘class clang::StackFrameContext’
  299 | class StackFrameContext : public LocationContext {
      |       ^~~~~~~~~~~~~~~~~
48.304 [563/2/3809] Building AMDGPUGenRegisterInfo.inc...
49.076 [563/1/3810] Building AMDGPUGenRegisterBank.inc...
ninja: build stopped: subcommand failed.

@steakhal
Copy link
Contributor

I wonder how did the "premerge" checks step succeed, if we had build errors.
Does anyone know why was it green right before the merge but surfaced build errors after the merge?

Xazax-hun pushed a commit that referenced this pull request Feb 11, 2025
…t fix (#126620)

Reapplying changes from #125638
after buildbot failures.

Buildbot failures fixed in 029e7e9,
latest commit on this PR. It was a problem with a declared class member
with same name as its type. Sorry!
github-actions bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 11, 2025
…s + buildbot fix (#126620)

Reapplying changes from llvm/llvm-project#125638
after buildbot failures.

Buildbot failures fixed in 029e7e98dc9956086adc6c1dfb0c655a273fbee6,
latest commit on this PR. It was a problem with a declared class member
with same name as its type. Sorry!
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…m#125638)

Fixes llvm#123459.

Previously, when the StackAddrEscapeChecker checked return values, it
did not scan into the structure of the return SVal. Now it does, and we
can catch some more false negatives that were already mocked out in the
tests in addition to those mentioned in
llvm#123459.

The warning message at the moment for these newly caught leaks is not
great. I think they would be better if they had a better trace of why
and how the region leaks. If y'all are happy with these changes, I would
try to improve these warnings and work on normalizing this SVal checking
on the `checkEndFunction` side of the checker also.

Two of the stack address leak test cases now have two warnings, one
warning from return expression checking and another from`
checkEndFunction` `iterBindings` checking. For these two cases, I prefer
the warnings from the return expression checking, but I couldn't figure
out a way to drop the `checkEndFunction` without breaking other
`checkEndFunction` warnings that we do want. Thoughts here?
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…t fix (llvm#126620)

Reapplying changes from llvm#125638
after buildbot failures.

Buildbot failures fixed in 029e7e9,
latest commit on this PR. It was a problem with a declared class member
with same name as its type. Sorry!
@Flandini
Copy link
Contributor Author

@steakhal, looks like the premerge checks built with clang 20 https://buildkite.com/llvm-project/github-pull-requests/builds/145477#0194f106-3262-4d2b-922c-b3810220acd1/6-4595. I build locally with clang 18.

This type of error is caught by g++, not clang++: https://godbolt.org/z/7Y445Pn13.

These failed CI builds/tests look like they are built with gcc/g++ maybe? Some explicitly invoke g++, others call /usr/bin/c++

@Flandini
Copy link
Contributor Author

Worth adding a g++ pre-merge build? Can individual subprojects change their pre-merge checks?

@steakhal
Copy link
Contributor

Worth adding a g++ pre-merge build? Can individual subprojects change their pre-merge checks?

I don't have all the context, as I didn't follow this closely, so I wouldn't raise this.
However, if you think it's worth pursuing and avoiding in the future, feel free to summarize it in a question at https://discourse.llvm.org/c/infrastructure/15. They should tell us if it would make sense.

@Flandini
Copy link
Contributor Author

Did some looking in previous issues. Seems like this was raised when LLVM used bugzilla. This is an ill-formed but no diagnostic required situation #14747 (comment).

joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
…m#125638)

Fixes llvm#123459.

Previously, when the StackAddrEscapeChecker checked return values, it
did not scan into the structure of the return SVal. Now it does, and we
can catch some more false negatives that were already mocked out in the
tests in addition to those mentioned in
llvm#123459.

The warning message at the moment for these newly caught leaks is not
great. I think they would be better if they had a better trace of why
and how the region leaks. If y'all are happy with these changes, I would
try to improve these warnings and work on normalizing this SVal checking
on the `checkEndFunction` side of the checker also.

Two of the stack address leak test cases now have two warnings, one
warning from return expression checking and another from`
checkEndFunction` `iterBindings` checking. For these two cases, I prefer
the warnings from the return expression checking, but I couldn't figure
out a way to drop the `checkEndFunction` without breaking other
`checkEndFunction` warnings that we do want. Thoughts here?
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
…t fix (llvm#126620)

Reapplying changes from llvm#125638
after buildbot failures.

Buildbot failures fixed in 029e7e9,
latest commit on this PR. It was a problem with a declared class member
with same name as its type. Sorry!
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…m#125638)

Fixes llvm#123459.

Previously, when the StackAddrEscapeChecker checked return values, it
did not scan into the structure of the return SVal. Now it does, and we
can catch some more false negatives that were already mocked out in the
tests in addition to those mentioned in
llvm#123459.

The warning message at the moment for these newly caught leaks is not
great. I think they would be better if they had a better trace of why
and how the region leaks. If y'all are happy with these changes, I would
try to improve these warnings and work on normalizing this SVal checking
on the `checkEndFunction` side of the checker also.

Two of the stack address leak test cases now have two warnings, one
warning from return expression checking and another from`
checkEndFunction` `iterBindings` checking. For these two cases, I prefer
the warnings from the return expression checking, but I couldn't figure
out a way to drop the `checkEndFunction` without breaking other
`checkEndFunction` warnings that we do want. Thoughts here?
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…t fix (llvm#126620)

Reapplying changes from llvm#125638
after buildbot failures.

Buildbot failures fixed in 029e7e9,
latest commit on this PR. It was a problem with a declared class member
with same name as its type. Sorry!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negatives clang-analyzer-core.StackAddressEscape when storing pointers/references in container
5 participants