[Lldb-commits] [lldb] [lldb] Fix GCC's `-Wreturn-type` warnings (PR #127974)

via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 20 01:11:53 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: None (foxtran)

<details>
<summary>Changes</summary>

This patch fixes `-Wreturn-type` warnings which happens if LLVM is built with GCC compiler (14.1 is used for detecting)

Warnings:
```
llvm-project/lldb/source/ValueObject/DILLexer.cpp: In static member function ‘static llvm::StringRef lldb_private::dil::Token::GetTokenName(Kind)’:
llvm-project/lldb/source/ValueObject/DILLexer.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
   33 | }
      | ^
```
and:
```
llvm-project/lldb/source/DataFormatters/TypeSummary.cpp: In member function ‘virtual std::string lldb_private::TypeSummaryImpl::GetSummaryKindName()’:
llvm-project/lldb/source/DataFormatters/TypeSummary.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^
```

Technically, it is a bug in GCC (see #<!-- -->115345), however, UBSan with Clang should detect these places, therefore it would be nice to provide a return statement for all possible inputs (even invalid). 

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


2 Files Affected:

- (modified) lldb/source/DataFormatters/TypeSummary.cpp (+2) 
- (modified) lldb/source/ValueObject/DILLexer.cpp (+2) 


``````````diff
diff --git a/lldb/source/DataFormatters/TypeSummary.cpp b/lldb/source/DataFormatters/TypeSummary.cpp
index 2c863b364538f..1b73efa398d43 100644
--- a/lldb/source/DataFormatters/TypeSummary.cpp
+++ b/lldb/source/DataFormatters/TypeSummary.cpp
@@ -58,6 +58,8 @@ std::string TypeSummaryImpl::GetSummaryKindName() {
     return "c++";
   case Kind::eBytecode:
     return "bytecode";
+  case default:
+    return "unknown";
   }
 }
 
diff --git a/lldb/source/ValueObject/DILLexer.cpp b/lldb/source/ValueObject/DILLexer.cpp
index c7acfec347af4..a637fc1c978c7 100644
--- a/lldb/source/ValueObject/DILLexer.cpp
+++ b/lldb/source/ValueObject/DILLexer.cpp
@@ -29,6 +29,8 @@ llvm::StringRef Token::GetTokenName(Kind kind) {
     return "l_paren";
   case Kind::r_paren:
     return "r_paren";
+  case default:
+    return "unknown";
   }
 }
 

``````````

</details>


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


More information about the lldb-commits mailing list