Skip to content

Commit 449af81

Browse files
authored
[Clang] Fix crash for incompatible types in inline assembly (#119098)
Fixed issue #118892.
1 parent 24c2744 commit 449af81

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

clang/lib/Sema/SemaStmtAsm.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,16 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
664664
SmallerValueMentioned |= OutSize < InSize;
665665
}
666666

667+
// If the input is an integer register while the output is floating point,
668+
// or vice-versa, there is no way they can work together.
669+
bool FPTiedToInt = (InputDomain == AD_FP) ^ (OutputDomain == AD_FP);
670+
667671
// If the smaller value wasn't mentioned in the asm string, and if the
668672
// output was a register, just extend the shorter one to the size of the
669673
// larger one.
670-
if (!SmallerValueMentioned && InputDomain != AD_Other &&
674+
if (!SmallerValueMentioned && !FPTiedToInt && InputDomain != AD_Other &&
671675
OutputConstraintInfos[TiedTo].allowsRegister()) {
676+
672677
// FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen
673678
// crash when the size larger than the register size. So we limit it here.
674679
if (OutTy->isStructureType() &&

clang/test/Sema/asm.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,24 @@ void test19(long long x)
365365
// FIXME: This case should be supported by codegen, but it fails now.
366366
asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: input with type 'st_size128' (aka 'struct _st_size128') matching output with type 'long long'}}
367367
}
368+
369+
typedef int int2 __attribute__((ext_vector_type(2)));
370+
371+
// GH118892
372+
void test20(char x) {
373+
double d;
374+
float f;
375+
376+
asm ("fabs" : "=t" (d): "0" (x)); // expected-error {{unsupported inline asm: input with type 'char' matching output with type 'double'}}
377+
asm ("fabs" : "=t" (x): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'char'}}
378+
asm ("fabs" : "=t" (f): "0" (d)); // no-error
379+
asm ("fabs" : "=t" (d): "0" (f)); // no-error
380+
381+
st_size64 a;
382+
asm ("fabs" : "=t" (d): "0" (a)); // expected-error {{unsupported inline asm: input with type 'st_size64' (aka 'struct _st_size64') matching output with type 'double'}}
383+
asm ("fabs" : "=t" (a): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'st_size64' (aka 'struct _st_size64')}}
384+
385+
int2 v;
386+
asm ("fabs" : "=t" (d): "0" (v)); // expected-error {{unsupported inline asm: input with type 'int2' (vector of 2 'int' values) matching output with type 'double'}}
387+
asm ("fabs" : "=t" (v): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'int2' (vector of 2 'int' values)}}
388+
}

0 commit comments

Comments
 (0)