@@ -153,6 +153,12 @@ clang::NamedDecl *IRForTarget::DeclForGlobal(GlobalValue *global_val) {
153153 return DeclForGlobal (global_val, m_module);
154154}
155155
156+ // / Returns true iff the mangled symbol is for a static guard variable.
157+ static bool isGuardVariableSymbol (llvm::StringRef mangled_symbol) {
158+ return mangled_symbol.startswith (" _ZGV" ) || // Itanium ABI guard variable
159+ mangled_symbol.startswith (" @4IA" ); // Microsoft ABI guard variable
160+ }
161+
156162bool IRForTarget::CreateResultVariable (llvm::Function &llvm_function) {
157163 lldb_private::Log *log (
158164 lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -171,14 +177,14 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) {
171177 result_name = value_symbol.first ();
172178
173179 if (result_name.contains (" $__lldb_expr_result_ptr" ) &&
174- !result_name. startswith ( " _ZGV " )) {
180+ !isGuardVariableSymbol (result_name )) {
175181 found_result = true ;
176182 m_result_is_pointer = true ;
177183 break ;
178184 }
179185
180186 if (result_name.contains (" $__lldb_expr_result" ) &&
181- !result_name. startswith ( " _ZGV " )) {
187+ !isGuardVariableSymbol (result_name )) {
182188 found_result = true ;
183189 m_result_is_pointer = false ;
184190 break ;
@@ -1529,14 +1535,12 @@ bool IRForTarget::ResolveExternals(Function &llvm_function) {
15291535}
15301536
15311537static bool isGuardVariableRef (Value *V) {
1532- Constant *Old = nullptr ;
1538+ Constant *Old = dyn_cast<Constant>(V) ;
15331539
1534- if (!( Old = dyn_cast<Constant>(V)) )
1540+ if (!Old)
15351541 return false ;
15361542
1537- ConstantExpr *CE = nullptr ;
1538-
1539- if ((CE = dyn_cast<ConstantExpr>(V))) {
1543+ if (auto CE = dyn_cast<ConstantExpr>(V)) {
15401544 if (CE->getOpcode () != Instruction::BitCast)
15411545 return false ;
15421546
@@ -1545,12 +1549,8 @@ static bool isGuardVariableRef(Value *V) {
15451549
15461550 GlobalVariable *GV = dyn_cast<GlobalVariable>(Old);
15471551
1548- if (!GV || !GV->hasName () ||
1549- (!GV->getName ().startswith (" _ZGV" ) && // Itanium ABI guard variable
1550- !GV->getName ().endswith (" @4IA" ))) // Microsoft ABI guard variable
1551- {
1552+ if (!GV || !GV->hasName () || !isGuardVariableSymbol (GV->getName ()))
15521553 return false ;
1553- }
15541554
15551555 return true ;
15561556}
0 commit comments