Skip to content

Commit cc3a505

Browse files
[SelectionDAG] Fix assertion failure on inline asm register type mismatch (#166615)
Resolves #166057 --------- Co-authored-by: Phoebe Wang <phoebe.wang@intel.com>
1 parent b15e220 commit cc3a505

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ bool IsX86_MMXType(llvm::Type *IRType) {
2727
static llvm::Type *X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
2828
StringRef Constraint,
2929
llvm::Type *Ty) {
30+
bool IsMMXCons = llvm::StringSwitch<bool>(Constraint)
31+
.Cases({"y", "&y", "^Ym"}, true)
32+
.Default(false);
33+
if (IsMMXCons && Ty->isVectorTy() &&
34+
cast<llvm::VectorType>(Ty)->getPrimitiveSizeInBits().getFixedValue() !=
35+
64)
36+
return nullptr; // Invalid MMX constraint
37+
3038
if (Constraint == "k") {
3139
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGF.getLLVMContext());
3240
return llvm::FixedVectorType::get(Int1Ty, Ty->getScalarSizeInBits());

clang/test/CodeGen/X86/mmx-inline-asm-error.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// RUN: %clang_cc1 -verify -triple x86_64-unknown-unknown -emit-llvm-only %s
2+
// RUN: %clang_cc1 -verify=omp -triple x86_64-unknown-unknown -emit-llvm-only -fopenmp %s
23
typedef int vec256 __attribute__((ext_vector_type(8)));
34

45
vec256 foo(vec256 in) {
56
vec256 out;
67

78
asm("something %0" : : "y"(in)); // expected-error {{invalid input size for constraint 'y'}}
9+
// omp-error@+1 {{invalid type 'vec256' (vector of 8 'int' values) in asm input for constraint 'y'}}
810
asm("something %0" : "=y"(out)); // expected-error {{invalid output size for constraint '=y'}}
11+
// omp-error@+1 {{invalid type 'vec256' (vector of 8 'int' values) in asm input for constraint 'y'}}
912
asm("something %0, %0" : "+y"(out)); // expected-error {{invalid output size for constraint '+y'}}
1013

1114
return out;
1215
}
13-

0 commit comments

Comments
 (0)