When LLVM's location discriminator value limit is exceeded, emit loca… · rust-lang/rust@45ef927 (original) (raw)

`@@ -9,7 +9,7 @@ use rustc_middle::mir::{Body, SourceScope};

`

9

9

`use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};

`

10

10

`use rustc_middle::ty::{self, Instance};

`

11

11

`use rustc_session::config::DebugInfo;

`

12

``

`-

use rustc_span::{BytePos, hygiene};

`

``

12

`+

use rustc_span::{BytePos, DUMMY_SP, hygiene};

`

13

13

``

14

14

`use super::metadata::file_metadata;

`

15

15

`use super::utils::DIB;

`

`@@ -85,23 +85,15 @@ fn make_mir_scope<'ll, 'tcx>(

`

85

85

` discriminators,

`

86

86

` parent,

`

87

87

`);

`

88

``

`-

if let Some(parent_scope) = debug_context.scopes[parent] {

`

89

``

`-

parent_scope

`

90

``

`-

} else {

`

91

``

`-

// If the parent scope could not be represented then no children

`

92

``

`-

// can be either.

`

93

``

`-

debug_context.scopes[scope] = None;

`

94

``

`-

instantiated.insert(scope);

`

95

``

`-

return;

`

96

``

`-

}

`

``

88

`+

debug_context.scopes[parent]

`

97

89

`} else {

`

98

90

`// The root is the function itself.

`

99

91

`let file = cx.sess().source_map().lookup_source_file(mir.span.lo());

`

100

``

`-

debug_context.scopes[scope] = Some(DebugScope {

`

``

92

`+

debug_context.scopes[scope] = DebugScope {

`

101

93

`file_start_pos: file.start_pos,

`

102

94

`file_end_pos: file.end_position(),

`

103

``

`-

..debug_context.scopes[scope].unwrap()

`

104

``

`-

});

`

``

95

`+

..debug_context.scopes[scope]

`

``

96

`+

};

`

105

97

` instantiated.insert(scope);

`

106

98

`return;

`

107

99

`};

`

`@@ -112,7 +104,7 @@ fn make_mir_scope<'ll, 'tcx>(

`

112

104

`{

`

113

105

`// Do not create a DIScope if there are no variables defined in this

`

114

106

`` // MIR SourceScope, and it's not inlined, to avoid debuginfo bloat.

``

115

``

`-

debug_context.scopes[scope] = Some(parent_scope);

`

``

107

`+

debug_context.scopes[scope] = parent_scope;

`

116

108

` instantiated.insert(scope);

`

117

109

`return;

`

118

110

`}

`

`@@ -145,14 +137,7 @@ fn make_mir_scope<'ll, 'tcx>(

`

145

137

`},

`

146

138

`};

`

147

139

``

148

``

`-

let mut debug_scope = Some(DebugScope {

`

149

``

`-

dbg_scope,

`

150

``

`-

inlined_at: parent_scope.inlined_at,

`

151

``

`-

file_start_pos: loc.file.start_pos,

`

152

``

`-

file_end_pos: loc.file.end_position(),

`

153

``

`-

});

`

154

``

-

155

``

`-

if let Some((_, callsite_span)) = scope_data.inlined {

`

``

140

`+

let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {

`

156

141

`let callsite_span = hygiene::walk_chain_collapsed(callsite_span, mir.span);

`

157

142

`let callsite_scope = parent_scope.adjust_dbg_scope_for_span(cx, callsite_span);

`

158

143

`let loc = cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callsite_span);

`

`@@ -175,29 +160,29 @@ fn make_mir_scope<'ll, 'tcx>(

`

175

160

`// Note further that we can't key this hashtable on the span itself,

`

176

161

`// because these spans could have distinct SyntaxContexts. We have

`

177

162

`// to key on exactly what we're giving to LLVM.

`

178

``

`-

let inlined_at = match discriminators.entry(callsite_span.lo()) {

`

``

163

`+

match discriminators.entry(callsite_span.lo()) {

`

179

164

`Entry::Occupied(mut o) => {

`

180

165

`*o.get_mut() += 1;

`

``

166

`+

// NB: We have to emit something here or we'll fail LLVM IR verification

`

``

167

`+

// in at least some circumstances (see issue #135322) so if the required

`

``

168

`+

// discriminant cannot be encoded fall back to the dummy location.

`

181

169

`unsafe { llvm::LLVMRustDILocationCloneWithBaseDiscriminator(loc, *o.get()) }

`

``

170

`+

.unwrap_or_else(|| {

`

``

171

`+

cx.dbg_loc(callsite_scope, parent_scope.inlined_at, DUMMY_SP)

`

``

172

`+

})

`

182

173

`}

`

183

174

`Entry::Vacant(v) => {

`

184

175

` v.insert(0);

`

185

``

`-

Some(loc)

`

186

``

`-

}

`

187

``

`-

};

`

188

``

`-

match inlined_at {

`

189

``

`-

Some(inlined_at) => {

`

190

``

`-

debug_scope.as_mut().unwrap().inlined_at = Some(inlined_at);

`

191

``

`-

}

`

192

``

`-

None => {

`

193

``

`-

// LLVM has a maximum discriminator that it can encode (currently

`

194

``

`-

// it uses 12 bits for 4096 possible values). If we exceed that

`

195

``

`-

// there is little we can do but drop the debug info.

`

196

``

`-

debug_scope = None;

`

``

176

`+

loc

`

197

177

`}

`

198

178

`}

`

199

``

`-

}

`

``

179

`+

});

`

200

180

``

201

``

`-

debug_context.scopes[scope] = debug_scope;

`

``

181

`+

debug_context.scopes[scope] = DebugScope {

`

``

182

`+

dbg_scope,

`

``

183

`+

inlined_at: inlined_at.or(parent_scope.inlined_at),

`

``

184

`+

file_start_pos: loc.file.start_pos,

`

``

185

`+

file_end_pos: loc.file.end_position(),

`

``

186

`+

};

`

202

187

` instantiated.insert(scope);

`

203

188

`}

`