Skip to content

Commit 4728433

Browse files
committed
make asm diagnostic instruction optional
`DiagnosticInfoInlineAsm::getInstruction` may return a null pointer, so the instruction shouldn't be blindly unwrapped.
1 parent 0633c55 commit 4728433

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/librustc_codegen_llvm/llvm/diagnostic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl OptimizationDiagnostic<'ll> {
8888
pub struct InlineAsmDiagnostic<'ll> {
8989
pub cookie: c_uint,
9090
pub message: &'ll Twine,
91-
pub instruction: &'ll Value,
91+
pub instruction: Option<&'ll Value>,
9292
}
9393

9494
impl InlineAsmDiagnostic<'ll> {
@@ -107,7 +107,7 @@ impl InlineAsmDiagnostic<'ll> {
107107
InlineAsmDiagnostic {
108108
cookie,
109109
message: message.unwrap(),
110-
instruction: instruction.unwrap(),
110+
instruction,
111111
}
112112
}
113113
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(asm)]
2+
3+
// only-x86_64
4+
5+
fn main() {
6+
unsafe {
7+
asm!("int $3"); //~ ERROR too few operands for instruction
8+
//~| ERROR invalid operand in inline asm
9+
}
10+
}

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:7:9
3+
|
4+
LL | asm!("int $3");
5+
| ^^^^^^^^^^^^^^^
6+
7+
error: <inline asm>:1:2: error: too few operands for instruction
8+
int
9+
^
10+
11+
--> $DIR/issue-23458.rs:7:9
12+
|
13+
LL | asm!("int $3");
14+
| ^^^^^^^^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+

0 commit comments

Comments
 (0)