@@ -155,6 +155,15 @@ clang::NamedDecl *IRForTarget::DeclForGlobal(GlobalValue *global_val) {
155
155
return DeclForGlobal (global_val, m_module);
156
156
}
157
157
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
+
158
167
bool IRForTarget::CreateResultVariable (llvm::Function &llvm_function) {
159
168
lldb_private::Log *log (
160
169
lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -172,15 +181,17 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) {
172
181
for (StringMapEntry<llvm::Value *> &value_symbol : value_symbol_table) {
173
182
result_name = value_symbol.first ();
174
183
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) {
177
189
found_result = true ;
178
190
m_result_is_pointer = true ;
179
191
break ;
180
192
}
181
193
182
- if (result_name.contains (" $__lldb_expr_result" ) &&
183
- !result_name.startswith (" _ZGV" )) {
194
+ if (result_name.contains (" $__lldb_expr_result" ) && !is_guard_var) {
184
195
found_result = true ;
185
196
m_result_is_pointer = false ;
186
197
break ;
@@ -1528,14 +1539,12 @@ bool IRForTarget::ResolveExternals(Function &llvm_function) {
1528
1539
}
1529
1540
1530
1541
static bool isGuardVariableRef (Value *V) {
1531
- Constant *Old = nullptr ;
1542
+ Constant *Old = dyn_cast<Constant>(V) ;
1532
1543
1533
- if (!( Old = dyn_cast<Constant>(V)) )
1544
+ if (!Old)
1534
1545
return false ;
1535
1546
1536
- ConstantExpr *CE = nullptr ;
1537
-
1538
- if ((CE = dyn_cast<ConstantExpr>(V))) {
1547
+ if (auto CE = dyn_cast<ConstantExpr>(V)) {
1539
1548
if (CE->getOpcode () != Instruction::BitCast)
1540
1549
return false ;
1541
1550
@@ -1544,12 +1553,8 @@ static bool isGuardVariableRef(Value *V) {
1544
1553
1545
1554
GlobalVariable *GV = dyn_cast<GlobalVariable>(Old);
1546
1555
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 ()))
1551
1557
return false ;
1552
- }
1553
1558
1554
1559
return true ;
1555
1560
}
0 commit comments