[llvm] [MC] getSymbolOffsetImpl - only use report_fatal_error if ReportError is true, else just return false (PR #96493)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 07:36:56 PDT 2024


https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/96493

Fixes static analysis warnings regarding uninitialized values - this appears to have been introduced by fee224f942b707d855e97f8b0f1e31c70667d7ee

Fix by inspection, I don't have a test case

>From 2d214d4bbcdd0d9d809f8652500e11ce559fdb33 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Mon, 24 Jun 2024 15:34:43 +0100
Subject: [PATCH] [MC] getSymbolOffsetImpl - only use report_fatal_error if
 ReportError is true, else just return false

Fixes static analysis warnings regarding uninitialized return values - this appears to have been introduced by fee224f942b707d855e97f8b0f1e31c70667d7ee

Fix by inspection, I don't have a test case
---
 llvm/lib/MC/MCFragment.cpp | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp
index 9e9a03af945dc..29087a1766477 100644
--- a/llvm/lib/MC/MCFragment.cpp
+++ b/llvm/lib/MC/MCFragment.cpp
@@ -64,9 +64,12 @@ static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S,
 
   // If SD is a variable, evaluate it.
   MCValue Target;
-  if (!S.getVariableValue()->evaluateAsValue(Target, Layout))
-    report_fatal_error("unable to evaluate offset for variable '" +
-                       S.getName() + "'");
+  if (!S.getVariableValue()->evaluateAsValue(Target, Layout)) {
+    if (ReportError)
+      report_fatal_error("unable to evaluate offset for variable '" +
+                         S.getName() + "'");
+    return false;
+  }
 
   uint64_t Offset = Target.getConstant();
 
@@ -95,12 +98,12 @@ static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S,
 }
 
 bool MCAsmLayout::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const {
-  return getSymbolOffsetImpl(*this, S, false, Val);
+  return getSymbolOffsetImpl(*this, S, /*ReportError=*/false, Val);
 }
 
 uint64_t MCAsmLayout::getSymbolOffset(const MCSymbol &S) const {
   uint64_t Val;
-  getSymbolOffsetImpl(*this, S, true, Val);
+  getSymbolOffsetImpl(*this, S, /*ReportError=*/true, Val);
   return Val;
 }
 



More information about the llvm-commits mailing list