Skip to content

Commit

Permalink
[X86] Don't crash on bad operand modifiers in inline assembly
Browse files Browse the repository at this point in the history
Summary: Previously if a modifer was placed on a non-GPR register class we would hit an assert or crash.

Reviewers: echristo

Reviewed By: echristo

Subscribers: eraman, llvm-commits

Differential Revision: https://reviews.llvm.org/D45751

llvm-svn: 330238
  • Loading branch information
topperc committed Apr 18, 2018
1 parent aea1513 commit 8704612
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Target/X86/X86AsmPrinter.cpp
Expand Up @@ -372,6 +372,12 @@ static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
unsigned Reg = MO.getReg();
bool EmitPercent = true;

if (!X86::GR8RegClass.contains(Reg) &&
!X86::GR16RegClass.contains(Reg) &&
!X86::GR32RegClass.contains(Reg) &&
!X86::GR64RegClass.contains(Reg))
return true;

switch (Mode) {
default: return true; // Unknown mode.
case 'b': // Print QImode register
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/CodeGen/X86/inline-asm-bad-modifier.ll
@@ -0,0 +1,8 @@
; RUN: not llc -mtriple=x86_64-- < %s 2>&1 | FileCheck %s

;CHECK: error: invalid operand in inline asm: 'vmovd ${1:x}, $0'
define i32 @foo() {
entry:
%0 = tail call i32 asm sideeffect "vmovd ${1:x}, $0", "=r,x,~{dirflag},~{fpsr},~{flags}"(<2 x i64> <i64 240518168632, i64 240518168632>)
ret i32 %0
}

0 comments on commit 8704612

Please sign in to comment.