Skip to content

Convert unreachable return statement into llvm_unreachable #129627

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 1 commit into from
Mar 6, 2025

Conversation

shafik
Copy link
Collaborator

@shafik shafik commented Mar 4, 2025

Static analysis flags the final return statement in ReadExtensionBlock as unreachable and indeed it is since there is no way to exit the while(true) loop besides a return statement.

So I am converting it into a llvm_unreachable to explicitly document this.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

Changes

Static analysis flags the final return statement in ReadExtensionBlock as unreachable and indeed it is since there is no way to exit the while(true) loop besides a return statement.

So I am converting it into a llvm_unreachable to explicitly document this.


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

1 Files Affected:

  • (modified) clang/lib/Serialization/ASTReader.cpp (+1-1)
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index ea4b233a6c573..ca09c3d79d941 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -5329,7 +5329,7 @@ llvm::Error ASTReader::ReadExtensionBlock(ModuleFile &F) {
     }
   }
 
-  return llvm::Error::success();
+  llvm_unreachable("ReadExtensionBlock should return from while loop");
 }
 
 void ASTReader::InitializeContext() {

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM!

@shafik shafik merged commit 4b454af into llvm:main Mar 6, 2025
14 checks passed
@shafik shafik deleted the ReadExtensionBlock_unreachable_return branch March 7, 2025 01:02
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
Static analysis flags the final return statement in `ReadExtensionBlock`
as unreachable and indeed it is since there is no way to exit the
`while(true)` loop besides a *return statement*.

So I am converting it into a `llvm_unreachable` to explicitly document
this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants