@@ -24,6 +24,7 @@ use crate::value::Value;
24
24
use rustc:: mir;
25
25
use rustc:: session:: config:: { self , DebugInfo } ;
26
26
use rustc:: ty:: { self , Instance , InstanceDef , ParamEnv , Ty } ;
27
+ use rustc_codegen_ssa:: common:: TypeKind ;
27
28
use rustc_codegen_ssa:: debuginfo:: type_names;
28
29
use rustc_codegen_ssa:: mir:: debuginfo:: { DebugScope , FunctionDebugContext , VariableKind } ;
29
30
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
@@ -188,14 +189,68 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
188
189
unsafe {
189
190
let debug_loc = llvm:: LLVMGetCurrentDebugLocation ( self . llbuilder ) ;
190
191
let instr = if is_by_val {
191
- llvm:: LLVMRustDIBuilderInsertDbgValueAtEnd (
192
+ let llval = variable_alloca;
193
+
194
+ let instr = llvm:: LLVMRustDIBuilderInsertDbgValueAtEnd (
192
195
DIB ( cx) ,
193
- variable_alloca ,
196
+ llval ,
194
197
dbg_var,
195
198
addr_ops. as_ptr ( ) ,
196
199
addr_ops. len ( ) as c_uint ,
197
200
debug_loc,
198
- self . llbb ( ) )
201
+ self . llbb ( ) ,
202
+ ) ;
203
+
204
+ // HACK(eddyb) keep the value we passed to `llvm.dbg.value`
205
+ // alive if we're not optimizing, otherwise LLVM will eagerly
206
+ // destroy it (and debuggers will show `<optimized out>`),
207
+ // if there are no other uses forcing the value to be computed.
208
+ // FIXME(#68817) implement the correct behavior in LLVM.
209
+ if self . sess ( ) . opts . optimize == config:: OptLevel :: No {
210
+ let llty = cx. val_ty ( llval) ;
211
+
212
+ // Avoid creating LLVM inline asm with unsupported types,
213
+ // usually ZST structs.
214
+ let asm_supported = match self . type_kind ( llty) {
215
+ // Floats.
216
+ TypeKind :: Half |
217
+ TypeKind :: Float |
218
+ TypeKind :: Double |
219
+ TypeKind :: X86_FP80 |
220
+ TypeKind :: FP128 |
221
+ TypeKind :: PPC_FP128 |
222
+ // Integers.
223
+ TypeKind :: Integer |
224
+ TypeKind :: Pointer |
225
+ // Vectors.
226
+ TypeKind :: Vector |
227
+ TypeKind :: X86_MMX => true ,
228
+
229
+ TypeKind :: Void |
230
+ TypeKind :: Label |
231
+ TypeKind :: Function |
232
+ TypeKind :: Struct |
233
+ TypeKind :: Array |
234
+ TypeKind :: Metadata |
235
+ TypeKind :: Token => false ,
236
+ } ;
237
+
238
+ if asm_supported {
239
+ let asm = SmallCStr :: new ( "" ) ;
240
+ let constraints = SmallCStr :: new ( "X" ) ;
241
+ let asm = llvm:: LLVMRustInlineAsm (
242
+ cx. type_func ( & [ llty] , cx. type_void ( ) ) ,
243
+ asm. as_ptr ( ) ,
244
+ constraints. as_ptr ( ) ,
245
+ llvm:: False ,
246
+ llvm:: False ,
247
+ llvm:: AsmDialect :: Att ,
248
+ ) ;
249
+ self . call ( asm, & [ llval] , None ) ;
250
+ }
251
+ }
252
+
253
+ instr
199
254
} else {
200
255
// FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
201
256
llvm:: LLVMRustDIBuilderInsertDeclareAtEnd (
@@ -583,7 +638,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
583
638
file_metadata,
584
639
loc. line as c_uint ,
585
640
type_metadata,
586
- self . sess ( ) . opts . optimize != config :: OptLevel :: No ,
641
+ true ,
587
642
DIFlags :: FlagZero ,
588
643
argument_index,
589
644
align. bytes ( ) as u32 ,
0 commit comments