-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang] Use StringRef::consume_front (NFC) #139472
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
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_StringRef_idiom_clang_consume_front
May 11, 2025
Merged
[clang] Use StringRef::consume_front (NFC) #139472
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_StringRef_idiom_clang_consume_front
May 11, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/139472.diff 4 Files Affected:
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index ba0d87fdc5d43..40627d6ffd3c9 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -40,8 +40,7 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef name)
// Skip asm prefix, if any. 'name' is usually taken directly from
// the mangled name of the enclosing function.
- if (!name.empty() && name[0] == '\01')
- name = name.substr(1);
+ name.consume_front("\01");
}
// Anchor the vtable to this translation unit.
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3513175b8b8ad..2a11eebf1b682 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4500,8 +4500,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
Flags |= llvm::DINode::FlagPrototyped;
}
- if (Name.starts_with("\01"))
- Name = Name.substr(1);
+ Name.consume_front("\01");
assert((!D || !isa<VarDecl>(D) ||
GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
@@ -4590,8 +4589,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
} else {
llvm_unreachable("not a function or ObjC method");
}
- if (!Name.empty() && Name[0] == '\01')
- Name = Name.substr(1);
+ Name.consume_front("\01");
if (D->isImplicit()) {
Flags |= llvm::DINode::FlagArtificial;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 49c2bef20925a..0d03923951a16 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3388,8 +3388,7 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
auto SL = E->getFunctionName();
assert(SL != nullptr && "No StringLiteral name in PredefinedExpr");
StringRef FnName = CurFn->getName();
- if (FnName.starts_with("\01"))
- FnName = FnName.substr(1);
+ FnName.consume_front("\01");
StringRef NameItems[] = {
PredefinedExpr::getIdentKindName(E->getIdentKind()), FnName};
std::string GVName = llvm::join(NameItems, NameItems + 2, ".");
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 3469676b74bc8..428a4b8335524 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4061,11 +4061,7 @@ namespace {
return false;
std::string BuiltinNameStr = BI.getName(BuiltinID);
StringRef BuiltinName = BuiltinNameStr;
- if (BuiltinName.starts_with("__builtin_") &&
- Name == BuiltinName.slice(strlen("__builtin_"), StringRef::npos)) {
- return true;
- }
- return false;
+ return BuiltinName.consume_front("__builtin_") && Name == BuiltinName;
}
bool VisitStmt(const Stmt *S) {
|
@llvm/pr-subscribers-clang-codegen Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/139472.diff 4 Files Affected:
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index ba0d87fdc5d43..40627d6ffd3c9 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -40,8 +40,7 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef name)
// Skip asm prefix, if any. 'name' is usually taken directly from
// the mangled name of the enclosing function.
- if (!name.empty() && name[0] == '\01')
- name = name.substr(1);
+ name.consume_front("\01");
}
// Anchor the vtable to this translation unit.
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3513175b8b8ad..2a11eebf1b682 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4500,8 +4500,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
Flags |= llvm::DINode::FlagPrototyped;
}
- if (Name.starts_with("\01"))
- Name = Name.substr(1);
+ Name.consume_front("\01");
assert((!D || !isa<VarDecl>(D) ||
GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
@@ -4590,8 +4589,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
} else {
llvm_unreachable("not a function or ObjC method");
}
- if (!Name.empty() && Name[0] == '\01')
- Name = Name.substr(1);
+ Name.consume_front("\01");
if (D->isImplicit()) {
Flags |= llvm::DINode::FlagArtificial;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 49c2bef20925a..0d03923951a16 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3388,8 +3388,7 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
auto SL = E->getFunctionName();
assert(SL != nullptr && "No StringLiteral name in PredefinedExpr");
StringRef FnName = CurFn->getName();
- if (FnName.starts_with("\01"))
- FnName = FnName.substr(1);
+ FnName.consume_front("\01");
StringRef NameItems[] = {
PredefinedExpr::getIdentKindName(E->getIdentKind()), FnName};
std::string GVName = llvm::join(NameItems, NameItems + 2, ".");
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 3469676b74bc8..428a4b8335524 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4061,11 +4061,7 @@ namespace {
return false;
std::string BuiltinNameStr = BI.getName(BuiltinID);
StringRef BuiltinName = BuiltinNameStr;
- if (BuiltinName.starts_with("__builtin_") &&
- Name == BuiltinName.slice(strlen("__builtin_"), StringRef::npos)) {
- return true;
- }
- return false;
+ return BuiltinName.consume_front("__builtin_") && Name == BuiltinName;
}
bool VisitStmt(const Stmt *S) {
|
arsenm
approved these changes
May 11, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:codegen
IR generation bugs: mangling, exceptions, etc.
clang
Clang issues not falling into any other category
debuginfo
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.