Skip to content

[lldb] Fix GCC's -Wreturn-type warnings #127974

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
merged 2 commits into from
Feb 21, 2025

Conversation

foxtran
Copy link
Member

@foxtran foxtran commented Feb 20, 2025

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 Clang (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).

@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

@llvm/pr-subscribers-lldb

Author: None (foxtran)

Changes

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 --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";
   }
 }
 

@foxtran foxtran force-pushed the fix/gcc-return-type branch from 5d5aea8 to c51a546 Compare February 20, 2025 09:25
@foxtran foxtran force-pushed the fix/gcc-return-type branch from c51a546 to d36ed84 Compare February 20, 2025 09:26
Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

The default clause prevents the "uncovered enumerator" from firing is a new value is added to the enum (and it's actually against the coding standards). The recommended solution is to place llvm_unreachable after the switch like so

Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

Thanks.

@foxtran
Copy link
Member Author

foxtran commented Feb 21, 2025

@JDevlieghere, it is still not merged. Are there any extra checks?

@JDevlieghere
Copy link
Member

@JDevlieghere, it is still not merged. Are there any extra checks?

Nope, I just wasn't sure if you had commit access. I'll go ahead and merge it for you.

@JDevlieghere JDevlieghere merged commit 506deb0 into llvm:main Feb 21, 2025
7 checks passed
@foxtran foxtran deleted the fix/gcc-return-type branch February 21, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants