[llvm] [LLVM][Attribute/DataLayout] Assert failed parse / Test for self assignment (NFCI) (PR #169711)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 26 10:57:20 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: JP Hafer (jph-13)

<details>
<summary>Changes</summary>

Up-streaming more static analysis findings.

In Attributes.cpp:
Local variable CallerStackProbeSize "could" be read before it is initialized. -> added assertion

In DataLayout.cpp:
DataLayout doesn't test for self assignment. -> added

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


2 Files Affected:

- (modified) llvm/lib/IR/Attributes.cpp (+6-2) 
- (modified) llvm/lib/IR/DataLayout.cpp (+3) 


``````````diff
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 4ac2ebd55dcac..ca2488a761141 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -2605,8 +2605,12 @@ adjustCallerStackProbeSize(Function &Caller, const Function &Callee) {
     Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size");
     if (CallerAttr.isValid()) {
       uint64_t CallerStackProbeSize, CalleeStackProbeSize;
-      CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize);
-      CalleeAttr.getValueAsString().getAsInteger(0, CalleeStackProbeSize);
+      bool CallerParseError =
+          CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize);
+      bool CalleeParseError =
+          CalleeAttr.getValueAsString().getAsInteger(0, CalleeStackProbeSize);
+      assert((!CallerParseError && !CalleeParseError) &&
+             "Failed to parse stack-probe-size as integer");
 
       if (CallerStackProbeSize > CalleeStackProbeSize) {
         Caller.addFnAttr(CalleeAttr);
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index 49e1f898ca594..3553e788f7793 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -210,6 +210,9 @@ DataLayout::DataLayout(StringRef LayoutString) : DataLayout() {
 }
 
 DataLayout &DataLayout::operator=(const DataLayout &Other) {
+  if (this == &Other)
+    return *this;
+
   delete static_cast<StructLayoutMap *>(LayoutMap);
   LayoutMap = nullptr;
   StringRepresentation = Other.StringRepresentation;

``````````

</details>


https://github.com/llvm/llvm-project/pull/169711


More information about the llvm-commits mailing list