Skip to content

Commit 7ea8737

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ab4e7aeea216' from swift/release/6.0 into stable/20230725
2 parents 81ad91c + ab4e7ae commit 7ea8737

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,26 @@ void ClangPersistentVariables::RemovePersistentVariable(
5353

5454
RemoveVariable(variable);
5555

56-
const char *name = variable->GetName().AsCString();
56+
// Check if the removed variable was the last one that was created. If yes,
57+
// reuse the variable id for the next variable.
5758

58-
if (*name != '$')
59+
// Nothing to do if we have not assigned a variable id so far.
60+
if (m_next_persistent_variable_id == 0)
5961
return;
60-
name++;
61-
62-
bool is_error = false;
63-
64-
if (variable->GetCompilerType().GetTypeSystem()->SupportsLanguage(
65-
lldb::eLanguageTypeSwift)) {
66-
switch (*name) {
67-
case 'R':
68-
break;
69-
case 'E':
70-
is_error = true;
71-
break;
72-
default:
73-
return;
74-
}
75-
name++;
76-
}
7762

78-
uint32_t value = strtoul(name, nullptr, 0);
79-
if (is_error) {
80-
if (value == m_next_persistent_error_id - 1)
81-
m_next_persistent_error_id--;
82-
} else {
83-
if (value == m_next_persistent_variable_id - 1)
84-
m_next_persistent_variable_id--;
85-
}
63+
llvm::StringRef name = variable->GetName().GetStringRef();
64+
// Remove the prefix from the variable that only the indes is left.
65+
if (!name.consume_front(GetPersistentVariablePrefix(false)))
66+
return;
67+
68+
// Check if the variable contained a variable id.
69+
uint32_t variable_id;
70+
if (name.getAsInteger(10, variable_id))
71+
return;
72+
// If it's the most recent variable id that was assigned, make sure that this
73+
// variable id will be used for the next persistent variable.
74+
if (variable_id == m_next_persistent_variable_id - 1)
75+
m_next_persistent_variable_id--;
8676
}
8777

8878
std::optional<CompilerType>

lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ class ClangPersistentVariables
120120
uint32_t m_next_user_file_id = 0;
121121
// The counter used by GetNextPersistentVariableName
122122
uint32_t m_next_persistent_variable_id = 0;
123-
/// The counter used by GetNextResultName when is_error is true.
124-
uint32_t m_next_persistent_error_id;
125123

126124
typedef llvm::DenseMap<const char *, clang::TypeDecl *>
127125
ClangPersistentTypeMap;

0 commit comments

Comments
 (0)