Skip to content

Commit 8e50140

Browse files
committed
make asm diagnostic instruction optional
`DiagnosticInfoInlineAsm::getInstruction` may return a null pointer, so the instruction shouldn't be blindly unwrapped. Fixes #23458.
1 parent e7f5d48 commit 8e50140

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/librustc_codegen_llvm/llvm/diagnostic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl OptimizationDiagnostic<'ll> {
9898
pub struct InlineAsmDiagnostic<'ll> {
9999
pub cookie: c_uint,
100100
pub message: &'ll Twine,
101-
pub instruction: &'ll Value,
101+
pub instruction: Option<&'ll Value>,
102102
}
103103

104104
impl InlineAsmDiagnostic<'ll> {
@@ -117,7 +117,7 @@ impl InlineAsmDiagnostic<'ll> {
117117
InlineAsmDiagnostic {
118118
cookie,
119119
message: message.unwrap(),
120-
instruction: instruction.unwrap(),
120+
instruction,
121121
}
122122
}
123123
}

src/test/ui/issues/issue-23458.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(asm)]
12+
13+
fn main() {
14+
unsafe {
15+
asm!("int $3"); //~ ERROR too few operands for instruction
16+
//~| ERROR invalid operand in inline asm
17+
}
18+
}

src/test/ui/issues/issue-23458.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: invalid operand in inline asm: 'int $3'
2+
--> $DIR/issue-23458.rs:15:9
3+
|
4+
LL | asm!("int $3"); //~ ERROR too few operands for instruction
5+
| ^^^^^^^^^^^^^^^
6+
7+
error: <inline asm>:1:2: error: too few operands for instruction
8+
int
9+
^
10+
11+
--> $DIR/issue-23458.rs:15:9
12+
|
13+
LL | asm!("int $3"); //~ ERROR too few operands for instruction
14+
| ^^^^^^^^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+

0 commit comments

Comments
 (0)