Skip to content

Commit 7f7b296

Browse files
committed
[lldb] Reland "Refactor guard variable checks in IRForTarget"
It seems the broken guard variable check for Windows was a feature(TM) and not a bug, so let's keep add a flag to the guard check that keeps the old behavior in the places where we ignored guard variables before. llvm-svn: 368688
1 parent 73f702f commit 7f7b296

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ clang::NamedDecl *IRForTarget::DeclForGlobal(GlobalValue *global_val) {
155155
return DeclForGlobal(global_val, m_module);
156156
}
157157

158+
/// Returns true iff the mangled symbol is for a static guard variable.
159+
static bool isGuardVariableSymbol(llvm::StringRef mangled_symbol,
160+
bool check_ms_abi = true) {
161+
bool result = mangled_symbol.startswith("_ZGV"); // Itanium ABI guard variable
162+
if (check_ms_abi)
163+
result |= mangled_symbol.startswith("@4IA"); // Microsoft ABI
164+
return result;
165+
}
166+
158167
bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) {
159168
lldb_private::Log *log(
160169
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
@@ -172,15 +181,17 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) {
172181
for (StringMapEntry<llvm::Value *> &value_symbol : value_symbol_table) {
173182
result_name = value_symbol.first();
174183

175-
if (result_name.contains("$__lldb_expr_result_ptr") &&
176-
!result_name.startswith("_ZGV")) {
184+
// Check if this is a guard variable. It seems this causes some hiccups
185+
// on Windows, so let's only check for Itanium guard variables.
186+
bool is_guard_var = isGuardVariableSymbol(result_name, /*MS ABI*/ false);
187+
188+
if (result_name.contains("$__lldb_expr_result_ptr") && !is_guard_var) {
177189
found_result = true;
178190
m_result_is_pointer = true;
179191
break;
180192
}
181193

182-
if (result_name.contains("$__lldb_expr_result") &&
183-
!result_name.startswith("_ZGV")) {
194+
if (result_name.contains("$__lldb_expr_result") && !is_guard_var) {
184195
found_result = true;
185196
m_result_is_pointer = false;
186197
break;
@@ -1528,14 +1539,12 @@ bool IRForTarget::ResolveExternals(Function &llvm_function) {
15281539
}
15291540

15301541
static bool isGuardVariableRef(Value *V) {
1531-
Constant *Old = nullptr;
1542+
Constant *Old = dyn_cast<Constant>(V);
15321543

1533-
if (!(Old = dyn_cast<Constant>(V)))
1544+
if (!Old)
15341545
return false;
15351546

1536-
ConstantExpr *CE = nullptr;
1537-
1538-
if ((CE = dyn_cast<ConstantExpr>(V))) {
1547+
if (auto CE = dyn_cast<ConstantExpr>(V)) {
15391548
if (CE->getOpcode() != Instruction::BitCast)
15401549
return false;
15411550

@@ -1544,12 +1553,8 @@ static bool isGuardVariableRef(Value *V) {
15441553

15451554
GlobalVariable *GV = dyn_cast<GlobalVariable>(Old);
15461555

1547-
if (!GV || !GV->hasName() ||
1548-
(!GV->getName().startswith("_ZGV") && // Itanium ABI guard variable
1549-
!GV->getName().endswith("@4IA"))) // Microsoft ABI guard variable
1550-
{
1556+
if (!GV || !GV->hasName() || !isGuardVariableSymbol(GV->getName()))
15511557
return false;
1552-
}
15531558

15541559
return true;
15551560
}

0 commit comments

Comments
 (0)